Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #2911 > unrolled thread
| Started by | "Sjoerd C. de Vries" <sjoerd.c.devries@gmail.com> |
|---|---|
| First post | 2011-06-02 23:11 +0000 |
| Last post | 2011-06-02 23:11 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.soft-sys.math.mathematica
Re: Portfolio Optimization "Sjoerd C. de Vries" <sjoerd.c.devries@gmail.com> - 2011-06-02 23:11 +0000
| From | "Sjoerd C. de Vries" <sjoerd.c.devries@gmail.com> |
|---|---|
| Date | 2011-06-02 23:11 +0000 |
| Subject | Re: Portfolio Optimization |
| Message-ID | <is95bc$60r$1@smc.vnet.net> |
There is no difference between row and column vectors in Mathematica, so you don't need to do a Transpose in order to do a matrix multiplication. The following works:
In[86]:= (*Variance Covariance Matrix*)Covariants = {{0.000572843,
0.000223023, 0.000109176}, {0.000223023, 0.000387437,
0.0000987402}, {0.000109176, 0.0000987402, 0.007320276}}
(*Asset Weights Vector*)
weights = {w1, w2, w3}
(*Optimize Portfolio Variance*)
NMinimize[{weights.Covariants.weights, w1 + w2 + w3 == 1}, {w1, w2,
w3}]
Out[86]= {{0.000572843, 0.000223023, 0.000109176}, {0.000223023,
0.000387437, 0.0000987402}, {0.000109176, 0.0000987402, 0.00732028}}
Out[87]= {w1, w2, w3}
Out[88]= {0.000327596, {w1 -> 0.309102, w2 -> 0.659653,
w3 -> 0.0312441}}
BTW the NMinimize call could have been written more nicely as:
NMinimize[{weights.Covariants.weights, Total[weights] == 1}, weights]
Cheers-- Sjoerd
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web