使用r語言做garch模型_使用GARCH估計貨幣波動率

使用r語言做garch模型

Asset prices have a high degree of stochastic trends inherent in the time series. In other words, price fluctuations are subject to a large degree of randomness, and therefore it is very difficult to forecast asset prices using traditional time series models such as ARIMA.

資產價格具有時間序列固有的高度隨機趨勢。 換句話說,價格波動受到很大程度的隨機性影響,因此很難使用諸如ARIMA之類的傳統時間序列模型來預測資產價格。

Moreover, with much of the trading done on an algorithmic basis today — prices are constantly adjusting on the basis of such forecasts — making it quite hard to exploit an advantage in the markets.

而且,由于當今許多交易都是基于算法進行的-價格在這種預測的基礎上不斷調整-因此很難在市場中利用優勢。

For instance, suppose I build a time series model to predict rainfall in a city for the next three months. My time series model could have a strong degree of accuracy as the forecasts will not influence rainfall levels in the future. However, if everyone uses an ARIMA model to predict asset price fluctuations for the next three months — then subsequent trading on the basis of those forecasts will directly influence previous forecasts — rendering them invalid in many cases.

例如,假設我建立了一個時間序列模型來預測未來三個月城市的降雨。 我的時間序列模型可能具有很高的準確性,因為預測不會影響將來的降雨量。 但是,如果每個人都使用ARIMA模型來預測未來三個月的資產價格波動-那么根據這些預測進行的后續交易將直接影響先前的預測-在許多情況下使它們無效。

背景 (Background)

As a result, it is common to model projected volatility of an asset price in the financial markets — as opposed to forecasting projected price outright.

因此,通常在金融市場中對資產價格的預計波動率建模,而不是直接預測預測價格。

Let’s see how this can be accomplished using Python. A GARCH model is used to forecast volatility for the EUR/USD and GBP/USD currency pairs, using data from January 2017 — January 2018.

讓我們看看如何使用Python來實現。 GARCH模型用于使用2017年1月至2018年1月的數據預測EUR / USD和GBP / USD貨幣對的波動。

The data is sourced from FRED using the Quandl library:

數據使用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')

The series are converted to logarithmic format to smooth out the time series:

該系列將轉換為對數格式,以平滑時間序列:

歐元/美元 (EUR/USD)

英鎊/美元 (GBP/USD)

Image for post
Source: Quandl
資料來源:Quandl

The data is then first-differenced to approximate a Gaussian distribution.

然后對數據進行一階微分以近似高斯分布。

Dickey-Fuller tests show a p-value of 0 for both series — indicating that we reject the null hypothesis that a unit root is present at the 5% level of significance, i.e. stationarity or trend stationarity is indicated as being present in the model.

Dickey-Fuller檢驗顯示兩個系列的p值均為0,這表明我們拒絕零假設,即單位根以5%的顯著性水平存在,即模型中指示存在平穩性或趨勢平穩性。

EUR/USD: Dickey-Fuller Test Results

歐元/美元:迪基-富勒測試結果

>>> result = ts.adfuller(data, 1)
>>> result(-16.26123019770431,
3.564065405943774e-29,
0,
247,
{'1%': -3.457105309726321,
'5%': -2.873313676101283,
'10%': -2.5730443824681606},
-1959.704886024891)

GBP/USD: Dickey-Fuller Test Results

英鎊/美元:迪基-富勒測試結果

>>> result = ts.adfuller(data, 1)
>>> result(-12.380335699861567,
5.045829408723097e-23,
1,
246,
{'1%': -3.457215237265747,
'5%': -2.873361841566324,
'10%': -2.5730700760129555},
-1892.8308007824835)

Additionally, a visual screening of QQ plots show that the series now largely follow a normal distribution:

此外,對QQ圖的可視化篩選顯示,該系列現在基本上遵循正態分布:

EUR/USD: QQ Plot

歐元/美元:QQ情節

Image for post
Source: Jupyter Notebook Output
資料來源:Jupyter Notebook輸出

GBP/USD: QQ Plot

英鎊/美元:QQ情節

Image for post
Source: Jupyter Notebook Output
資料來源:Jupyter Notebook輸出

GARCH建模 (GARCH Modelling)

A GARCH(1,1) model is built to predict the volatility for the last 30 days of trading data for both currency pairs. The previous data is used as the training set for the GARCH model.

建立了GARCH(1,1)模型以預測兩種貨幣對的交易數據的最后30天的波動性。 先前的數據用作GARCH模型的訓練集。

# split into train/test
n_test = 30
train, test = data[:-n_test], data[-n_test:]
# define model
model = arch_model(train, mean='Zero', vol='GARCH', p=1, q=1)

The predictions are generated as follows:

預測生成如下:

# fit model
model_fit = model.fit()
# forecast the test set
yhat = model_fit.forecast(horizon=n_test)

