2016-12-30 4 views
1

私はPyAlgoTradeの学習とテストを開始しました.SMAとRSIのような技術のコードの背後にあるロジックを理解するのは苦労しています。 私はself.info()関数が変数として受け取るデータフレームフィードを出力することを理解していますが、下に掲載されたコードの最後の行にあるSMAとRSIの後の[-1]の役割は何ですか?Pyalgotrade SMAコーディングの明確化

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])) 

答えて

0

負のインデックスは、単に配列の「後部」端から数えていることを意味します。

つまり、[-1]は配列の最後の要素を表し、[-2]は「ほぼ最後」などを表します。