def random_system_for_regression(config, rules, log_level="on"): my_system = System([Account(), PortfoliosFixed(), PositionSizing(), ForecastCombineEstimated(), ForecastScaleCapEstimated(), rules, RawData()], csvFuturesData(), config) my_system.set_logging_level(log_level) return my_system
def futures_system(data=None, config=None, trading_rules=None, log_level="on"): """ :param data: data object (defaults to reading from csv files) :type data: sysdata.data.Data, or anything that inherits from it :param config: Configuration object (defaults to futuresconfig.yaml in this directory) :type config: sysdata.configdata.Config :param trading_rules: Set of trading rules to use (defaults to set specified in config object) :type trading_rules: list or dict of TradingRules, or something that can be parsed to that :param log_level: How much logging to do :type log_level: str >>> system=futures_system(log_level="off") >>> system System with stages: accounts, portfolio, positionSize, rawdata, combForecast, forecastScaleCap, rules >>> system.rules.get_raw_forecast("EDOLLAR", "ewmac2_8").dropna().head(2) ewmac2_8 1983-10-10 0.695929 1983-10-11 -0.604704 ewmac2_8 2015-04-21 0.172416 2015-04-22 -0.477559 >>> system.rules.get_raw_forecast("EDOLLAR", "carry").dropna().head(2) carry 1983-10-10 0.952297 1983-10-11 0.854075 carry 2015-04-21 0.350892 2015-04-22 0.350892 """ if data is None: data = csvFuturesData() if config is None: config = Config( "systems.provided.futures_chapter15.futuresconfig.yaml") rules = Rules(trading_rules) system = System([ Account(), PortfoliosFixed(), PositionSizing(), FuturesRawData(), ForecastCombine(), ForecastScaleCap(), rules ], data, config) system.set_logging_level(log_level) return system
def get_test_object_futures_with_portfolios(): """ Returns some standard test data """ data = csvFuturesData("sysdata.tests") rawdata = FuturesRawData() rules = Rules() config = Config("systems.provided.example.exampleconfig.yaml") capobject = ForecastScaleCapFixed() combobject = ForecastCombineFixed() posobject = PositionSizing() portfolio = PortfoliosFixed() return (portfolio, posobject, combobject, capobject, rules, rawdata, data, config)
def simplesystem(data=None, config=None, log_level="on"): """ Example of how to 'wrap' a complete system """ if config is None: config = Config("systems.provided.example.simplesystemconfig.yaml") if data is None: data = csvFuturesData() my_system = System([Account(), PortfoliosFixed(), PositionSizing(), ForecastCombineFixed(), ForecastScaleCapFixed(), Rules() ], data, config) my_system.set_logging_level(log_level) return my_system
my_config.instrument_weight_estimate = dict(method="shrinkage", date_method="in_sample") my_system = System( [my_account, fcs, my_rules, fixed_combiner, possizer, portfolio_estimate], data, my_config) my_system.set_logging_level("on") print(my_system.portfolio.get_instrument_weights().tail(5)) print(my_system.portfolio.get_instrument_diversification_multiplier().tail(5)) ## or fixed from systems.portfolio import PortfoliosFixed portfolio = PortfoliosFixed() my_config.instrument_weights = dict(US10=.1, EDOLLAR=.4, CORN=.3, SP500=.2) my_config.instrument_div_multiplier = 1.5 my_system = System([fcs, my_rules, fixed_combiner, possizer, portfolio], data, my_config) print(my_system.portfolio.get_notional_position("EDOLLAR").tail(5)) """ Have we made some dosh? """ my_system = System( [fcs, my_rules, fixed_combiner, possizer, portfolio, my_account], data, my_config) profits = my_system.accounts.portfolio()
system1.positionSize.get_volatility_scalar(instrument_code).mean() * 2.0) original_capital = system1.config.notional_trading_capital accounts_this_instr = [] for target_max in [1.0, 2.0, 3.0, 4.0]: # reset trading capital config = system1.config config.use_SR_costs = False config.notional_trading_capital = original_capital * target_max / max_position system1 = System([ Account(), PortfoliosFixed(), PositionSizing(), FuturesRawData(), ForecastCombineFixed(), ForecastScaleCapFixed(), Rules() ], csvFuturesData(), config) system1.set_logging_level("on") system1_rounded = system1.accounts.portfolio(roundpositions=True) system1_unrounded = system1.accounts.portfolio(roundpositions=False) system2 = System([ Account(), PortfoliosFixed(),
system1.set_logging_level("on") max_position=float(system1.positionSize.get_volatility_scalar(instrument_code).mean()*2.0) original_capital = system1.config.notional_trading_capital accounts_this_instr=[] for target_max in [1.0, 2.0, 3.0, 4.0]: ## reset trading capital config=system1.config config.use_SR_costs=False config.notional_trading_capital=original_capital *target_max / max_position system1 = System([Account(), PortfoliosFixed(), PositionSizing(), FuturesRawData(), ForecastCombineFixed(), ForecastScaleCapFixed(), Rules()], csvFuturesData(), config) system1.set_logging_level("on") system1_rounded=system1.accounts.portfolio(roundpositions=True) system1_unrounded=system1.accounts.portfolio(roundpositions=False) system2 = System([Account(), PortfoliosFixed(), PositionSizing(), FuturesRawData(), ForecastWithBinary(), ForecastScaleCapFixed(), Rules()], csvFuturesData(), config) system2.set_logging_level("on") system2_rounded=system2.accounts.portfolio(roundpositions=True) system2_unrounded=system2.accounts.portfolio(roundpositions=False)