solved why Backtrader buy price is 0 解決交易成交價是0
作者:互联网
1. Yahoo finincal data
df0 = yf.download(ucode, date_start, date_end, auto_adjust = False )
用yfinance抓取指數數據。
2. Backtracker has $0 buy price after trade
def notify_trade( self , trade): if not trade.isclosed: return self .log( 'OPERATION PROFIT (%s) (%s) (%s days), %s, %.2f, %.0f, %.2f, %.2f' % ( self .inds[trade.data._name][ 'singal_in' ], self .inds[trade.data._name][ 'singal_out' ], trade.barlen, trade.data._name, trade.price, trade.size, trade.pnl, trade.pnlcomm))
notify_trade() 是顥示每筆已完成的交易(包含開倉和平倉)的成本價,賣出價,利潤,持倉天數。
但其中一筆交易的成本價是$0。
3. Backtrader open position
https://www.backtrader.com/docu/cerebro/cheat-on-open/cheat-on-open/
由於要避免後視鏡誤差,所以在觸發買入/賣出條件後,使用下一個bar的開盤價,作為交割價。
4. Drop empty / 0 open price
df0 = yf.download(ucode, date_start, date_end, auto_adjust=False) df0.replace(0, np.nan, inplace=True) df0.dropna(inplace=True) df0.drop_duplicates(keep=False, inplace=False)
注入數據前,先剔除空白/重覆的數據。
标签:%.,False,價是,self,df0,trade,solved,buy,open 来源: https://www.cnblogs.com/chenkuang/p/16493511.html