Python Pyalgotrade SMA编码澄清
我已经开始学习和测试PyAlgoTrade,很难理解一些技术(如SMA和RSI)代码背后的逻辑。 我知道self.info()函数会输出它作为变量的数据帧提要,但是,下面代码最后一行SMA和RSI后面的[-1]的作用是什么Python Pyalgotrade SMA编码澄清,python,pyalgotrade,technical-indicator,Python,Pyalgotrade,Technical Indicator,我已经开始学习和测试PyAlgoTrade,很难理解一些技术(如SMA和RSI)代码背后的逻辑。 我知道self.info()函数会输出它作为变量的数据帧提要,但是,下面代码最后一行SMA和RSI后面的[-1]的作用是什么 from pyalgotrade import strategy from pyalgotrade.barfeed import yahoofeed from pyalgotrade.technical import ma from pyalgotrade.technical
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]表示“几乎最后一个”,依此类推。负索引的意思是:从数组的“后端”开始计数 换句话说,[-1]表示数组中的最后一个元素,[-2]表示“几乎最后一个”,依此类推