Skip to content

Static Portfolio Optimization

5 messages · Mark Leeds, Jorge Nieves, Dirk Eddelbuettel +1 more

#
On 1 October 2009 at 15:01, markleeds at verizon.net wrote:
| I think I remember Adrian Trapletti implemented static portfolio
| optimization using quadprog in tseries. It's been a long time so I don't
| remember the details ( it may be restricted to long only but you can add
| variables to make<br />it handle long short ) but you may want to check
| tseries out. 

Correct -- the tseries package has done since time immportal. 

And some seven or eight years ago I sent Adrian a patch, styled after the
discussion in Huang and Litzenberger, that adds the ability to have long and
short positions.  

Which Adrian promptly added and which has been there ever since:

R> head(as.zoo(EuStockMarkets))
           DAX  SMI  CAC FTSE
1991(130) 1629 1678 1773 2444
1991(131) 1614 1688 1750 2460
1991(132) 1607 1679 1718 2448
1991(133) 1621 1684 1708 2470
1991(134) 1618 1687 1723 2485
1991(135) 1611 1672 1714 2467
R> X <- diff(log(as.zoo(EuStockMarkets)))
R> res <- portfolio.optim(X)                 ## Long only
R> res$pw
[1] 0.0000 0.3958 0.0000 0.6042
R> res <- portfolio.optim(X, shorts=TRUE)    ## Long/Short
R> res$pw
[1]  0.02550  0.38213 -0.06377  0.65614
R> 

This is arguably a better example than the one in help(portfolio.optim) so
maybe I should send Kurt a new patch :)

Dirk
#
Thanks for your responses. I found the function "portfolio.optim" and
the tseries series package and a document with explanations. The
function indeed allows for shorts. However, I still do not see how to
pass into the function the vector of expected values and the covariance
matrix. The function's input is the time series themselves. It seems
that the function internally computes both the expected values and the
covariance matrix, and then it performs the optimization.  Please
correct me if I am not reading right the function description and its
specifications.

Thanks, 


Jorge Nieves


-----Original Message-----
From: Dirk Eddelbuettel [mailto:edd at debian.org] 
Sent: Thursday, October 01, 2009 04:25 PM
To: markleeds at verizon.net
Cc: Jorge Nieves; r-sig-finance at stat.math.ethz.ch;
jessevel at andrew.cmu.edu
Subject: Re: [R-SIG-Finance] Static Portfolio Optimization
On 1 October 2009 at 15:01, markleeds at verizon.net wrote:
| I think I remember Adrian Trapletti implemented static portfolio 
| optimization using quadprog in tseries. It's been a long time so I 
| don't remember the details ( it may be restricted to long only but you

| can add variables to make<br />it handle long short ) but you may want

| to check tseries out.

Correct -- the tseries package has done since time immportal. 

And some seven or eight years ago I sent Adrian a patch, styled after
the discussion in Huang and Litzenberger, that adds the ability to have
long and short positions.  

Which Adrian promptly added and which has been there ever since:

R> head(as.zoo(EuStockMarkets))
           DAX  SMI  CAC FTSE
1991(130) 1629 1678 1773 2444
1991(131) 1614 1688 1750 2460
1991(132) 1607 1679 1718 2448
1991(133) 1621 1684 1708 2470
1991(134) 1618 1687 1723 2485
1991(135) 1611 1672 1714 2467
R> X <- diff(log(as.zoo(EuStockMarkets)))
R> res <- portfolio.optim(X)                 ## Long only
R> res$pw
[1] 0.0000 0.3958 0.0000 0.6042
R> res <- portfolio.optim(X, shorts=TRUE)    ## Long/Short
R> res$pw
[1]  0.02550  0.38213 -0.06377  0.65614
R> 

This is arguably a better example than the one in help(portfolio.optim)
so maybe I should send Kurt a new patch :)

Dirk

--
Three out of two people have difficulties with fractions.
#
On 1 October 2009 at 15:25, Dirk Eddelbuettel wrote:
| Correct -- the tseries package has done since time immportal. 

Oops: "... has done this since time immortal" is what I meant.  Someone
please write semantic and syntactic checker for Emacs....

Sorry, Dirk
 
| And some seven or eight years ago I sent Adrian a patch, styled after the
| discussion in Huang and Litzenberger, that adds the ability to have long and
| short positions.  
| 
| Which Adrian promptly added and which has been there ever since:
| 
| R> head(as.zoo(EuStockMarkets))
|            DAX  SMI  CAC FTSE
| 1991(130) 1629 1678 1773 2444
| 1991(131) 1614 1688 1750 2460
| 1991(132) 1607 1679 1718 2448
| 1991(133) 1621 1684 1708 2470
| 1991(134) 1618 1687 1723 2485
| 1991(135) 1611 1672 1714 2467
| R> X <- diff(log(as.zoo(EuStockMarkets)))
| R> res <- portfolio.optim(X)                 ## Long only
| R> res$pw
| [1] 0.0000 0.3958 0.0000 0.6042
| R> res <- portfolio.optim(X, shorts=TRUE)    ## Long/Short
| R> res$pw
| [1]  0.02550  0.38213 -0.06377  0.65614
| R> 
| 
| This is arguably a better example than the one in help(portfolio.optim) so
| maybe I should send Kurt a new patch :)
| 
| Dirk
| 
| -- 
| Three out of two people have difficulties with fractions.
| 
| _______________________________________________
| R-SIG-Finance at stat.math.ethz.ch mailing list
| https://stat.ethz.ch/mailman/listinfo/r-sig-finance
| -- Subscriber-posting only.
| -- If you want to post, subscribe first.
#
Jorge Nieves wrote:
[...]

This bothers me on two counts:

1) computational
2) subject matter

That Jorge is not finding the functionality
that he wants means that modular programming
is not being used.  The modular approach
would have a function that does the optimization
with the expected returns and variance as
arguments.  That function would then be
used by a function that does the larger task.

Okay, an advantage of R is that it is generally
easy to modify functions for your own purposes.
But it is better to organize ocmputations so
that people don't feel compelled to do that.
Let's abandon the SAS monolith culture.

I haven't investigated the functions that are
under discussion, so perhaps I am misunderstanding
what they are doing.  But if they are using the
history of returns to predict future returns, that
is almost always going to be pretty much complete
nonsense -- with or without the Efficient Market
Hypothesis.

I would hope the R community embrace quality in
subject matter decisions as well as computational
quality.


Patrick Burns
patrick at burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of "The R Inferno" and "A Guide for the Unwilling S User")