Closed max0x7ba closed 1 month ago
Describe the current behavior rsi function in train_and_evaluate.ipynb calculation is incorrect by construction:
rsi
train_and_evaluate.ipynb
def rsi(price: 'pd.Series[pd.Float64Dtype]', period: float) -> 'pd.Series[pd.Float64Dtype]': r = price.diff() upside = np.minimum(r, 0).abs() downside = np.maximum(r, 0).abs() rs = upside.ewm(alpha=1 / period).mean() / downside.ewm(alpha=1 / period).mean() return 100*(1 - (1 + rs) ** -1)
In the code upside is actually the downside and vice versa. abs() applied without discrimination or good reason only masks the error in the calculation.
upside
abs()
Describe the expected behavior
One fix is:
upside = np.maximum(r, 0) downside = -np.minimum(r, 0)
or, simpler:
upside = r.clip(lower=0) downside = -r.clip(upper=0)
Fixed
Describe the current behavior
rsi
function intrain_and_evaluate.ipynb
calculation is incorrect by construction:In the code
upside
is actually the downside and vice versa.abs()
applied without discrimination or good reason only masks the error in the calculation.Describe the expected behavior
One fix is:
or, simpler: