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

[GT] SVN Commit r630 - trunk/Scripts



Author: thomas
Date: 2008-06-10 07:26:33 +0200 (Tue, 10 Jun 2008)
New Revision: 630

Modified:
   trunk/Scripts/analyze_backtest.pl
   trunk/Scripts/backtest.pl
   trunk/Scripts/backtest_many.pl
   trunk/Scripts/backtest_multi.pl
   trunk/Scripts/display_indicator.pl
   trunk/Scripts/display_signal.pl
   trunk/Scripts/graphic.pl
   trunk/Scripts/manage_portfolio.pl
   trunk/Scripts/scan.pl
Log:
As discussed in http://www.geniustrader.org/lists/devel/msg02588.html,
moved the responsibility for opening and closing DB back to the scripts.
Every script that needs to load market data, will have to go through
the following steps:
1. use vars qw($db);
2. my $db = create_db_object();
3. use the $db object, which typically will be
my ($calc, $first, $last) = 
    find_calculator($db, $code, $timeframe, $full, $start, $end, $nb_item, $max_loaded_items);
4. $db->disconnect;
Care must be taken that there will be only one $db->disconnect encountered
during execution. If multiple databases are created, existing connections
are reused.


Modified: trunk/Scripts/analyze_backtest.pl
===================================================================
--- trunk/Scripts/analyze_backtest.pl	2008-06-10 05:10:25 UTC (rev 629)
+++ trunk/Scripts/analyze_backtest.pl	2008-06-10 05:26:33 UTC (rev 630)
@@ -109,6 +109,7 @@
    $template='/' . $template unless ($template =~ /\\|\//);
    $interp->exec($template, s => $s, l => $l, codes => \%codes, db => $db);
    print $output;
+   $db->disconnect;
 } else { 
    GT::Report::AnalysisList($spool, $set);
 }

Modified: trunk/Scripts/backtest.pl
===================================================================
--- trunk/Scripts/backtest.pl	2008-06-10 05:10:25 UTC (rev 629)
+++ trunk/Scripts/backtest.pl	2008-06-10 05:26:33 UTC (rev 630)
@@ -7,6 +7,7 @@
 use lib '..';
 
 use strict;
+use vars qw($db);
 
 use GT::Prices;
 use GT::Portfolio;
@@ -336,8 +337,10 @@
 # Verify dates and adjust to timeframe, comment out if not desired
 check_dates($timeframe, $start, $end);
 
-my ($calc, $first, $last) = find_calculator($code, $timeframe, $full, $start, $end, $nb_item, $max_loaded_items);
+my $db = create_db_object();
 
+my ($calc, $first, $last) = find_calculator($db, $code, $timeframe, $full, $start, $end, $nb_item, $max_loaded_items);
+
 # The real work happens here
 my $analysis = backtest_single($pf_manager, $sys_manager, $broker, $calc, $first, $last);
 
@@ -442,6 +445,8 @@
     print "\n";
 }
 
+$db->disconnect;
+
 if ( $set ) {
   # Store intermediate result
   my $bkt_spool = GT::BackTest::Spool->new($outputdir);

Modified: trunk/Scripts/backtest_many.pl
===================================================================
--- trunk/Scripts/backtest_many.pl	2008-06-10 05:10:25 UTC (rev 629)
+++ trunk/Scripts/backtest_many.pl	2008-06-10 05:26:33 UTC (rev 630)
@@ -7,6 +7,7 @@
 use lib '..';
 
 use strict;
+use vars qw($db);
 
 use GT::Prices;
 use GT::Portfolio;
@@ -249,8 +250,11 @@
 	next;
     }
     my $code = $list->get($d);
-    my ($calc, $first, $last) = find_calculator($code, $timeframe, $full, $start, $end, $nb_item, $max_loaded_items);
 
