时间序列因果关系_分析具有因果关系的时间序列干预:货币波动

时间序列因果关系

When examining a time series, it is quite common to have an intervention influence that series at a particular point.

在检查时间序列时,在特定时间点对该序列产生干预影响是很常见的。

Some examples of this could be:

例如:

  • An advertising campaign that results in a significant change in sales

    导致销售发生重大变化的广告活动
  • A positive change in traffic policy that results in lower road deaths

    交通政策的积极变化,可减少道路死亡人数
  • A change in economic policy that affects asset prices

    影响资产价格的经济政策变化

The problem with analysing the effects of interventions is that one is then unable to examine how that series would have trended without that intervention.

分析干预措施效果的问题在于,如果没有该干预措施,人们将无法检查该系列趋势。

For instance, suppose that a company implements an advertising campaign with the intent of boosting sales. While sales data can be recorded post-intervention — it is not possible to say what the sales would have been without that intervention.

例如,假设一家公司实施了旨在促进销售的广告活动。 虽然销售数据可以记录后干预-这是不可能说什么销售本来没有这种干预。

我们的例子 (Our Example)

For this example, let us consider the impact of an interest rate change on currency fluctuations.

对于此示例,让我们考虑利率变化对货币波动的影响

When a central bank manipulates interest rates — this is hypothesised to have a significant impact on a currency as it affects the perceived value of that currency relative to others in the market.

当中央银行操纵利率时,假设这会对货币产生重大影响,因为它会影响该货币相对于市场上其他货币的感知价值。

However, what if we wish to quantify such an impact? Let’s see how this works with the causalimpact package. This package was originally developed by Google for R, but we will use the Python version (pycasualimpact) in this example.

但是,如果我们希望量化这种影响怎么办? 让我们看看它如何与causalimpact包一起工作。 该软件包最初是由Google for R开发的,但是在此示例中,我们将使用Python版本(pycasualimpact)。

Let’s consider fluctuations in the GBP/USD for the year 2017.

让我们考虑一下2017年英镑/美元的波动。

In November 2017, the Bank of England decided to raise interest rates.

2017年11月,英格兰银行决定提高利率。

We will use causalimpact in an attempt to investigate:

我们将使用因果影响来调查:

  1. what the forecasted GBP/USD rate would have been in the absence of such an intervention

    如果不采取这种干预措施,英镑/美元的汇率将是多少?
  2. whether such an intervention is significant and has affected the currency level

    此类干预是否重大并已影响货币水平

In order to determine whether such an intervention has a significant effect on a time series — we must use a suitable covariate (X). This covariate must not be affected by the intervention.

为了确定此类干预是否会对时间序列产生重大影响,我们必须使用适当的协变量(X)。 此协变量不得受到干预的影响。

For instance, we can see that for the year 2017, the European Central Bank left interest rates unchanged (and have done since):

例如,我们可以看到,欧洲中央银行在2017年维持利率不变(此后一直这样做):

Image for post
Source: tradingeconomics.com
资料来源:tradingeconomics.com

Taking this into account, the EUR/USD will be used as the covariate for this example.

考虑到这一点,本示例将使用EUR / USD作为协变量。

X = eurusd
y = gbpusd

While it is hypothesised that the currency will be affected by fluctuations in the greenback as well as many other macroeconomic conditions — it is assumed that the Bank of England intervention does not impact the EUR/USD.

假设该货币将受到美元波动以及许多其他宏观经济状况的影响-假设英格兰银行的干预不会影响欧元/美元。

分析 (Analysis)

The relevant currency pairs are downloaded from the FRED database using Quandl:

使用Quandl从FRED数据库下载相关货币对:

>>> eurusd = quandl.get("FRED/DEXUSEU", start_date='2017-01-01', end_date='2018-01-01', api_key='enter_api_key')>>> gbpusd = quandl.get("FRED/DEXUSUK", start_date='2017-01-01', end_date='2018-01-01', api_key='enter_api_key')
gbpusd

Here is a plot of the two currency pairs:

这是两个货币对的图表:

英镑/美元 (GBP/USD)

Image for post
Source: Federal Reserve Economic Data
资料来源:美联储经济数据

欧元/美元 (EUR/USD)

Image for post
Source: Federal Reserve Economic Data
资料来源:美联储经济数据

With the rate decision by the Bank of England having been taken on 2nd November 2017, t = 0 to 229 is defined as the pre-period (before intervention) and t = 230 to 248 is defined as the post-period (after intervention).

由于英格兰银行已于2017年11月2日做出利率决定,因此将t = 0到229定义为前期(干预之前),将t = 230到248定义为后期(干预之后) 。

data = pd.DataFrame({'y': y, 'X': X}, columns=['y', 'X'])
pre_period = [0, 229]
post_period = [230, 248]

According to the official GitHub for this package, this model “uses a classical Kalman Filter approach for solving the statespace equations”.

根据该软件包的官方GitHub的说法,该模型“使用经典的Kalman滤波方法来求解状态空间方程”。

The posterior inference can be generated as follows:

可以如下生成后验推断:

>>> ci = CausalImpact(data, pre_period, post_period)
>>> print(ci.summary())
>>> print(ci.summary(output='report'))
>>> ci.plot()

Here is the generated output:

这是生成的输出:

Posterior Inference {Causal Impact}
Average Cumulative
Actual 1.34 25.46
Prediction (s.d.) 1.32 (0.0) 25.17 (0.08)
95% CI [1.32, 1.33] [25.01, 25.33]
Absolute effect (s.d.) 0.02 (0.0) 0.29 (0.08)
95% CI [0.01, 0.02] [0.13, 0.45]
Relative effect (s.d.) 1.15% (0.32%) 1.15% (0.32%)
95% CI [0.52%, 1.77%] [0.52%, 1.77%]
Posterior tail-area probability p: 0.0
Posterior prob. of a causal effect: 100.0%

According to the above findings, the actual GBP/USD rate comes in at 1.34, while the rate without the intervention would have been 1.32.

根据上述发现,英镑/美元的实际汇率为1.34 ,而没有干预的汇率将为1.32

Moreover, the model indicates that there is a 100% posterior probability of a causal effect.

此外,该模型表明因果关系的后验概率为100%。

When analysing the more detailed report, the output also states:

在分析更详细的报告时,输出还指出:

The probability of obtaining this effect by chance is very small(Bayesian one-sided tail-area probability p = 0.0).This means the causal effect can be considered statisticallysignificant.

偶然获得此效应的可能性很小(贝叶斯单侧尾部区域概率p = 0.0)。这意味着因果效应在统计上是有意义的。

From this standpoint, the evidence suggests that the GBP/USD trended higher than it would have done without an interest rate rise. Here is an overview of the actual rate vs predictions:

从这个角度来看,有证据表明,英镑/美元的趋势要高于没有加息的情况。 以下是实际费率与预测的概述:

Image for post
Source: Jupyter Notebook Output
资料来源:Jupyter Notebook输出

As mentioned, Python uses a different approach than R in generating forecasts without an intervention — the latter relying more on a Bayesian approach that emphasises user prior knowledge. Indeed, one could try both methods to verify if the forecasts being generated coincide.

如前所述,Python使用R的方法与R不同,无需干预即可生成预测-后者更多地依赖于强调用户先验知识的贝叶斯方法。 确实,可以尝试两种方法来验证所生成的预测是否一致。

结论 (Conclusion)

This has been an introductory example to the causalimpact library and how the effects of interventions can be examined across a time series.

这是因果影响库的介绍性示例,以及如何在整个时间序列中检查干预措施的影响。

Many thanks for your time, and any questions or feedback are greatly welcomed.

非常感谢您的宝贵时间,我们欢迎您提出任何问题或反馈。

The Jupyter Notebook for this example is available at the MGCodesandStats repository as referenced below.

MGCodesandStats存储库中提供了此示例的Jupyter Notebook,如下所述。

Disclaimer: This article is written on an “as is” basis and without warranty. It was written with the intention of providing an overview of data science concepts, and should not be interpreted as investment advice, or any other sort of professional advice.

免责声明:本文按“原样”撰写,不作任何担保。 本文档旨在概述数据科学概念,不应将其解释为投资建议或任何其他形式的专业建议。

翻译自: https://towardsdatascience.com/analysing-time-series-interventions-with-causalimpact-currency-fluctuations-e6ab14a30768

时间序列因果关系

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/389315.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

微生物 研究_微生物监测如何工作,为何如此重要

微生物 研究Background背景 While a New York Subway station is bustling with swarms of businessmen, students, artists, and millions of other city-goers every day, its floors, railings, stairways, toilets, walls, kiosks, and benches are teeming with non-huma…

Linux shell 脚本SDK 打包实践, 收集assets和apk, 上传FTP

2019独角兽企业重金招聘Python工程师标准>>> git config user.name "jenkins" git config user.email "jenkinsgerrit.XXX.net" cp $JENKINS_HOME/maven.properties $WORKSPACE cp $JENKINS_HOME/maven.properties $WORKSPACE/app cp $JENKINS_…

opencv:卷积涉及的基础概念,Sobel边缘检测代码实现及卷积填充模式

具体参考我的另一篇文章: opencv:卷积涉及的基础概念,Sobel边缘检测代码实现及Same(相同)填充与Vaild(有效)填充 这里是对这一篇文章的补充! 卷积—三种填充模式 橙色部分为image, 蓝色部分为…

怎么查这个文件在linux下的哪个目录

因为要装pl/sql所以要查找tnsnames.ora文件。。看看怎么查这个文件在linux下的哪个目录 find / -name tnsnames.ora 查到: /opt/app/oracle/product/10.2/network/admin/tnsnames.ora/opt/app/oracle/product/10.2/network/admin/samples/tnsnames.ora 还可以用loca…

无法从套接字中获取更多数据_数据科学中应引起更多关注的一个组成部分

无法从套接字中获取更多数据介绍 (Introduction) Data science, machine learning, artificial intelligence, those terms are all over the news. They get everyone excited with the promises of automation, new savings or higher earnings, new features, markets or te…

web数据交互_通过体育运动使用定制的交互式Web应用程序数据科学探索任何数据...

web数据交互Most good data projects start with the analyst doing something to get a feel for the data that they are dealing with.大多数好的数据项目都是从分析师开始做一些事情,以便对他们正在处理的数据有所了解。 They might hack together a Jupyter n…

C# .net 对图片操作

using System.Drawing;using System.Drawing.Drawing2D;using System.Drawing.Imaging;public class ImageHelper{/// <summary>/// 获取图片中的各帧/// </summary>/// <param name"pPath">图片路径</param>/// <param name"pSaveP…

数据类型之Integer与int

数据类型之Integer与int Java入门 基本数据类型 众所周知&#xff0c;Java是面向对象的语言&#xff0c;一切皆对象。但是为了兼容人类根深蒂固的数据处理习惯&#xff0c;加快常规数据的处理速度&#xff0c;提供了9种基本数据类型&#xff0c;他们都不具备对象的特性&#xf…

PCA(主成分分析)思想及实现

PCA的概念&#xff1a; PCA是用来实现特征提取的。 特征提取的主要目的是为了排除信息量小的特征&#xff0c;减少计算量等。 简单来说&#xff1a; 当数据含有多个特征的时候&#xff0c;选取主要的特征&#xff0c;排除次要特征或者不重要的特征。 比如说&#xff1a;我们要…

【安富莱二代示波器教程】第8章 示波器设计—测量功能

第8章 示波器设计—测量功能 二代示波器测量功能实现比较简单&#xff0c;使用2D函数绘制即可。不过也专门开辟一个章节&#xff0c;为大家做一个简单的说明&#xff0c;方便理解。 8.1 水平测量功能 8.2 垂直测量功能 8.3 总结 8.1 水平测量功能 水平测量方…

深度学习数据更换背景_开始学习数据科学的最佳方法是了解其背景

深度学习数据更换背景数据科学教育 (DATA SCIENCE EDUCATION) 目录 (Table of Contents) The Importance of Context Knowledge 情境知识的重要性 (Optional) Research Supporting Context-Based Learning (可选)研究支持基于上下文的学习 The Context of Data Science 数据科学…

熊猫数据集_用熊猫掌握数据聚合

熊猫数据集Data aggregation is the process of gathering data and expressing it in a summary form. This typically corresponds to summary statistics for numerical and categorical variables in a data set. In this post we will discuss how to aggregate data usin…

IOS CALayer的属性和使用

一、CALayer的常用属性 1、propertyCGPoint position; 图层中心点的位置&#xff0c;类似与UIView的center&#xff1b;用来设置CALayer在父层中的位置&#xff1b;以父层的左上角为原点&#xff08;0&#xff0c;0&#xff09;&#xff1b; 2、 property CGPoint anchorPoint…

GridView详解

快速预览&#xff1a;GridView无代码分页排序GridView选中&#xff0c;编辑&#xff0c;取消&#xff0c;删除GridView正反双向排序GridView和下拉菜单DropDownList结合GridView和CheckBox结合鼠标移到GridView某一行时改变该行的背景色方法一鼠标移到GridView某一行时改变该行…

访问模型参数,初始化模型参数,共享模型参数方法

一. 访问模型参数 对于使用Sequential类构造的神经网络&#xff0c;我们可以通过方括号[]来访问网络的任一层。回忆一下上一节中提到的Sequential类与Block类的继承关系。 对于Sequential实例中含模型参数的层&#xff0c;我们可以通过Block类的params属性来访问该层包含的所有…

QZEZ第一届“饭吉圆”杯程序设计竞赛

终于到了饭吉圆杯的开赛&#xff0c;这是EZ我参与的历史上第一场ACM赛制的题目然而没有罚时 不过题目很好&#xff0c;举办地也很成功&#xff0c;为法老点赞&#xff01;&#xff01;&#xff01; 这次和翰爷&#xff0c;吴骏达 dalao&#xff0c;陈乐扬dalao组的队&#xff0…

谈谈数据分析 caoz_让我们谈谈开放数据…

谈谈数据分析 caozAccording to the International Open Data Charter(1), it defines open data as those digital data that are made available with the technical and legal characteristics necessary so that they can be freely used, reused and redistributed by any…

数据创造价值_展示数据并创造价值

数据创造价值To create the maximum value, urgency, and leverage in a data partnership, you must present the data available for sale or partnership in a clear and comprehensive way. Partnerships are based upon the concept that you are offering value for valu…

Java入门系列-22-IO流

File类的使用 Java程序如何访问文件&#xff1f;通过 java.io.File 类 使用File类需要先创建文件对象 File filenew File(String pathname);&#xff0c;创建时在构造函数中指定物理文件或目录&#xff0c;然后通过文件对象的方法操作文件或目录的属性。 \ 是特殊字符&#xff…

缺了一部分

学Java好多年&#xff0c;也参与一次完整项目&#xff0c;觉得让自己写项目写不出来&#xff0c;总觉得缺了一部分。 在这方面愚笨&#xff0c;不知道缺在哪里。以前觉得是知识不够牢固&#xff0c;于是重复去学&#xff0c;发现就那些东西。如果没有业务来熟悉的话&#xff0c…