Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Playing around with Bollinger Bands.

Editor's Note: This algo uses an early version of our API that is no longer fully supported. Please clone this algo if you would like to try Tjerk's code!

Most surprising to me is that my intention was that the algorithm would never have an abs(position) of over 100 shares but the output shows that the system places multiple consecutive opening and closing orders.

Can anyone explain the reason for this? Are orders executed asynchronously or is there a lag between between placing an order and the update of data.positions (or did I make a silly mistake)?

It also raises the question whether an order always succeeds? I guess it's a valid assumption during backtesting but it might be different once the platform supports live trading and ideally I'd like to use the same API.

3 responses

@Tjerk, thank you for the questions.

The best answer, I think, is to share our simulation code. To that end I've shared the source code of our transaction simulator. Shortly, we will be offering the entirety of Zipline, our backtester, under BSD-3. Until then, I hope this critical piece of the system will be enough to clarify the transaction simulation behavior.

How our simulator works

The prose description is that orders are placed asynchronously and queued inside our simulator. Orders are then compared to the flow of historical trades, and we simulate "transactions" to represent the filling of an algorithms orders.

  • Orders are filled asynchronously. If you place an order at minute=3, we start filling in minute=4. This is to avoid any look ahead bias.
  • Orders are treated as market orders with a "good 'til close" time to live. If an order is partially filled, we keep the remainder open for the rest of the market day. If an order is not filled by market close, the unfilled portion is canceled.
  • Our simulator runs with style=PARTIAL_VOLUME. This means that we calculate a price impact, based on the share of volume an order would take from the current bar.
  • We also limit the algorithm to no more than 25% of a given bar, to avoid expected discontinuities in the market response to a huge order.
  • Impact is treated symmetrically - long orders will push the price up, short orders will drive it down, but in equal measure based on the order amount.
  • Orders do not always succeed. If an order cannot be filled by the end of the day, the unfilled portion is canceled.
  • Algorithms cannot currently cancel orders.

Why open source

On a more philosophical note, we are open sourcing our backtester precisely because we want the behavior to be well scrutinized by the community. We think blackbox backtesting for investment algorithms is a scourge. There is a desperate need for standard backtesting, simply to provide coherent comparisons between algorithms and algorithm authors. Our goal is to make Zipline a common yardstick to compare many types of algorithms, whether developed on Quantopian, by individuals, or by firms. We chose the BSD license to make it very friendly and easy to reuse Zipline internally, in other commercial products, and other open source projects. We are also following in the footsteps of major opensource advances in data science, like Pandas/numpy/ipython.

A quick note on live trading

For a backtester to be at all accurate, it needs to be compared to the results from real trading.

We are working on providing not just simulation, but also live trading via Quantopian. We have a lot of work to do before that can be possible, but our vision is to provide a seamless transition from backtesting, to paper trading, to live trading. One of the most important benefits for users will be the aggregation of real life order and transaction data, which can then be used to test and improve the backtester and simulation itself.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

That is a great algorithm. It's going to take me a bit to wrap my head around the details.

I think one of the questions you're asking is "did these orders fill correctly, or is there a bug?" I don't know right now, but I'll dig into it. There are no open bugs in the order fill part of the backtester, but there must be some there! As we find them, we'll fix them. This is reason number 258 why we need to open source zipline so everyone who wants to can find and fix any bugs!

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Hi,

There has been some user interest in this algo, but the Quantopian API has changed a bit since it was first posted. I did some clean up and posted it here: https://www.quantopian.com/posts/bollinger-bands

thanks,
fawce