Now, let’s compare the predicted variance with the actual 5-day rolling variance across the test set.

現在,讓我們將預測方差與整個測試集的實際5天滾動方差進行比較。

歐元/美元 (EUR/USD)

Predicted Variance

預測方差

test.rolling(window=5).var().plot(style='g')
pyplot.title("5-day Rolling Variance")
Image for post
Source: Jupyter Notebook Output
資料來源:Jupyter Notebook輸出

5-day Rolling Variance

5天滾動差異

pyplot.plot(yhat.variance.values[-1, :])
pyplot.title("Predicted Variance")
pyplot.show()
Image for post
Source: Jupyter Notebook Output
資料來源:Jupyter Notebook輸出

We see that the GARCH model predicts a drop in volatility for the last 30 days (as measured by variance) — this is confirmed by a visual inspection of the actual 5-day rolling variance.

我們看到,GARCH模型預測了最近30天的波動性下降(以方差衡量),這通過對實際5天滾動方差的目視檢查得到確認。

Let’s have a look at the comparisons across the GBP/USD.

讓我們看一下英鎊/美元之間的比較。

英鎊/美元 (GBP/USD)

Predicted Variance

預測方差

Image for post
Source: Jupyter Notebook Output
資料來源:Jupyter Notebook輸出

5-day Rolling Variance

5天滾動差異

Image for post
Source: Jupyter Notebook Output
資料來源:Jupyter Notebook輸出

We can see that while the scale for the predicted variance is much narrower than the actual 5-day rolling variance — both instances are predicting a decrease in variance across the 30-day test period.

我們可以看到,盡管預測方差的標度比實際5天滾動方差要窄得多,但兩個實例都預測了30天測試期間方差的減少。

This corresponds with what we actually observe — there was little movement in both the EUR/USD and GBP/USD currency pairs in December 2017 relative to that of other months in the trading year.

這與我們實際觀察到的情況相對應-與交易年度的其他月份相比,2017年12月的EUR / USD和GBP / USD貨幣對幾乎沒有變化。

結論 (Conclusion)

This has been an illustration of how GARCH can be used to model time series volatility.

這說明了如何使用GARCH對時間序列波動性進行建模。

Hope you found the article useful, and any questions or feedback are greatly appreciated. The GitHub repository for this example, as well as other relevant references are available below.

希望您覺得這篇文章對您有用,對您的任何問題或反饋都深表感謝。 下面提供了此示例的GitHub存儲庫以及其他相關參考。

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/estimating-currency-volatility-using-garch-e373cf82179d

使用r語言做garch模型

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/391348.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/391348.shtml
英文地址,請注明出處:http://en.pswp.cn/news/391348.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

ARC下的內存泄漏

##ARC下的內存泄漏 ARC全稱叫 ARC(Automatic Reference Counting)。在編譯期間,編譯器會判斷對象的使用情況,并適當的加上retain和release,使得對象的內存被合理的管理。所以,從本質上說ARC和MRC在本質上是一樣的,都是…

python:校驗郵箱格式

# coding:utf-8import redef validateEmail(email):if re.match("^.\\(\\[?)[a-zA-Z0-9\\-\\.]\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", email) ! None:# if re.match("/^\w[a-z0-9]\.[a-z]{2,4}$/", email) ! None:print okreturn okelse:print failret…

cad2019字體_這些是2019年最有效的簡歷字體

cad2019字體When it comes to crafting the perfect resume to land your dream job, you probably think of just about everything but the font. But font is a key part of your first impression to recruiters and employers.當制作一份完美的簡歷來實現理想的工作時&…

Go語言實戰 : API服務器 (4) 配置文件讀取及連接數據庫

讀取配置文件 1. 主函數中增加配置初始化入口 先導入viper包 import (..."github.com/spf13/pflag""github.com/spf13/viper""log")在 main 函數中增加了 config.Init(*cfg) 調用,用來初始化配置,cfg 變量值從命令行 f…

方差偏差權衡_偏差偏差權衡:快速介紹

方差偏差權衡The bias-variance tradeoff is one of the most important but overlooked and misunderstood topics in ML. So, here we want to cover the topic in a simple and short way as possible.偏差-方差折衷是機器學習中最重要但被忽視和誤解的主題之一。 因此&…

win10 uwp 讓焦點在點擊在頁面空白處時回到textbox中

原文:win10 uwp 讓焦點在點擊在頁面空白處時回到textbox中在網上 有一個大神問我這樣的問題:在做UWP的項目,怎么能讓焦點在點擊在頁面空白處時回到textbox中? 雖然我的小伙伴認為他這是一個 xy 問題,但是我還是回答他這個問題。 首…

python:當文件中出現特定字符串時執行robot用例

