Quantzone

Matlab Finance Code

Mean-variance portfolio optimization using GA and PATTERNSEARCH

Please see PORTOPTGADS, by following link ‘Published m-files’ below.

PS. The cool picture is a visualization of Rastrigin’s function, taken from Genetic Algorithm and Direct Search Toolbox documentation.

Convert covariance matrix to correlation matrix

The function is “remix” of native matlab cov2corr() function, which produces correlation matrix with elements on its main diagonal slightly greater or less then 1. So it can’t be used in various further computations, for example in squareform() function.

The problem can be resolved simply by setting all the diagonal elements to 1 (freaky way) or by using variance instead of std while computing correlation matrix (covariance(x,y)/sqrt(var(x)*var(y)) instead of covariance(x,y)/(std(x)*std(y))).

Frontier Demo

Retrieve stock data from Yahoo and draw the rolling frontier 3D graph of the defined stocks during the defined date range. Can’t get COP’s stock data correctly when I tried, not sure whether Yahoo’s or Matlab’s falt. b is the begin date. e is the end date. l is the list of stocks. d stores the data retrieved. t stores the dates. p stores the prices. r stores the return rates.

Efficient Frontier GUI

Demo graphical user interface that finds an unconstrained mean-variance efficient frontier given asset price data. This data can come from Yahoo finance, where you can find the optimial portfolio for any set of assets you choose, or from a supplied Microsoft Access database.

  • About

    Matlab Finance Code Collector

  • Tag Cloud

  • Recent Comments

  • Meta