Advertisement
mjaniec

Generating stable equity line

Oct 24th, 2012
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.48 KB | None | 0 0
  1. # read post: http://www.reakkt.com/2012/10/how-to-generate-save-investment-strategy.html
  2.  
  3. k <- 500 # liczba strategii
  4.  
  5. n <- 500 # dlugosc okresu modelowania
  6.  
  7. x <- matrix(NA,n,k)
  8.  
  9. for (i in 1:k) x[,i] <- rnorm(n,mean=runif(1,0.01,0.05),sd=runif(1,1,6))/100
  10.  
  11. range(cov(x))
  12.  
  13. x <- sapply(1:k, function(i) cumsum(x[,i]))
  14.  
  15. y <- rowSums(x)
  16.  
  17. par(mfrow=c(2,1))
  18.  
  19. matplot(x,type="l",lty="solid",xlab="time",ylab="return")
  20.  
  21. plot(y,type="l",xlab="time",ylab="return")
  22.  
  23. par(mfrow=c(1,1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement