Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Developing some ideas...

This post will be updated every week using the knowledge we gain during our Investment-Seminar at University...

The first thing is a simple backtest of investing 50% in the Amazon stock (other 50% are cash) against the overall market between 01/02/12 and 08/31/17. Simple stuff but it will become more complex.

23 responses

Our next task was to create a MA cross-over strategy. I choose the EMA30 and the EMA100 of the Amazon stock for that. If the EMA100<EMA30 go long and go cash otherwise .I also ran a backtest with a long-short strategy but the results were worse. The backtest is attached. I would recommend some tips improve the code.

Now we had to program some trading signals. My task was to create an algo using the ADX and DI indicators. The backtest is attached. I used again the Amazon stock as the benchmark.
As you can see, I mad use of the talib library with its indicators. So maybe I did some mistakes using it. For any help or improvement proposal, I would be thankful.

Hey guys,
my next task was to rebuild a squeeze momentum indicator. Here I had to look if the market has entered a squeeze (Bollinger Bands are within the Keltner Channel (I used both with a timeperiod of 20 days and sma setup). To determine the trading direction I used the DI-indicators. The backtest is attached. I tested this with the Mc Donald's stock and the stock is also the benchmark. As before, I used the Talib library for most of the calculations.
For any help or improvement proposal, I would be thankful.

Our next task was to normalize the returns of our investment with the returns of the market (S&P500). Therefore we have to calculate the beta of our tradingalgo with the market. The code is nearly the same as before. Unfortunately I was not able to calculate it, so I choose to calculated the beta (last 30 days) for the underlying stock (McDonald's). The code is attached. For any help how I can calculate the beta of my investment for a specific duration, I would be very thankful.

I corrected some mistakes I did in my last code and also implemented a new indicator (ADX) to the code. It changed the results a bit.

I build a code using the RSI(14) indicator to get used to the Pipeline universe. But it's still kind of a black hole for me. The code is based on the code of the pipeline tutorial and the next step is to combine the code with a second indicator and also weight the stocks in the portfolio.

Consider also then some of GK's multi-factor long-short equity w/ RSI-based short_term_reversal risk factor nullification and DW's mentioned there.

As I mentioned in the last post, I want to further improve this code. The first thing I did:
I changed the code above a little bit and introduced an strict ristriction of the max number of the stocks the algo invests (10 stocks with the highest and lowest RSI). So it will invest in max 20 stocks (I will further try what is the best number).
But unfortunately was not able so for to combine the code with another indicator. I tried it with the EMA-based one. I will post this code also. For any help I would be very thankful

@Blue Seahawk: thank you for your hint! I will have a look at it

here is the code I mentioned above

Finally I mad the code running. Additionally to the RSI, I implemented an EWMA based indicator using the percentage difference between the 10 and the 30 day average. I also ranked the stock with the help of both indicators and invested in 15 stocks long and in 15 stocks short. If you have some ideas how I can improve the code I would be very thankful.

Weights proportional to rsi and trade info while tracking the two lowest pnl

@Blue Seahawk: thank you very much for that. It's a nice improvement for the algorithm. I was also thinking about implementing a weighting like that into the code as a next step. :)

This is a code I am currently also working on. With just one stock it is running by using the talib library, but when I tried to implement it with Pipeline to dynamically choose the stocks but it didn't run and give me some error messages I don't understand actually. I am a newbie with pipeline and so far I didn't have an Intuition how to use pipeline correctly. With this code I want to choose stocks where the BollingerBands are within the KeltnerChannel so that they might brake out because they are squeezed. As an additional momentum indicator I choose a ADX above 25 and to determine the direction of the trade I used a comparison of the absolut value of the Directional Indicators (go long if |DI+| > |DI-| and vice versa for short). At the beginning of the code I use some helper functions to build some costum factors. It would be great if you maybe have some ideas how to fix the code so that it is working. Thanks in advance.

The latest code... I adapted the improvements into the RSI/EMA code to calculate RSI-weighted long/short positions.

Hey you resolved that. And higher returns.

Trade Info and tracking the 5 lowest PnL

Hey. Actually the results are the same for the codes. Or did I do something wrong...
I will post the 2 backtests I did.
(here: my code with investing in just 20 stocks (10 long - 10 short)

the second one with your code

Yeah, the change on line 136 for example wouldn't be read because of my return on line 122.

Try CompareIt from https://www.grigsoft.com/. Essential and one of the few pieces of software I really couldn't do without. Search & Replace is another. Also while I'm at it, I like Notepad++. There's one other thing I use all the time but it isn't available to mortals, it is too old, an ancient version of Paintshop Pro, very lightweight/fast with just basics that I use for screenshots.

Ok. But what is the difference if the results are the same? Maybe you can explain it to me, because I don't see a difference...

This is a pipeline code combining the Bollinger Bands with a SMA. It was my first try for a running code using pipeline. Maybe it helps someone else.

This code als uses the EMI/RSI indication as before. We had to implement some fundamentals, so I choosed the P/E ratio as an additional indicator (stocks with the highest and lowest P/E ratio because they are maybe over- or undervalued). Additionally I changed the base universe to the QTradableStocksUS and filtered out the 2000 most liquid stocks using the AvgDollarVolume of the last 10 trading days. If you have some suggestions how I can improve the code further, they are more than welcome.

This is the latest code so far. I added an additional filter regarding the book-yield ratio from all stock of the QTradablestocksUS universe. And then choosing the ones with the lowest and highest ratio. The rest of the code is the same as before (exception: using data of morningstar instead of Fundamentals to make the algo running faster). If you have some ideas how I can improve the code I would be very thankful.

For this week I tried to change my Code and implement another signal instead of the crossing averages. But unfortunately this code is not working well. So I will try to fix this.