7.4 Fillers

2020-04-26  本文已影响0人  wanggs66

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

定义一个Filler

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

Where:

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

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:

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:

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:

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

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

上一篇 下一篇

猜你喜欢

热点阅读