BackTrader 中文文档(四)(2)

本文涉及的产品
公共DNS(含HTTPDNS解析),每月1000万次HTTP解析
云解析 DNS,旗舰版 1个月
全局流量管理 GTM,标准版 1个月
简介: BackTrader 中文文档(四)

BackTrader 中文文档(四)(1)https://developer.aliyun.com/article/1489240

BacktraderCSVData

解析用于测试的自定义 CSV 数据。

特定参数:

  • dataname:要解析的文件名或类似文件的对象

行:

* close
* low
* high
* open
* volume
* openinterest
* datetime

参数:

* dataname (None)
* name ()
* compression (1)
* timeframe (5)
* fromdate (None)
* todate (None)
* sessionstart (None)
* sessionend (None)
* filters ([])
* tz (None)
* tzinput (None)
* qcheck (0.0)
* calendar (None)
* headers (True)
* separator (,)

CSVDataBase

实现 CSV 数据源的类的基类

该类负责打开文件,读取行并对其进行标记

子类只需要覆盖:

  • _loadline(tokens)

_loadline的返回值(True/False)将是由此基类覆盖的_load的返回值

行:

* close
* low
* high
* open
* volume
* openinterest
* datetime

参数:

* dataname (None)
* name ()
* compression (1)
* timeframe (5)
* fromdate (None)
* todate (None)
* sessionstart (None)
* sessionend (None)
* filters ([])
* tz (None)
* tzinput (None)
* qcheck (0.0)
* calendar (None)
* headers (True)
* separator (,)

Chainer

链接数据的类

行:

* close
* low
* high
* open
* volume
* openinterest
* datetime

参数:

* dataname (None)
* name ()
* compression (1)
* timeframe (5)
* fromdate (None)
* todate (None)
* sessionstart (None)
* sessionend (None)
* filters ([])
* tz (None)
* tzinput (None)
* qcheck (0.0)
* calendar (None)

DataClone

行:

* close
* low
* high
* open
* volume
* openinterest
* datetime

参数:

* dataname (None)
* name ()
* compression (1)
* timeframe (5)
* fromdate (None)
* todate (None)
* sessionstart (None)
* sessionend (None)
* filters ([])
* tz (None)
* tzinput (None)
* qcheck (0.0)
* calendar (None)

DataFiller

此类将使用来自基础数据源的以下信息位填充源数据中的间隙

  • 时间框架和压缩以确定输出条的维度
  • sessionstart 和 sessionend

如果数据源在 10:31 和 10:34 之间缺少���,且时间框架为分钟,则输出将使用最后一条条的收盘价(10:31)填充 10:32 和 10:33 分钟的条

条可能会缺失,因为其他原因

参数:

