各バーで pyalgotrade を使用する場合、株式の平均約定価格が必要です... getAvgFillPrice 関数のコールアウトを使用して同じ値を取得する方法がわかりません。これは、次の取引に参加するかどうかを決定するのに役立ちます. どんな助けでも大歓迎です。私は次のコードを試しました:
from pyalgotrade.broker import backtesting
from pyalgotrade import broker
from pyalgotrade import plotter
from pyalgotrade.broker import Order
class Str1(strategy.BacktestingStrategy):
def __init__(self, feed, instrument, qty):
strategy.BacktestingStrategy.__init__(self,feed,1000000)
self.__qty = qty
self.__instrument = instrument
self.__priceDS = feed[instrument].getPriceDataSeries()
self.__lowDS = feed[instrument].getLowDataSeries()
self.__highDS = feed[instrument].getLowDataSeries()
def onBars(self, bars):
shares = self.getBroker().getShares(self.__instrument)
avg_price = Order.getAvgFillPrice(self.__instrument)
price = bars[self.__instrument].getPrice()
bar = bars[self.__instrument]
print(avg_price)
しかし、次のエラーが表示されます。
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.3\helpers\pydev\pydevd.py", line 1664, in <module>
main()
File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.3\helpers\pydev\pydevd.py", line 1658, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.3\helpers\pydev\pydevd.py", line 1068, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.3\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "E:/pyalgotrader/new.py", line 109, in <module>
myStrategy.run()
File "E:\pyalgotrader\venv\lib\site-packages\pyalgotrade\strategy\__init__.py", line 512, in run
self.__dispatcher.run()
File "E:\pyalgotrader\venv\lib\site-packages\pyalgotrade\dispatcher.py", line 109, in run
eof, eventsDispatched = self.__dispatch()
File "E:\pyalgotrader\venv\lib\site-packages\pyalgotrade\dispatcher.py", line 97, in __dispatch
if self.__dispatchSubject(subject, smallestDateTime):
File "E:\pyalgotrader\venv\lib\site-packages\pyalgotrade\dispatcher.py", line 75, in __dispatchSubject
ret = subject.dispatch() is True
File "E:\pyalgotrader\venv\lib\site-packages\pyalgotrade\feed\__init__.py", line 108, in dispatch
self.__event.emit(dateTime, values)
File "E:\pyalgotrader\venv\lib\site-packages\pyalgotrade\observer.py", line 61, in emit
handler(*args, **kwargs)
File "E:\pyalgotrader\venv\lib\site-packages\pyalgotrade\strategy\__init__.py", line 505, in __onBars
self.onBars(bars)
File "E:/pyalgotrader/new.py", line 38, in onBars
avg_price = Order.getAvgFillPrice(self.__instrument)
File "E:\pyalgotrader\venv\lib\site-packages\pyalgotrade\broker\__init__.py", line 275, in getAvgFillPrice
return self.__avgFillPrice
AttributeError: 'str' object has no attribute '_Order__avgFillPrice'
この点でどんな助けも感謝します...