Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
New to Quant, looking for help

I have attached the backtest of a bollinger band algorithm I started. If you clone the algorithm, you will see that I set it to buy when below the lower band, and short when above the upper. I then told it to exit the positions when between the bands. Or at least that's what I was trying to do. If I comment out the second elif that exits when between the bands, the returns are 50%, but with it the returns are 5%. I have several questions about this.

  1. Why do the returns drop so significantly? Is it because I am holding the positions for a much shorter amount of time?

  2. When I set the order_target_percent() to 0, does that sell the stock of JJ I have, or does it hold on to the stock?

  3. Without the second elif statement, the long or short positions would be kept until the price went above the upper or below the lower bands respectively, right? In other words, if I were to remove the second elif statement and run the algo, when it goes long on the stock it will hold that position until the price rises above the upper band, right? If this is the case, does the order_target_percent() function sell the stock as fast as possible and then pick up the short position immediately after?

  4. Is there anyone that would be willing to meet either in person (Houston, Texas) or virtually to talk about different algorithms, how to improve them, talk about the quantopian platform, or just be available for questions in general?

5 responses

Since I couldn't get the full backtest to complete, I have pasted my code from the IDE for a potfolio optimization algorithm in a cell of the attached notebook. I would love feedback on this too, if anyone has some time. I know I am new, but I am serious about learning as much as possible about technical analysis and algorithmic trading.

One last question: How does one go about actually investing using quantopian? I understand you can enter the contest and pit your algo against others and the best algo wins $5000, but how do I set up an algorithm to trade with my own money without entering the contest?

@Matthew Carlin re: "How does one go about actually investing using quantopian?"

The short answer is, as of Aug 22, 2017, Quantopian doesn't support live trading. This can be a bit confusing when looking through the forum posts since there are a lot of references to live trading before that date.

I personally am using IBridgePy and trade through an Interactive Brokers account. I use the Quantopian platform for backtesting and the associated Pyfolio integration for results analysis and of course the forums here are a great source of help/inspiration. However, my actual live trading is done in the cloud on an Amazon EC2 instance running Linux Ubuntu / IBridgePy / IB Gateway. The BIGGEST issue (though there are many others close behind) is getting data. I tried using data from Interactive Brokers but now use a third party called Intrinio for pricing and a bit of fundamental data. The algos often don't port perfectly but one can literally copy and paste from a Quantopian algo.

Take a look at these posts for some ideas

https://www.quantopian.com/posts/in-light-of-quantopian-shutting-down-live-trading-what-would-be-the-alternative-option
https://www.quantopian.com/posts/questionnaire-for-quantopian-live-brokerage-traders

Good luck

@Dan
Thanks for the detailed post. Did you rewrite pipeline and order_optimal?

I don't use either pipeline or order_optimal_portfolio in my live trading algos. Just use the basics which are supported by IBridgePy.

Pipeline, while a convenient way to get fundamental data on Quantopian, is primarily a tool to speed up backtests by pre-fetching data. For live trading this isn't really possible (can't pre-fetch future data though that could be very profitable). The bigger issue is how to source fundamental data when trading live. As mentioned in the previous post I use Intrinio and make HTTP calls in the code. Very simple. A single line pandas 'read_csv' method (see https://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html) can grab a bunch of data and put it into a dataframe.

I would like to use 'order_optimal_portfolio' but I don't.

I actually run a universe screen in a Quantopian notebook (eg Q3000US then some filters along with the sector info) and cut and paste results to a CSV file at the beginning of each month. My live algo reads this file, fetches live price, volume, and a little bit of fundamental data for those securities, and then orders accordingly.

Thanks Dan for the detailed explanation!