The unfashionable Markowitz

Posted By: MatPed

The unfashionable Markowitz - 05/16/16 10:05

Hi,
I have experimented the scripts posted in the Financial Hacker blog, and I found unexpected behaviors.

The Markowitz script most of the time does not provide better results than 1/N allocation strategy. This is an example. The ETFs:

"XMUS.MI", // db x-trackers MSCI USA Index UCITS ETF 1C EUR LU0274210672 CAP
"XEMB.MI", // db x-trackers II Emerging Markets Liquid Eurobond UCITS ETF 1C EUR LU0321462953 CAP
"XGIN.MI", // db x-trackers II iBoxx Global Inflation-Linked UCITS ETF 1C EUR LU0290357929 CAP
"EMG.MI", // Lyxor Ucits Etf Eumts Infl Linked Inv Gr FR0010174292 CAP
"EMI.MI", // Lyxor UCITS ETF EuroMTS Inflation Linked Investment Grade (DR) (EUR) FR0010174292 CAP
"XFFE.MI", // db x-trackers II Fed Funds Effective Rate UCITS EUR LU0321465469 CAP

(just copy and paste this set in the original scripts)

provide a good HeatMap, but not a good MVOtest.
I can not say why. I have tried several set of ETFs and, most of the times, the MVO was not as good than 1/N allocation strategy.

I have seen that results vary a lot based on the data quality of the ETFs chosen and the mix of mean/Variance more than based on quality of the "heatmap".

The first point of attention was the quality of data. Be aware that Yahoo sometimes download less data than expected. Yahoo ETF graph goes back to 2008 while you download only 2 years for testing. (some sort of filter/check could help)

The second point of attention was ETF with profit periodic distribution. It seems that they works not as good than ETFs with capitalized profits, but I can not mathematically prove my impressions

Heatmap and MVOTest of previous ETF Sample attached.

I am very interested in improving ETFs allocation strategy, and I was very disappointed that MVO did not perform as expected. I am looking forward to someone else experience and feedback.

Ciao

Attached picture Heatmap.png
Attached picture MVOTest.png
Posted By: jcl

Re: The unfashionable Markowitz - 05/16/16 11:27

Yes, it depends on the components. You normally use more components, such as 20 or 30. Here's a modified script that reads a selection of the most popular ETFs from an asset list in the Strategy folder (both attached).

Your result is also relatively untypical. The typical result that I get with most portfolios is either a much higher profit with the red max return line, or a lower profit but a much better Sharpe ratio with the blue minimum variance line. You can see that with the attached system. For live trading you would normally use the minimum variance version, even though the absolute return is smaller than 1/N. Do many experiments with other ETFs!

Attached File
MVOTest2.c  (43 downloads)
Attached File
ETFs2.csv  (39 downloads)
Posted By: MatPed

Re: The unfashionable Markowitz - 05/16/16 12:22

Thank You,
I will work on this. Based on your experience make any difference use ETF that capitalize or distribute profit?

Ciao
Posted By: jcl

Re: The unfashionable Markowitz - 05/17/16 14:16

It does not make a difference for the portfolio weights, since the historical prices include the dividends. It could make a difference for the tax declaration, since AFAIK dividends are treated differently than profits in some countries. If dividends are distributed, reinvest them.
Posted By: MatPed

Re: The unfashionable Markowitz - 05/17/16 15:43

ok, thank you
Posted By: Jeff1228

Re: The unfashionable Markowitz - 02/10/17 01:25

I'm interested in this topic and jad some communication with jcl on Financial Hacker, I use ZorroS and my broker is IB, I want to test MVO and get all the metrics just like Z8. I'm new to programming, barely managed some codes like follwoing:

function run()
{
set(PARAMETERS);
BarPeriod = 1440;
LookBack = 252 ;
NumYears = 7;
Verbose = 0;
set(PRELOAD); // allow extremely long lookback period
NumWFOCycles = 5;
MonteCarlo = 1000;
Capital = 100000;//intent to calculate CARG

assetList("AssetsETF.csv");

string Names[NN];
vars Returns[NN];
var Means[NN];
var Covariances[NN][NN];
var Weights[NN];

int OldLots[NN] ;//positions

var Allmystake = 100000 ;//equals to Capital
var VFactor = 10;
int i,j;
static var BestVariance = 0;
static var MinVariance = 0;
static int Month = 0;

//Get Assets History and calculate returns
int N = 0;
while(Names[N] = loop((Assets)))
{
if(is(INITRUN))
assetHistory(Names[N],FROM_YAHOO);
asset(Names[N]);
Returns[N] = series((priceClose(0)-priceClose(1))/priceClose(1));
if(N++ >= NN) break;
}

//Initialize Allmystake and positions

if(is(FIRSTRUN))
{
Allmystake = 100000;
printf("n%d Initial Allmystake: %d$", date(), Allmystake);
for(i=0; i<N; i++)
{
OldLots[i] = 0;
}
}

if(tdm() == 1 && !is(LOOKBACK)) {
{
for(i=0; i<N; i++) {
Allmystake += OldLots[i]*priceClose(); //recalculate the Allmystake upon the positions
Means[i] = Moment(Returns[i],LookBack,1);
for(j=0; j<N; j++)
Covariances[N*i+j] = Covariance(Returns[i],Returns[j],LookBack);
}

BestVariance = markowitz(Covariances,Means,N,0.5);
MinVariance = markowitzReturn(0,0);

markowitzReturn(Weights,MinVariance+VFactor/100.*(BestVariance-MinVariance));//change the positions as to new weights

Month++;

for(i=0; i<N; i++)
{
asset(Names[i]);
MarginCost = priceClose()/Leverage;
int NewLots = Allmystake*Weights[i]/MarginCost;

printf("n%s : Date%d OldLots: %d NewLots: %d %.0f$", Names[i], date(), OldLots[i], NewLots,priceClose());

if (NewLots > OldLots[i])
enterLong(NewLots-OldLots[i]);

else if(NewLots < OldLots[i])
exitLong(0,0,OldLots[i]-NewLots);

OldLots[i] = NewLots;

}
}
Allmystake = 0;//reset Allmystake
printf("nDate %d ",date());
}
}

Unfortunately something went so wrong, Allmystake has always been 0 and no positions have been reported.I guess I didn't calculate Allmystake properly, which is the total equity I can invest.

Anyone can help? Thank you in advance.

Jeff
© 2024 lite-C Forums