Computing portfolio returns and standard deviation for 1000 funds

Hi everybody,

I have a panel with 10000 firms and 70 years of each firms return. Now I've wanted to create 1000 artificial mutual funds, each of which creates an equal-weighted portfolio of 5% of the 10000 firms.

I've used this loop:

counter <- 1
funds <- as.data.frame(matrix(NA)) #collect returns and sds for all funds


for (m in 1:1000) {

panel$include <- 0
subset <- sample(1:10000,50,replace=FALSE) #50 firms ids drawn at random

for (i in 1:50) {
  
  panel$include[panel$firmid == subset [i]] <- 1
}

new.data <- subset(panel, include ==1)


port.returns
port.sd

funds[counter, 1] <- port.returns
funds[counter,2] <- port.sd

counter <- counter+1 #refresh counter

}

As you can see I left out the portfolio return and the standard deviation. I am a bit confused. How can I manage to compute the portfolio return of my 50 firms when they're are equal-weighted. Does anybody know which code I could use to compute the portfolio return and the standard deviation?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.