numpy - Slow Stochastic Implementation in Python Pandas -


i new pandas , need function calculating slow stochastic. think should possible without difficulty not familiar advanced apis in pandas.

my data frame contains, 'open', 'high', 'low' , 'close' prices , indexed on dates. information should enough calculate slow stochastic.

following formula calculating slow stochastic: %k = 100[(c - l14)/(h14 - l14)]   c = recent closing price  l14 = low of 14 previous trading sessions  h14 = highest price traded during same 14-day period.  %d = 3-period moving average of %k  

you can rolling_* family of functions.

e.g., 100[(c - l14)/(h14 - l14)] can found by:

import pandas pd  l, h = pd.rolling_min(c, 4), pd.rolling_max(c, 4) k = 100 * (c - l) / (h - l)  

and rolling mean can found by:

pd.rolling_mean(k, 3) 

moreover, if you're stuff, can check out pandas & econometrics.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -