日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2023/11/29 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 时间序列因果关系_分析具有因果关系的时间序列干预:货币波动 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

時間序列因果關系

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:

我們將使用因果影響來調查:

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

    如果不采取這種干預措施,英鎊/美元的匯率將是多少?
  • 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年維持利率不變(此后一直這樣做):

    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)

    Source: Federal Reserve Economic Data資料來源:美聯儲經濟數據

    歐元/美元 (EUR/USD)

    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:

    從這個角度來看,有證據表明,英鎊/美元的趨勢要高于沒有加息的情況。 以下是實際費率與預測的概述:

    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

    時間序列因果關系

    總結

    以上是生活随笔為你收集整理的时间序列因果关系_分析具有因果关系的时间序列干预:货币波动的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。