@@ -759,17 +759,22 @@ def _get_kdj_default(self):
759759 self ['kdjd' ] = self ['kdjd_{}' .format (self .KDJ_WINDOW )]
760760 self ['kdjj' ] = self ['kdjj_{}' .format (self .KDJ_WINDOW )]
761761
762- def _get_cr (self , window = 26 ):
762+ def _get_cr (self , windows = None ):
763763 """ Energy Index (Intermediate Willingness Index)
764764
765765 https://support.futunn.com/en/topic167/?lang=en-us
766766 Use the relationship between the highest price, the lowest price and
767767 yesterday's middle price to reflect the market's willingness to buy
768768 and sell.
769769
770- :param window : window of the moving sum
770+ :param windows : window of the moving sum
771771 :return: None
772772 """
773+ if windows is None :
774+ window = 26
775+ else :
776+ window = self .get_int_positive (windows )
777+
773778 middle = self ._tp ()
774779 last_middle = self ._shift (middle , - 1 )
775780 ym = self ._shift (middle , - 1 )
@@ -779,10 +784,22 @@ def _get_cr(self, window=26):
779784 p2_m = pd .concat ((last_middle , low ), axis = 1 ).min (axis = 1 )
780785 p1 = self ._mov_sum (high - p1_m , window )
781786 p2 = self ._mov_sum (ym - p2_m , window )
782- self ['cr' ] = cr = p1 / p2 * 100
783- self ['cr-ma1' ] = self ._shifted_cr_sma (cr , self .CR_MA1 )
784- self ['cr-ma2' ] = self ._shifted_cr_sma (cr , self .CR_MA2 )
785- self ['cr-ma3' ] = self ._shifted_cr_sma (cr , self .CR_MA3 )
787+
788+ if windows is None :
789+ cr = 'cr'
790+ cr_ma1 = 'cr-ma1'
791+ cr_ma2 = 'cr-ma2'
792+ cr_ma3 = 'cr-ma3'
793+ else :
794+ cr = 'cr_{}' .format (window )
795+ cr_ma1 = 'cr_{}-ma1' .format (window )
796+ cr_ma2 = 'cr_{}-ma2' .format (window )
797+ cr_ma3 = 'cr_{}-ma3' .format (window )
798+
799+ self [cr ] = cr = p1 / p2 * 100
800+ self [cr_ma1 ] = self ._shifted_cr_sma (cr , self .CR_MA1 )
801+ self [cr_ma2 ] = self ._shifted_cr_sma (cr , self .CR_MA2 )
802+ self [cr_ma3 ] = self ._shifted_cr_sma (cr , self .CR_MA3 )
786803
787804 def _shifted_cr_sma (self , cr , window ):
788805 cr_sma = self ._sma (cr , window )
@@ -1108,7 +1125,10 @@ def _get_kama(self, column, windows, fasts=None, slows=None):
11081125
11091126 # start with simple moving average
11101127 kama = self ._sma (col , window )
1111- last_kama = kama .iloc [window - 1 ]
1128+ if len (kama ) >= window :
1129+ last_kama = kama .iloc [window - 1 ]
1130+ else :
1131+ last_kama = 0.0
11121132 for i in range (window , len (kama )):
11131133 cur = smoothing .iloc [i ] * (col .iloc [i ] - last_kama ) + last_kama
11141134 kama .iloc [i ] = cur
0 commit comments