TAYU Academy course material · Python Quant Trading Lab
Course Notes
1. Understand the core idea of “SMA strategy backtest” and explain it in your own words
2. Master this module's focus: Developing strategies with Backtrader
3. Complete the assignment on your own and check it against the reference answer
The delivery of SMA backtest includes input hash, parameters, execution agreement, cost, cash, and position, and code correctness is not judged based on an increase in equity.
Backtrader's basic structure includes Cerebro (the engine), DataFeed, Strategy (the `next` method), Broker (fees and slippage), and Analyzer (performance analysis). By default, market orders are filled at the opening price of the next candle, which helps to avoid the bias caused by using the current candle's closing price. Backtesting should account for the spread and commissions.
Example: Buy when the Simple Moving Average (SMA) (10) crosses above the SMA (30), and sell when it crosses below, after accounting for commission and slippage, compare the equity curves before and after the cost is included. The cost often significantly reduces the short-term strategy's profitability.
Run dependency-free self-check → run two engines → verify order quantities/fees/final equity → check prefix causality → retain difference report.
Compare research_lab and Backtrader on fixed synthetic inputs; allow a 1e−6 floating-point difference, and write three things neither covers.
Equity should be within tolerance limits and should not cover real market orders, forex margin, overnight fees, or delayed rejects. A matching result proves consistency under the same assumptions but does not prove real profitability.
If the buy signal is generated at 100 on day t, and the opening price on day t+1 is 103 with a closing price of 104, the normal next opening price would be 103, and this cannot be recorded as 100. Costs and slippage should be set and compared with the net result afterward. Orders should not be resubmitted when in the Submitted/Accepted state; the hold flag should be cleared when in Completed/Canceled/Rejected states.
Do not claim to use the default next open execution after closing without enabling cheat-on-close; do not equate the backtest results from different matching agreements directly.
Install the dependencies listed for this lab in the README first. If a dependency or platform is unavailable, mark the lab as not run; downloading the source is not evidence of running it.
python backtrader_lab.py1. Fills at the next candle's open by default
2. Include spread, commission and slippage
3. Use Analyzer to output metrics that can be checked
Risk warning: leveraged trading in forex, precious metals and similar products carries a high level of risk and you may lose all of your capital, or more. This course is for education only. It is not investment advice and does not promise any return. Example prices and contract specifications are teaching assumptions; always use what your own platform discloses. Past performance and backtests do not indicate future results.
All values, prices, accounts and cases in this course are teaching assumptions; the fixed materials can be reproduced offline. Marking a lesson complete only records your study. It is not a certification, a service approval or a promise of returns. Workbooks and answer files are currently provided in Chinese.
The delivery of SMA backtest includes input hash, parameters, execution agreement, cost, cash, and position, and code correctness is not judged based on an increase in equity.
Record your work and compare the reference result. Self-checks are not verified competence.
Completion records your own study, not verified competence. Exercises use fictional data; no real account or deposit is required.