I have the following R code to generate 100 random weights
# Creating a matrix to store the weights
all_wts <- matrix(nrow = 100,
ncol = length(tickers))1 = 100 ### number of tickers 4 `
# run the for loop 100 times.
for (i in 1:np1) {
wts <- runif(length(tickers))
wts <- wts/sum(wts)`
# Storing weight in the matrix
all_wts[i,] <- wts }
So I should have a matrix of weights
$$ w= \begin{bmatrix}
w_1 & w_2 & w_3 & w_4 \
\vdots& \vdots & \vdots & \vdots \
\vdots & \vdots & \vdots & \vdots \
\end{bmatrix}$$
where first row
$$ w^* = \begin{bmatrix}w1 & w2 &w3& w4 \end{bmatrix} $$ is the first set of random weights etc .
Now my second step is to multiply first set of random weights with another matrix called $$R_t $$ where $$R_t = \begin{bmatrix}
A_1 & A_2 &A_3 & A_4 \
\vdots& \vdots & \vdots & \vdots \
A_{1,252} & A_{2,252} & A_{3,252}& A_{4,252} \
\end{bmatrix}$$
a1<- all_wts[1,]
b<-return
yts <- rowSums(a1*b)
Then I repeat this multiplication with the second random weights such as
a2<- all_wts[2,]
b<-return
yts2 <- rowSums(a2*b)
I do this for all 100 random weights. My question is, how can I write one code to implement all multiplications for each random weights in and store the results of step 2 for each random weights in a new matrix so I can move to the third step which needs the results of step 2.
Any ideas will be appreciated.