Hello,
Is there a way to calculate WRSI n-days ago ?
I found this function
class Prev_N_RSI(CustomFactor):
"""
Remember to set the window length to N + what the window really is
If the desired lookback N is 2 days and the RSI window is 14 days,
Then set the window_length to 2+14=16
"""
inputs = [USEquityPricing.close]
# Default window length RSI window = 14 / N = 0
# Override this when instantiating the factor
window_length = 14
def compute(self, today, assets, out, closes):
# Below is just for readibility RSI length assumed to be 14 days
rsi_window_length = 14
diffs = np.diff(closes[0:rsi_window_length], axis=0)
ups = np.nanmean(np.clip(diffs, 0, np.inf), axis=0)
downs = abs(np.nanmean(np.clip(diffs, -np.inf, 0), axis=0))
out[:] = 100 - (100 / (1 + (ups / downs)))
But it does not calculate well the past RSI (n-days ago). The actual RSI is pretty close from RSI we can find on Finviz or softwares but the RSI 4 days ago for example is very different. See my post (last one) here for more details : https://www.quantopian.com/posts/coding-a-custom-indicator-rsi-ema
I believe it is because it is not Wilder's RSI but then how can we calculate a RSI n-days ago which is equivalent to "popular" (Finviz, Investing, softwares etc) RSI ?
I want to return stocks of which RSI 5 days ago (e.g.) was higher than actual RSI, which is around 50.
I am not looking to backtest for the moment, just to build a screener. Is it possible to do this in a notebook, just with a pipeline ? Using USEquityPricing.
Do you have any idea how can I do that ?
*Edit : I tried to do like in Prev_N_RSI function, that is putting 16 (14+2) for rsi_len for RSI 2 days ago, but it does not work very well.
I noticed RSI does not vary anymore from window_length=75-80.
But I'm glad the actual RSI is far better calculated than with the built-in function !