pythondict-quant: a course of Backtrader examples for quantitative trading
Quant Examples Based on Backtrader.
At a glance
- What is it?
- pythondict-quant collects the source code behind a Chinese-language quantitative investing tutorial series built on Backtrader, covering MACD, KDJ, harami patterns, average trade profit, a custom MySQL data feed, convertible bonds, Prometheus monitoring and a survey of tools like Lean, Alphalens and Qlib. The code is dated, undocumented and carries no licence.
- Who is it for?
- Use pythondict-quant as a teaching reference if you want to read short, complete Backtrader programs for specific strategies rather than a maintained library. Do not adopt it as a dependency: the repository has no LICENSE file, the licence is recorded as unknown, the newest tutorial dates from 2021, and the last push was on 2026-06-04.
- Can I use it commercially?
- Not without permission. GitHub finds no licence file in the repository, and without a licence all rights are reserved by default: you may read the code but not reuse it. Check the README, or ask the authors, before using it.
- Is it still maintained?
- Yes. The repository last received commits 141 days ago.
- What is it written in?
- Mainly Python, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on October 22, 2026, and from our analysis. They are not legal advice.
Editorial analysis
What the repository actually is: the code behind a tutorial series
The repository description is one line: quant examples based on Backtrader. The README expands it. This GitHub repository records the source code for a series of quantitative investing tutorial articles published on the site pythondict.com, which presents itself as a Python tutorial site with a companion public account.
The framing in the README is worth more than the code itself. It opens by pointing out that many technical investment textbooks illustrate an indicator with a chart of a rising stock, and that the chosen chart may be an illusion, because the author picked a stock whose trend already suited the indicator being praised. Strategies that way do not necessarily fit every stock, and readers are taken in by them. The conclusion the author draws is that judging a strategy requires backtest evidence, numbers rather than flowery words, and that teaching people to produce that evidence is the stated purpose of the tutorial series.
That is a reasonable way to frame a tutorial repository, and it sets the expectation for what is inside. The code here is written to be read. Each directory is a self-contained example attached to one article, named for the topic rather than for a reusable API.
The numbered folders and the Backtrader foundation
The repository is a flat list of numbered directories, each holding the code for one tutorial article. The top level starts at 01.begin for the introduction, then 02.easy_macd_strategy for a straightforward MACD strategy, 03.macd_in_A_market for the same idea applied to A-shares, the mainland China stock market. It continues with 04.kdj_with_macd, 05.kdj_macd_in_A_market, 06.average_profit, 07.harami, 08.harami_in_A_market, 09.custom_data_source, 10.converted_bond and 11.eastmoney_with_prom_grafana, then jumps to 13.alphalens_factor_backtest and 15.rl_learning. The numbering mirrors the article series, and the two gaps correspond to articles that are written up but have no directory here.
A shared naming convention is visible in the folder names, which combine the strategy with the market where relevant: the MACD and KDJ examples each appear twice, once generic and once pointed at A-share data. The harami pattern gets the same treatment.
Everything is built on Backtrader, and the README credits the Backtrader developers, linking to the mementum/backtrader project. That single dependency is what makes the series readable end to end. The same handful of concepts, the strategy class, the data feed, the broker configuration and the analyser, repeat across the examples, so a reader who follows the first tutorial has the vocabulary for the rest.
The strategy examples: MACD, KDJ, harami and average trade profit
The core of the series is a set of classic technical indicators, each built backtest and then built again against A-share data.
MACD gets the first two tutorials, one introducing the indicator and one backtesting it on A-shares. The follow-up articles in the series listed in the README cover the KDJ strategy and then the KDJ strategy on A-shares, the harami pattern and then the harami strategy backtested on A-shares, and a tutorial on average trade profit that returns to the MACD example. The final question of the pattern series is posed in the article title as a question about whether the harami pattern is genuinely useful, which is the honest framing for a pattern that gets read two ways by different practitioners.
Two things are worth noticing about how the series is organised. Each strategy is taught twice, once as a generic idea and once against a real market, and the second version is where the data source question becomes concrete, because A-share data does not arrive in the format a US-oriented example assumes. And the average profit tutorial is not a new strategy but a measurement, which suggests the series is teaching the reader to evaluate rather than just to replicate.
The remaining directories cover adjacent ground: a custom MySQL data feed, a convertible bond strategy, Prometheus and Grafana monitoring, Alphalens for single-factor analysis, and a reinforcement learning tutorial.
Data sources: A-shares, a custom MySQL feed and convertible bonds
The 09.custom_data_source directory exists because Backtrader needs to be told where the data comes from, and for a Chinese market the answer is not a free CSV download. The tutorial introduces a custom MySQL data feed, which is the practical approach when you keep price history in a database you control and want the backtest to read from it directly. The article on the custom MySQL data feed is listed with a November 2020 date, which is late enough in the series that the reader already knows why the built-in feeds are not enough.
The 10.converted_bond directory covers a different asset class again, a convertible bond strategy, with the article dated March 2021. Convertible bonds behave differently from plain shares, and a strategy file that transfers from one to the other without adjustment is a common source of meaningless backtest results. The tutorial exists, so the author was working through that rather than ignoring it.
The 11.eastmoney_with_prom_grafana directory is the odd one out. Instead of a strategy it builds monitoring: a tutorial on Prometheus with Grafana and Python, published under the quantitative investing series but aimed at tracking the popularity rankings of stocks on Eastmoney, a Chinese market data site, in near real time. It is the point where the series stops being about backtests and starts being about operations.
The remaining two directories are surveys rather than strategy code. There is a directory for the Alphalens factor backtest tool and one for reinforcement learning, the latter accompanied by an article asking what reinforcement learning is and how well stock prediction actually works.
Tooling the series points at: Lean, Alphalens, Qlib and reinforcement learning
Three of the articles in the series are about other projects rather than about code in this repository, and for a reader deciding what to learn next they are the most valuable part.
One introduces Lean, described as an excellent and easy to use open source quantitative trading platform. Another covers Alphalens, presented as a tool for single-factor backtests, which corresponds to the 13.alphalens_factor_backtest directory. A third covers Qlib, described in the article title as Microsoft's open source and the world's first AI quant investment platform.
These are recommendations about tooling, and they come with a specific framing. The Reinforcement learning article asks two questions, what reinforcement learning is and how well it works for predicting stocks, which is the tone the series uses throughout: a technique is introduced, then its measured effect is questioned.
For an engineer choosing a starting point, this is a reading list in a coherent order. Backtrader first, since every example is built on it and it is the framework you will actually modify. Alphalens next, because factor analysis sits alongside indicator strategies. Then Lean and Qlib, which are full platforms rather than libraries and would be a change of scale.
One caveat belongs here. The articles were written between 2020 and 2021, so the state of these projects when the author evaluated them is not necessarily their state now, and the recommendations carry no version numbers.
The installation problem the README solves with a pinned matplotlib
The README's feedback section carries a single troubleshooting entry, and it is specific. If you hit an ImportError about not being able to import the name warnings, the instruction is to install a specific matplotlib version:
pip install matplotlib==3.2.2That single line is the most informative thing in the repository about its age. The error is a known symptom of matplotlib versions that are too new for the plotting code in these examples, and the fix is a downgrade to a version from the era when the tutorials were written.
Read as a whole, the troubleshooting note tells you that the examples are pinned in practice to the library versions of 2020 and 2021, even though nothing in the repository declares that formally. There is no requirements file at the top level, no pinned Backtrader version and no environment specification. The install instructions are in a README paragraph rather than in a manifest, and the only concrete version constraint given anywhere is the matplotlib pin in the feedback section.
That has a direct consequence for anyone running these examples today. The recommended route is a Python environment of the right vintage, isolated from whatever else is installed, with matplotlib pinned to 3.2.2 and a Backtrader version close to the one the code was written against. Expect to spend time on environment setup before you see a single backtest result, and treat that as part of the cost of the examples rather than a fault in them.
Limits: no licence, dated examples and the illusion the series warns about
The most consequential limitation is legal rather than technical. The top level of the repository contains no LICENSE file, and the licence is recorded as unknown. Without a licence, the default position under copyright law is that no permission is granted to copy, modify or redistribute the code. You can read it and learn from it, which is what a tutorial is for, but treating these files as the basis of your own project needs the author's permission, and the site contact is the route to that.
The second limitation is age. The articles run from April 2020 to November 2021, the matplotlib pin is from that same window, and the most recent push to the repository was on 2026-06-04 with no GitHub releases attached. Whatever changed in that last push, the tutorial content is from five years ago, and a Backtrader API that has since shifted will not be reflected in these files.
The third limitation is the one the README itself raises, and it applies to these examples as much as to any strategy you might find elsewhere. A backtest proves that a rule would have produced a certain result on a particular set of prices, which is not the same as a prediction of what happens next. The series earns credit for insisting on that distinction, and it loses a little by offering only backtest evidence and no live or paper trading record. A reader who wants to know whether any of these strategies works should look for a strategy whose behaviour has been checked outside the sample it was built on.
Editorial conclusion
Use pythondict-quant as a teaching reference if you want to read short, complete Backtrader programs for specific strategies rather than a maintained library. Do not adopt it as a dependency: the repository has no LICENSE file, the licence is recorded as unknown, the newest tutorial dates from 2021, and the last push was on 2026-06-04. Verify first that you can install the pinned matplotlib==3.2.2, since that pin is what the README prescribes for the ImportError, and re-check every Backtrader API call against the version you have installed before running any example against live data.
Frequently asked questions
What does the pythondict-quant repository contain?
It holds the source code behind a series of quantitative investing tutorial articles published on pythondict.com, organised into numbered directories that map to individual articles, from 01.begin through 15.rl_learning. The examples are built on Backtrader.
How do I fix the ImportError about cannot import name 'warnings' when running these examples?
The README prescribes installing a specific matplotlib version, with the command pip install matplotlib==3.2.2. The pin reflects the library versions these examples were written against.
Which strategies does the pythondict-quant tutorial series cover?
The series covers MACD, the KDJ strategy, the harami pattern and average trade profit, each generally taught once as a generic idea and once backtested on A-share data, plus a custom MySQL data feed and a convertible bond strategy. Later articles survey Lean, Alphalens, Qlib and reinforcement learning.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/ckend-pythondict-quant)