1- """Module to run the program - use optimization tool if asked"""
1+ """Module to run the program - use optimization tools if desired"""
2+
23from pnl import PnL
34from manip_data import ManipData as md
45from date_manip import DateManip as dm
56from optimize .genetic_algorithm import GenAlgo as ga
6- from indicator import Indicator
77
88class Optimize (PnL ):
99
1010 def __init__ (self ):
11+ """Function that initializes stuff.
12+
13+ It resets the `self.series` with `self.init_series()` and dictionary that track the pnl
14+ `self.trades_track` with `reset_value()` when we optimize.
15+ """
1116 super ().__init__ ()
1217 self .init_series ()
1318 self .reset_value ()
1419 self .params = {}
1520
1621 def __call__ (self ):
22+ """Function do different things dependent if we optimize or not"""
1723
18- # If we optimize
1924 if self .is_walkfoward :
2025 self .walk_foward ()
2126 else :
22- Indicator .calcul_indicator (self )
27+ self .calcul_indicator ()
2328 self .pnl_ ()
24- self .first_write = md .write_csv_ (self .dir_output , self .name_out , self .first_write , add_doc = "" ,
25- is_walkfoward = self .is_walkfoward , ** self .pnl_dict )
29+ md .write_csv_ (self .dir_output , self .name_out , add_doc = "" , is_walkfoward = self .is_walkfoward , ** self .pnl_dict )
2630
27- def execute_ (self , add_doc = "" ):
28- """ Just runs the whole program without optimization
31+ def walk_foward (self ):
32+ """Function that do the walk-foward analysis ( optimization).
2933
30- Load data (and clean), calculate indicators, check for signal, calculate pnl + write results to file
31- """
34+ First it runs through the divided period (1 period interval for training and testing). We have to choose
35+ properly `self.start_date` and `self.end_date` as they set the numbers of period.
3236
37+ Then the program runs through each training and testing period (in `self.dict_name_`). The program optimizes
38+ only in the training period `self.training_name_`. The results are store in the folder results and
39+ results_training for the training period and results_test for the testing period.
40+
41+ Parameters
42+ ----------
43+ `self.start_date` : datetime object
44+ Set in `initialize.py`. Beginning date of training and testing.
45+ `self.end_date` : datetime object
46+ Set in `initialize.py`. End date of training and testing.
47+
48+ """
3349
34- def walk_foward (self ):
3550 md_ = md
3651
3752 _first_time = True
@@ -48,7 +63,7 @@ def walk_foward(self):
4863 if _first_time :
4964 md_ (self .dir_output ,self .name_out ,extension = key_ ).erase_content ()
5065 self .init_series ()
51- Indicator .calcul_indicator (self )
66+ self .calcul_indicator ()
5267 if key_ == self .training_name_ : #we only optimize for the training period
5368 self .optimize_param ()
5469 self .pnl_dict ,self .params = ga (self ).__call__ ()
@@ -64,11 +79,13 @@ def walk_foward(self):
6479 _first_time = False
6580
6681 def assign_value (self ):
67- """ Function to assign the value to each optimized parameters obtained in the optimization function"""
82+ """ Function to assign the value to each optimized parameters obtained in the optimization module.
83+
84+ The `genetic_algorithm.py` return the dictionary with the value and when we test in `r_square_tr.py` they are
85+ in a different format"""
6886
6987 for item in range (len (self .op_param )):
7088 if len (self .op_param [item ]) > 1 :
7189 self .op_param [item ][0 ][self .op_param [item ][1 ]] = self .params [self .op_param [item ][1 ]]
7290 else :
73- setattr (self , self .op_param [item ][0 ], self .params [self .op_param [item ][0 ]])
74- t = 5
91+ setattr (self , self .op_param [item ][0 ], self .params [self .op_param [item ][0 ]])
0 commit comments