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

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

主站蜘蛛池模板: 阜康市| 蒙城县| 枞阳县| 镇江市| 河源市| 广灵县| 那曲县| 乌拉特前旗| 海南省| 临江市| 翼城县| 肥东县| 乌拉特后旗| 汉源县| 惠水县| 乐陵市| 彝良县| 河津市| 兰考县| 石棉县| 从江县| 亳州市| 临洮县| 托克托县| 宁海县| 平阳县| 西青区| 宜君县| 哈尔滨市| 虎林市| 克山县| 宝丰县| 淮滨县| 澄江县| 台山市| 福海县| 博白县| 金昌市| 咸宁市| 武城县| 肇庆市|