Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Pyalgotrade SMA编码澄清_Python_Pyalgotrade_Technical Indicator - Fatal编程技术网

Python Pyalgotrade SMA编码澄清

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

我已经开始学习和测试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 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]表示“几乎最后一个”,依此类推