Practitioner course in programming
Building a Backtester with Backtrader
A working command of Backtrader, the open-source Python backtesting framework: feeds, strategies, indicators, realistic costs, position sizing and analyzers, and a clear view of what it cannot model.
Backtrader is one of the most used open-source backtesting frameworks in Python. It is a good teacher: its design separates data, strategy, broker and analysis cleanly, and that separation is the right habit whatever tool you use later.
What does Backtrader do for you, and what does it hide?
It runs your strategy bar by bar, keeps track of orders, cash and positions, and reports the result. It also makes choices on your behalf: how an order on one bar fills on the next, what commission is charged, whether slippage exists. The defaults are optimistic. Half of this course is learning to replace them with assumptions you can defend.
Why build on a framework instead of writing a backtester from scratch?
For most daily and intraday strategies a framework is faster and less error-prone than a first home-made engine. The course still ends by showing what a framework cannot model, so you know when the extra work of your own engine is justified. Python for Algorithmic Trading builds that engine.
Who is this course for?
Traders who want to test rules properly before risking money, and analysts who need a fast, reproducible testing tool. It pairs naturally with Backtesting: Methods, Pitfalls and Validation, which covers the statistics of judging a result.
What you will be able to do
- Load daily and intraday data into Backtrader and run multi-asset tests.
- Write strategies and custom indicators with correct handling of lookback periods.
- Model commissions, slippage and fill rules instead of accepting the defaults.
- Use sizers and analyzers to report returns, drawdowns and trade statistics.
- Explain which market effects the framework does not model and how to test around them.
Syllabus, module by module
How Backtrader is organised
Cerebro, data feeds, strategies, brokers, sizers, observers and analyzers.
Data feeds
CSV and pandas feeds, timeframes, resampling, and several instruments in one test.
Strategies and indicators
The next() loop, lookback periods, built-in indicators and writing your own.
Orders and fills
Market, limit and stop orders, fill rules on bar data, and the cheat-on-open setting.
Costs
Commission schemes, slippage settings, and how much they change a result.
Sizing and analysis
Sizers, analyzers for returns, drawdown and trades, and exporting results.
Limits of the framework
No order book, bar-level fills, speed on large universes, and when to write your own engine.
How the certificate is earned
An assessed project: you implement a published strategy rule in Backtrader with realistic costs, compare it with a simple benchmark, and submit the code with a short report on the assumptions. On a pass you receive the Course certificate in Building a Backtester with Backtrader, issued by the Institute with a verification code. Read how certification works.
Before you start
Working Python with pandas, and an understanding of what a trading strategy and a backtest are.
Questions applicants ask
Is Backtrader still maintained?
Backtrader is open source and widely used, but its main repository has seen little development in recent years. The course teaches it because it is clear and well documented, and the final module covers when to move to another tool.
Is Backtrader good for intraday or high-frequency strategies?
It handles intraday bars. It does not model an order book or queue position, so it is not suitable for testing high-frequency strategies. The High-Frequency Trading track covers those methods.