Backtrader中文筆記之Position(持倉情況)


Position on an asset is usually checked from within a Strategy with:

資產情況通常通過以下方式從策略內部進行檢查:

  • position (a property) or getposition(data=None, broker=None)

    Which will return the position on datas[0] of the strategy in the default broker provided by cerebro

  • 它將返回策略的數據[0]在大腦提供的默認券商【經紀人】中的位置
  • 通過self.getposition內的參數就可以拿到指定數據【也就是后續指定股票】的持倉情況

A position is simply the indication of:

持倉位置僅表示:

  • An asset is being held with size

  • 持有股票的數量大小
  • The average price is price

  • 持倉的平均價格

It serves as a status and can for example be used in deciding if an order has to be issued or not (example: long positions are only entered if no position is open)

它作為一種狀態,例如可用於決定是否必須發出訂單(例如:只有在沒有空頭頭寸時才輸入多頭頭寸)

 

Reference: Position

class backtrader.position.Position(size=0, price=0.0)

Keeps and updates the size and price of a position. The object has no relationship to any asset. It only keeps size and price.

保持並更新倉位的大小和價格。對象與任何資產都沒有關系。它只保留尺寸和價格。

Member Attributes:

成員屬性:

* size (int): current size of the position

* price (float): current price of the position

The Position instances can be tested using len(position) to see if size is not null

可以使用len(Position)測試Position實例,看看size是否不為null


免責聲明!

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



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