【Python 量化交易】CCI技术指标

CCI Source Code

class CCIIndicator(object):
    def __init__(self,
                 low: pd.Series,
                 high: pd.Series,
                 close: pd.Series,
                 n: int = 14,
                 ):
        self._low = low.copy()
        self._high = high.copy()
        self._close = close.copy()
        self._N = n
        self._run()
        pass

    def _run(self):
        self.TP = (self._high + self._low + self._close)/3
        self.MA = self.TP.rolling(window=self._N).mean()
        self.MD = self.TP.rolling(window=self._N).apply(lambda x: abs(x-x.mean()).mean(), raw=False)
        self.cci = (self.TP - self.MA) / (0.015 * self.MD)

    def data(self):
        return pd.Series(self.cci, name='cci')

【Python 量化交易】CCI技术指标_第1张图片
欢迎关注~ SandQuant 专注于全球金融数据和量化投资策略

你可能感兴趣的:(SandQuant,沙矿量化,python,开发语言,后端)