Hi, I was wondering if there is any way to screen a strategy on every single shares of the SP 500.
Just to be clear. I want to see if a mean reverting strategy that works well on the SP 500 could be applied to a basket of stocks instead than to the whole index. It would be interesting to see if there is a particular basket that contribute to the “mean revertingness” of SP 500 and isolate it.
Many thanks
Francesco
We could simulate profit generated by a strategy of each individual stock of a shares list.. but it would be tricky, depends of the strategy itself! and it would only be possible on the last 254 bars (history limitation of ProScreener).
If you could expose the strategy (or the probacktest code), I could lend an hand 🙂
Thank you Nicolas,
the strategies I had in mind are the one that we published on the SP 500
S&P 500 daily RSI(2) long short strategy
and
S&P 500 mean reverting strategy
Let me know if you think you can work something out of them and if I can do anything to help
Thank you!
Quick example of the first one converted into a screener:
a = 5
b = 20
cl = RSI[2]<a
cs = RSI[2]>100-a
if cl then
long=1
short=0
entrylong=close
endif
if cs then
long=0
short=1
entryshort=close
endif
if long and RSI[2]>100-(a+b) and close < open then
long=0
gain=(close-entrylong)+gain
//sell at market
endif
if short and RSI[2]<(a+b) then
short=0
gain=(entryshort-close)+gain
//exitshort at market
endif
screener[gain](gain)
Your a and b variables are optimized in ProBacktest, so I took dummy values for them. The gain is in points, not in money, depends of shares quantity you bought for each stock of course ..
Wait a minute, I think I made something wrong..
Hmmm, please review my code, I think it should be good now 🙂
a = 5
b = 20
cl = RSI[2]<a
cs = RSI[2]>100-a
if cl and long=0 then
long=1
short=0
entrylong=close
endif
if cs and short=0 then
long=0
short=1
entryshort=close
endif
if long and RSI[2]>100-(a+b) and close < open then
long=0
gain=(close-entrylong)+gain
//sell at market
endif
if short and RSI[2]<(a+b) then
short=0
gain=(entryshort-close)+gain
//exitshort at market
endif
screener[gain](gain)
Thank you Nicolas, the code is fine but I am not very confident with screeners. Let me understand, if I select “daily” screening the resultsa are computed on the last 2 years right?
Yes, beginning 254 bars ago from now.