0

我刚刚开始使用 pyalgotrade,使用我在网上获得的修改后的示例代码,该代码使用VWAP(交易量调整平均值)计算,以及软件自己获取雅虎历史数据的方法,我注意到输出VWAP计算似乎是错误的雅虎调整其音量,而软件工具假定音量未调整。

这是代码。注意执行后生成的图表,并注意VWAP计算的中断。我将 Nasdaq 的数据与它加载的 yahoos 进行了比较,并注意到 Yahoo 的音量已经调整,尽管它没有说是调整的。我确实将标志设置为使用调整后的数据,但软件不会将其用于 VWAP 计算,因为我相信它假定交易量未调整。

如果有人能确定一种我可以纠正问题的方法,我将不胜感激。我可以用来覆盖其自己的 VWAP 计算的方法会很好。另外我也不知道如何向提供者报告错误,因为我是新手。

 from pyalgotrade import strategy
 from pyalgotrade.barfeed import yahoofeed
 from pyalgotrade import plotter
 from pyalgotrade.tools import yahoofinance
 from pyalgotrade.technical import vwap  #Volume Weighted Average Price

 import os

 class MyStrategy(strategy.BacktestingStrategy):
def __init__(self, feed, instrument, vwapWindowSize):



    strategy.BacktestingStrategy.__init__(self, feed)
    self.__instrument = instrument
    self.setUseAdjustedValues(True)     #   use adjusted close

    self.__vwap = vwap.VWAP(feed[instrument], vwapWindowSize )           # ,useTypicalPrice=True)

def getVWAPDS(self):

  return self.__vwap

def onBars(self, bars):

    vwap = self.__vwap[-1]
    if vwap == None:
        return

    shares = self.getBroker().getShares(self.__instrument)

                   #priceAdj = bars[self.__instrument].getAdjClose()
    price = bars[self.__instrument].getClose()
    notional = shares * price
    if price < vwap * 0.995 and notional > 0:
        self.marketOrder(self.__instrument, -100)
    elif price > vwap * 1.005 and notional < 1000000:
        self.marketOrder(self.__instrument, 100) 


def main(plot):
instrument = "aapl"
vwapWindowSize = 5

# Download the bars.
feed = yahoofinance.build_feed([instrument], 2011, 2016, "./data",)

myStrategy = MyStrategy(feed, instrument, vwapWindowSize)

if plot:
   plt = plotter.StrategyPlotter(myStrategy, True, False, True)
plt.getInstrumentSubplot(instrument).addDataSeries("vwap", myStrategy.getVWAPDS())

myStrategy.run()
print "Result: %.2f" % myStrategy.getResult()

if plot:
    plt.plot()

if __name__ == "__main__":
main(True)
4

1 回答 1

0

它将在下一个版本中修复。感谢您报告此事。

于 2016-03-06T01:49:28.387 回答