Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backtest.simulate_trading might return results #54

Closed
femtotrader opened this issue Jun 24, 2016 · 3 comments
Closed

Backtest.simulate_trading might return results #54

femtotrader opened this issue Jun 24, 2016 · 3 comments

Comments

@femtotrader
Copy link
Contributor

So it will be possible to save them (CSV, JSON, YAML, Pickle...)

Moreover it will be possible to use backtest results for unit testing purpose.

@femtotrader
Copy link
Contributor Author

So in examples/... . py

we will have

def run(config, testing):
    ...
    results = backtest.simulate_trading(testing=testing)
    return results

@femtotrader
Copy link
Contributor Author

femtotrader commented Jun 24, 2016

Here is how a test for a strategy could be written

    def test_sp500tr_buy_and_hold_backtest(self):
        """
        Test sp500tr_buy_and_hold
        Bar 0, at 2010-01-04 00:00:00
        Bar 1628, at 2016-06-22 00:00:00
        """
        results = examples.sp500tr_buy_and_hold_backtest.run(self.config, testing=self.testing)
        for (key, expected) in [
            ('sharpe', 0.5969),
            ('max_drawdown_pct', 5.0308),
            ('max_drawdown', 30174.01)
        ]:
            value = float(results[key])
            self.assertAlmostEqual(expected, value)
        for (key, expected) in [
                ('equity_returns', {'min': -1.6027, 'max': 1.2553, 'first': 0.0000, 'last': -0.0580}),
                ('drawdowns', {'min': 0.0, 'max': 30174.01, 'first': 0.0, 'last': 4537.02}),
                ('equity', {'min': 488958.0, 'max': 599782.01, 'first': 500000.0, 'last': 595244.99})
            ]:
            values = results[key]
            self.assertAlmostEqual(float(min(values)), expected['min'])
            self.assertAlmostEqual(float(max(values)), expected['max'])
            self.assertAlmostEqual(float(values.iloc[0]), expected['first'])
            self.assertAlmostEqual(float(values.iloc[-1]), expected['last'])

we probably don't need such tests for every strategy but one like this could avoid regression

For others strategies we can only test sharpe

    def test_mac_backtest(self):
        """
        Test mac_backtest
        """
        results = examples.mac_backtest.main(self.config, testing=self.testing)
        self.assertAlmostEqual(float(results['sharpe']), 0.6018)


    def test_strategy_backtest(self):
        """
        Test strategy_backtest
        """
        results = examples.strategy_backtest.main(self.config, testing=self.testing)
        self.assertAlmostEqual(float(results['sharpe']), -7.5299)

@femtotrader
Copy link
Contributor Author

Closed by bffc1a1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants