psy没有在bt跟talib里,只能自己实现
class Psy(bt.Indicator):lines = ('psy',)params = (('period', 20),)def __init__(self):passdef next(self):if len(self.data) < self.p.period + 1:self.l.psy[0] = 0returndif = np.zeros((self.p.period))for i in range(-self.p.period + 1 , 1, 1):dif[i] = self.data[i] - self.data[i - 1]dif_count = np.sum(np.where(dif > 0, 1, 0))self.l.psy[0] = dif_count / self.p.period * 100
。
如果觉得《PSY 公式的 backtrader Indicator 实现》对你有帮助,请点赞、收藏,并留下你的观点哦!