systems.basesystem.System

Here are the examples of the python api systems.basesystem.System taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

8 Examples 7

Example 1

Project: pysystemtrade Source File: test_correlation.py
    def setUp(self):
        (accounts, fcs, rules, rawdata, data,
         config) = get_test_object_futures_with_rules_and_capping_estimate()
        system = System([accounts, rawdata, rules, fcs,
                         ForecastCombineEstimated()], data, config)
        setattr(self, "system", system)

Example 2

Project: pysystemtrade Source File: simplesystem.py
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

Example 3

Project: pysystemtrade Source File: test_forecasts.py
    def testCarryRule(self):
        data = csvFuturesData("sysdata.tests")

        rawdata = FuturesRawData()
        rules = Rules()
        system = System([rawdata, rules], data)
        rule = TradingRule(carry,
                           ["rawdata.daily_annualised_roll",
                            "rawdata.daily_returns_volatility"],
                           dict(smooth_days=90))
        ans = rule.call(system, "EDOLLAR")
        self.assertAlmostEqual(ans.iloc[-1][0], 0.411686026, 5)

Example 4

Project: pysystemtrade Source File: basesystem.py
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

Example 5

Project: pysystemtrade Source File: estimatedsystem.py
def futures_system(data=None, config=None,
                   trading_rules=None, log_level="terse"):
    """

    :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)
    :param trading_rules: list or dict of TradingRules, or something that can be parsed to that

    :param log_level: Set of trading rules to use (defaults to set specified in config object)
    :type log_level: str

    """

    if data is None:
        data = csvFuturesData()

    if config is None:
        config = Config(
            "systems.provided.futures_chapter15.futuresestimateconfig.yaml")

    rules = Rules(trading_rules)

    system = System([Account(), Portfolios(), PositionSizing(), FuturesRawData(), ForecastCombine(),
                     ForecastScaleCap(), rules], data, config)

    system.set_logging_level(log_level)

    return system

Example 6

Project: pysystemtrade Source File: test_base_systems.py
Function: test_name
    def testName(self):
        stage = SystemStage()
        stage.name = "test"
        data = Data()
        stage._protected = ["protected"]

        system = System([stage], data, None)
        print(system._cache)

        system.set_item_in_cache(3, ("test", "a"), "US10")
        print(system._cache)

        self.assertEqual(system.get_item_from_cache(("test", "a"), "US10"), 3)

        def afunction(system, instrument_code, stage,
                      wibble, another_wibble=10):
            return instrument_code + wibble + str(another_wibble) + stage.name

        def anestedfunction(system, instrument_code,
                            keyname, stage, wibble, another_wibble=10):
            return instrument_code + wibble + keyname + \
                str(another_wibble) + stage.name

        ans = system.calc_or_cache("b", "c", afunction, stage, "d")
        print(system._cache)

        ans = system.calc_or_cache("b", "c", afunction, stage, "d", 20.0)
        print(system._cache)

        ans = system.calc_or_cache_nested(
            "c", "SP500", "thing", anestedfunction, stage, "k")
        print(system._cache)

        ans = system.calc_or_cache(
            "b", ALL_KEYNAME, afunction, stage, "e", 120.0)
        print(system._cache)

        ans = system.calc_or_cache(
            "protected", ALL_KEYNAME, afunction, stage, "e", 120.0)

        ans = system.get_item_from_cache(("test""c"), "SP500", "thing")
        print(system._cache)

        system._delete_item_from_cache(("test", "b"), "c")
        print(system._cache)

        ans = system.set_item_in_cache(10.0, ("test", "protected"), "SP500")
        print(system._cache)

        print(system.get_item_from_cache(("test", "b"), ALL_KEYNAME))

        ans = system.set_item_in_cache("protected", ("test2", 10.0), "SP500")

        print(system._cache)

        print(system.get_items_across_system())
        print(system.get_items_with_data())
        print(system.get_protected_items())
        print(system.get_items_for_instrument("SP500"))
        print(system.get_itemnames_for_stage("test"))

        system.delete_items_for_stage("test2")

        print(system._cache)

        system.delete_items_across_system()

        print(system._cache)

        system.delete_items_across_system(True)

        print(system._cache)

        system.delete_items_for_instrument("SP500")
        print(system._cache)

        system.delete_items_for_instrument("SP500", True)
        print(system._cache)

        system.delete_item(("test", "a"))

        print(system._cache)

Example 7

Project: pysystemtrade Source File: test_forecasts.py
    def testRules(self):

        # config=Config(dict(trading_rules=dict(ewmac=dict(function="systems.provided.example.rules.ewmac_forecast_with_defaults"))))
        data = csvFuturesData("sysdata.tests")

        rules = Rules(
            dict(function="systems.provided.example.rules.ewmac_forecast_with_defaults"))
        system = System([rules], data)

        ans = system.rules.get_raw_forecast("EDOLLAR", "rule0")
        self.assertAlmostEqual(ans.iloc[-1][0], 2.1384223788141838, 5)

        config = Config(dict(trading_rules=dict(ewmac=dict(
            function="systems.provided.example.rules.ewmac_forecast_with_defaults"))))
        rules = Rules()
        system = System([rules], data, config)
        ans = system.rules.get_raw_forecast("EDOLLAR", "ewmac")
        self.assertAlmostEqual(ans.iloc[-1][0], 2.1384223788141838, 5)

        config = Config("systems.provided.example.exampleconfig.yaml")
        rawdata = RawData()

        rules = Rules()
        system = System([rules, rawdata], data, config)
        ans = system.rules.get_raw_forecast("EDOLLAR", "ewmac8")
        self.assertAlmostEqual(ans.iloc[-1][0], 0.16438313875, 5)

Example 8

Project: pysystemtrade Source File: test_forecasts.py
    def testCallingTradingRule(self):

        # config=Config(dict(trading_rules=dict(ewmac=dict(function="systems.provided.example.rules.ewmac_forecast_with_defaults"))))
        data = csvFuturesData("sysdata.tests")

        rawdata = RawData()
        rules = Rules()
        system = System([rawdata, rules], data)

        # Call with default data and config
        rule = TradingRule(ewmac_forecast_with_defaults)
        ans = rule.call(system, "EDOLLAR")
        self.assertAlmostEqual(ans.iloc[-1][0], 2.1384223788141838, 5)

        # Change the data source
        rule = TradingRule(("systems.provided.example.rules.ewmac_forecast_with_defaults_no_vol",
                            ["rawdata.get_daily_prices", "rawdata.daily_returns_volatility"], dict()))

        ans = rule.call(system, "EDOLLAR")
        self.assertAlmostEqual(ans.iloc[-1][0], 0.029376, 5)

        rule = TradingRule(dict(function="systems.provided.example.rules.ewmac_forecast_with_defaults_no_vol",
                                data=["rawdata.get_daily_prices",
                                      "rawdata.daily_returns_volatility"],
                                other_args=dict(Lfast=50, Lslow=200)))
        ans = rule.call(system, "EDOLLAR")
        self.assertAlmostEqual(ans.iloc[-1][0], 3.84426755)