-
Notifications
You must be signed in to change notification settings - Fork 8
/
run_DRL.py
51 lines (41 loc) · 1.52 KB
/
run_DRL.py
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
# common library
import pandas as pd
import numpy as np
import time
from stable_baselines.common.vec_env import DummyVecEnv
# preprocessor
from preprocessing.preprocessors import *
# config
from config.config import *
# model
from model.models import *
import os
def run_model() -> None:
"""Train the model."""
# read and preprocess data
preprocessed_path = "/content/30-D1-20182022.csv"
if os.path.exists(preprocessed_path):
data = pd.read_csv(preprocessed_path, index_col=0)
else:
data = preprocess_data()
data = add_turbulence(data)
data.to_csv(preprocessed_path)
print(data.head())
print(data.size)
# 2015/10/01 is the date that validation starts
# 2016/01/01 is the date that real trading starts
# unique_trade_date needs to start from 2015/10/01 for validation purpose
unique_trade_date = data[(data.datadate > 20200701)&(data.datadate <= 20220701)].datadate.unique()
print(unique_trade_date)
# rebalance_window is the number of months to retrain the model
# validation_window is the number of months to validation the model and select for trading
rebalance_window = 50
validation_window = 50
## Ensemble Strategy
run_ensemble_strategy(df=data,
unique_trade_date= unique_trade_date,
rebalance_window = rebalance_window,
validation_window=validation_window)
#_logger.info(f"saving model version: {_version}")
if __name__ == "__main__":
run_model()