from systems.provided.futures_chapter15.estimatedsystem import futures_system from sysdata.configdata import Config my_config=Config("examples.breakout.breakoutfuturesestimateconfig.yaml") system=futures_system(config=my_config) system.config.notional_trading_capital=100000 system.set_logging_level("on") system.accounts.portfolio().stats() system.portfolio.get_instrument_weights().plot() from matplotlib.pyplot import show show()
import inspect import sys; sys.path.append('../..') import inspect from copy import copy from systems.provided.futures_chapter15.estimatedsystem import futures_system system=futures_system() #system.config.forecast_scalar_estimate['min_periods']=50 #system.config.forecast_scalar_estimate['pool_instruments']=False res = system.forecastScaleCap.get_forecast_scalar("US10", "carry") print (res.tail())
import inspect import logging import pandas as pd import sys; sys.path.append('../..') from matplotlib.pyplot import show, title from systems.provided.futures_chapter15.estimatedsystem import futures_system system=futures_system() #system.forecastScaleCap.get_scaled_forecast("EDOLLAR", "ewmac64_256").plot() res=system.rules.get_raw_forecast("CRUDE_W", "carry") res.to_csv("out.csv") print (res.head(5)) f = '../../sysdata/legacycsv/CRUDE_W_price.csv' df = pd.read_csv(f,index_col=0,parse_dates=True) from syscore.accounting import accountCurve account = accountCurve(df.PRICE, forecast=res) tmp = account.percent() print(tmp.stats())
both_plot=pd.concat([ewmac_all, break_all], axis=1) print(both_plot.corr()) both_plot.plot() show() """ # full backtest compare my_config = Config("examples.breakout.breakoutfuturesestimateconfig.yaml") # will do all instruments we have data for del (my_config.instruments) # temporarily remove breakout rules my_config.rule_variations = evariations my_config.forecast_weight_estimate["method"] = "equal_weights" system_old = futures_system(config=my_config, log_level="on") # new system has all trading rules new_config = Config("examples.breakout.breakoutfuturesestimateconfig.yaml") new_config.rule_variations = bvariations new_config.forecast_weight_estimate["method"] = "equal_weights" del (new_config.instruments) system_new = futures_system(config=new_config, log_level="on") curve1 = system_old.accounts.portfolio() curve2 = system_new.accounts.portfolio() print(curve1.stats()) print(curve2.stats())
from matplotlib.pyplot import show, title from systems.provided.futures_chapter15.estimatedsystem import futures_system system=futures_system() system.config.forecast_weight_estimate["pool_instruments"]=True system.config.forecast_weight_estimate["method"]="bootstrap" system.config.forecast_weight_estimate["equalise_means"]=False system.config.forecast_weight_estimate["monte_runs"]=200 system.config.forecast_weight_estimate["bootstrap_length"]=104 system=futures_system(config=system.config) system.combForecast.get_raw_forecast_weights("CORN").plot() title("CORN") show()
import inspect from systems.provided.futures_chapter15.estimatedsystem import futures_system from sysdata.configdata import Config my_config = Config("examples.breakout.breakoutfuturesestimateconfig.yaml") system = futures_system(config=my_config) system.config.notional_trading_capital = 100000 system.set_logging_level("on") system.accounts.portfolio().stats() system.portfolio.get_instrument_weights().plot() from matplotlib.pyplot import show show()
## limit the rules to just breakout for now my_config = Config("examples.breakout.breakoutfuturesestimateconfig.yaml") my_config.trading_rules = dict([(rule_name, my_config.trading_rules[rule_name]) for rule_name in variations]) system = futures_system(config=my_config, log_level="on") print(system.combForecast.get_forecast_weights("EUROSTX").irow(-1)) print(system.combForecast.get_forecast_weights("V2X").irow(-1)) ## now include other rules """ my_config = Config("examples.breakout.breakoutfuturesestimateconfig.yaml") #my_config.forecast_weight_estimate["method"]="bootstrap" system = futures_system(config=my_config, log_level="on") bvariations=["breakout"+str(ws) for ws in [10, 20, 40, 80, 160, 320]] #cProfile.run("system.accounts.pandl_for_all_trading_rules_unweighted().to_frame()","restats") system.accounts.pandl_for_all_trading_rules_unweighted().to_frame().loc[:, bvariations].cumsum().plot() show() """ variations=["breakout"+str(ws) for ws in [10, 20, 40, 80, 160, 320]]+[ "ewmac%d_%d" % (fast, fast*4) for fast in [2,4,8,16,32, 64]]+["carry"] corr_result=system.combForecast.get_forecast_correlation_matrices("US10") matrix=corr_result.corr_list[-1] matrix=pd.DataFrame(matrix, columns=corr_result.columns) matrix=matrix.round(2)