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)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM