7.1 Broker

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

class backtrader.brokers.BackBroker()

Broker Simulator

The simulation supports different order types, checking a submitted order cash requirements against current cash, keeping track of cash and value for each iteration of cerebro and keeping the current position on different datas.

cash is adjusted on each iteration for instruments like futures for

which a price change implies in real brokers the addition/substracion of
cash.

Change the broker and params

Params:

A callable with signature: callable(order, price, ago)

Please check the Order documentation and reference for things available inside an Order instance

In order to get the bar volume (for example) do: volume = order.data.voluume[ago]

The callable must return the executed size (a value >= 0)

The callable may of course be an object with call matching the aforementioned signature

Note:

Note: if slip_perc is non zero, it takes precendence over this.

This also applies to some of the other executions, because the logic tries to detect if the opening price would match the requested price/execution type when moving to a new bar.

If True the broker will offer a match by capping slippage at high/low prices in case they would be exceeded. True情况下只要是不超过high、low经过滑点调整后的价格都可执行

If False the broker will not match the order with the current prices and will try execution during the next iteration。False 情形下,如果滑点调整后的价格超过high/low则无法执行

Limit orders, given the exact match price requested, will be matched even if slip_match is False.

This option controls that behavior.

If True, then Limit orders will be matched by capping prices to the limit / high/low prices 如果为True,可以在high、low经slippage调整后的价格区间内进行匹配

If False and slippage exceeds the cap, then there will be no match如果为False, 超过high、low区间之外的价格无法按照limit进行匹配

Provide slippage even if the price falls outside the high - low range.滑点调整后的价格可以超过high/low

If False and slippage exceeds the cap, then there will be no match

Cheat-On-Close Setting this to True with set_coc enables matching a Market order to the closing price of the bar in which the order was issued. This is actually cheating, because the bar is closed and any order should first be matched against the prices in the next bar

Cheat-On-Open Setting this to True with set_coo enables matching a Market order to the opening price, by for example using a timer with cheat set to True, because such a timer
gets executed before the broker has evaluated

Assign generated interest (if any) to the profit and loss of operation that reduces a position (be it long or short). There may be cases in which this is undesired, because different strategies are competing and the interest would be assigned on a non-deterministic basis to any of them.

If True then cash will be increased when a stocklike asset is shorted and the calculated value for the asset will be negative.

If False then the cash will be deducted as operation cost and the calculated value will be positive to end up with the same amount

This parameter controls the start value for measuring the performance in a fund-like way, i.e.: cash can be added and deducted increasing the amount of shares. Performance is not measured using the net asset value of the porftoflio but using the value of the fund

If this is set to True analyzers like TimeReturn can automatically calculate returns based on the fund value and not on the total net asset value

上一篇 下一篇

猜你喜欢

热点阅读