Skip to content

Instantly share code, notes, and snippets.

@jsrimr
Created September 6, 2019 04:52
Show Gist options
  • Save jsrimr/0c5da0cd3637a148d6c02f58c79a5eb2 to your computer and use it in GitHub Desktop.
Save jsrimr/0c5da0cd3637a148d6c02f58c79a5eb2 to your computer and use it in GitHub Desktop.
def fnRSI(m_Df, m_N=15):
m_Df = m_Df.c
U = np.where(m_Df.diff(1) > 0, m_Df.diff(1), 0)
D = np.where(m_Df.diff(1) < 0, m_Df.diff(1) *(-1), 0)
AU = pd.DataFrame(U).rolling( window=m_N, min_periods=m_N).mean()
AD = pd.DataFrame(D).rolling( window=m_N, min_periods=m_N).mean()
RSI = AU.div(AD+AU)[0].mean()
return RSI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment