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

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

Zipline Risk and Performance Metrics的更多相关文章

  1. Performance Metrics(性能指标1)

    Performance Metrics(性能指标) 在我们开始旅行本书之前,我必须先了解本书的性能指标和希望优化后的结果,在第二章中,我们探索更多的性能检测工具和性能指标,可是,您得会使用这些工具和明 ...

  2. 7 Java Performance Metrics to Watch After a Major Release--转

    原文地址:https://dzone.com/articles/7-java-performance-metrics-to-watch-after-a-major-1 The Java perform ...

  3. Performance Metrics(性能指标2)

    这一章我们将讨论性能指标的优化(如CPU利用率和执行时间的优化是如此的重要),下面是一章本书性能优化的章节示意图: 不同的指标都适合于不同的性能测量领域,如数据库访问时间的性能测量可能不适合评价一个客 ...

  4. Zipline Beginner Tutorial

    Zipline Beginner Tutorial Basics Zipline is an open-source algorithmic trading simulator written in ...

  5. Zipline入门教程

    Zipline Beginner Tutorial Basics 基础 Zipline is an open-source algorithmic trading simulator written ...

  6. Performance Monitor4:监控SQL Server的IO性能

    SQL Server的IO性能受到物理Disk的IO延迟和SQL Server内部执行的IO操作的影响.在监控Disk性能时,最主要的度量值(metric)是IO延迟,IO延迟是指从Applicati ...

  7. 使用Metrics.NET 构建 ASP.NET MVC 应用程序的性能指标

    通常我们需要监测ASP.NET MVC 或 Web API 的应用程序的性能时,通常采用的是自定义性能计数器,性能计数器会引发无休止的运维问题(损坏的计数器.权限问题等).这篇文章向你介绍一个新的替代 ...

  8. Performance Monitor3:监控SQL Server的内存压力

    SQL Server 使用的资源受到操作系统的调度,同时,SQL Server在内部实现了一套调度算法,用于管理从操作系统获取的资源,主要是对内存和CPU资源的调度.一个好的数据库系统,必定在内存中缓 ...

  9. Performance Monitor2:Peformance Counter

    Performance Counter 是量化系统状态或活动的一个数值,Windows Performance Monitor在一定时间间隔内(默认的取样间隔是15s)获取Performance Co ...

随机推荐

  1. Python|PyCharm安装scrapy包

    [转]http://www.cnblogs.com/xiaoli2018/p/4566639.html

  2. spring boot热部署pom.xml配置

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  3. 将多个文件夹内的txt合并

    import os import re def text_create(name): """ 创建txt文件夹 """ desktop_pa ...

  4. Android4.4之后休眠状态下Alarm不准时的问题

    Android4.4及之后休眠状态下Alarm不准时的问题 为了减轻功耗,延长电池使用时间.Android 4.4及之后的版本号採用非精准闹钟机制.以及休眠状态下的wakeup类型的alarm不会实时 ...

  5. [转]VC传递消息sendmessage

    SendMessage的基本结构如下: SendMessage( HWND hWnd,  //消息传递的目标窗口或线程的句柄. UINT Msg, //消息类别(这里可以是一些系统消息,也可以是自己定 ...

  6. scala 测试类

    class NetworkUtilTest extends FunSuite with Matchers { test("testIp2Int") { val ip = Netwo ...

  7. CheckBox和richTextBox

    namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { Initialize ...

  8. js监听文本框变化事件

    用js有两种写法: 法一: <!DOCTYPE HTMl> <html> <head> <title> new document </title& ...

  9. js 刷新后不提示并保留控件状态

    保存后,想提示一下并保留查询条件的状态,发现可以用document.forms[0].submit();继续提交达到刷新的目的 代码如下: ScriptManager.RegisterStartupS ...

  10. WCF服务三:svc文件详解

    在前面的文章中讲述过WCF服务的宿主程序主要包括:三种,在那篇文章中,简单的描述了如何把一个WCF服务寄宿到IIS上面,这篇文章中将具体讲述如何把一个WCF服务寄宿到IIS上面. 一.新建一个WCF服 ...