GitHub 中的問題實際上是在推動文檔部分的完成,或者説明我瞭解 backtrader 是否具有我從最初時刻就設想的易用性和靈活性以及在此過程中做出的決定。
在本例中為問題 #9。
這個問題最終似乎可以歸結為:
- 最終使用者是否可以輕鬆地擴展現有機制,以 lines 的形式添加額外的資訊,這些資訊會傳遞到其他現有的價格資訊點,如 
open、high等? 
據我所知,問題的答案是:是的
海報似乎有以下要求(來自第6期):
-  
正在解析為 CSV 格式的數據來源
 -  
用於
GenericCSVData載入資訊此通用 csv 支援是為回應此問題#6 而開發的
 -  
一個額外的欄位,顯然包含需要沿著解析的CSV數據傳遞的P / E資訊
 
讓我們以 CSV Data Feed 開發和通用 CSV Data Feed 示例帖子為基礎。
步驟:
-  
假設在解析的CSV數據中設置了P / E資訊
 -  
用作
GenericCSVData基類 -  
擴展存在 lines (open/high/low/close/volumen/openinterest)
pe -  
添加參數讓調用方確定 P/E 資訊的欄位置
 
結果:
from backtrader.feeds import GenericCSVData
class GenericCSV_PE(GenericCSVData):
    # Add a 'pe' line to the inherited ones from the base class
    lines = ('pe',)
    # openinterest in GenericCSVData has index 7 ... add 1
    # add the parameter to the parameters inherited from the base class
    params = (('pe', 8),)
工作已經完成...
稍後,在策略中使用此 data feed :
import backtrader as bt
....
class MyStrategy(bt.Strategy):
    ...
    def next(self):
        if self.data.close > 2000 and self.data.pe < 12:
            # TORA TORA TORA --- Get off this market
            self.sell(stake=1000000, price=0.01, exectype=Order.Limit)
    ...
繪製額外的市盈率 line
顯然,在data feed中沒有對額外line的自動繪圖支援。
最好的選擇是在那個 line 上做一個SimpleMovingAverage,並將其繪製在一個單獨的軸上:
import backtrader as bt
import backtrader.indicators as btind
....
class MyStrategy(bt.Strategy):
    def __init__(self):
        # The indicator autoregisters and will plot even if no obvious
        # reference is kept to it in the class
        btind.SMA(self.data.pe, period=1, subplot=False)
    ...
    def next(self):
        if self.data.close > 2000 and self.data.pe < 12:
            # TORA TORA TORA --- Get off this market
            self.sell(stake=1000000, price=0.01, exectype=Order.Limit)
    ...