回测 —Zipline 已死?还是只需重启 Zipline-Reloaded? Backtesting – Is Zipline Dead? Or does it just need a reload?
此处有一文章 https://www.followingthetrend.com/2021/12/backtesting-is-zipline-dead-or-does-it-just-need-a-reload/
标题: Backtesting – Is Zipline Dead? Or does it just need a reload? 使用豆包转译了一下。
回测 ——Zipline 已死?还是只需重启?
我在 2019 年出版的《交易进化》(Trading Evolved)一书专注于教你如何用 Python 对交易策略进行回测。在那本书里,我使用了 Zipline 库,并提供了大量源代码以及使用示例。Zipline 是由一家名为 Quantopian 的公司开发的,我有幸对这家公司有深入了解。
Quantopian 打造了这个回测库,并免费提供,包括源代码。他们还创建了一个网站,在上面你可以使用该回测器的托管版本,还有免费的分钟级数据。他们提供了工具、数据和计算能力。很难让人不喜欢这个创意。他们还举办了顶尖的量化金融会议,每年在纽约举办大型活动,在新加坡也举办过几次。我很清楚,我曾多次在这两个地方的活动中担任演讲嘉宾。
但最终,这家公司还是失败了。这实在令人惋惜,人们会非常怀念它。在我看来,问题在于他们不想将自身真正的优势货币化。他们对在线回测收费、开展量化经纪业务或其他更明显的盈利方式毫无兴趣。他们想成为一家对冲基金。
他们的计划是在网站上举办竞赛,任何人都可以提交自己的交易算法。这些算法在风险、相关性以及诸多限制方面必须符合非常严格的标准。获胜者有机会被纳入实际的投资组合,总体设想是通过这种方式打造一只众包对冲基金。有科恩(Cohen)的资金支持,这个实验持续了好几年,但由于看不到获得可观回报的希望,他们失去了资金支持,最终倒闭。剩下的少数员工被罗宾汉(Robin Hood)公司录用。
看着这一切发生很令人难过,但真正让人痛心的是他们直接关闭了网站、优秀的论坛,放弃了一切。多年的在线资源一夜之间就被删除,就因为有人不想花一百美元来维持域名。
到目前为止,情况看起来不太乐观。
开源社区来救援
在 Quantopian 运营期间,开发进度相当缓慢。他们主要关注在线环境,而不是为本地使用提供尽可能好的回测器。其他一些令人烦恼的问题包括过于注重向后兼容性,这导致依赖项非常陈旧。
开源社区接手后,开发速度大大加快。出现了一些有意思的分支版本,但我个人会选择 Zipline-Reloaded。
它已更新到 Python、Pandas 等的最新版本,修复了漏洞,并且一直在积极维护。还有什么不喜欢的呢?
Zipline-Reloaded 是一个巨大的进步。它解决了 Quantopian 可能要好几年才能解决的问题。
Zipline 已死,Zipline-Reloaded 万岁!
我已经更新了《交易进化》这本书,以反映对这个库的转变以及所需的细微语法变化。如果你用的是 Kindle 版本,更新应该会自动推送。过去几个月购买了平装本的读者也应该收到了更新后的代码。不过这些变化很小,你通过阅读 Zipline-Reloaded 的文档(地址:Zipline — Zipline 3.0 docs)就能轻松掌握。
语法变化不大,但现在你可以使用 Python 3.9、Pandas 1.2.4,再次进入现代编程环境!Zipline-Reloaded 这个库是由斯特凡・扬森(Stefan Jansen)构建并维护的,他做得非常出色。他还更新了 Pyfolio、Empyrical 和 Alphalens 库。非常感谢,斯特凡!
所以,回答那个最常见的问题,Zipline 死了吗?并没有。它重获新生,变得更强大、更出色。
https://pypi.org/project/zipline-reloaded/
斯特凡・扬森(Stefan Jansen)的开源书籍: Machine Learning for Trading
===========================================================================
In the past year, that is by far the most common question I get. Now that Quantopian went the way of the Dodo, is Zipline dead? Should we switch to a different backtesting engine? The short answer is that the rumors of Zipline’s demise are exaggerated, but let’s take it from the start.
My 2019 book Trading Evolved focuses on teaching you how to use Python to backtest trading strategies. In that book, I use the Zipline library and provide plenty of source code and examples of how to use this. Zipline was made by a company called Quantopian, a company I had the privilege to get to know up close.
Quantopian built this backtesting library and made it available for free, including the source code. They also made a website where you could use a hosted version of this backtester, complete with free minute level data. They gave you the tools, the data and the computing power. It was hard not to love that idea. They also had one of the very best quant finance conferences, with a large event in New York every year and a few times in Singapore as well. I should know, I was a speaker at their events in both locations quite a few times.
They did ultimately fail, as a company. That is a crying shame and they will be sorely missed. The problem, in my view, is that they did not want to monetize the part that was their real strength. They had no interest in charging for online backtesting, or starting a quant focused brokerage arm, or other more obvious ways of seeing profit. They wanted to be a hedge fund.
The plan was to have competitions on their website, where anyone can submit their trading algos. These would have to adhere to very strict criteria in terms of risk, correlations, and a whole bunch of limitations. The winners would have a shot of being included in an actual, live portfolio and the general idea would be that a crowd sourced hedge fund would rise from this. With Cohen money to burn, this experiment went on for some years, but with no prospect of reaching meaningful returns, they lost their backing and folded the shop. The few people left standing were offered jobs with Robin Hood.
This was sad to watch, but what really painful was how they simply took down their site, their excellent discussion forum and just dropped everything. Years of online resources were just deleted overnight as someone didn’t feel like paying a hundred bucks to maintain the domains.
So far, it didn’t look great.
Open Source Community to the Rescue
The good news is this. When Zipline was abandoned, it didn’t die. It was reborn, stronger and better.
When Quantopian was running the show, development was rather slow. Their primary focus was on their online environment, rather than providing the best possible backtester for local usage. Among other somewhat annoying things were the focus on backwards compatibility, which lead to very outdated dependencies.
As the open source community took over, development started moving far quicker. There have been a few interesting forks spawned, but my own choice would be Zipline-Reloaded.
Updated to the latest versions of Python, Pandas etc., bugs fixed, actively maintained. What’s not to like?
Zipline-Reloaded is a huge leap forward. It has fixed issues that Quantopian would have taken years do get around to.
Zipline is dead, long live Zipline-Reloaded!
I have updated Trading Evolved to reflect the shift to this library and the minor syntax changes needed. If you have the Kindle version, that update should be automatically available. Anyone who bought the paperback in the past few months should also have gotten the updated code. The changes are rather minor though, and you can easily pick it up by reading the Reloaded documentation.
The syntax changes are minor, but now you work with Python 3.9, Pandas 1.2.4 and be in a modern world again! This library, Zipline-Reloaded, is built and maintained by Stefan Jansen, and he’s going a great job at it. He has also updated Pyfolio, Empyrical and Alphalens. Vielen Dank, Stefan!
So to answer that most common of questions, whether Zipline is dead. No. It’s reloaded and reborn stronger and better.
https://pypi.org/project/zipline-reloaded/