zoukankan      html  css  js  c++  java
  • Zipline Risk and Performance Metrics

    Risk and Performance Metrics 风险和性能指标

    The risk and performance metrics are summarizing values calculated by Zipline when running a simulation. These metrics can be about the performance of an algorithm, like returns or cash flow, or the riskiness of an algorithm, like volatility or beta. Metrics may be reported minutely, daily, or once at the end of a simulation. A single metric may choose to report at multiple time-scales where appropriate.

    风险和性能指标汇总了Zipline在运行模拟时计算的值。 这些指标可能与算法的性能有关,如回报或现金流量,或算法的风险,如波动率或贝塔值。 度量可以在模拟结束时每分钟或每天进行一次报告。 一个指标可以选择在适当的时间范围内报告多个时间尺度。

    Metrics Sets 度量集

    Zipline groups risk and performance metrics into collections called “metrics sets”. A single metrics set defines all of the metrics to track during a single backtest. A metrics set may contain metrics that report at different time scales. The default metrics set will compute a host of metrics, such as algorithm returns, volatility, Sharpe ratio, and beta.

    Zipline将风险和绩效指标分为称为“指标集”的集合。 单个度量集定义了在单个后向测试期间要跟踪的所有度量。 指标集可能包含以不同时间尺度报告的指标。 默认指标集将计算大量指标,如算法返回值,波动率,夏普比率和测试版。

    Selecting the Metrics Set 选择度量集

    When running a simulation, the user may select the metrics set to report. How you select the metrics set depends on the interface being used to run the algorithm.

    运行模拟时,用户可以选择要报告的指标集。 如何选择度量集取决于用于运行算法的接口。

    Command Line and IPython Magic 命令行和IPython Magic

    When running with the command line or IPython magic interfaces, the metrics set may be selected by passing the --metrics-set argument. For example:

    使用命令行或IPython魔术接口运行时,可通过传递--metrics-set参数来选择度量标准集。 例如:

    $ zipline run algorithm.py -s 2014-01-01 -e 2014-02-01 --metrics-set my-metrics-set

    run_algorithm

    When running through the run_algorithm() interface, the metrics set may be passed with the metrics_set argument. This may either be the name of a registered metrics set, or a set of metric object. For example:

    在运行run_algorithm()接口时,可以使用metrics_set参数传递度量标准集。 这可能是已注册度量标准集的名称,也可能是一组度量对象。 例如:

    run_algorithm(..., metrics_set='my-metrics-set')
    run_algorithm(..., metrics_set={MyMetric(), MyOtherMetric(), ...})

    Running Without Metrics

    Computing risk and performance metrics is not free, and contributes to the total runtime of a backtest. When actively developing an algorithm, it is often helpful to skip these computations to speed up the debugging cycle. To disable the calculation and reporting of all metrics, users may select the built-in metrics set none. For example:

    风险和性能指标的计算不是免费的,它们会被算入回测的总体运行时间。 在开发算法时,跳过这些计算可以加快调试周期,这通常是很有帮助的。 要禁用所有指标的计算和报告,用户可以选择内置指标设置为none。 例如:

    $ zipline run algorithm.py -s 2014-01-01 -e 2014-02-01 --metrics-set none

    Defining New Metrics 定义新指标

    A metric is any object that implements some subset of the following methods: 度量标准是实现以下方法的一部分的任何对象:

    • start_of_simulation
    • end_of_simulation
    • start_of_session
    • end_of_session
    • end_of_bar

    These functions will be called at the time indicated by their name, at which point the metric object may collect any needed information and optionally report a computed value. If a metric does not need to do any processing at one of these times, it may omit a definition for the given method.

    这些函数将在其名称所指示的时间被调用,此时度量对象可以收集任何所需的信息并且可选地报告计算的值。 如果度量标准在这些时间中不需要进行任何处理,则可以省略给定方法的定义。

    A metric should be reusable, meaning that a single instance of a metric class should be able to be used across multiple backtests. Metrics do not need to support multiple simulations at once, meaning that internal caches and data are consistent between start_of_simulation and end_of_simulation.

    度量标准应该是可重用的,这意味着度量标准类的单个实例应该能够在多个后测中使用。 度量标准不需要一次支持多个模拟,这意味着start_of_simulation和end_of_simulation之间的内部缓存和数据是一致的。

    start_of_simulation

    The start_of_simulation method should be thought of as a per-simulation constructor. This method should initialize any caches needed for the duration of a single simulation. start_of_simulation方法应该被认为是每个模拟构造函数。 此方法应该初始化单个仿真期间所需的任何缓存。

    The start_of_simulation method should have the following signature: start_of_simulation方法应具有以下签名:

    def start_of_simulation(self,
                            ledger,
                            emission_rate,
                            trading_calendar,
                            sessions,
                            benchmark_source):
        ...
    

    ledger is an instance of Ledger which is maintaining the simulation’s state. This may be used to lookup the algorithm’s starting portfolio values. ledger是维护模拟状态的Ledger实例。 这可以用来查找算法的起始投资组合值。

    emission_rate is a string representing the smallest frequency at which metrics should be reported. emission_rate will be either minute or daily. When emission_rate is daily, end_of_bar will not be called at all. emission_rate是一个字符串,代表应该报告度量标准的最小频率。 emission_rate将是分钟或每天。 当emission_rate是每天时,end_of_bar根本不会被调用。

    trading_calendar is an instance of TradingCalendar which is the trading calendar being used by the simulation. trading_calendar是TradingCalendar的一个实例,它是模拟使用的交易日历。

    sessions is a pandas.DatetimeIndex which is holds the session labels, in sorted order, that the simulation will execute. sessions是一个pandas.DatetimeIndex,它保存按照排序顺序的会话标签,模拟将执行。

    benchmark_source is an instance of BenchmarkSource which is the interface to the returns of the benchmark specified by set_benchmark(). benchmark_source是BenchmarkSource的一个实例,它是由set_benchmark()指定的基准测试返回的接口。

    end_of_simulation

    The end_of_simulation method should have the following signature:

    def end_of_simulation(self,
                          packet,
                          ledger,
                          trading_calendar,
                          sessions,
                          data_portal,
                          benchmark_source):
        ...
    

    ledger is an instance of Ledger which is maintaining the simulation’s state. This may be used to lookup the algorithm’s final portfolio values.

    packet is a dictionary to write the end of simulation values for the given metric into. packet是一个字典,用于将给定量度的模拟值的末尾写入。

    trading_calendar is an instance of TradingCalendar which is the trading calendar being used by the simulation. trading_calendar是TradingCalendar的一个实例,它是模拟使用的交易日历。

    sessions is a pandas.DatetimeIndex which is holds the session labels, in sorted order, that the simulation has executed.  sessions是一个pandas.DatetimeIndex,它保存模拟执行的会话标签,按排序顺序。

    data_portal is an instance of DataPortal which is the metric’s interface to pricing data.  data_portal是DataPortal的一个实例,它是衡量数据定价的接口。

    benchmark_source is an instance of BenchmarkSource which is the interface to the returns of the benchmark specified by set_benchmark(). benchmark_source是BenchmarkSource的一个实例,它是由set_benchmark()指定的基准测试返回的接口。

    start_of_session

    The start_of_session method may see a slightly different view of the ledger or data_portal than the previous end_of_session if the price of any futures owned move between trading sessions or if a capital change occurs. 如果任何期货在交易时段之间的所有权价格发生变化或发生资本变化,start_of_session方法可能会看到与前一个end_of_session略有不同的ledger或data_portal视图。

    The start_of_session method should have the following signature: start_of_session方法应具有以下签名:

    def start_of_session(self,
                         ledger,
                         session_label,
                         data_portal):
        ...
    

    ledger is an instance of Ledger which is maintaining the simulation’s state. This may be used to lookup the algorithm’s current portfolio values.  ledge是维护模拟状态的Ledger实例。 这可以用来查找算法的当前投资组合值。

    session_label is a Timestamp which is the label of the session which is about to run. session_label是一个Timestamp,它是即将运行的会话的标签。

    data_portal is an instance of DataPortal which is the metric’s interface to pricing data. data_portal是DataPortal的一个实例,它是衡量数据定价的接口。

    end_of_session

    The end_of_session method should have the following signature:

    def end_of_session(self,
                       packet,
                       ledger,
                       session_label,
                       session_ix,
                       data_portal):
    

    packet is a dictionary to write the end of session values. This dictionary contains two sub-dictionaries: daily_perf and cumulative_perf. When applicable, the daily_perf should hold the current day’s value, and cumulative_perf should hold a cumulative value for the entire simulation up to the current time. packet是一个字典,用于写入会话值的结尾。该字典包含两个子字典:daily_perf和cumulative_perf。 适用时,daily_perf应该保存当天的值,并且cumulative_perf应该保持到当前时间为止的整个模拟的累积值。

    ledger is an instance of Ledger which is maintaining the simulation’s state. This may be used to lookup the algorithm’s current portfolio values. ledger是维护模拟状态的Ledger实例。 这可以用来查找算法的当前投资组合值。

    session_label is a Timestamp which is the label of the session which is has just completed. session_label是一个Timestamp,它是刚刚完成的会话的标签。

    session_ix is an int which is the index of the current trading session being run. This is provided to allow for efficient access to the daily returns through ledger.daily_returns_array[:session_ix + 1]. session_ix是一个整型变量,它是当前正在运行的交易时段的指数。 这是为了通过ledger.daily_returns_array[:session_ix + 1]有效访问每日回报。

    data_portal is an instance of DataPortal which is the metric’s interface to pricing data. data_portal是DataPortal的一个实例,它是衡量数据定价的接口

    end_of_bar

    Note

    end_of_bar is only called when emission_mode is minute.  end_of_bar仅在emission_mode为分钟时被调用。

    The end_of_bar method should have the following signature: end_of_bar方法应该具有以下签名:

    def end_of_bar(self,
                   packet,
                   ledger,
                   dt,
                   session_ix,
                   data_portal):
    

    packet is a dictionary to write the end of session values. This dictionary contains two sub-dictionaries: minute_perf and cumulative_perf. When applicable, the minute_perf should hold the current partial day’s value, and cumulative_perf should hold a cumulative value for the entire simulation up to the current time. packet是一个字典,用于写入会话值的结尾。 该词典包含两个子词典:minute_perf和cumulative_perf。 适用时,minute_perf应保存当前的部分日期值,并且cumulative_perf应持有到当前时间为止的整个模拟的累积值。

    ledger is an instance of Ledger which is maintaining the simulation’s state. This may be used to lookup the algorithm’s current portfolio values. ledger是维护模拟状态的Ledger实例。 这可以用来查找算法的当前投资组合值。

    dt is a Timestamp which is the label of bar that has just completed. dt是一个时间戳,它是刚刚完成的柱的标签。

    session_ix is an int which is the index of the current trading session being run. This is provided to allow for efficient access to the daily returns through ledger.daily_returns_array[:session_ix + 1]. session_ix是一个int,它是当前正在运行的交易时段的指数。 这是为了通过ledger.daily_returns_array [:session_ix + 1]有效访问每日回报。

    data_portal is an instance of DataPortal which is the metric’s interface to pricing data. data_portal是DataPortal的一个实例,它是衡量数据定价的接口。

    Defining New Metrics Sets 定义新的度量集

    Users may use zipline.finance.metrics.register() to register a new metrics set. This may be used to decorate a function taking no arguments which returns a new set of metric object instances. For example: 用户可以使用zipline.finance.metrics.register()注册一个新的度量集。 这可以用来装饰一个没有参数的函数,它返回一组新的度量对象实例。 例如:

    from zipline.finance import metrics
    
    @metrics.register('my-metrics-set')
    def my_metrics_set():
        return {MyMetric(), MyOtherMetric(), ...}

    This may be embedded in the user’s extension.py. 这可能嵌入在用户的extension.py中。

    The reason that a metrics set is defined as a function which produces a set, instead of just a set, is that users may want to fetch external data or resources to construct their metrics. By putting this behind a callable, users do not need to fetch the resources when the metrics set is not being used.

    将度量集定义为产生集而不仅仅是集的函数的原因是用户可能想要获取外部数据或资源来构建其度量。 通过将其设置为可调用,用户不需要在未使用度量标准时获取资源。

  • 相关阅读:
    大型网站技术架构-阅读笔记1
    如何发挥一个字节的极限,存储大量内容
    利用easyui创建一个简单的登录页面
    linux tomcat 快捷操作
    linux 安装jdk
    Linux-查看服务器的信息
    HTTP协议(1)
    Linux-ps命令
    Linux-tcpdump命令
    转载-测试新人培训方法之目标法
  • 原文地址:https://www.cnblogs.com/bitquant/p/9076154.html
Copyright © 2011-2022 走看看