[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [system-traders] get statistics on historical trades



Hi,

> How can I use geniustrader to give me the various statistics on this
> just as if it were a backtest?

Use the script attached to this mail. The exact format of the csv-
file is described in my Trading Journal 
(http://www.olfsworld.de/software/trading/otj/). 

To analyze the resulting file you have to patch 
GT::Analyzers::Process with the attached patch and load the portfolio 
with "load ./portfolio.xml". Please be aware that the code of the 
patch is very chaotic ...  

CU, Olf
-- 
Visit my world: http://www.olfsworld.de


#!/usr/bin/perl -w

# Copyright 2004 Raphaël Hertzog, Oliver Bossert
# This file is distributed under the terms of the General Public License
# version 2 or (at your option) any later version.

use lib '..';

use strict;
use vars qw($db);

use Carp::Datum (":all", defined($ENV{'GTDEBUG'}) ? "on" : "off");
use GT::Prices;
use GT::Calculator;
use GT::Report;
use GT::Conf;
use GT::Eval;
use GT::DateTime;
use Getopt::Long;
use Time::localtime;

use GT::Indicators::MaxDrawDown;
use GT::Portfolio;
use GT::Portfolio::Position;
use GT::Tools qw(:conf);
use GT::BackTest::SpoolNew;
use GT::Portfolio::Order;


GT::Conf::load();

=head1 NAME

portfolio_from_csv.pl

=head1 SYNOPSIS

  ./portfolio_from_csv.pl <infile> <outfile>

=cut


# Load the portfolio
my $infile = shift;
my $outfile = shift;
my $pf = GT::Portfolio->new();
my $db = create_db_object();

# Get all options
my ($init) = (10000);
GetOptions("init=s" => \$init);

# Set initial value
$pf->set_initial_value($init);

open IN, "$infile" or die "Could not open File: $infile!";

while (<IN>) {
  chomp;
  next if (/^\#/);
  next if (/^\s*$/);
  my ($id, $code, $nb, $type, $opendate, $openvalue, $closedate, $closevalue,
      $fee, $text) = split /\t/, $_;

  my $nb = 1;
  my $order = GT::Portfolio::Order->new;
  if (lc($type) eq "long") {
    $order->set_buy_order;
  } else {
    $order->set_sell_order;
  }
  $order->set_type_limited;
  $order->set_price($openvalue);
  $order->set_submission_date($opendate);
  $order->set_quantity($nb);
#  $order->set_source($id) if ($id);
  my $pos = $pf->new_position($code, $id, $opendate);
  $pos->set_timeframe(GT::DateTime::name_to_timeframe("day"));
  $pf->apply_order_on_position($pos, $order, $openvalue, $opendate);

  # Closing the Position
  if (lc($type) ne "long") {
    $order->set_buy_order;
  } else {
    $order->set_sell_order;
  }
  $order->set_type_limited;
  $order->set_price($closevalue);
  $order->set_submission_date($closedate);
  $order->set_quantity($nb);
#  $order->set_source($id) if ($id);
  $pf->apply_order_on_position($pos, $order, $closevalue, $closedate);

  # Evaluation
  my $q = $db->get_prices($code);
  my $calc = GT::Calculator->new($q);
  $calc->set_code($code);
  my $date_o = $calc->prices->find_nearest_date($opendate);
  my $date = $calc->prices->find_nearest_date($closedate);
  my $i = $calc->prices->date($date);

  my $first = $calc->prices->date($opendate);
  for (my $j=$first-1; $j<=$i; $j++) {
    $pos->set_quantity(0) if ($j==$i);
#    $pf->apply_pending_orders_on_position( $pos, $calc, $i );
    $pf->store_evaluation($calc->prices->at($j)->[$DATE]);
  }


}

close IN;

$pf->store($outfile);

$db->disconnect;
Der folgende Teil dieser Nachricht enthält einen Anhang im
sogenannten Internet MIME Nachrichtenformat.
Wenn Sie Pegasus Mail oder ein beliebiges anderes MIME-kompatibles
Email-System verwenden, sollte Sie den Anhang mit Ihrem Email-System
speichern oder anzeigen können. Anderenfalls fragen Sie Ihren Administrator.

The following section of this message contains a file attachment
prepared for transmission using the Internet MIME message format.
If you are using Pegasus Mail, or any another MIME-compliant system,
you should be able to save it or view it from within your mailer.
If you cannot, please ask your system administrator for assistance.

   ---- Datei Information/File information -----------
     Datei/File:  process.patch
     Datum/Date:  19 Aug 2004, 21:09
     Größe/Size:  17093 bytes.
     Typ/Type:    Unbekannt

Attachment: process.patch
Description: Binary data