Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Algor for the RSI (Need Help)

Dear Community,
I tried to built an algo which is buying stocks when the RSI is showing an oversold market and selling when its overbought.
Please read my code an help me to fix the problems which remain.
The Algo is not buying because of some reason...
I also have a problem with some commands (line 20, 26, 45).
Kind regards and thanks for advice...

here you have some further information for my task..

  1. Strategy: Invest 100% if a signal is bullish; 0% if bearish. Bullish: fast technical indicator (TI) >=slow TI.
    Bearish: when not bullish.
    Exception: max investment on Mondays: 50%.
  2. Tis are assigned individually. If you have not been assigned a TI, contact us by email. You can select TI parameters yourself (we recommend defaults from stockcharts.com. There you can also find calculation formulas for TIs).
  3. Underlying stock: SPY (its an S&P 500 ETF). NB: This was not discussed in class.
  4. Investment timeframe: Jan 1, 2010 - Apr 1, 2017.
  5. Initial investment: $1,000,000.
  6. Calculate the signal 1 minute before the market close (c-1). Invest at market close (c) on a daily basis.
  7. Create a Quantopian account and see if someone may have implemented a similar algorithm already. You can clone that algo and use it as a starting point.
  8. You should publish your algo as a new forum post in the Quantopian board with a one sentence description of your investment strategy.
  9. NB: Most likely the returns of your strategy will be negative. It is OK - the purpose is to validate your ability to take part in the seminar.
4 responses

Why do you put them in 5 different functions? Are you shorting when the RSI goes above 80, or just closing the position? Also are you going to sell half the portfolio every monday? I am going to work on it, and see what i can come up with.

I think your real problem, is there won't be a trigger, unless the RSI reaches below 20. The market was pretty good from 2010 on, and might not hit that low.

I use one function for every day of the week.
Yes when the market is overbought (RSI over 80) i'm selling.
I wanted to buy only half the portfolio on mondays when the I get a buying signal. Did I accidentally mix up the buying and selling orders? wups..
thanks for your afford :)

I used a getdatetime to check if it was monday, that will remove a lot of your functions.
Are you shorting the spy when the RSI is above 80 or closing the position? Because that is a big difference.

Does TI stand for technical indicator? And what are your fast and slow TIs?

I moved oversold to 35, just to get a signal. It will invest half the port if it is monday, and 100% if it is not monday. It will close the position when it is above 80. I don't get a reading below 20 very often.

the getdatetime function looks pretty good.. thanks for that.

I don't short the position if the RSI is above 80 but that would be a nice and feasible idea.. maybe we could think about that

to be honest I don't know what to do with the technical indicators.. I'm a rookie in quantopian but TI stands for technical indicator.

to move the the mark to 35 is a clever idea to get a signal.. I thought about that too..

so what is left.. the most important thing for me is to deal with the TI...maybe you have ideas.. I work on it, too..
thanks in advance