#!/afs/tr/proj/tools/bin/perl # Typical usage is 'egrep "CFsn|SSTO|RSen" ticker | perl if-price.pl | xgraph' @monconv = (-99999, 0, 31, 31+28, 31+28+31, 31+28+31+30, 31+28+31+30+31, 31+28+31+30+31+30, 31+28+31+30+31+30+31, 31+28+31+30+31+30+31*2, 31+28+31+30+31+30+31*2+30, 31+28+31+30+31+30+31*2+30+31, 31+28+31+30+31+30+31*2+30+31+30, -99999); sub ConvertDate { local ($date) = @_; local ($time); local ($year, $mon, $day, $hour, $min, $sec) = m=(\d\d)/(\d\d)/(\d\d) (\d\d):(\d\d):(\d\d)=; $time = (($year-1)*365 + $monconv[$mon] + $day-1) + ($hour + ($min + $sec/60)/60)/24; $time -= 93*365+$monconv[10]; # 1-Oct-94 is base date } sub Remove { local ($offset) = @_; splice (@times, $offset, 1); splice (@quant, $offset, 1); splice (@price, $offset, 1); splice (@capital, $offset, 1); splice (@people, $offset, 1); } #open (IN, "$ENV{HOME}/info/ideaf/ticker") # || die ("Couldn't find ticker file"); $allIssues = 0; # don't exclude issues in .exclude file foreach (@ARGV) { next unless (/^-/); if (/^-all/i) { $allIssues = 1; } else { push (@args, $_); } shift; } %exclude = (); # 1 if excluded if (!$allIssues && open (EXCLUDE, "$ENV{HOME}/info/ideaf/if-price.exclude")) { local (@issues); push (@issues, split) while (); close EXCLUDE; foreach (@issues) { $exclude{$_} = 1; } } while (<>) { ($symbol, $quant, $price, $date, $summary, $capital, $people) = m=([\w\$]+)\s+(\d+)\s+(\d+)\s+(9[4-9]/\d+/\d+ \d+:\d+:\d+)(\s+(\d+)\s+(\d+))?$=; $summary, $people; # unused next if (!$symbol); next if ($exclude{$symbol}); $time = &ConvertDate ($date); $times{$symbol} .= ",$time"; $quant{$symbol} .= ",$quant"; $price{$symbol} .= ",$price"; $capital{$symbol} .= ",$capital"; $people{$symbol} .= ",$people"; } @symbols = keys(%times); $showPeople = # show number of owners of issue $showCapitalization = # show issue capitalization $showVolume = # show trading volme (@symbols == 1); # show all if only one issue foreach (@args) { $debug++ if (/^-d/i); $showVolume = 1 if (/^-vol/i); $showCapitalization = 1 if (/^-cap/i); $showPeople = 1 if (/^-peop/i); $showVolume = $showCapitalization = $showPeople = 0 if (/^-price/i); # price only } foreach $symbol (@symbols) { @times = split(',',$times{$symbol}); @quant = split(',',$quant{$symbol}); @price = split(',',$price{$symbol}); @capital = split(',',$capital{$symbol}); @people = split(',',$people{$symbol}); &Remove(0); # first element is null $avgQ = $quant[$#times]; $mcap = $capital[0]; $mpeop = $people[0]; $mprice = $price[0]; @avgQ = ($avgQ); for ($i=$#times; $i>0; $i--) { $mcap = $capital[$i] if ($capital[$i]>$mcap); $mpeop = $people[$i] if ($people[$i]>$mpeop); $mprice = $price[$i] if ($price[$i]>$mprice); $int = $times[$i-1]-$times[$i]; ($int >= 0) || die ("times not in decending order"); if ($int < 1e-5) { $sum = $quant[$i-1]+$quant[$i]; $price[$i-1] = ($price[$i]*$quant[$i]+$price[$i-1]*$quant[$i-1])/$sum; $quant[$i-1] = $sum; &Remove($i); next; } $scale = exp(-$int); $avgQ = $avgQ*$scale+$quant[$i-1]/$int*(1-$scale); unshift(@avgQ,$avgQ); $mavgQ = $avgQ if ($avgQ > $mavgQ); } $mprice = int(($mprice+9)/10)*10; # round up $mavgQ = int(($mavgQ+4)/5)*5; $mcap = int(($mcap+99)/100)*100; printf("\n\"$symbol%s\"\n", (($showVolume || $showCapitalization || $showPeople) ? " price" : "")); for ($i=0; $i<$#times; $i++) { printf "%.5g %.4g\n", $times[$i], $price[$i]; } if ($showVolume) { print "\n\"$symbol |Q|=$mavgQ\"\n"; for ($i=0; $i<$#times; $i++) { printf "%.5g %.4g\n", $times[$i], $avgQ[$i]/$mavgQ*$mprice; } print "\n\"$symbol Q=$mavgQ\"\n"; for ($i=0; $i<$#times; $i++) { printf "%.5g %.4g\n", $times[$i], $quant[$i]/$mavgQ*$mprice; } } if ($showCapitalization) { print "\n\"$symbol C=$mcap\"\n"; for ($i=0; $i<$#times; $i++) { printf "%.5g %.4g\n", $times[$i], $capital[$i]/$mcap*$mprice; } } if ($showPeople) { print "\n\"$symbol P=$mpeop\"\n"; for ($i=0; $i<$#times; $i++) { printf "%.5g %.4g\n", $times[$i], $people[$i]/$mpeop*$mprice; } } if ($debug) { printf STDERR " time Pr Quan AvgQua\n"; for ($i=$#times; $i>=0; $i--) { printf STDERR "%7.2f %2d %3d |%5.2f|\n", $times[$i], $price[$i], $quant[$i], $avgQ[$i]; } } # $y = ($vol ? $quant : ($cap ? $capital : $price)); # print "\"$symbol\"\n$prices{$symbol}\n"; }