def submit_backtest(strategy_name, initial_funds=1000, initial_balance=0, fill_prob=0.5, fee=0.0025, data_fnm='data/coinbaseUSD.npz', history_fnm=None, data_name='data', datapart='val', train_prop=0.8, val_prop=0.1, verbose=1, print_freq=10000, name=None, longname=None): if backtests.count({'name': name}) > 0: raise Exception('Backtest with that common name already added') max_id_test = backtests.find_one({}, sort=[('id', pymongo.DESCENDING)]) if max_id_test is None: max_id = -1 else: max_id = max_id_test['id'] curr_id = max_id + 1 if name is None: name = '{}_backtest_{}'.format(strategy_name, curr_id) if longname is None: longname = name if history_fnm is None: history_fnm = '{}_history.npz'.format(name) strategy_fnm = strategies.find_one({'name': strategy_name})['fnm'] strategy_id = strategies.find_one({'name': strategy_name})['id'] strategy_mod = SourceFileLoader('strategy', strategy_fnm).load_module() strategy = strategy_mod.strategy backtest(strategy, initial_funds, initial_balance, fill_prob, fee, None, data_fnm, history_fnm, data_name, datapart, None, train_prop, val_prop, verbose, print_freq) backtests.insert({ 'name': name, 'longname': longname, 'id': curr_id, 'fnm': abspath(history_fnm), 'strategy_id': strategy_id }) print('Backtest submitted with name {} and id {}'.format(name, curr_id))
from cointk.backtest import backtest from cointk.strategies import RandomStrategy import random random.seed(1) strategy_random = RandomStrategy() backtest(strategy_random, data_fnm='data/coinbaseUSD.npz', plot_fnm='plots/SimpleRandom-full.html')
from cointk.prescient_sim import compute_prescient from cointk.strategies.prescient import QtyIndependent from cointk.backtest import backtest strategy = QtyIndependent() compute_prescient( strategy, history_fnm='prescient_histories/qty_independent.npz') backtest(strategy, datapart='train', verbose=1)
from cointk.prescient_sim import compute_prescient from cointk.strategies.prescient import QtySemidependent from cointk.backtest import backtest strategy = QtySemidependent() compute_prescient(strategy, history_fnm='prescient_histories/qty_independent.npz') backtest(strategy, datapart='train')
from cointk.backtest import backtest from cointk.strategies import NaiveStrategy strategy = NaiveStrategy(n_prices=1000, threshold=0.8) backtest(strategy)
from cointk.backtest import backtest from cointk.strategies import EMAPriceCrossover strategy = EMAPriceCrossover(ma_length=10000, qty=-1, decision='increasing', verbose=1) backtest(strategy, plot_fnm='plots/EMA-full.html')
from cointk.backtest import backtest from cointk.strategies import EMAPriceCrossover import random random.seed(1) strategy = EMAPriceCrossover(ma_length=10000, qty=-1, trend_threshold=2, decision_logic='order_once', verbose=1) backtest(strategy, plot_fnm='plots/EMA-full.html', datapart='train', plot_args={'initial_funds': 1000})
from cointk.backtest import backtest from cointk.strategies import OldNaiveStrategy import random random.seed(1) strategy = OldNaiveStrategy(n_prices=100, threshold=0.8) # Use the 100k test dataset backtest(strategy, data_fnm='data/coinbaseUSD_100k_sample.npz', plot_name='plots/Naive-test-100k-threshhold-0.8.html', verbose=1)