예제 #1
0
    def testCallingTradingRule(self):

        # config=Config(dict(trading_rules=dict(ewmac=dict(function="systems.provided.rules.ewmac..ewmac_forecast_with_defaults"))))
        NOTUSEDrawdata, data, NOTUSEDconfig = get_test_object()

        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.tail(1).values[0], -3.280028, 5)

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

        ans = rule.call(system, "EDOLLAR")
        self.assertAlmostEqual(ans.tail(1).values[0], -1.24349, 5)

        rule = TradingRule(
            dict(
                function="systems.provided.rules.ewmac.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.tail(1).values[0], -3.025001057146)
예제 #2
0
    def testCarryRule(self):
        NOTUSEDrawdata, data, NOTUSEDconfig = get_test_object()

        rawdata = RawData()
        rules = Rules()
        system = System([rawdata, rules], data)
        rule = TradingRule(
            carry,
            [
                "rawdata.daily_annualised_roll",
            ],
            dict(smooth_days=90),
        )
        ans = rule.call(system, "EDOLLAR")
        self.assertAlmostEqual(ans.tail(1).values[0], 0.138302, 5)