Backtrader中文筆記之Trade(交易)


Trade

Definition of a trade:

  • A Trade is open when the a position in a instrument goes from 0 to a size X which may positive/negative for long/short positions)

  • 當工具中的A倉位從0變為大小X時,交易是開放的的狀態,這可能是多頭/空頭因為持倉的正/負)
  • A Trade is closed when a position goes from X to 0.

  • 當倉位從X到0時,交易關閉

The followig two actions:

主要跟隨着兩個行為:

  • positive to negative

  • 正轉負
  • negative to positive

  • 負轉正

Are actually seen as:

  實際上被視為:
  1. A trade has been closed (position went to 0 from X)

  2. 交易已結束(頭寸從X變為0)
  3. A new trade has been open (position goes from 0 to Y)

  4. 一個新的交易已經打開(頭寸從0變為Y)

Trades are only informative and have no user callable methods.

交易只是可取的信息,沒有可調用的方法。

 

 

Reference: Trade

class backtrader.trade.Trade(data=None, tradeid=0, historyon=False, size=0, price=0.0, value=0.0, commission=0.0)

Keeps track of the life of an trade: size, price, commission (and value?)

跟蹤交易的生命周期:規模、價格、佣金(和價值?)

An trade starts at 0 can be increased and reduced and can be considered closed if it goes back to 0.

一次交易從0可以增加或者減少,再回到0,可以被視為結束。

The trade can be long (positive size) or short (negative size)

交易可以是多頭(多單),空頭(空單)

An trade is not meant to be reversed (no support in the logic for it)

交易不是要逆轉的(在邏輯上沒有支持)

Member Attributes:

  • ref: unique trade identifier

  • 唯一的交易標識符
  • status (int): one of Created, Open, Closed

  • 交易的狀態0,1,2
  • tradeid: grouping tradeid passed to orders during creation The default in orders is 0

  • 分組在創建期間傳遞給訂單的tradeid訂單中的默認值為0
  • size (int): current size of the trade

  • 當前的交易數量,只有在Open的時候,能看到
  • price (float): current price of the trade

  • 交易對的開盤價,計算單筆利潤的時候可以用到
  • value (float): current value of the trade

  • commission (float): current accumulated commission

  • pnl (float): current profit and loss of the trade (gross pnl)

  • pnl(浮動):交易當期損益(總pnl)
  • pnlcomm (float): current profit and loss of the trade minus commission (net pnl)

  • isclosed (bool): records if the last update closed (set size to null the trade

  • isclosed(bool):記錄上次更新是否關閉(將size設置為空交易)所以關閉的時候,無法讀取到size
  • isopen (bool): records if any update has opened the trade

  • isopen(bool):記錄是否有任何更新打開交易,為isclosed的相反參數,表示沒有交易對的情況
  • justopened (bool): if the trade was just opened

  • justopened(bool):如果交易剛剛開始
  • baropen (int): bar in which this trade was opened

  • baropen (int):這比交易開始的bar
  • dtopen (float): float coded datetime in which the trade was opened

    • Use method open_datetime to get a Python datetime.datetime or use the platform provided num2date method
  • barclose (int): bar in which this trade was closed

  • dtclose (float): float coded datetime in which the trade was closed

    • Use method close_datetime to get a Python datetime.datetime or use the platform provided num2date method
  • barlen (int): number of bars this trade was open

  • historyon (bool): whether history has to be recorded

  • history (list): holds a list updated with each “update” event containing the resulting status and parameters used in the update

    The first entry in the history is the Opening Event The last entry in the history is the Closing Event


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM