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

posted @ 2020-09-18 11:47  就是想学习  阅读(4002)  评论(0编辑  收藏  举报