#coding:utf-8 import os import datetime import timedef execute_rpt_db_full_effe_cainiao_city():flag Truewhile flag:# 判斷該文件是否存在# os.path.isfile("/home/ytospid/opt/docker/jsc_spider/jsc_spider/log/call_proc.log")# 存在則獲取昨天日期字符串…

MySQL分庫分表方案

1. MySQL分庫分表方案 1.1. 問題:1.2. 回答: 1.2.1. 最好的切分MySQL的方式就是:除非萬不得已,否則不要去干它。1.2.2. 你的SQL語句不再是聲明式的(declarative)1.2.3. 你招致了大量的網絡延時1.2.4. 你失去…

linux創建sudo用戶_Linux終極指南-創建Sudo用戶

linux創建sudo用戶sudo stands for either "superuser do" or "switch user do", and sudo users can execute commands with root/administrative permissions, even malicious ones. Be careful who you grant sudo permissions to – you are quite lit…

重學TCP協議(1) TCP/IP 網絡分層以及TCP協議概述

1. TCP/IP 網絡分層 TCP/IP協議模型(Transmission Control Protocol/Internet Protocol),包含了一系列構成互聯網基礎的網絡協議,是Internet的核心協議,通過20多年的發展已日漸成熟,并被廣泛應用于局域網和…

分節符縮寫p_p值的縮寫是什么?

分節符縮寫pp是概率嗎? (Is p for probability?) Technically, p-value stands for probability value, but since all of statistics is all about dealing with probabilistic decision-making, that’s probably the least useful name we could give it.從技術…

Spring-----AOP-----事務

xml文件中&#xff1a; 手動處理事務&#xff1a; 設置數據源 <bean id"dataSource" class"com.mchange.v2.c3p0.ComboPooledDataSource"> <property name"driverClass" value"com.mysql.jdbc.Driver"></property…

[測試題]打地鼠

Description 小明聽說打地鼠是一件很好玩的游戲&#xff0c;于是他也開始打地鼠。地鼠只有一只&#xff0c;而且一共有N個洞&#xff0c;編號為1到N排成一排&#xff0c;兩邊是墻壁&#xff0c;小明當然不可能百分百打到&#xff0c;因為他不知道地鼠在哪個洞。小明只能在白天打…

在PHP服務器上使用JavaScript進行緩慢的Loris攻擊[及其預防措施!]

Forget the post for a minute, lets begin with what this title is about! This is a web security-based article which will get into the basics about how HTTP works. Well also look at a simple attack which exploits the way the HTTP protocol works.暫時忘掉這個帖…

三星為什么要賣芯片?手機干不過華為小米,半導體好掙錢!

據外媒DigiTimes報道&#xff0c;三星有意向其他手機廠商出售自家的Exynos芯片以擴大市場份額。知情人士透露&#xff0c;三星出售自家芯片旨在提高硅晶圓工廠的利用率&#xff0c;同時提高它們在全球手機處理器市場的份額&#xff0c;尤其是中端市場。 三星為什么要賣芯片&…

重學TCP協議(2) TCP 報文首部

1. TCP 報文首部 1.1 源端口和目標端口 每個TCP段都包含源端和目的端的端口號&#xff0c;用于尋找發端和收端應用進程。這兩個值加上IP首部中的源端IP地址和目的端IP地址唯一確定一個TCP連接 端口號分類 熟知端口號&#xff08;well-known port&#xff09;已登記的端口&am…

linux:vim中全選復制

全選&#xff08;高亮顯示&#xff09;&#xff1a;按esc后&#xff0c;然后ggvG或者ggVG 全部復制&#xff1a;按esc后&#xff0c;然后ggyG 全部刪除&#xff1a;按esc后&#xff0c;然后dG 解析&#xff1a; gg&#xff1a;是讓光標移到首行&#xff0c;在vim才有效&#xf…

機器學習 預測模型_使用機器學習模型預測心力衰竭的生存時間-第一部分

機器學習 預測模型數據科學 &#xff0c; 機器學習 (Data Science, Machine Learning) 前言 (Preface) Cardiovascular diseases are diseases of the heart and blood vessels and they typically include heart attacks, strokes, and heart failures [1]. According to the …

程序2:word count

本程序改變自&#xff1a;http://blog.csdn.net/zhixi1050/article/details/72718638 語言&#xff1a;C 編譯環境&#xff1a;visual studio 2015 運行環境&#xff1a;Win10 做出修改的地方&#xff1a;在原碼基礎上修改了記錄行數的功能&#xff0c;刪去了不完整行數的記錄&…

重學TCP協議(3) 端口號及MTU、MSS

1. 端口相關的命令 1.1 查看端口是否打開 使用 nc 和 telnet 這兩個命令可以非常方便的查看到對方端口是否打開或者網絡是否可達。如果對端端口沒有打開&#xff0c;使用 telnet 和 nc 命令會出現 “Connection refused” 錯誤 1.2 查看監聽端口的進程 使用 netstat sudo …