Comments (3)
So in examples/... . py
we will have
def run(config, testing):
...
results = backtest.simulate_trading(testing=testing)
return results
from qstrader.
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)
from qstrader.
Closed by bffc1a1
from qstrader.
Related Issues (20)
- BUG: AttributeError: 'SMASignal' object has no attribute 'update' HOT 1
- Use with crypto
- QSTrader Documentation links are broken or moved
- no module named qstrader
- Dangling function
- Use of Assets!
- Documentation correction
- Pandas 1.3.x?
- How should a pair/pool trading strategy be implemented? HOT 2
- strategy_backtest.run() error, your assistance please HOT 1
- Please provide SPY CSV file please !! HOT 1
- Documentation HOT 1
- SimulatedBroker Issue HOT 1
- Lack of timestamp data from yahoo finance results in testing of qstrader with sixty_forty.py impossible
- Massive fail of the modules from qstrader HOT 2
- No module named 'qstrader.price_parser' ,for help HOT 2
- Scaled down order in simulated broker mentioned but not implemented?
- Compatibility with python 3.11 -error when plotting HOT 1
- timestamp date format in 60-40 portfolio HOT 3
- Click version requirement HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from qstrader.