* `fill_price` (def: None): if None (or evaluates to False),the
  closing price will be used, else the passed value (which can be
  for example ‘NaN’ to have a missing bar in terms of evaluation but
  present in terms of time
* `fill_vol` (def: NaN): used to fill the volume of missing bars
* `fill_oi` (def: NaN): used to fill the openinterest of missing bars

行:

* close
* low
* high
* open
* volume
* openinterest
* datetime

参数:

* dataname (None)
* name ()
* compression (1)
* timeframe (5)
* fromdate (None)
* todate (None)
* sessionstart (None)
* sessionend (None)
* filters ([])
* tz (None)
* tzinput (None)
* qcheck (0.0)
* calendar (None)
* fill_price (None)
* fill_vol (nan)
* fill_oi (nan)

DataFilter

此类从给定数据源中过滤条。除了 DataBase 的标准参数外,它还接受一个funcfilter参数,该参数可以是任何可调用对象

逻辑:

  • funcfilter将与基础数据源一起调用它可以是任何可调用对象
  • 返回值 True:将使用当前数据源的条形值
  • 返回值 False:将丢弃当前数据源的条形值

行:

* close
* low
* high
* open
* volume
* openinterest
* datetime

参数:

* dataname (None)
* name ()
* compression (1)
* timeframe (5)
* fromdate (None)
* todate (None)
* sessionstart (None)
* sessionend (None)
* filters ([])
* tz (None)
* tzinput (None)
* qcheck (0.0)
* calendar (None)
* funcfilter (None)

GenericCSVData

根据参数定义的顺序和字段存在性解析 CSV 文件

特定参数(或特定含义):

  • dataname:要解析的文件名或类似文件的对象
  • 行参数(日期时间,开盘价,最高价…)采用数值
    -1 的值表示 CSV 源中该字段的缺失
  • 如果time存在(参数 time >=0),则源包含分开的日期和时间字段,这些字段将被组合
  • nullvalue
    如果应该存在的值缺失(CSV 字段为空),将使用的值
  • dtformat:用于解析日期时间 CSV 字段的格式。有关格式,请参阅 python strptime/strftime 文档。如果指定了数值,则将按以下方式解释
  • 1:值是int类型的 Unix 时间戳,表示自 1970 年 1 月 1 日起的秒数
  • 2:值是float类型的 Unix 时间戳
  • 如果传递了可调用对象
  • 它将接受一个字符串并返回一个 datetime.datetime 的 python 实例
  • tmformat:如果“存在”,则用于解析时间 CSV 字段的格式(“时间”CSV 字段的默认值是不存在)

行:

* close
* low
* high
* open
* volume
* openinterest
* datetime

参数:

* dataname (None)
* name ()
* compression (1)
* timeframe (5)
* fromdate (None)
* todate (None)
* sessionstart (None)
* sessionend (None)
* filters ([])
* tz (None)
* tzinput (None)
* qcheck (0.0)
* calendar (None)
* headers (True)
* separator (,)
* nullvalue (nan)
* dtformat (%Y-%m-%d %H:%M:%S)
* tmformat (%H:%M:%S)
* datetime (0)
* time (-1)
* open (1)
* high (2)
* low (3)
* close (4)
* volume (5)
* openinterest (6)

IBData

交互经纪人数据源。

支持参数dataname中的以下合同规范:

  • TICKER # 股票类型和 SMART 交易所
  • TICKER-STK # 股票和 SMART 交易所
  • TICKER-STK-EXCHANGE # 股票
  • TICKER-STK-EXCHANGE-CURRENCY # 股票
  • TICKER-CFD # 差价合约和 SMART 交易所
  • TICKER-CFD-EXCHANGE # 差价合约
  • TICKER-CDF-EXCHANGE-CURRENCY # 股票
  • TICKER-IND-EXCHANGE # 指数
  • TICKER-IND-EXCHANGE-CURRENCY # 指数
  • TICKER-YYYYMM-EXCHANGE # 期货
  • TICKER-YYYYMM-EXCHANGE-CURRENCY # 期货
  • TICKER-YYYYMM-EXCHANGE-CURRENCY-MULT # 期货
  • TICKER-FUT-EXCHANGE-CURRENCY-YYYYMM-MULT # 期货
  • TICKER-YYYYMM-EXCHANGE-CURRENCY-STRIKE-RIGHT # 期权
  • TICKER-YYYYMM-EXCHANGE-CURRENCY-STRIKE-RIGHT-MULT # 期权
  • TICKER-FOP-EXCHANGE-CURRENCY-YYYYMM-STRIKE-RIGHT # 期权
  • TICKER-FOP-EXCHANGE-CURRENCY-YYYYMM-STRIKE-RIGHT-MULT # 期权
  • CUR1.CUR2-CASH-IDEALPRO # 外汇
  • TICKER-YYYYMMDD-EXCHANGE-CURRENCY-STRIKE-RIGHT # 期权
  • TICKER-YYYYMMDD-EXCHANGE-CURRENCY-STRIKE-RIGHT-MULT # 期权
  • TICKER-OPT-EXCHANGE-CURRENCY-YYYYMMDD-STRIKE-RIGHT # 期权
  • TICKER-OPT-EXCHANGE-CURRENCY-YYYYMMDD-STRIKE-RIGHT-MULT # 期权

参数:

  • sectype(默认值:STK
    如果在dataname规范中未提供,应用的默认值为security type
  • exchange(默认值:SMART
    如果在dataname规范中未提供,应用的默认值为exchange
  • currency(默认值:''
    如果在dataname规范中未提供,应用的默认值为currency
  • historical(默认值:False
    如果设置为True,数据源将在首次下载数据后停止。
    标准数据源参数fromdatetodate将被用作参考。
    如果请求的持续时间大于 IB 根据所选数据的时间框架/压缩允许的持续时间,则数据源将进行多次请求。
  • what(默认值:None)如果为None,则将为历史数据请求使用不同资产类型的默认值:
  • 对于现金资产‘BID’
  • 对于任何其他‘交易’
  • 如果希望使用其他值,请查阅 IB API 文档
  • rtbar(默认值:False
    如果设置为True,则使用 Interactive Brokers 提供的5 秒实时数据条作为最小跳动。根据文档,它们对应实时值(一旦被 IB 收集和整理)
    如果为False,则将使用基于接收到的跳动的RTVolume价格。在CASH资产的情况下(例如 EUR.JPY),将始终使用RTVolume,并从中获取bid价格(根据散布在互联网上的文献,这是 IB 的行业事实标准)
    即使设置为True,如果数据被重新采样/保持到低于 Seconds/5 的时间框架/压缩,将不会使用实时条,因为 IB 不会在该水平以下提供它们
  • qcheck(默认值:0.5
    以秒为单位的时间,如果未收到数据,则唤醒以正确重新采样/回放数据包并将通知传递给链路上游的机会
  • backfill_start(默认值:True
    在开始时执行回填。将在单个请求中获取最大可能的历史数据。
  • backfill(默认值:True
    在断开/重新连接周期后执行回填。间隙持续时间将用于下载尽可能少的数据量
  • backfill_from(默认值:None
    可以传递一个额外的数据源来进行初始层次的回填。一旦数据源耗尽并且如果需要,将从 IB 进行回填。理想情况下,这是为了从已存储的源(如磁盘上的文件)回填,但不限于此。
  • latethrough(默认:False
    如果数据源被重新采样/回放,一些 ticks 可能会因为已经交付的重新采样/回放的 bar 而来得太晚。如果这是 True,那些 ticks 将无论如何都会被放过。
    检查 Resampler 文档以查看如何考虑这些 ticks。
    如果在 IBStore 实例中设置 timeoffsetFalse,并且 TWS 服务器时间与本地计算机时间不同步,则可能会发生这种情况。
  • tradename(默认:None)对某些特定情况(如CFD,其中价格由一种资产提供,交易发生在另一种资产上)很有用
  • SPY-STK-SMART-USD -> SP500 ETF(将被指定为 dataname
  • SPY-CFD-SMART-USD -> 这是对应的 CFD,它提供的不是价格跟踪,而是在这种情况下将是交易资产(指定为 tradename

参数中的默认值是为了允许类似 \TICKER这样的东西,其中参数sectype(默认:STK)和 exchange(默认:SMART`)被应用。

一些资产如 AAPL 需要包括 currency 的完整规范(默认:‘’),而像 TWTR 这样的其他资产可以直接传递。

  • AAPL-STK-SMART-USD 是 dataname 的完整规范。
    或者:IBData 作为 IBData(dataname='AAPL', currency='USD'),它使用默认值(STKSMART)并覆盖货币为 USD

Lines:

* close
* low
* high
* open
* volume
* openinterest
* datetime

参数:

* dataname (None)
* name ()
* compression (1)
* timeframe (5)
* fromdate (None)
* todate (None)
* sessionstart (None)
* sessionend (None)
* filters ([])
* tz (None)
* tzinput (None)
* qcheck (0.5)
* calendar (None)
* sectype (STK)
* exchange (SMART)
* currency ()
* rtbar (False)
* historical (False)
* what (None)
* useRTH (False)
* backfill_start (True)
* backfill (True)
* backfill_from (None)
* latethrough (False)
* tradename (None)

InfluxDB

Lines:

* close
* low
* high
* open
* volume
* openinterest
* datetime

参数:

* dataname (None)
* name ()
* compression (1)
* timeframe (5)
* fromdate (None)
* todate (None)
* sessionstart (None)
* sessionend (None)
* filters ([])
* tz (None)
* tzinput (None)
* qcheck (0.0)
* calendar (None)
* host (127.0.0.1)
* port (8086)
* username (None)
* password (None)
* database (None)
* startdate (None)
* high (high_p)
* low (low_p)
* open (open_p)
* close (close_p)
* volume (volume)
* ointerest (oi)

MT4CSVData

解析 Metatrader4 历史中心的 CSV 导出文件。

特定参数(或特定含义):

  • dataname:要解析的文件名或文件对象
  • 使用 GenericCSVData 并简单修改参数

Lines:

* close
* low
* high
* open
* volume
* openinterest
* datetime

BackTrader 中文文档(四)(3)https://developer.aliyun.com/article/1489244

相关文章
|
5月前
|
Unix 索引 Python
BackTrader 中文文档(一)(2)
BackTrader 中文文档(一)
114 0
|
5月前
|
索引
BackTrader 中文文档(六)(2)
BackTrader 中文文档(六)
79 0
|
5月前
|
存储 编解码 API
BackTrader 中文文档(四)(1)
BackTrader 中文文档(四)
64 1
|
5月前
|
存储 数据库连接 数据库
BackTrader 中文文档(三)(2)
BackTrader 中文文档(三)
78 0
|
5月前
|
数据可视化
BackTrader 中文文档(三)(3)
BackTrader 中文文档(三)
45 0
|
5月前
|
存储 算法 索引
BackTrader 中文文档(三)(1)
BackTrader 中文文档(三)
101 0
|
5月前
BackTrader 中文文档(一)(4)
BackTrader 中文文档(一)
58 0
|
5月前
|
索引 Python
BackTrader 中文文档(五)(3)
BackTrader 中文文档(五)
64 0
|
5月前
|
存储 缓存 Shell
BackTrader 中文文档(二)(3)
BackTrader 中文文档(二)
108 0
|
5月前
|
存储 DataX Python
BackTrader 中文文档(五)(1)
BackTrader 中文文档(五)
91 0