-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
65 lines (53 loc) · 1.68 KB
/
main.py
File metadata and controls
65 lines (53 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import pandas as pd
import yaml
from pathlib import Path
from src.modules.genetic_algorithm import GeneticAlgorithm
def load_config(path: Path = Path("config/config.yml")) -> dict:
with path.open("r") as file:
return yaml.safe_load(file)
def prepare_data(filepath: str, freq: str) -> pd.DataFrame:
"Load and preprocess data"
data = pd.read_parquet(filepath)
processed_data = (
data.rename(
columns={
"date": "Date",
"open": "Open",
"high": "High",
"low": "Low",
"close": "Close",
}
)
.loc[:, ["Date", "Open", "High", "Low", "Close"]]
.assign(Date=lambda x: pd.to_datetime(x["Date"]))
.set_index("Date")
.resample(freq)
.agg(
{
"Open": "first",
"High": "max",
"Low": "min",
"Close": "last",
}
)
.reset_index()
)
return processed_data
def main():
config = load_config()
btc_2018_hourly = prepare_data(r"data\BTC\BTC_2018_min.parquet", "h")
hyperparams = config["hyperparameters"]
ga_settings = config["genetic_algorithm_settings"]
ga_instance = GeneticAlgorithm(
df=btc_2018_hourly,
pop_size=ga_settings["pop_size"],
num_gens=ga_settings["num_gens"],
num_conds=hyperparams["num_conds"],
max_lag=hyperparams["max_lag"],
fitness_type=ga_settings["fitness_type"],
bullish_focus=ga_settings["focus_on_bullish_patterns"],
)
pygad_instance = ga_instance.create_instance()
pygad_instance.run()
if __name__ == "__main__":
main()