我已经开始学习和测试PyAlgoTrade,并且很难理解像SMA和RSI这样的技术代码背后的逻辑。 我明白自我信息()函数打印出它作为变量的数据帧提要,但是,在下面发布的代码的最后一行中,在SMA和RSI之后的[-1]扮演什么角色?在
from pyalgotrade import strategy
from pyalgotrade.barfeed import yahoofeed
from pyalgotrade.technical import ma
from pyalgotrade.technical import rsi
class MyStrategy(strategy.BacktestingStrategy):
def __init__(self, feed, instrument):
strategy.BacktestingStrategy.__init__(self, feed)
self.__rsi = rsi.RSI(feed[instrument].getCloseDataSeries(), 14)
self.__sma = ma.SMA(self.__rsi, 15)
self.__instrument = instrument
def onBars(self, bars):
bar = bars[self.__instrument]
self.info("%s %s %s" %(bar.getClose(), self.__rsi[-1], self.__sma[-1]))
负索引的意思是:从数组的“后端”开始计数。在
换句话说,[-1]表示数组中的最后一个元素,[-2]表示“几乎最后一个”,依此类推。在
相关问题 更多 >
编程相关推荐