def mySettings():
    settings = get_settings()

    # Set futures to trade
    futures_list = get_futures_list(filter_insignificant_lag=2)
    settings["markets"] = ["CASH", *futures_list]

    # Load LSTM models
    settings["lstm_models"] = {
        ticker: load_lstm_model(ticker)
        for ticker in futures_list
    }

    # Load XGBoost models
    settings["xgb_models"] = {
        ticker: load_xgb_model(ticker)
        for ticker in futures_list
    }

    # Load ARIMA parameters
    settings["arima_params"] = {
        ticker: load_arima_parameters(ticker)
        for ticker in futures_list
    }

    return settings
Beispiel #2
0
def mySettings():
    settings = get_settings()
    futures_list = get_futures_list(filter_insignificant_lag=2)
    settings["markets"] = ["CASH", *futures_list]
    settings["models"] = {
        ticker: load_lstm_model(ticker)
        for ticker in futures_list
    }
    return settings
Beispiel #3
0
def mySettings():
    settings = get_settings()
    futures_list = get_futures_list(filter_insignificant_lag=2)
    settings["markets"] = ["CASH", *futures_list]

    # Set parameters for GA
    settings['population_size'] = 100
    settings['tournament_size'] = 5
    settings['crossover_rate'] = 0.3
    settings['mutation_rate'] = 0.02
    settings['n_iter'] = 100

    return settings
def build_arima():
    futures_list = get_futures_list(filter_insignificant_lag_1_acf=True)
    for ticker in futures_list:
        print(f"{futures_list.index(ticker) + 1}/{len(futures_list)}: {ticker}")
        data = load_processed_data(ticker)
        data = data.loc[:"2020-12-31"]
        data = data.iloc[:-1]   
        data = data[['CLOSE']]
        arima_model = pmdarima.auto_arima(data)
        arima_model = arima_model.fit(data)
        p, d, q = arima_model.order
        arima_residuals = arima_model.arima_res_.resid
        
        params = {"p": p, "q": q, "d":d, "residuals": list(arima_residuals)}
        
        # Save model
        dire = f"./models/arima/param2/"
        os.makedirs(os.path.dirname(dire), exist_ok=True)
        with open(f'{dire}/{ticker}_params.txt', 'w') as f:
            json.dump(params, f, ensure_ascii=False)
            print(f"Saved parameters for {ticker}")
from models.xgboost.training_util import train_model
from systems.systems_util import get_futures_list
from utils.data_loader import load_processed_data

# Cross validation
ts_crossval = TimeSeriesSplit(n_splits=5)

# Define search space for bayesian optimisation
XGB_param_hyperopt = {
    "booster": hp.choice("booster", ["gblinear"]),
    "max_depth": scope.int(hp.quniform("max_depth", 1, 5, 1)),
    "subsample": hp.uniform("subsample", 0.4, 0.6),
    "colsample_bytree": hp.uniform("colsample_bytree", 0.5, 0.6),
    "colsample_bynode": hp.uniform("colsample_bynode", 0.4, 0.6),
    "colsample_bylevel": hp.uniform("colsample_bylevel", 0.4, 0.6),
    "gamma": hp.uniform("gamma", 0, 10),
    "min_child_weight": hp.uniform("min_child_weight", 1.5, 2.3),
    "n_estimators": 100,
    "reg_lambda": hp.uniform("reg_lambda", 1, 8),
    "reg_alpha": hp.uniform("reg_alpha", 0, 0.02),
}

futures = get_futures_list(filter_insignificant_lag=1)

# Pre-train models and save the weights
for ticker in futures:
    data = load_processed_data(ticker)
    data = data.loc[:"2020-12-31"]
    data = data.iloc[:-1]
    train_model(data, XGB_param_hyperopt, ts_crossval, ticker)
Beispiel #6
0
def execute():
    for ticker in get_futures_list(filter_insignificant_lag=1):
        if not is_model_trained_and_saved(ticker=ticker):
            train_and_save_model(ticker=ticker)
        else:
            print(f"Model for {ticker} is already trained and saved!")
Beispiel #7
0
def mySettings():
    settings = get_settings()
    settings["markets"] = [
        "CASH", *get_futures_list(filter_insignificant_lag_1_acf=True)
    ]
    return settings
Beispiel #8
0
from models.lgbm.training_util import split, train_model
from systems.systems_util import get_futures_list
from utils.data_loader import load_processed_data

FUTURES_LIST = get_futures_list(filter_insignificant_lag=2)

params = {
    'num_threads': 4,
    'num_class': 3,
    'objective': 'multiclassova',
    'seed': 123,
    'tree_learner': 'feature',
    'is_unbalance': True
}

# tune these
params['learning_rate'] = 0.03
params['boosting_type'] = 'gbdt'
params['metric'] = 'multi_logloss'
params['num_leaves'] = 15
params['extra_trees'] = True
params['sub_feature'] = 0.7
params['min_data'] = 20
params['max_depth'] = 20
params['num_iterations'] = 500
params['max_bin'] = 500

params['num_boost_round'] = 175
params['early_stopping_rounds'] = 30

Beispiel #9
0
def mySettings():
    settings = get_settings()
    futures_list = get_futures_list(filter_insignificant_lag=2)
    settings["markets"] = ["CASH", *futures_list]
    return settings
from utils.data_loader import load_processed_data
from systems.systems_util import get_futures_list
from models.lgbm.training_util import split, train_model

FUTURES_LIST = get_futures_list(filter_insignificant_lag_1_acf=True)

params = {'num_threads': 4,
          'num_class': 3,
          'objective': 'multiclassova',
          'seed': 123,
          'tree_learner': 'feature',
          'is_unbalance': True,

          }

# tune these
params['learning_rate'] = 0.03
params['boosting_type'] = 'gbdt'
params['metric'] = 'multi_logloss'
params['num_leaves'] = 15
params['extra_trees'] = True
params['sub_feature'] = 0.7
params['min_data'] = 20
params['max_depth'] = 20
params['num_iterations'] = 500
params['max_bin'] = 500

params['num_boost_round'] = 175
params['early_stopping_rounds'] = 30

def train(ticker):
Beispiel #11
0
from models.xgboost.training_util import train_model
from systems.systems_util import get_futures_list
from utils.data_loader import load_processed_data

# Cross validation
ts_crossval = TimeSeriesSplit(n_splits=5)

# Define search space for bayesian optimisation
XGB_param_hyperopt = {
    "booster": hp.choice("booster", ["gblinear"]),
    "max_depth": scope.int(hp.quniform("max_depth", 1, 5, 1)),
    "subsample": hp.uniform("subsample", 0.4, 0.6),
    "colsample_bytree": hp.uniform("colsample_bytree", 0.5, 0.6),
    "colsample_bynode": hp.uniform("colsample_bynode", 0.4, 0.6),
    "colsample_bylevel": hp.uniform("colsample_bylevel", 0.4, 0.6),
    "gamma": hp.uniform("gamma", 0, 10),
    "min_child_weight": hp.uniform("min_child_weight", 1.5, 2.3),
    "n_estimators": 100,
    "reg_lambda": hp.uniform("reg_lambda", 1, 8),
    "reg_alpha": hp.uniform("reg_alpha", 0, 0.02),
}

futures = get_futures_list(filter_insignificant_lag_1_acf=True)

# Pre-train models and save the weights
for ticker in futures:
    data = load_processed_data(ticker)
    data = data.loc[:"2020-12-31"]
    data = data.iloc[:-1]
    train_model(data, XGB_param_hyperopt, ts_crossval, ticker)