+    my $db = create_db_object();
+
+    my ($calc, $first, $last) = find_calculator($db, $code, $timeframe, $full, $start, $end, $nb_item, $max_loaded_items);
+
     # Fork a process to avoid memory consumption
     foreach (@desc_systems)
     {
@@ -283,6 +287,8 @@
 	$bkt_spool->sync();
     }
 
+    $db->disconnect;
+
     # Close the child 
     exit 0;
 }

Modified: trunk/Scripts/backtest_multi.pl
===================================================================
--- trunk/Scripts/backtest_multi.pl	2008-06-10 05:10:25 UTC (rev 629)
+++ trunk/Scripts/backtest_multi.pl	2008-06-10 05:26:33 UTC (rev 630)
@@ -7,6 +7,7 @@
 use lib '..';
 
 use strict;
+use vars qw($db);
 
 use GT::Prices;
 use GT::Portfolio;
@@ -241,8 +242,10 @@
   push @codes, $list->get($d);
 }
 
+my $db = create_db_object();
+
 # Now the hard part...
-my $analysis = backtest_multi($pf_manager, \
AT
sys_manager, \
AT
brokers, \
AT
codes, $timeframe, $full, $start, $end, $nb_item, $max_loaded_items, $init);
+my $analysis = backtest_multi($db, $pf_manager, \
AT
sys_manager, \
AT
brokers, \
AT
codes, $timeframe, $full, $start, $end, $nb_item, $max_loaded_items, $init);
 
 # Print the analysis
 GT::Report::Portfolio($analysis->{'portfolio'}, 1);
@@ -251,6 +254,7 @@
 #print "\n## Theoretical analysis (10keuros, full portfolio reinvested)\n";
 #GT::Report::PortfolioAnalysis($analysis->{'theoretical'}, $verbose);
 
+$db->disconnect;
 
 if ($set) {
     my $bkt_spool = GT::BackTest::Spool->new($outputdir);

Modified: trunk/Scripts/display_indicator.pl
===================================================================
--- trunk/Scripts/display_indicator.pl	2008-06-10 05:10:25 UTC (rev 629)
+++ trunk/Scripts/display_indicator.pl	2008-06-10 05:26:33 UTC (rev 630)
@@ -158,9 +158,11 @@
 my $indicator = create_standard_object("$indicator_module",
 					@ARGV);
 
+my $db = create_db_object();
+
 # Il faut cr� tout le framework
 my $indicator_name = $indicator->get_name;
-my ($calc, $first, $last) = find_calculator($code, $timeframe, $full, $start, $end, $nb_item, $max_loaded_items);
+my ($calc, $first, $last) = find_calculator($db, $code, $timeframe, $full, $start, $end, $nb_item, $max_loaded_items);
 
 
 # Au boulot
@@ -215,3 +217,5 @@
   }
 }
 
+$db->disconnect;
+

Modified: trunk/Scripts/display_signal.pl
===================================================================
--- trunk/Scripts/display_signal.pl	2008-06-10 05:10:25 UTC (rev 629)
+++ trunk/Scripts/display_signal.pl	2008-06-10 05:26:33 UTC (rev 630)
@@ -10,6 +10,7 @@
 use lib '..';
 
 use strict;
+use vars qw($db);
 
 use GT::Prices;
 use GT::Calculator;
@@ -191,8 +192,11 @@
 
 my $signal = create_standard_object($signal_module, @ARGV);
 my $signal_name = $signal->get_name;
-my ($calc, $first, $last) = find_calculator($code, $timeframe, $full, $start, $end, $nb_item, $max_loaded_items);
 
+my $db = create_db_object();
+
+my ($calc, $first, $last) = find_calculator($db, $code, $timeframe, $full, $start, $end, $nb_item, $max_loaded_items);
+
 # Launching the signal
 print "Testing signal $signal_name ...\n";
 $signal->detect_interval($calc, $first, $last);
@@ -227,3 +231,5 @@
     }
 }
 
+$db->disconnect;
+

