Example #1
0
import MAIN.Reinforcement as RL
import tensorflow as tf
import seaborn as sns
import matplotlib.pyplot as plt
from UTIL import FileIO
from STRATEGY.Cointegration import EGCointegration


# Read config
config_path  = 'CONFIG\config_train.yml'
config_train = FileIO.read_yaml(config_path)

# Read prices
x = pd.read_csv('STATICS\PRICE\JNJ.csv')
y = pd.read_csv('STATICS\PRICE\PG.csv')
x, y = EGCointegration.clean_data(x, y, 'date', 'close')

# Separate training and testing sets
train_pct = 0.7
train_len = round(len(x) * 0.7)
idx_train = list(range(0, train_len))
idx_test  = list(range(train_len, len(x)))
EG_Train = EGCointegration(x.iloc[idx_train, :], y.iloc[idx_train, :], 'date', 'close')
EG_Test  = EGCointegration(x.iloc[idx_test,  :], y.iloc[idx_test,  :], 'date', 'close')

# Create action space
n_hist    = list(np.arange(60, 601, 60))
n_forward = list(np.arange(120, 1201, 120))
trade_th  = list(np.arange(1,  5.1, 1))
stop_loss = list(np.arange(1,  2.1, 0.5))
cl        = list(np.arange(0.05,  0.11, 0.05))
Example #2
0
            if len(ts_c1) > len(ts_c2):
                ts_c1 = ts_c1.tail(len(ts_c2))
            elif len(ts_c1) < len(ts_c2):
                ts_c2 = ts_c2.tail(len(ts_c1))

            ts_c1.to_csv(path_or_buf='STATICS/FX/2019RT/candles_1.csv',
                         index=True,
                         index_label='date')
            ts_c2.to_csv(path_or_buf='STATICS/FX/2019RT/candles_2.csv',
                         index=True,
                         index_label='date')

            # Read prices
            x = pd.read_csv('STATICS/FX/2019RT/candles_1.csv')
            y = pd.read_csv('STATICS/FX/2019RT/candles_2.csv')
            x, y = EGCointegration.clean_data(x, y, 'date', 'close')
            EG_Train = []
            EG_Test = EGCointegration(x, y, 'date', 'close')

            if trained is False:
                # Create action space
                n_hist = list(np.arange(60, 601, 60))
                n_forward = list(np.arange(120, 1201, 120))
                trade_th = list(np.arange(
                    1, 5.1, 1))  # 1, 5.1, 1 # 5steps -- 1,  10.1, 2
                stop_loss = list(np.arange(
                    1, 2.1, 0.5))  # 1, 2.1, 0.5 # 3steps -- 2,  11.1, 3
                cl = list(np.arange(
                    0.05, 0.11,
                    0.05))  # 0.05, 0.11, 0.05 # 2steps -- 0.3,  0.71, 0.2
                actions = {