Finance-Quant

 view release on metacpan or  search on metacpan

scripts/FINANCE_QUANT_CACHE  view on Meta::CPAN

  my($filename,$symbol,$orders) = @_;
  my(@lines)=();

  return unless(defined $filename);
  return unless(-e $filename);

  my @results = ();
  
  if(-e $filename) {
    open(IN, $filename) or warn "Error: couldn't open file $filename : $!\n";

#    @files = sort grep(!/^\./, readdir(DIR));
    my $symbol = "";
    @lines=<IN>;
    foreach(@lines){

      if(trim($_) =~ m/(Txn|PL|Net|$date|\[1\]\ \"20*)/){


        if($_ =~ m/(.*) (.*) (.*) \@ (.*)/){
          my $ods = sprintf("%s %s %s %s",$1,$2,$3,$4);
          $symbol = $2;
          $ods =~ s/(\[1\]\ \"|\"$)//g;
          if($ods =~ /$symbol -/){

              push @{$orders->{SELL}},[split " ",$ods];

          }else{
              push @{$orders->{BUY}},[split " ",$ods];
          }


        }else{
          push @results,$_;
        }
      }

    }
    close(IN);
  }

  my @net = split " ",pop @results;

  my @last =  map {$_=[split(" ",$_)] } @results;#grep(/$date/, @results);
  
  
  #push @net,$symbol;

  $orders->{LAST}=[@last];   
  $orders->{NET}=[@net];   
  #@results,
  return  $orders;
}


sub tildeexp {
  my $path = shift;
  $path =~ s{^~([^/]*)} {  
          $1 
                ? (getpwnam($1))[7] 
                : ( $ENV{HOME} || $ENV{LOGDIR} || (getpwuid($>))[7])
          }ex;
  return $path;
}


END{

    my @fields =("changedDate","symbol","shares","avgFillPrice");

    my $meta = {"tablename"=>"orders"};


  my @keys = keys %{$orders->{ranking}};
     pop @keys;
  @keys = reverse sort { $a <=> $b  }  @keys;

  foreach (@keys) { 
    next if $_ =~ /Symbol=/;
    
    my $sym = $orders->{ranking}->{$_};
    
      printf("\n%s %s",$sym,$_);
    
    my @last = ();
    


#    if(defined($cache->{$sym}->{core}->{quote})){
    
        my $sell =$cache->{$sym}->{core}->{quote}->{result}->{SELL};
        my $buy =$cache->{$sym}->{core}->{quote}->{result}->{BUY};
        
        my @orders=();
        
        
        push @orders, split "\n",$foo->print_table_data($meta,$buy,@fields);
        push @orders, split "\n",$foo->print_table_data($meta,$sell,@fields);
        foreach(@orders){
        
            $foo->{dbh}->do($_) unless(!$opts->{order});
            sleep 0.01;
        }


        
        #print Dumper @last unless(!$#last);
        
 #   }
    
    
  }


print "\n\n".form
"--------------------------------------------------------------------[INITIAL ACCOUNT 10000USD]-----------------------------------------------------------------",
"---------------------------------------------------------------------------------------------------------------------------------------------------------------",
"SYMBOL    BACKTEST-NET        PL_PCT              DATA-FILE                                PDF                               ORDER",
"---------------------------------------------------------------------------------------------------------------------------------------------------------------",
"[[[[[[[   [[[[[[[[       |||||||||||||   ||".("|"x30)." ||".("|"x30)." ||".("|"x45)." ||||||".("["x35);



( run in 2.974 seconds using v1.01-cache-2.11-cpan-fe3c2283af0 )