示例#1
0
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(),
        ForecastCombineFixed(),
        ForecastScaleCapFixed(), rules
    ], data, config)

    system.set_logging_level(log_level)

    return system
示例#2
0
文件: testdata.py 项目: cymond/sysy
def get_test_object_futures_with_rules_and_capping():
    """
    Returns some standard test data
    """
    data = csvFuturesData("sysdata.tests")
    rawdata = FuturesRawData()
    rules = Rules()
    config = Config("systems.provided.example.exampleconfig.yaml")
    capobject = ForecastScaleCapFixed()
    return (capobject, rules, rawdata, data, config)
示例#3
0
文件: testdata.py 项目: cymond/sysy
def get_test_object_futures_with_pos_sizing():
    """
    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()
    return (posobject, combobject, capobject, rules, rawdata, data, config)
示例#4
0
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
示例#5
0
my_system = System([empty_rules], data, my_config)
my_system.rules.get_raw_forecast("EDOLLAR", "ewmac32").tail(5)

from systems.forecast_scale_cap import ForecastScaleCapFixed, ForecastScaleCapEstimated

## we can estimate these ourselves
my_config.instruments = ["US10", "EDOLLAR", "CORN", "SP500"]
fcs_estimate = ForecastScaleCapEstimated()
my_system = System([fcs_estimate, 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)
fcs = ForecastScaleCapFixed()
my_system = System([fcs, my_rules], data, my_config)
print(
    my_system.forecastScaleCap.get_capped_forecast("EDOLLAR",
                                                   "ewmac32").tail(5))
"""
combine some rules
"""

from systems.forecast_combine import ForecastCombineFixed, ForecastCombineEstimated

## defaults
fixed_combiner = ForecastCombineFixed()
my_system = System([fcs, my_rules, fixed_combiner], data, my_config)
print(my_system.combForecast.get_forecast_weights("EDOLLAR").tail(5))
print(