@@ -10,8 +10,29 @@ class GenAlgo(PnL):
1010 """
1111
1212 def __init__ (self ,self_ , min_results = 10 , size_population = 20 , generations = 25 , co_rate = .6 ,
13- mutation_rate = .10 , fitness_level = 3 ):
14- """ Setting the parameters here"""
13+ mutation_rate = .10 ):
14+ """ Setting the parameters here
15+
16+ Parameters
17+ ----------
18+ `self_` : class instance
19+ This is the instance of the class where GenAlgo() class is called. We copy it in the constructor here
20+ `self.min_results` : int
21+ Minimum numbers of results needed to consider a chromosome in the training period. If we have under this
22+ number, the chromosome is not considerd
23+ `self.population` : int
24+ Size of a population (number of chromosomes_
25+ `self.generations` : int
26+ Number of generations
27+ `self.co_rate` : float
28+ Cross-over rate
29+ `self.mutation_rate` : float
30+ Mutation rate
31+ `self.fitness_function` : str
32+ Name of the fitness function. Ex: `self.sharpe_ratio_` name is defined in `initialize.py` and function
33+ is defined in `pnl.py`
34+
35+ """
1536
1637 super ().__init__ ()
1738 new_obj = copy .deepcopy (self_ )
@@ -22,17 +43,27 @@ def __init__(self,self_, min_results = 10, size_population = 20, generations = 2
2243 self .generations = generations
2344 self .co_rate = co_rate
2445 self .mutation_rate = mutation_rate
25- self .fitness_level = fitness_level
2646 self .fitness_function = self .sharpe_ratio_ #string name of the fitness function
27- self .nb_genes = len (self .op_param )
47+ self .nb_genes = len (self .op_param ) #nb of genes per chromosome
2848 self .results_pop = [] #pnl for the population
2949 self .population = []
3050
3151 def __call__ (self ):
3252 """Function that runs the genetic algo. This is the "main" function
3353
34- First, it creates
54+ First it creates the initial population in `self.create_chromosome()`. Then it optimize, run through each
55+ population and new generations in `self.run_generations()`. Finally the results are return with function
56+ `self.return_results()`
57+
58+ Return
59+ ------
60+ `self.pnl_dict` : dict
61+ pnl of the best chromosome
62+
63+ `self.op_param` : list
64+ parameters of the best chromosome
3565 """
66+
3667 self .create_chromosome ()
3768 self .run_generations ()
3869 return self .return_results ()
@@ -216,7 +247,7 @@ def cross_over(self,father,mother):
216247 self .assign_value (father ) #assign father value to new chromosome to be tested
217248
218249 def return_results (self ):
219- """Return the results of the best chromosome
250+ """Return the results of the best chromosome (1 chromosome)
220251
221252 Return
222253 ------
0 commit comments