Original link:tecdat.cn/?p=14200

Original source:Tuo End number according to the tribe public number

 

We’ve seen this before in the context of portfolio optimizationThe theory of MarkowitzIn which, the expected returns and covariance matrices are given

 

> pzoo = zoo ( StockIndex , order.by = rownames ( StockIndex ) )
> rzoo = ( pzoo / lag ( pzoo , k = -1) - 1 ) * 100
> 

ans <- do.call ( method , list ( x = x , ... ) ) + return ( getCov ( ans ) )} > covmat=Moments(as.matrix(rzoo),"CovClassic")
> (covmat=round(covmat,1))
SP500 N225 FTSE100 CAC40 GDAX HSI
SP500   17.8 12.7 13.8 17.8 19.5 18.9
N225    12.7 36.6 10.8 15.0 16.2 16.7
FTSE100 13.8 10.8 17.3 18.8 19.4 19.1
CAC40   17.8 15.0 18.8 30.9 29.9 22.8
GDAX    19.5 16.2 19.4 29.9 38.0 26.1
HSI     18.9 16.7 19.1 22.8 26.1 58.1
Copy the code

Now we can visualize the efficient boundary (and acceptable portfolio) below

> points(sqrt(diag(covmat)),er,pch=19,col="blue") > text(sqrt(diag(covmat)),er,names(er),pos=4, Col = "blue", cex = 6) > polygon (u, v, border = NA, col = RGB (0, 1,. 3))Copy the code

 

It’s actually hard to visualize what’s important on this graph: the correlation between earnings. It is not a point (univariate, with expected returns and standard deviation), but an efficient boundary. For example, this is our correlation matrix

SP500 N225 FTSE100 CAC40 GDAX HSI SP500 1.00 0.50 0.79 0.76 0.75 0.59 N225 0.50 0.43 0.45 0.43 0.36 FTSE100 0.79 0.43 1.00 0.81 0.76 0.60 CAC40 0.76 0.45 0.81 1.00 0.87 0.54 GDAX 0.75 0.43 0.76 0.87 1.00 0.56 HSI 0.59 0.36 0.60 0.54 0.56 1.00Copy the code

We can actually change the correlation between FT500 and FTSE100 (here.786)

courbe=function(r=.786){ ef plot(ef$sd,ef$er,type="l",xlab="Standard Deviation",ylab="Expected Return", Points (SQRT (diag (covmat)), er, PCH = 19, col = c (" blue ", "red"),1,2,1,1,1 (2) [c]) polygon (u, v, border = NA, col = RGB (0, 1,. 3))}Copy the code

For example, if the correlation coefficient is 0.6, we get the following effective boundary

> courbe(.6)
Copy the code

 

And have a stronger correlation

> courbe(.9)
Copy the code

 

Obviously, correlation matters. But more importantly, expected returns and covariances are not given but estimated. Previously, we did use standard estimators for variance matrices. But consider using another estimator that is more reliable

covmat=Moments(as.matrix(rzoo),"CovSde") points(sqrt(diag(covmat)),er,pch=19,col="blue") The text (SQRT (diag (covmat)), er, names (er), pos = 4, col = "blue", cex. = 6) polygon (u, v, border = NA, col = RGB (0, 1,. 3))Copy the code

 

It does affect the (horizontal) position of the point, because the variance is now different and the effective boundary is significantly lower.

To illustrate the last point, to show that we do have estimators based on observed benefits, what if we observe different benefits? One way to understand what might happen is to use a bootstrap program, such as Daily revenue.

> plot(ef$sd,ef$er,type="l",xlab="Standard Deviation",ylab="Expected Return", Xlim = c (3.5, 11), ylim = c (0,2.5), col = "white", LWD = 1.5) > polygon (u, v, border = NA, col = RGB (0, 1,. 3)) > for (I in 1:100) {+ + + er=apply(as.matrix(rzoo)[id,],2,mean) + points(sqrt(diag(covmat))[k],er[k],cex=.5) + }Copy the code

 

 

Or other assets

 

This is what we get on the (estimated) efficient boundary

> polygon(u,v,border=NA,col= RGB (0,0,1,.3)) > for(I in 1:100){+ + + + ef < -efficient. frontier(er, covmat, Alpha. Min = 2.5, alpha. Max = 2.5, nport = 50) + lines (ef $sd, ef $er, col = "red") +}Copy the code

 

As a result, it is difficult to assess whether a portfolio is optimal, at least statistically.


reference

1. Machine learning to identify changing stock market conditions — the application of hidden Markov model (HMM)

2. Garch-dcc model and DCC (MVT) modeling estimation in R language

3.R language implementation Copula algorithm modeling dependency case analysis report

4.R language uses ARIMA model to predict stock returns

5. Implementation of LASSO regression, Ridge regression and Elastic Net model in R language

6. Use R language to realize neural network to predict stock cases

7. Realization of R language volatility prediction: ARCH model and HAR-RV model

8.R language how to do Markov switching model