Historical Returns and Covariance for Portfolio Optimization
Summary
The discussion outlines a basic historical-data workflow for choosing portfolio weights: calculate asset returns, estimate their covariance matrix, and optimize for minimum variance or for minimum variance at a target expected return. It also points to portfolio software that supports investment constraints, different objectives, custom covariance estimates, and periodic rebalancing. The proposed weights indicate portfolio allocations, though they do not by themselves specify a complete schedule of buy and sell transactions; that also depends on current holdings and the rebalancing rule.
The exchange gives no performance study or evidence that historical estimates will maximize future portfolio value. Its main caveat is that expected returns are uncertain, making return-targeted optimization especially sensitive to model estimates. Historical covariance and returns can also change over time, while transaction costs and other practical trading constraints are not addressed. The material is most useful as an introduction to mean-variance portfolio construction, rather than as a method for guaranteeing maximum realized wealth.
Key ideas
- Estimate asset returns and their covariance matrix from historical price data.
- Minimum-variance optimization can use a return target, but that introduces uncertain expected-return estimates.
- Optimized weights describe allocations and require current holdings and a rebalance rule to translate into trades.
- Portfolio optimization software can express investment constraints and different risk or return objectives.
Tags
Full text
# portfolio optimisation based on historical prices # portfolio optimisation based on historical prices I'm hoping somebody can help me with the following problem (I'm not a quant). I have a SQL table which contains the historic prices for 3 securities, x,y and z. It has the date and the price. I have to a write a program that, for each year, outputs the buy/sell transactions necessary to maximise the value of the portfolio. The portfolio has an initial fund of £20000. yes this a test, but it's not homework. I don't know where to begin, I don't need help with the coding but I do need some assistance with the algorithm/math? Thanks. ## Answer by Jan Sila (score 1, accepted) https://quant.stackexchange.com/a/30060 firstly you need to calculate logarithmic returns and then depends on the software you use. For instance `R` has everything already coded. If you want to to it yourself (recommended if you say programming is not an issue), then I found this quite straight forward and shows the code in `R` as well. 1) get the returns 2) calculate covariance matrix 3) optimise either to find a Global Minimum Variance portfolio, or minimum variance portfolio given a level of return. But then you are adding more uncertainty to the model as you don't really know what is the true expected return. 4) You will get your vector of weights and find returns of the portfolio. The weights are the transaction you need - if it is positive, you're buying, if negative you are selling the asset short. If you need the returns in $, then sum up the logarithmic returns and transform them back by taking the exponential of them and subtract 1; you get the cumulative return at the end of the period 5) Follow the link, it walks you through it quite nicely in detail.. If you need anything else, comment :) ## Answer by rbm (score 0) https://quant.stackexchange.com/a/30064 If you don't want to write all the code yourself, you can you `R`, package `PortfolioAnalytics`. It allows you to create portfolio (`portfolio.spec`), and optimization constraints (`add.constraint`) and set objectives (`add.objective`) and optimize it. Example code ``` portfolio <- portfolio.spec(assets=fund.names) portfolio <- add.constraint(portfolio , type="full_investment") portfolio <- add.constraint(portfolio , type="long_only") portfolio <- add.objective(portfolio, type="risk", name="var") # monthly rebalancing, 2 year training, 2 year rolling: portfolio.optimized <- optimize.portfolio.rebalancing(returns, portfolio, ptimize_method="quadprog", rebalance_on="months", training_period=24, rolling_window=24) ``` The package is quite flexible, you can add group constraints, long/short/box constraints; add objectives for risk minimizing, mean maximizing, quadratic utility maximizing etc; supports `quadprog` solver etc. It also allows you to plugin your own covariance matrix (e.g. if you don't want to use `cov` but your own like robust covariance matrix estimate). And has support for parallel processing. Plenty of code samples in vignette: https://cran.r-project.org/web/packages/PortfolioAnalytics/PortfolioAnalytics.pdf
Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.