Modified: trunk/Scripts/graphic.pl
===================================================================
--- trunk/Scripts/graphic.pl	2008-06-10 05:10:25 UTC (rev 629)
+++ trunk/Scripts/graphic.pl	2008-06-10 05:26:33 UTC (rev 630)
@@ -7,6 +7,7 @@
 use lib '..';
 
 use strict;
+use vars qw($db);
 
 use GT::Prices;
 use GT::Calculator;
@@ -292,7 +293,7 @@
              --add="Curve(Indicators::SMA  38, [0,0,255])" \
              --add="Curve(Indicators::SMA 100, [0,255,0])" \
              --add="Curve(Indicators::SMA 200, [255,0,0])" \
-             --title=Daily history of %c
+             --title="Daily history of %c" \
              13000 > test.png
 
 ./graphic.pl --add="Curve(Indicators::EMA 5,[255,0,0])" \
@@ -354,7 +355,10 @@
 
 pod2usage( -verbose => 2) if ($man);
 my $code = shift || pod2usage(1);
-my ($calc, $first, $last) = find_calculator($code, $timeframe, $full, $start, $end, $nb_item, $max_loaded_items);
+
+my $db = create_db_object();
+
+my ($calc, $first, $last) = find_calculator($db, $code, $timeframe, $full, $start, $end, $nb_item, $max_loaded_items);
 $nb_item = $last - $first + 1;
 
 GT::Conf::default("Graphics::Driver", "GD");
@@ -772,6 +776,9 @@
 $graphic->display($driver, $picture);
 $driver->dump($picture);
 
+$db->disconnect;
+
+
 # This functions get in input a string like "Object(arg1,arg2,Arg3)"
 # where each arg may itself be an Object with its own argument. It
 # returns the object name followed by all the arguments.

Modified: trunk/Scripts/manage_portfolio.pl
===================================================================
--- trunk/Scripts/manage_portfolio.pl	2008-06-10 05:10:25 UTC (rev 629)
+++ trunk/Scripts/manage_portfolio.pl	2008-06-10 05:26:33 UTC (rev 630)
@@ -259,6 +259,7 @@
 	   "backup!" => \$backup,
 	   "verbose+" => \$verbose,
 	   "option=s" => \
AT
options, "help!" => \$man);
+$timeframe = GT::DateTime::name_to_timeframe($timeframe);
 
 foreach (@options) {
     my ($key, $value) = split (/=/, $_);
@@ -430,7 +431,7 @@
             }
 
             $pos = $pf->new_position($code, $source, $date);
-            $pos->set_timeframe(GT::DateTime::name_to_timeframe($timeframe));
+            $pos->set_timeframe($timeframe);
             # here is the only place one can make a distinction between
             # long and short orders/positions
             # but the only distinction(s) being considered is(are) $marged

Modified: trunk/Scripts/scan.pl
===================================================================
--- trunk/Scripts/scan.pl	2008-06-10 05:10:25 UTC (rev 629)
+++ trunk/Scripts/scan.pl	2008-06-10 05:26:33 UTC (rev 630)
@@ -337,8 +337,10 @@
     }
     my $code = $list->get($d);
 
-    my ($calc, $first, $last) = find_calculator($code, $timeframe, $full, $start, $end, $nb_item, $max_loaded_items);
+    my $db = create_db_object();
 
+    my ($calc, $first, $last) = find_calculator($db, $code, $timeframe, $full, $start, $end, $nb_item, $max_loaded_items);
+
     my $i;
     if ($calc->prices->has_date($date)) {
 	$i = $calc->prices->date($date);
@@ -376,6 +378,8 @@
 
     }
 
+    $db->disconnect;
+
     # Close the child 
     exit 0;
 }
@@ -388,9 +392,9 @@
 }
 $msg->remove;
 
-
 # Display results
 my $db = create_db_object();
+
 foreach my $name (@list_systems) {
     my $object = $systems->{$name}{'object'};
     if (ref($object) =~ /GT::Systems/) {
@@ -435,6 +439,7 @@
 	print "</ul>" if ($html);
     }
 }
+
 $db->disconnect;