官术网_书友最值得收藏!

Correlation

Correlation plays a very important role in quant finance. It not only determines the relation between the financial attributes but also plays a crucial role in predicting the future of financial instruments. Correlation is the measure of linear relationship between the two financial attributes. Now let us try to compute the different types of correlation in R using Sampledata, which is used in identifying the orders of components of predictive financial models.

Correlation can be computed by the following code. Let's first subset the data and then run the function for getting correlation:

x<-Sampledata[,2:5] 
rcorr(x, type="pearson") 

This generates the following correlation matrix, which shows the measure of linear relationship between the various daily level prices of a stock:

Autocorrelation

Autocorrelation is the correlation of the series with its past or future values. It is also known as serial correlation and lagged correlation. It plays a critical role in time series prediction modeling. The function acf computes estimates of the autocorrelation function.

The following code when executed gives the autocorrelation of the series with its lagged values:

acf(Sampledata$Volume) 

The graph is as follows:

Autocorrelation

Figure 2.10: Plot showing autocorrelation of series with its lag

This gives the plot of autocorrelations of the series with its lagged values. There are other options in functions such as lag.max, plot, and so on.

Partial autocorrelation

Partial autocorrelation of a time series is the correlation with its own lagged values, controlling for the values of the time series at all shorter lags. It is also used in time series modeling for identifying the orders of the components of forecasting techniques. It is computed by using the following code:

pacf(Sampledata$Volume) 

It also contains other options such as how many lags you want to use and plot. The preceding code gives the following plot:

Partial autocorrelation

Figure 2.11: Plot showing partial autocorrelation of series with its lag

Cross-correlation

Cross-correlation is a measure of the similarity of two series as a function of the displacement of one relative to the other. Just like acf and pacf, it also plays a crucial role in time series forecasting. It can be computed by using the following function:

ccf(Sampledata$Volume,Sampledata$High, main = "ccf plot") 

When the preceding code gets executed, it generates the following plot:

Cross-correlation

Figure 2.12: Plot showing cross-correlation of two series

主站蜘蛛池模板: 安达市| 太原市| 阿拉尔市| 平阳县| 岳阳县| 兴文县| 特克斯县| 贺兰县| 江永县| 孟连| 景谷| 淳化县| 太湖县| 阿荣旗| 封开县| 宝清县| 尼勒克县| 曲阳县| 广元市| 南漳县| 罗江县| 黎城县| 朔州市| 托里县| 高台县| 西昌市| 凤阳县| 海口市| 小金县| 攀枝花市| 正宁县| 宁远县| 苍南县| 山西省| 孝昌县| 会同县| 涿州市| 邢台县| 金门县| 高台县| 全州县|