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
- Manually create an instance of this class with the desired params and use cerebro.broker = instance to set the instance as the broker for the run execution
- Use the set_xxx to set the value using cerebro.broker.set_xxx where \xxx` stands for the name of the parameter to set
Params:
- cash (default: 10000): starting cash
- commission (default: CommInfoBase(percabs=True)) base commission scheme which applies to all assets
- eosbar (default: False): With intraday bars consider a bar with the same time as the end of session to be the end of the session. This is not usually the case, because some bars (final auction) are produced by many exchanges for many products for a couple of minutes after the end of the session
- filler (default: None)
A callable with signature: callable(order, price, ago)
- order: obviously the order in execution. This provides access to the data (and with it the ohlc and volume values), the execution type, remaining size (order.executed.remsize) and others.
Please check the Order documentation and reference for things available inside an Order instance
-
price the price at which the order is going to be executed in the ago bar
-
ago: index meant to be used with order.data for the extraction of the ohlc and volume prices. In most cases this will be 0 but on a corner case for Close orders, this will be -1.
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
- slip_perc (default: 0.0) Percentage in absolute termns (and positive) that should be used to slip prices up/down for buy/sell orders
Note:
-
0.01 is 1%
-
0.001 is 0.1%
-
slip_fixed (default: 0.0) Percentage in units (and positive) that should be used to slip prices up/down for buy/sell orders 相对于一个unit的百分比?points
Note: if slip_perc is non zero, it takes precendence over this.
- slip_open (default: False) whether to slip prices for order execution which would specifically used the opening price of the next bar. An example would be Market order which is executed with the next available tick, i.e: the opening price of the bar .如果slip_open设定为True, 则执行价格会在open上做调整,但是不能超过当日的high/low
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.
- slip_match (default: True)
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则无法执行
- slip_limit (default: True)
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进行匹配
- slip_out (default: False)
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
- coc (default: False)
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
- coo (default: False)
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
- int2pnl (default: True)
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.
- shortcash (default: True)
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
- fundstartval (default: 100.0)
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
- fundmode (default: False)
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
网友评论