my_system = System([my_rules], data)
my_system.rules.get_raw_forecast("EDOLLAR", "ewmac32").tail(5)

from sysdata.configdata import Config
my_config = Config()
my_config

empty_rules = Rules()
my_config.trading_rules = dict(ewmac8=ewmac_8, ewmac32=ewmac_32)
my_system = System([empty_rules], data, my_config)
my_system.rules.get_raw_forecast("EDOLLAR", "ewmac32").tail(5)

from systems.forecast_scale_cap import ForecastScaleCap

# we can estimate these ourselves
my_config.instruments = ["US10", "EDOLLAR", "CORN", "SP500"]
my_config.use_forecast_scale_estimates = True

fcs = ForecastScaleCap()
my_system = System([fcs, my_rules], data, my_config)
print(
    my_system.forecastScaleCap.get_forecast_scalar("EDOLLAR",
                                                   "ewmac32").tail(5))

# or we can use the values from the book
my_config.forecast_scalars = dict(ewmac8=5.3, ewmac32=2.65)
my_config.use_forecast_scale_estimates = False
fcs = ForecastScaleCap()
my_system = System([fcs, my_rules], data, my_config)
print(
    my_system.forecastScaleCap.get_capped_forecast("EDOLLAR",
Exemple #2
0
from sysdata.configdata import Config
my_config = Config()
my_config

empty_rules = Rules()
my_config.trading_rules = dict(ewmac8=ewmac_8, ewmac32=ewmac_32)
my_system = System([empty_rules], data, my_config)
my_system.rules.get_raw_forecast("EDOLLAR", "ewmac32").tail(5)


from systems.forecast_scale_cap import ForecastScaleCap


## we can estimate these ourselves
my_config.instruments=[ "US10", "EDOLLAR", "CORN", "SP500"]
my_config.use_forecast_scale_estimates=True
fcs=ForecastScaleCap()
my_system = System([fcs, my_rules], data, my_config)
print(my_system.forecastScaleCap.get_forecast_scalar("EDOLLAR", "ewmac32").tail(5))

## or we can use the values from the book
my_config.forecast_scalars = dict(ewmac8=5.3, ewmac32=2.65)
my_config.use_forecast_scale_estimates=False
fcs=ForecastScaleCap()
my_system = System([fcs, my_rules], data, my_config)
print(my_system.forecastScaleCap.get_capped_forecast(
    "EDOLLAR", "ewmac32").tail(5))

"""
combine some rules
Exemple #3
0
from systems.basesystem import System
from sysdata.csvdata import csvFuturesData
from systems.forecasting import Rules
from systems.forecasting import TradingRule

data = csvFuturesData()

ewmac_8 = TradingRule((ewmac, [], dict(Lfast=8, Lslow=32)))
ewmac_32 = TradingRule(dict(function=ewmac, other_args=dict(Lfast=32, Lslow=128)))
my_rules = Rules(dict(ewmac8=ewmac_8, ewmac32=ewmac_32))

my_config = Config()
my_config
my_config.trading_rules = dict(ewmac8=ewmac_8, ewmac32=ewmac_32)

## we can estimate these ourselves

#my_config.instruments=[ "US20", "NASDAQ", "SP500"]
my_config.instruments=[ "SP500"]
my_config.forecast_weight_estimate=dict(method="one_period")
my_config.use_forecast_weight_estimates=True
my_account = Account()
combiner = ForecastCombine()
fcs=ForecastScaleCap()
my_system = System([my_account, fcs, my_rules, combiner], data, my_config)

print(my_system.combForecast.get_forecast_weights("SP500").tail(5))
print('forecast_diversification_multiplier')
print(my_system.combForecast.get_forecast_diversification_multiplier("SP500").tail(5))

Exemple #4
0
from systems.provided.example.rules import ewmac_forecast_with_defaults as ewmac
from sysdata.configdata import Config
from systems.account import Account
from systems.forecast_combine import ForecastCombine
from systems.forecast_scale_cap import ForecastScaleCap
from systems.basesystem import System
from sysdata.csvdata import csvFuturesData
from systems.forecasting import Rules
from systems.forecasting import TradingRule
from systems.portfolio import PortfoliosEstimated
from systems.positionsizing import PositionSizing

data = csvFuturesData()
my_config = Config()
my_config.instruments = ["US20", "SP500"]

ewmac_8 = TradingRule((ewmac, [], dict(Lfast=8, Lslow=32)))
ewmac_32 = TradingRule(
    dict(function=ewmac, other_args=dict(Lfast=32, Lslow=128)))
my_rules = Rules(dict(ewmac8=ewmac_8, ewmac32=ewmac_32))

my_system = System([
    Account(),
    PortfoliosEstimated(),
    PositionSizing(),
    ForecastScaleCap(), my_rules,
    ForecastCombine()
], data, my_config)
my_system.config.forecast_weight_estimate['method'] = "equal_weights"
my_system.config.instrument_weight_estimate['method'] = "bootstrap"
Exemple #5
0
from systems.account import Account
from systems.forecast_combine import ForecastCombine
from systems.forecast_scale_cap import ForecastScaleCap
from systems.basesystem import System
from sysdata.csvdata import csvFuturesData
from systems.forecasting import Rules
from systems.forecasting import TradingRule

data = csvFuturesData()
my_config = Config()

ewmac_8 = TradingRule((ewmac, [], dict(Lfast=8, Lslow=32)))
ewmac_32 = TradingRule(dict(function=ewmac, other_args=dict(Lfast=32, Lslow=128)))
my_rules = Rules(dict(ewmac8=ewmac_8, ewmac32=ewmac_32))
my_config.trading_rules = dict(ewmac8=ewmac_8, ewmac32=ewmac_32)

#my_config.instruments=[ "US20", "NASDAQ", "SP500"]
my_config.instruments=[ "SP500"]
my_config.forecast_weight_estimate=dict(method="bootstrap")
my_config.forecast_weight_estimate['monte_runs']=50
my_config.use_forecast_weight_estimates=True
my_system = System([Account(), ForecastScaleCap(), my_rules, ForecastCombine()], data, my_config)
logging.debug(my_system.combForecast.get_forecast_weights("SP500").tail(5))

# DEBUG:root:             ewmac32    ewmac8
# 2015-12-07  0.632792  0.367208
# 2015-12-08  0.632930  0.367070
# 2015-12-09  0.633066  0.366934
# 2015-12-10  0.633201  0.366799
# 2015-12-11  0.633335  0.366665
Exemple #6
0
        subsys_positions = pd.concat(subsys_positions, axis=1).ffill()
        subsys_positions.columns = instrument_list
        instrument_weights = fix_weights_vs_pdm(raw_instr_weights, subsys_positions)
        weighting=system.config.instrument_weight_ewma_span  
        instrument_weights = pd.ewma(instrument_weights, weighting) 
        return instrument_weights

    
if __name__ == "__main__": 
     
    random.seed(0)
    np.random.seed(0)

    data = csvFuturesData()
    my_config = Config()
    my_config.instruments=["US20", "SP500"]

    ewmac_8 = TradingRule((ewmac, [], dict(Lfast=8, Lslow=32)))
    ewmac_32 = TradingRule(dict(function=ewmac, other_args=dict(Lfast=32, Lslow=128)))
    my_rules = Rules(dict(ewmac8=ewmac_8, ewmac32=ewmac_32))

    my_system = System([Account(), PortfoliosEstimated(), PositionSizing(), ForecastScaleCap(), my_rules, ForecastCombine()], data, my_config)
    my_system.config.forecast_weight_estimate['method']="equal_weights"
    my_system.config.instrument_weight_estimate['method']="bootstrap"
    my_system.config.instrument_weight_estimate["monte_runs"]=1
    my_system.config.instrument_weight_estimate["bootstrap_length"]=250
    print(my_system.portfolio.get_instrument_diversification_multiplier(my_system))

    # 10,250 weights=0.75,0.25 idm=1.26
    # 30,250 weights=0.75,0.25