344 Chapter 12
Range(“Results”).Cells(counter, 5) = ActiveSheet.
Range(“x_2”)
Range(“Results”).Cells(counter, 6) = ActiveSheet.
Range(“x_3”)
Range(“Results”).Cells(counter, 7) = ActiveSheet.
Range(“x_4”)
Next counter
End Sub ActiveSheet.Range(“x_3”)
Range(“Results”).Cells(counter, 7) = _
ActiveSheet.Range(“x_4”)
Next counter
End Sub
The program includes two subroutines: Solve calls the Excel Solver;
and the subroutine Doit repeatedly calls the solver for different values
of the range named Constant (this is cell C8 in the spreadsheet),
putting the output in a range called Results.
The fi nal output looks like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
ABCDEFGH I JKLMNO
RESULTS
Variance-covariance matrix Means c Sigma Mean x
1
x
2
x
3
0.10 0.03 -0.08 0.05 8% Ctrl+A works the VBA program -0.035 20.24% 8.70% 0.6049 0.0885 0.3066
0.03 0.20 0.02 0.03 9% which calculates efficient -0.03 20.25% 8.70% 0.6042 0.0887 0.3070
-0.08 0.02 0.30 0.20 10% portfolios for no-short sales. -0.025 20.25% 8.70% 0.6035 0.0890 0.3075
0.05 0.03 0.20 0.90 11% This program iteratively -0.02 20.25% 8.71% 0.6027 0.0893 0.3080
substitutes a constant ranging -0.015 20.25% 8.71% 0.6017 0.0897 0.3086
c 16.0% <-- This is the constant from -3.5% 'till 16% (1/2% -0.01 20.26% 8.71% 0.6007 0.0901 0.3092
jumps) and calculates the -0.005 20.26% 8.71% 0.5994 0.0908 0.3098
optimal portfolio. 0 20.27% 8.71% 0.5982 0.0912 0.3106
x
1
0.0000 0 0.005 20.27% 8.71% 0.5968 0.0917 0.3115
x
2
0.0000 0 0.01 20.28% 8.72% 0.5950 0.0926 0.3123
x
3
0.0000 0 0.015 20.29% 8.72% 0.5932 0.0934 0.3134
x
4
1.0000 0 0.02 20.30% 8.72% 0.5910 0.0943 0.3147
Total 1.0000 <-- =SUM(B11:B14) 0.025 20.31% 8.73% 0.5885 0.0953 0.3161
0.03 20.32% 8.73% 0.5856 0.0965 0.3179
Portfolio mean 11.00% <-- {=MMULT(TRANSPOSE(B11:B14),G3:G6)} 0.035 20.34% 8.74% 0.5821 0.0980 0.3199
Portfolio sigma 94.87% <-- {=SQRT(MMULT(TRANSPOSE(B11:B14),MMULT(B3:E6,B11:B14)))} 0.04 20.37% 8.74% 0.5779 0.0998 0.3224
Theta -5.27% <-- =(B17-C8)/B18 0.045 20.41% 8.75% 0.5726 0.1019 0.3255
0.05 20.46% 8.76% 0.5659 0.1047 0.3294
0.055 20.54% 8.78% 0.5572 0.1083 0.3345
0.06 20.67% 8.80% 0.5452 0.1133 0.3415
0.065 20.90% 8.82% 0.5277 0.1205 0.3518
0.07 21.36% 8.87% 0.4992 0.1324 0.3684
0.075 23.27% 9.01% 0.4267 0.1630 0.3856
PORTFOLIO OPTIMIZATION WITHOUT SHORT SALES
12.4.1 Adding a Reference to Solver in VBA
If the preceding routine does not work, you may need to add a reference
to Solver in the VBA editor. Press [Alt] + F11 to get to the editor and
check the reference.