美文网首页
7.4 Fillers

7.4 Fillers

作者: wanggs66 | 来源:发表于2020-04-26 22:25 被阅读0次

Volume Fillers 可以设定成交量中的多少数量用于订单的匹配。

定义一个Filler

class MyFiller(object):
    def __call__(self, order, price, ago):
       pass

Where:

  • order is the order which is going to be executed

This object gives access to the data object which is the target of the operation, creation sizes/prices, execution prices/sizes/remaining sizes and other details

  • price at which the order is going to be executed

  • ago is the index to the data in the order in which to look for the volume and price elements

In almost all cases this will be 0 (current point in time) but in a corner case to cover Close orders this may be -1

To for example access the bar volume do:

barvolume = order.data.volume[ago]

Adding a Filler to the broker

import backtrader as bt

cerebro = Cerebro()
cerebro.broker.set_filler(bt.broker.fillers.FixedSize())

Create subclassed of BrokerBack

import backtrader as bt

cerebro = Cerebro()
filler = bt.broker.fillers.FixedSize()
newbroker = bt.broker.BrokerBack(filler=filler)
cerebro.broker = newbroker

Reference

class backtrader.fillers.FixedSize()
Returns the execution size for a given order using a percentage of the volume in a bar.

This percentage is set with the parameter perc

Params:

  • size (default: None) maximum size to be executed. The actual volume of the bar at execution time is also a limit if smaller than the size

If the value of this parameter evaluates to False, the entire volume of the bar will be used to match the order

class backtrader.fillers.FixedBarPerc()
Returns the execution size for a given order using a percentage of the volume in a bar.

This percentage is set with the parameter perc

Params:

  • perc (default: 100.0) (valied values: 0.0 - 100.0)

Percentage of the volume bar to use to execute an order

class backtrader.fillers.BarPointPerc()
Returns the execution size for a given order. The volume will be distributed uniformly in the range high-low using minmov to partition.

From the allocated volume for the given price, the perc percentage will be used

Params:

  • minmov (default: 0.01)

Minimum price movement. Used to partition the range high-low to proportionally distribute the volume amongst possible prices

  • perc (default: 100.0) (valied values: 0.0 - 100.0)

Percentage of the volume allocated to the order execution price to use for matching

相关文章

网友评论

      本文标题:7.4 Fillers

      本文链接:https://www.haomeiwen.com/subject/gssswhtx.html