Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #2901

Re: Portfolio Optimization

From Bob Hanlon <hanlonr@cox.net>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Portfolio Optimization
Date 2011-06-02 23:10 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <is958d$5u6$1@smc.vnet.net> (permalink)

Show all headers | View raw


Covariants = {
   {0.000572843, 0.000223023, 0.000109176},
   {0.000223023, 0.000387437, 0.0000987402},
   {0.000109176, 0.0000987402, 0.007320276}};

weights = Transpose[{{w1}, {w2}, {w3}}];

{{w1, w2, w3}}

As the error message stated, weights.Covariants.Transpose[weights] is not a number

weights.Covariants.Transpose[weights]

{{w2 (0.000223023 w1 + 0.000387437 w2 + 0.0000987402 w3) + 
   w1 (0.000572843 w1 + 0.000223023 w2 + 0.000109176 w3) + (0.000109176 w1 + 
      0.0000987402 w2 + 0.00732028 w3) w3}}

Use Part

NMinimize[{
  (weights.Covariants.Transpose[weights])[[1, 1]],
  w1 + w2 + w3 == 1}, {w1, w2, w3}]

{0.000327596, {w1 -> 0.309102, w2 -> 0.659653, w3 -> 0.0312441}}


Bob Hanlon

---- Priyan Fernando <priyan.fernando@gmail.com> wrote: 

=============
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.


Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: Portfolio Optimization Bob Hanlon <hanlonr@cox.net> - 2011-06-02 23:10 +0000

csiph-web