使用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