Remove redundant loss.replace, add constants for magic numbers, document threading safety

This commit is contained in:
Justin Oros
2026-02-04 16:54:13 -07:00
parent 6c878c4e63
commit a35e6b6d8e
2 changed files with 17 additions and 2 deletions
-1
View File
@@ -10,7 +10,6 @@ def rsi(data, window=14):
delta = data.diff()
gain = (delta.where(delta > 0, 0)).rolling(window=window).mean()
loss = (-delta.where(delta < 0, 0)).rolling(window=window).mean()
loss = loss.replace(0, 1e-10)
loss = loss.clip(lower=1e-10)
rs = gain / loss
rsi_val = 100 - (100 / (1 + rs))