Skip to content

Commit 24e6024

Browse files
new version
1 parent 7bd44a6 commit 24e6024

5 files changed

Lines changed: 47 additions & 12 deletions

File tree

alpha_vantage_.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212
class AlphaVantage():
1313
"""
14-
Class to get the data from alphavantage
15-
"""
14+
Class to get the data from alphavantage"""
1615

1716
@classmethod
1817
def intraday_fx(cls):
@@ -31,5 +30,4 @@ def intraday_fx(cls):
3130
return data_
3231

3332
av_ = AlphaVantage()
34-
data_ = av_.intraday_fx()
35-
t = 5
33+
data_ = av_.intraday_fx()

charting.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
""" Module with chart functions
2+
"""
3+
14
import matplotlib.pyplot as plt
25
import pandas as pd
36
import numpy as np
@@ -70,6 +73,7 @@ def chart_marker(cls, marker_signal, marker_, color_mark, **marker):
7073
**marker : keyword arguments
7174
contains the place we want mark, the color of the mark and the type of mark
7275
"""
76+
7377
cls.series.set_index(cls.x_axis,inplace = True)
7478
fig = plt.figure()
7579

main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
""" This is the main module which execute the program """
2+
13
import indicators.regression.linear_regression as lr
24
import indicators.regression.mann_kendall as mk
35
import charting as cht
@@ -14,7 +16,7 @@ def __init__(self):
1416
self.default_data, series_test=self.series, **self.indicator)
1517
t = 5
1618
def chart_signal(self):
17-
"""Marks signal on chart"""
19+
"""Marks signal on chart (no entry, only when the indicators trigger a signal)"""
1820
self.cht_.chart_rsquare(list(self.indicator.keys())[1],r_square_level=self.r_square_level)
1921

2022
def chart_trigger(self):

manip_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Module that act as a helper to manipulate csv and pandas Dataframe"""
1+
"""Helper module to manipulate csv and pandas Dataframe"""
22
import csv
33
import pandas as pd
44
import datetime as dt

optimize/genetic_algorithm.py

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)