Help R
Vous souhaitez réagir à ce message ? Créez un compte en quelques clics ou connectez-vous pour continuer.
Le Deal du moment : -20%
Ecran PC GIGABYTE 28″ LED M28U 4K ( IPS, 1 ms, ...
Voir le deal
399 €

Comment coder quatre exercice selon J

Aller en bas

Comment coder quatre exercice selon J Empty Comment coder quatre exercice selon J

Message par Admin Mer 18 Mar - 2:01

#1
Er <- matrix( diff(log(STOCKS)),dim(STOCKS)[1]-1 ,dim(STOCKS)[2])
Vc <- covars(Er)

install.packages("quadprog")
library('quadprog')

#2
Optimal <- function(a,b,c,d) {
w <- solve.QP(a,b,t(c),d,meq=1)
return(w)
}

Dmat <- Vc
dvec <- matrix(colMeans(Er),dim(Er)[2],1)
amat <- rbind(rep(1,5),diag(5))
Amat <- t(amat)
bvec <- c(1,rep(0,5))

Sol<-solve.QP(Dmat,dvec,Amat,bvec,meq=1,factorized=FALSE)

Sol$solution

#3
n <- 200
lambda <- matrix(seq(-5,5,length.out=n),n,1)
solution <- matrix(NA,dim(STOCKS)[2],n)
for (i in 1:n) {
solution[i,] <- solve.QP(Dmat,dvec/lambda[i],Amat,bvec,meq=1,factorized=FALSE)$solution
}

Ep <- matrix(NA,n,1)
Vp <- matrix(NA,n,1)
for (i in 1:n) {
Ep[i,] <- PortRet(solution[i,],dvec)
Vp[i,] <- PortSig(Solution[i,],Dmat)
}

Matplot(Vp,Ep)
plot(Vp,Ep)

Admin
Admin

Messages : 8
Date d'inscription : 17/03/2015

https://help-r.kanak.fr

Revenir en haut Aller en bas

Revenir en haut


 
Permission de ce forum:
Vous ne pouvez pas répondre aux sujets dans ce forum