Backtrader中文笔记之Broker(券商,经纪人)

Reference

class backtrader.brokers.BackBroker()

class backtrader.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.

价格变化意味着在真正的经纪人中增加/减少现金。

Supported order types:

支持的定单类型:

  • Market: to be executed with the 1st tick of the next bar (namely the open price)

  • 市场价:执行在下个bar的开盘价执行
  • Close: meant for intraday in which the order is executed with the closing price of the last bar of the session

  • 收盘:是指当日交易中,以交易日最后一个交易日的收盘价执行指令
  • Limit: executes if the given limit price is seen during the session

  • 限制价格:如果在会话期间看到给定的限价,则执行
  • Stop: executes a Market order if the given stop price is seen

  • 止损价格:如果看到给定的止损价格,则执行市场指令
  • StopLimit: sets a Limit order in motion if the given stop price is seen

  • StopLimit:如果看到给定的止损价格,则设置一个动态的限价指令

Because the broker is instantiated by Cerebro and there should be (mostly) no reason to replace the broker, the params are not controlled by the user for the instance. To change this there are two options:

由于券商【经纪人】是由Cerebro实例化的,而且(大多数情况下)没有理由替换券商【经纪人】,因此实例的用户不控制参数。要更改此设置,有两个选项:

  1. 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

  2. 使用所需的参数手动创建此类的实例券商【经纪人】并使用cerebro.broker=instance将实例设置为运行执行的券商【经纪人】
  3. Use the set_xxx to set the value using cerebro.broker.set_xxx where xxx` stands for the name of the parameter to set

  4. 使用set_xxx设置值,使用cerebro.broker.set_xxx其中xxx`表示要设置的参数的名称

Note

cerebro.broker is a property supported by the getbroker and setbroker methods of Cerebro

cerebro.broker是一个属性,支持Cerebro的getbrokersetbroker方法.

Params:

  • cash (default: 10000): starting cash

  • cash (default: 10000):开始的现金
  • commission (default: CommInfoBase(percabs=True)) base commission scheme which applies to all assets

  • 佣金(默认值:CommInfoBase(percabs=True))适用于所有资产的基本佣金方案
  • checksubmit (default: True) check margin/cash before accepting an order into the system

  • checksubmit(默认值:True)在系统中接受订单之前检查保证金/现金
  • 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

  • eosbar(默认值:False):对于日内条形图,将与会话结束时间相同的bar视为会话的结束。通常情况并非如此,因为有些bar(最终拍卖)是由许多交易所在交易结束后的几分钟内为许多产品生产的
  • filler这一块不是很理解,感觉是一个函数,但具体功能未知
  • filler (default: None)

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

  • 一个可以调用的签名: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.

    • 定单:显然是执行中的定单。这提供了对数据(以及ohlc和成交量)、执行类型、剩余大小的访问(order.executed.remsize)以及其它信息。
    • 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栏中执行定单价格
    • 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.

    • ago:索引用于订单数据用于提取ohlc和批量价格。在大多数情况下,这将是0,但在结束订单的情况下,这将是-1。
    • In order to get the bar volume (for example) do: volume = order.data.volume[ago]

    • 为了得到bar的volume(例如)do: volume=order.data.volume[ago]

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

  • callable必须返回执行的大小(值>=0)
  • The callable may of course be an object with __call__ matching the aforementioned signature

  • 当然,可调用对象可以是一个与前述签名匹配的对象
  • With the default None orders will be completely executed in a single shot

  • 默认情况下,命令将在一次操作中完全执行
  • slip_perc (default: 0.0) Percentage in absolute termns (and positive) that should be used to slip prices up/down for buy/sell orders

  • slip_perc(默认值:0.0)绝对条件下的百分比(和正值),用于向上/向下滑动买入/卖出订单的价格
  • 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

  • slip_fixed(默认值:0.0)单位百分比(正数),用于向上/向下滑动买入/卖出订单的价格
  • Note: if slip_perc is non zero, it takes precendence over this.

  • 注:如果slip_perc不为零,则它会先于此值。
  • 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感觉专门为用于开盘价成交的逻辑
  • slip_open(默认值:False)是否为订单执行滑出价格,它将专门使用下一个条的开盘价。一个例子是市场订单,它是用下一个可用的tick来执行的,即:bar的开盘价。
  • 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.

  • 这也适用于其他一些执行,因为当移动到一个新的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.

  • 如果是真的,券商【经纪人】将提供一个匹配的上限,在高/低价格,以防超过他们。

    If False the broker will not match the order with the current prices and will try execution during the next iteration

  • 如果为False,则券商【经纪人】将不匹配订单与当前价格,并将在下一次迭代中尝试执行
  • slip_limit (default: True)

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

  • 即使slip_match为False,也将匹配所请求的精确匹配价格的限价订单。
  • This option controls that behavior.

  • 此选项控制该行为。
  • If True, then Limit orders will be matched by capping prices to the limit / high/low prices

  • 如果为真,则限价订单将通过限制价格/高/低价格来匹配
  • If False and slippage exceeds the cap, then there will be no match

  • 如果为假和滑动超过上限,那么将没有匹配
  • slip_out (default: False)

    Provide slippage even if the price falls outside the high - low range.

  • 即使价格跌到高-低范围之外,也要提供滑动。
  • coc (default: False)

  • Cheat-On-Close Setting this to True with set_coc enables

  • 可以通过set_coc来设置coc
  • 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
     将“市场”指令与发出指令的bar的收盘价相匹配。这实际上是欺骗,因为bar是已经收盘,任何订单都应该首先与下一个bar的价格相匹配
  • coo (default: False)

    Cheat-On-Open Setting this to True with set_coo enables

  • 可以通过set_coo来设置coo
  • 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
     将“Market”订单与开盘价相匹配,例如使用“cheat”设置为“True”的计时器,因为这样的计时器在经纪人评估之前就被执行了
  • 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

  • 此参数控制基金类方式衡量业绩的起始值,即:增加份额可以增加或减少现金。业绩不是用porftoflio的资产净值来衡量的,而是用基金的价值来衡量的
  • 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

  • 如果设置为True,像TimeReturn这样的分析器可以根据基金价值而不是总资产净值自动计算收益

