I would appreciate help with how to save multiple vectors in a list, where the vectors are obtained by the help of an equation in R.
Using the fact that portfolios from the minimum variance line satisfy w = s*w_min+(1−s)*w_m I want to compute optimal portfolios for s =[-2,2] with step-size 0.1. I have already computed w_min (minimum variance portfolio) and w_m (market portfolio). And I have found that one can print out all the optimal portfolios (the vectors) using the following:
for(s in seq(-2, 2, by=0.1)){
my_out <- (s*w_min)+(1-s)*w_m
print(my_out)}
And this gives me outputs in the following correct form (though more than what is presented below):
## BBD OXY NOK AAPL MSFT
## [1,] -0.4111434 -0.1284589 -0.1824016 0.4634135 1.25859
## BBD OXY NOK AAPL MSFT
## [1,] -0.3953277 -0.1217342 -0.1734786 0.4559005 1.23464
And now I want to save these results in a list in R so that I can use these different optimal portfolios for future calculations, this is my attempt of doing this:
my_vec <- list() # Create empty list
for(s in seq(-2, 2, by=0.1)) { # Head of for-loop
my_out <- (s*w_min)+(1-s)*w_m # Create some output
my_vec <- c(my_vec, my_out) # Save output in vector
}
But this does not give the result I am looking for. Instead of giving me the first portfolio when calling my_vec[1] I am given ## [1] -0.4111434 which is the first value in the first portfolio. What is it that prevents each portfolio from being saved as a vector?
Edit: Here is w_min and w_m as requested
w_min
## BBD OXY NOK AAPL MSFT
## [1,] 0.06332585 0.07328322 0.08528878 0.2380229 0.5400793
w_m
## BBD OXY NOK AAPL MSFT
## [1,] -0.09483055 0.006035851 -0.003941358 0.3131531 0.779583