Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #2895 > unrolled thread
| Started by | Priyan Fernando <priyan.fernando@gmail.com> |
|---|---|
| First post | 2011-06-02 11:17 +0000 |
| Last post | 2011-06-02 23:12 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
Portfolio Optimization Priyan Fernando <priyan.fernando@gmail.com> - 2011-06-02 11:17 +0000
Re: Portfolio Optimization Albert Retey <awnl@gmx-topmail.de> - 2011-06-02 23:12 +0000
| From | Priyan Fernando <priyan.fernando@gmail.com> |
|---|---|
| Date | 2011-06-02 11:17 +0000 |
| Subject | Portfolio Optimization |
| Message-ID | <is7rfr$rhe$1@smc.vnet.net> |
Hi!
I am trying to run a portfolio optimizer in Mathematica. That is, minimising
the variance of a portfolio of assets.
(* 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 = Transpose[{{w1}, {w2}, {w3}}]
(* Optimize Portfolio Variance*)
NMinimize[{weights.Covariants.Transpose[weights],
w1 + w2 + w3 == 1}, {w1, w2, w3}]
The output Mathematica throws is as follows:
*NMinimize::nnum: "The function value {{0.00408844}} is not a number at
{w1,w2,w3} = {-0.63531,0.918621,0.716689}. "*
However if I program the same optimization in Excel (using Solver to find
optimal weights) I see the weights should be {0.309102831, 0.659653054,
0.031244115} as this gives a lower portoflio variance of 0.0003276.
Does anyone know why Mathematica is giving me the wrong answer? And, why is
it saying the funcion value is not a number?
Thanks for your all your comments,
Priyan.
[toc] | [next] | [standalone]
| From | Albert Retey <awnl@gmx-topmail.de> |
|---|---|
| Date | 2011-06-02 23:12 +0000 |
| Message-ID | <is95dn$62s$1@smc.vnet.net> |
| In reply to | #2895 |
Am 02.06.2011 13:17, schrieb Priyan Fernando:
> Hi!
>
> I am trying to run a portfolio optimizer in Mathematica. That is,
> minimising the variance of a portfolio of assets.
>
> (* 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 = Transpose[{{w1}, {w2}, {w3}}]
>
> (* Optimize Portfolio Variance*)
> NMinimize[{weights.Covariants.Transpose[weights], w1 + w2 + w3 == 1},
> {w1, w2, w3}]
>
> The output Mathematica throws is as follows: *NMinimize::nnum: "The
> function value {{0.00408844}} is not a number at {w1,w2,w3} =
> {-0.63531,0.918621,0.716689}. "*
>
> However if I program the same optimization in Excel (using Solver to
> find optimal weights) I see the weights should be {0.309102831,
> 0.659653054, 0.031244115} as this gives a lower portoflio variance of
> 0.0003276.
>
> Does anyone know why Mathematica is giving me the wrong answer? And,
> why is it saying the funcion value is not a number?
NMinimize wants an expression that evaluates to a number, yours does
evaluate to a List of a List, which represents an 1x1 Matrix. This does
work and yields the expected results:
NMinimize[{(weights.Covariants.Transpose[weights])[[1, 1]],
w1 + w2 + w3 == 1}, {w1, w2, w3}]
hth,
albert
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web