5 my $path='E:\BGI\gaosj\dat\\';
8 print "perl $0 <begin date(\"10/22/2009\")> [days for UD (2)]\n";
18 my $BorderRatioU=1/4; # 1/4
19 my $BorderRatioD=1/5; # 1/5
21 $dayUD=2 unless $dayUD;
22 $dayUD=2 unless $dayUD == 1;
23 $date='10/22/2009' unless $date=~/^\d+\/\d
+\
/\d{4}$/;
24 print "Caltulating from [$date] to $Days days later with [$dayUD]...\n";
25 my (%Names,%Max,%Min,%Files,%Values,%P);
27 opendir INDIR
,$path or warn "[!]Error opening [$path]: $!\n";
28 for my $file (readdir INDIR
) {
29 if ($file =~ /([^.]+)\.txt$/i) { $Files{$1}=$file;}
34 my ($inref,$max,$min)=@_;
35 my ($cur,$p,$ud)=@
$inref;
36 my ($av,$ap,$aud,$bv,$bp,$bud);
37 if ($cur*(1+$UpRate) > $max) {
41 } elsif ($cur*(1-$UpRate) < $min) {
52 $av=$cur*(1+$aud*$UpRate);
53 $bv=$cur*(1+$bud*$UpRate) if $bp != 0;
54 if ($bp == 0) { return [[$av,$ap,$aud]]; }
55 else {return [[$av,$ap,$aud],[$bv,$bp,$bud]];}
56 #my @t=([$av,$ap,$aud],[$bv,$bp,$bud]);
57 #return [[$av,$ap,$aud],[$bv,$bp,$bud]];
61 MAIN
: for my $id (keys %Files) {
62 open IN
,'<',$path.$Files{$id} or die "[!]Error opening [$path$Files{$id}]: $!\n";
64 $line =~ /(\d+) (.+) \S+$/;
67 #print "$id\t$1\t",$Names{$ID},"\n";
69 my ($max0,$min0,$end0,$endpre,$endpt)=(-999999,999999,-1,-1,-1);
71 # 日期 开盘 最高 最低 收盘 成交量 成交额
72 my ($dateitem,$begin,$max,$min,$end)=split /\t/;
73 $max0=$max if $max0<$max;
74 $min0=$min if $min0>$min;
75 if ($date eq $dateitem) {
77 $endpre=($dayUD==2)?
$endpt:$begin;
84 #print "$Max{$id},$Min{$id}\t$end0\n";
85 if ($end0==-1 or $endpre==-1 or $end0==$endpre) {
86 # if ($end0==-1 or $end0==$endpre or ! defined $endpre) {
87 #warn "[!]$date not found in $id !\n";
92 #print "$Max{$id},$Min{$id}\t$end0\t";
93 #my $Result=&Cal($max0,$min0,$end0);
94 my $UDbegin=($end0>=$endpre)?
1:-1;
95 my @Days=([[$end0,1,$UDbegin]]); # ($cur,$p,$ud)
96 #my @Days=([[$end0,$UpRatio,$UDbegin],[$end0,1-$UpRatio,-$UDbegin]]);
97 my $max=($max0-$end0)*$BorderRatioU+$end0;
98 my $min=($min0-$end0)*$BorderRatioU+$end0;
99 for (my $i=1;$i<=$Days;$i++) { # 0..4
101 push @
{$Days[$i]},@
{&Cal
($_,$max,$min)} for @
{$Days[$i-1]};
104 for my $day (@Days) {
106 my ($ups,$upp,$downs,$downp)=(0,0,0,0);
108 my ($cur,$p,$ud)=@
$_;
109 #if ($cur >= $end0) {
122 #print "$resv\t$resp\n";# if $resv > 1;
125 warn "[!]$skip skipped !\n" if $skip;
127 my @KEYs=sort {$P{$b} <=> $P{$a}} keys %P;
131 print "$key\t$Names{$key}:\t$P{$key}\n";
136 print "$key\t$Names{$key}:\t$P{$key}\n";
143 for (sort {$b <=> $a} keys %t) {
144 print "$_\t$t{$_}\n";