Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (1 invisible), 672 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
The unfashionable Markowitz #459410
05/16/16 10:05
05/16/16 10:05
Joined: Feb 2015
Posts: 652
Milano, Italy
M
MatPed Offline OP
User
MatPed  Offline OP
User
M

Joined: Feb 2015
Posts: 652
Milano, Italy
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 Files
Heatmap.png (181 downloads)
MVOTest.png (13 downloads)
Re: The unfashionable Markowitz [Re: MatPed] #459412
05/16/16 11:27
05/16/16 11:27
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
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 Files
MVOTest2.c (43 downloads)
ETFs2.csv (39 downloads)
Re: The unfashionable Markowitz [Re: jcl] #459414
05/16/16 12:22
05/16/16 12:22
Joined: Feb 2015
Posts: 652
Milano, Italy
M
MatPed Offline OP
User
MatPed  Offline OP
User
M

Joined: Feb 2015
Posts: 652
Milano, Italy
Thank You,
I will work on this. Based on your experience make any difference use ETF that capitalize or distribute profit?

Ciao

Re: The unfashionable Markowitz [Re: MatPed] #459419
05/17/16 14:16
05/17/16 14:16
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
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.

Re: The unfashionable Markowitz [Re: jcl] #459422
05/17/16 15:43
05/17/16 15:43
Joined: Feb 2015
Posts: 652
Milano, Italy
M
MatPed Offline OP
User
MatPed  Offline OP
User
M

Joined: Feb 2015
Posts: 652
Milano, Italy
ok, thank you

Re: The unfashionable Markowitz [Re: MatPed] #464393
02/10/17 01:25
02/10/17 01:25
Joined: Jan 2017
Posts: 64
J
Jeff1228 Offline
Junior Member
Jeff1228  Offline
Junior Member
J

Joined: Jan 2017
Posts: 64
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

Last edited by Jeff1228; 02/10/17 01:40.

Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1