[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GT] SVN Commit r604 - trunk/Scripts
Author: thomas
Date: 2008-04-14 14:21:45 +0200 (Mon, 14 Apr 2008)
New Revision: 604
Modified:
trunk/Scripts/backtest.pl
trunk/Scripts/backtest_multi.pl
Log:
Provide consistent parameters to analyze results of backtests: --set and --output-directory
Modified: trunk/Scripts/backtest.pl
===================================================================
--- trunk/Scripts/backtest.pl 2008-04-14 02:51:41 UTC (rev 603)
+++ trunk/Scripts/backtest.pl 2008-04-14 12:21:45 UTC (rev 604)
@@ -162,6 +162,14 @@
use GT::CloseStrategy::<close_strategy_name> as a close strategy.
+=item --set=SETNAME
+
+Stores the backtest results in the "backtests" directory (refer to your options file for the location of this directory) using the set name SETNAME. Use the --set option of analyze_backtest.pl to differentiate between the different backtest results in your directory.
+
+=item --output-directory=DIRNAME
+
+Override the "backtests" directory in the options file.
+
=item --verbose
=back
@@ -193,15 +201,17 @@
# Manage options
my ($full, $nb_item, $start, $end, $timeframe, $max_loaded_items) =
(0, 0, '', '', 'day', -1);
-my ($verbose, $html, $display_trades, $template, $graph_file, $ofname, $broker, $system, $store_file) =
- (0, 0, 0, '', '', '', '', '', '');
+my ($verbose, $html, $display_trades, $template, $graph_file, $ofname, $broker, $system, $store_file, $outputdir, $set) =
+ (0, 0, 0, '', '', '', '', '', '', '', '');
my (@mmname, @tfname, @csname);
+$outputdir = GT::Conf::get("BackTest::Directory") || '';
GetOptions('full!' => \$full, 'nb-item=i' => \$nb_item,
"start=s" => \$start, "end=s" => \$end,
"max-loaded-items" => \$max_loaded_items,
"timeframe=s" => \$timeframe,
'verbose!' => \$verbose, 'html!' => \$html,
'template=s' => \$template, 'display-trades!' => \$display_trades,
+ 'output-directory=s' => \$outputdir, 'set=s' => \$set,
'money-management=s' => \
AT
mmname, 'graph=s' => \$graph_file,
'trade-filter=s' => \
AT
tfname, 'order-factory=s' => \$ofname,
'close-strategy=s' => \
AT
csname, 'broker=s' => \$broker,
@@ -215,6 +225,11 @@
die "You must give at least one --close-strategy argument !\n";
}
+if (! -d $outputdir)
+{
+ die "The directory '$outputdir' doesn't exist !\n";
+}
+
# Create the entire framework
my $pf_manager = GT::PortfolioManager->new;
my $sys_manager = GT::SystemManager->new;
@@ -385,3 +400,20 @@
GT::Report::PortfolioAnalysis($analysis->{'real'}, $verbose);
print "\n";
}
+
+if ( $set ) {
+ # Store intermediate result
+ my $bkt_spool = GT::BackTest::Spool->new($outputdir);
+ my $stats = [ $analysis->{'real'}{'std_performance'},
+ $analysis->{'real'}{'performance'},
+ $analysis->{'real'}{'max_draw_down'},
+ $analysis->{'real'}{'std_buyandhold'},
+ $analysis->{'real'}{'buyandhold'}
+ ];
+
+ $bkt_spool->update_index();
+ $bkt_spool->add_alias_name($sys_manager->get_name, $sys_manager->alias_name);
+ $bkt_spool->add_results($sys_manager->get_name, $code, $stats,
+ $analysis->{'portfolio'}, $set);
+ $bkt_spool->sync();
+}
Modified: trunk/Scripts/backtest_multi.pl
===================================================================
--- trunk/Scripts/backtest_multi.pl 2008-04-14 02:51:41 UTC (rev 603)
+++ trunk/Scripts/backtest_multi.pl 2008-04-14 12:21:45 UTC (rev 604)
@@ -34,16 +34,23 @@
# Gestion des options
my ($full, $nb_item, $start, $end, $timeframe, $max_loaded_items) =
(0, 0, '', '', 'day', -1);
-my ($outputdir, $alias) =
+my ($outputdir, $set) =
('', '');
+$outputdir = GT::Conf::get("BackTest::Directory") || '';
GetOptions('full!' => \$full, 'nb-item=i' => \$nb_item,
"start=s" => \$start, "end=s" => \$end,
"max-loaded-items" => \$max_loaded_items,
"timeframe=s" => \$timeframe,
- 'output-directory=s' => \$outputdir, 'alias=s' => \$alias );
+ 'output-directory=s' => \$outputdir, 'set=s' => \$set );
$timeframe = GT::DateTime::name_to_timeframe($timeframe);
my $init = 10000;
+# Checks
+if (! -d $outputdir)
+{
+ die "The directory '$outputdir' doesn't exist !\n";
+}
+
# read the system-description
my $filename = shift;
my $xs = new XML::Simple( ForceArray => 1,
@@ -140,7 +147,7 @@
#GT::Report::PortfolioAnalysis($analysis->{'theoretical'}, $verbose);
-if ($outputdir ne '') {
+if ($set) {
my $bkt_spool = GT::BackTest::SpoolNew->new($outputdir);
my $stats = [ $analysis->{'real'}{'std_performance'},
$analysis->{'real'}{'performance'},
@@ -149,15 +156,14 @@
$analysis->{'real'}{'buyandhold'}
];
- $alias = "MULTI" if ( $alias eq '' );
-
delete $analysis->{'portfolio'}->{objects};
- print STDERR $alias . " --> " . $filename . "\n";
- $bkt_spool->add_alias_name($alias."-".$filename, $alias);
+ print STDERR $set . " --> " . $filename . "\n";
- $bkt_spool->add_results($alias."-".$filename, "GDAXI", $stats,
- $analysis->{'portfolio'}, $alias);
+ $bkt_spool->update_index();
+ $bkt_spool->add_alias_name($set."-".$filename, $set);
+ $bkt_spool->add_results($set."-".$filename, "MULTI", $stats,
+ $analysis->{'portfolio'}, $set);
$bkt_spool->sync();
}