set_cash(cash)

Sets the cash parameter (alias: setcash)

设置现金

get_cash()

Returns the current cash (alias: getcash)

查看当前现金

get_value(datas=None, mkt=False, lever=False)

Returns the portfolio value of the given datas (if datas is None, then the total portfolio value will be returned (alias: getvalue)

返回给定数据的资产组合值(如果datas为None,则返回组合的总值(别名:getvalue)

set_eosbar(eosbar)

Sets the eosbar parameter (alias: seteosbar

设置eosbar参数(别名:seteosbar

set_checksubmit(checksubmit)

Sets the checksubmit parameter

设置checksubmit(checksubmit)

set_filler(filler)

Sets a volume filler for volume filling execution

设置填充器(填充器)

set_coc(coc)

Configure the Cheat-On-Close method to buy the close on order bar

配置Cheat On Close方法来购买Close On order bar

set_coo(coo)

Configure the Cheat-On-Open method to buy the close on order bar

set_int2pnl(int2pnl)

Configure assignment of interest to profit and loss

set_fundstartval(fundstartval)

Set the starting value of the fund-like performance tracker

set_slippage_perc(perc, slip_open=True, slip_limit=True, slip_match=True, slip_out=False)

Configure slippage to be percentage based

set_slippage_fixed(fixed, slip_open=True, slip_limit=True, slip_match=True, slip_out=False)

Configure slippage to be fixed points based

get_orders_open(safe=False)

Returns an iterable with the orders which are still open (either not executed or partially executed

返回一个iterable,其中的订单仍处于打开状态(未执行或部分执行

The orders returned must not be touched.

退回的订单不能碰。

If order manipulation is needed, set the parameter safe to True

如果需要订单操作,请将参数safe设置为True

getcommissioninfo(data)

Retrieves the CommissionInfo scheme associated with the given data

setcommission(commission=0.0, margin=None, mult=1.0, commtype=None, percabs=True, stocklike=False, interest=0.0, interest_long=False, leverage=1.0, automargin=False, name=None)

This method sets a `` CommissionInfo`` object for assets managed in the broker with the parameters. Consult the reference for CommInfoBase

If name is None, this will be the default for assets for which no other CommissionInfo scheme can be found

addcommissioninfo(comminfo, name=None)

Adds a CommissionInfo object that will be the default for all assets if name is None

getposition(data)

Returns the current position status (a Position instance) for the given data

get_fundshares()

Returns the current number of shares in the fund-like mode

get_fundvalue()

Returns the Fund-like share value

add_cash(cash)

Add/Remove cash to the system (use a negative value to remove)

原文地址:https://www.cnblogs.com/sidianok/p/13690221.html