Forex Optimal Risky Portfolio

Hello Everyone,

This is gonna be a high theoretical and research topic. Essential statistics and applied statistics knowledge shall be thefore necessary.

The idea started into another topic, “The forex portfolio…” by Mastergunner99. The project involves applying Optimal risky portfolio theory to invest in the 28 combinations of the majors in an efficient way, and not simply “random” Equity/28.

Why investing in more pairs at the same time? Diversification and Hedging advantages were first mathematically formally prooved by Markowitz in the 50’s.

Knowing more in details standard deviation and correlation ρ (pearson) among pairs we could build an optimal risky portfolio, where securities are represented by the 28 traded pairs. In this way, we could form an efficient CAL and optimize capital allocation of the 28 pairs. What I mean with this is that, instead of investing E/28 in each pair, we could optimize the investment by dividing equity in a more efficient way.

ie. giving more % to pairs with correlation closer to 0, avoid to trade pairs with correlation close to 1, and using pairs with correlation close to -1 to hedge particular risky positions.

This means that by the end of the process, the amount of traded pairs could be reduced.

In order to reach HOW to form the portfolio, ie. how many % of Equity to invest in each pair (eg. 10% in EU, 15% in EJ etc etc) We need:

  • Covariances
  • Variances of each weight (pair) σ^2
  • Correlation ρ (pearson) among pairs
  • Expected return of each weight (E®)
  • Standard deviation σ

My main concern is about estimating the E® of each pair, as it really depends on individual set of TP (or alternitavely, estimating standard deviation, as it depends on individual set of SL) (ie. A (risk aversion)).

But yea we know that this is one of the main criticism moved to Markowitz theory… and we should also put in account different costs for different pairs (different spread), but that’s the least of the problems.

Average Fund manager (with an already well diversified portfolio, so not FX alone) makes what? 15% a year? but then you got who loses money… and we are still talking of institutionals/professionals… if we get down to retails, statistics fall fast and impressively. And what I wanna do is estimating E® not even of the whole market, but of each pair… it’s a hell of a work.

I did a fast search on web but there isn’t anythign at all… just people sharing their expected ROE lol which has zero integrity and vary pretty much, depending on the fantasy of the discloure xD

This is a big task that I can’t obviosuly accomplish on my own. As I stated above, the main issue we gotta solve is finding out E® and σ (and so σ^2), the rest comes as consequence :wink:

SO… who’s up for it?

TASK #1

For mathematical aspect of this work, no worries, I’ve an excel form for it. It is set for 2 risky assets, so I need someone please please that could turn this 2 assets form into a 28 risky assets form (obviously remove the chart except if you ahve a 28 dimensions eyes :D)Application_Ch_7_Two_Security_Model.zip (8.66 KB)

TASK #2

For calculating Standard deviation (and so variance), that represents risk of each pair, my idea is as follow:

As the formula is:

My idea is:

X= close of daily candle

and ofc <X> is the average of Xi (ie. x+x+x+…+xi).

I’d take in account 1 year of data, I think is good enough to give a realistic risk to start with.

What do you guys think of it?

My main concern with this is that it doesn’t take in account the WHOLE volatility of the pair (high-low), so maybe another way of calculating this one could be

X= high-low of daily candle

Any clue/advice??

Another big issue is that different pairs have different pip-value… oh god haha

Hi, thanks for opening the thread :slight_smile: Im all in, but Im not wery good with math, but as this is a wery interesting subject, Ill try to do something right :slight_smile:

Not that is that important at this stage, but for simplicity, start with MG99’s list of currencys, and D-pip’s risk ‘model’, dvs 1.5 ATR(8 weeks)?

Any way, Im working on understanding R, so I think its pretty easy to find the variance in there, Im a little unsure about correlation, but I doubt it would be that hard to find out :slight_smile:

Either way, Ill start taking a look at your spreadsheet, and reading up on Markowitz theory :slight_smile:

could you give a link to D-pip post ?

about [B]TASK #3[/B]

ie Estimating Expected return.

I think that, at this stage, where we are analysing the Forex portfolio on its own, and NOT putting it in comparison with any other security, we could give the same Er on every weight, and count everything on different standard deviation (ie risk).

How would I measure Er of each pair is as follows:

E(Rx)=(Probability of winning x profit - Probability of losing x lost) x number of trades in 1 year [all meant in percentage value]

I think keeping 1 year as time horizont is good enough at a theoretical stage

What do you guys think?

first try:


library(quantmod)

symbols <- c("USD/JPY",
"GBP/USD","USD/CHF","EUR/CHF",
"AUD/USD","GBP/NZD","NZD/CAD","NZD/JPY",
"AUD/NZD","EUR/NZD","GBP/AUD","GBP/CAD",
"AUD/JPY","CAD/JPY","EUR/GBP","CHF/JPY",
"USD/CAD","NZD/USD","GBP/CHF","EUR/AUD",
"EUR/JPY","GBP/JPY","EUR/CAD","AUD/CAD",
"CAD/CHF","AUD/CHF","NZD/CHF")

getSymbols(symbols,src="oanda", from="2012-01-01", to="2012-12-31", verbose=TRUE)

This unfortunatly only gave me the close value every day :confused:

[EDIT]
Here is the code that gives us all the data we need :slight_smile:


######################
# INIT
setInternet2(TRUE)

con = gzcon(url('http://www.systematicportfolio.com/sit.gz', 'rb'))
    source(con)
close(con)
 
library(quantmod)


#########################
# Lets load some symbols
symbols <- c(
"USDJPY","GBPUSD","USDCHF","EURCHF",
"AUDUSD","GBPNZD","NZDCAD","NZDJPY",
"AUDNZD","EURNZD","GBPAUD","GBPCAD",
"AUDJPY","CADJPY","EURGBP","CHFJPY",
"USDCAD","NZDUSD","GBPCHF","EURAUD",
"EURJPY","GBPJPY","EURCAD","AUDCAD",
"CADCHF","AUDCHF","NZDCHF","EURUSD"
)

USDJPY = getSymbols.fxhistoricaldata('USDJPY', 'hour', auto.assign = F, download=T)
GBPUSD = getSymbols.fxhistoricaldata('GBPUSD', 'hour', auto.assign = F, download=T)
USDCHF = getSymbols.fxhistoricaldata('USDCHF', 'hour', auto.assign = F, download=T)
EURCHF = getSymbols.fxhistoricaldata('EURCHF', 'hour', auto.assign = F, download=T)
AUDUSD = getSymbols.fxhistoricaldata('AUDUSD', 'hour', auto.assign = F, download=T)
GBPNZD = getSymbols.fxhistoricaldata('GBPNZD', 'hour', auto.assign = F, download=T)
NZDCAD = getSymbols.fxhistoricaldata('NZDCAD', 'hour', auto.assign = F, download=T)
NZDJPY = getSymbols.fxhistoricaldata('NZDJPY', 'hour', auto.assign = F, download=T)
AUDNZD = getSymbols.fxhistoricaldata('AUDNZD', 'hour', auto.assign = F, download=T)
EURNZD = getSymbols.fxhistoricaldata('EURNZD', 'hour', auto.assign = F, download=T)
GBPAUD = getSymbols.fxhistoricaldata('GBPAUD', 'hour', auto.assign = F, download=T)
GBPCAD = getSymbols.fxhistoricaldata('GBPCAD', 'hour', auto.assign = F, download=T)
AUDJPY = getSymbols.fxhistoricaldata('AUDJPY', 'hour', auto.assign = F, download=T)
CADJPY = getSymbols.fxhistoricaldata('CADJPY', 'hour', auto.assign = F, download=T)
EURGBP = getSymbols.fxhistoricaldata('EURGBP', 'hour', auto.assign = F, download=T)
CHFJPY = getSymbols.fxhistoricaldata('CHFJPY', 'hour', auto.assign = F, download=T)
USDCAD = getSymbols.fxhistoricaldata('USDCAD', 'hour', auto.assign = F, download=T)
NZDUSD = getSymbols.fxhistoricaldata('NZDUSD', 'hour', auto.assign = F, download=T)
GBPCHF = getSymbols.fxhistoricaldata('GBPCHF', 'hour', auto.assign = F, download=T)
EURAUD = getSymbols.fxhistoricaldata('EURAUD', 'hour', auto.assign = F, download=T)
EURJPY = getSymbols.fxhistoricaldata('EURJPY', 'hour', auto.assign = F, download=T)
GBPJPY = getSymbols.fxhistoricaldata('GBPJPY', 'hour', auto.assign = F, download=T)
EURCAD = getSymbols.fxhistoricaldata('EURCAD', 'hour', auto.assign = F, download=T)
AUDCAD = getSymbols.fxhistoricaldata('AUDCAD', 'hour', auto.assign = F, download=T)
CADCHF = getSymbols.fxhistoricaldata('CADCHF', 'hour', auto.assign = F, download=T)
AUDCHF = getSymbols.fxhistoricaldata('AUDCHF', 'hour', auto.assign = F, download=T)
NZDCHF = getSymbols.fxhistoricaldata('NZDCHF', 'hour', auto.assign = F, download=T)
#to.daily(EURUSD)

#Lets make a grid
correlation <- matrix(rep(0,28*28),nrow=28,ncol=28)
df <- as.data.frame(correlation)

rownames(df)<- symbols
colnames(df) <- symbols

##################################################################
# Lets do something interesting :D
for (x in 1:28) {
	for (y in 1:28) {
		#What to do
	}
}

What should we do we calculate in the first step? :slight_smile:

Well the close of the day is not optimal but is a start. Where could I find those data for 1 year to be easily copy and paste for a calculus? lets take ideally from 1 Jan to 31 Dec 2012 if available

I have found a solution to get all the data we need, except for 2 symbols, GBPNZD and GBPAUD, do you think we can continue our project without these, or do I need to find a solution?

any way, here are the daily data for the rest of the currencies:
Data.zip (833 KB)

[EDIT]Here is D-pips post:
http://forums.babypips.com/show-me-money-swing-trading/50672-forex-portfolio-how-gain-consistent-profits-staying-market-24-7-a-50.html#post458984

Many thx for the data. Of what period is it? i see 1347 or more days in here :o Remember I need only 2012 haha - that’s the power of inferential statistics :wink:
And yes its fine without the 2 pairs you wouldn’t find.

Is it possible to have this data in a more ordiante way, putting high on a colum, low on another etc etc? It’s way easier to sum.

Ill get back to you on that, its pretty make it a little more manageball, maybe tab sepperated collumns or something? :slight_smile:

anyway, here is a correlation table


"","USDJPY","GBPUSD","USDCHF","EURCHF","AUDUSD","NZDCAD","NZDJPY","AUDNZD","EURNZD","GBPCAD","AUDJPY","CADJPY","EURGBP","CHFJPY","USDCAD","NZDUSD","GBPCHF","EURAUD","EURJPY","GBPJPY","EURCAD","AUDCAD","CADCHF","AUDCHF","NZDCHF","EURUSD"
"USDJPY",0,0.023,-0.63,0.827,0.286,0.732,0.953,-0.707,0.209,-0.117,0.953,0.965,0.903,0.974,-0.099,0.577,-0.829,0.546,0.975,0.965,0.805,0.313,-0.626,-0.313,0.117,0.767
"GBPUSD",0.023,0,-0.671,0.138,0.465,0.142,0.21,-0.388,0.013,0.255,0.168,0.231,0.033,0.215,-0.793,0.526,0.017,0.207,0.204,0.285,0.132,-0.197,-0.114,-0.2,0.032,0.552
"USDCHF",-0.63,-0.671,0,-0.593,-0.283,-0.496,-0.695,0.805,-0.397,-0.232,-0.634,-0.722,-0.73,-0.79,0.495,-0.621,0.73,-0.738,-0.777,-0.778,-0.778,0.134,0.719,0.631,0.169,-0.96
"EURCHF",0.827,0.138,-0.593,0,0.353,0.676,0.847,-0.73,0.168,-0.235,0.826,0.849,0.863,0.825,-0.28,0.634,-0.671,0.523,0.864,0.826,0.722,0.209,-0.438,-0.227,0.227,0.794
"AUDUSD",0.286,0.465,-0.283,0.353,0,0.667,0.532,-0.319,-0.697,-0.464,0.562,0.462,0.113,0.31,-0.739,0.867,0.047,-0.387,0.32,0.397,-0.072,0.657,0.271,0.565,0.824,0.339
"NZDCAD",0.732,0.142,-0.496,0.676,0.667,0,0.86,-0.743,-0.347,-0.215,0.842,0.758,0.644,0.724,-0.273,0.858,-0.539,0.118,0.732,0.738,0.524,0.685,-0.34,0.111,0.603,0.613
"NZDJPY",0.953,0.21,-0.695,0.847,0.532,0.86,0,-0.801,-0.006,-0.222,0.99,0.985,0.853,0.956,-0.343,0.797,-0.744,0.422,0.961,0.968,0.717,0.406,-0.504,-0.168,0.336,0.822
"AUDNZD",-0.707,-0.388,0.805,-0.73,-0.319,-0.743,-0.801,0,-0.106,0.057,-0.71,-0.77,-0.79,-0.794,0.405,-0.749,0.727,-0.611,-0.8,-0.776,-0.721,-0.021,0.574,0.436,-0.172,-0.861
"EURNZD",0.209,0.013,-0.397,0.168,-0.697,-0.347,-0.006,-0.106,0,0.578,-0.038,0.106,0.417,0.28,0.352,-0.43,-0.523,0.851,0.271,0.204,0.617,-0.643,-0.72,-0.905,-0.922,0.355
"GBPCAD",-0.117,0.255,-0.232,-0.235,-0.464,-0.215,-0.222,0.057,0.578,0,-0.245,-0.209,-0.052,-0.026,0.386,-0.356,-0.082,0.422,-0.056,-0.041,0.34,-0.256,-0.569,-0.576,-0.667,0.092
"AUDJPY",0.953,0.168,-0.634,0.826,0.562,0.842,0.99,-0.71,-0.038,-0.245,0,0.979,0.815,0.938,-0.319,0.771,-0.7,0.35,0.943,0.958,0.673,0.477,-0.456,-0.092,0.36,0.77
"CADJPY",0.965,0.231,-0.722,0.849,0.462,0.758,0.985,-0.77,0.106,-0.209,0.979,0,0.865,0.974,-0.355,0.732,-0.761,0.495,0.977,0.986,0.734,0.287,-0.524,-0.249,0.227,0.844
"EURGBP",0.903,0.033,-0.73,0.863,0.113,0.644,0.853,-0.79,0.417,-0.052,0.815,0.865,0,0.926,-0.065,0.497,-0.953,0.753,0.937,0.871,0.922,0.093,-0.762,-0.538,-0.076,0.852
"CHFJPY",0.974,0.215,-0.79,0.825,0.31,0.724,0.956,-0.794,0.28,-0.026,0.938,0.974,0.926,0,-0.225,0.638,-0.868,0.645,0.997,0.989,0.863,0.209,-0.704,-0.431,0.044,0.886
"USDCAD",-0.099,-0.793,0.495,-0.28,-0.739,-0.273,-0.343,0.405,0.352,0.386,-0.319,-0.355,-0.065,-0.225,0,-0.728,-0.066,0.07,-0.232,-0.301,0.087,0.022,-0.248,-0.174,-0.452,-0.469
"NZDUSD",0.577,0.526,-0.621,0.634,0.867,0.858,0.797,-0.749,-0.43,-0.356,0.771,0.732,0.497,0.638,-0.728,0,-0.352,0.052,0.648,0.689,0.331,0.473,-0.114,0.166,0.667,0.691
"GBPCHF",-0.829,0.017,0.73,-0.671,0.047,-0.539,-0.744,0.727,-0.523,-0.082,-0.7,-0.761,-0.953,-0.868,-0.066,-0.352,0,-0.804,-0.861,-0.788,-0.929,-0.004,0.866,0.667,0.259,-0.786
"EURAUD",0.546,0.207,-0.738,0.523,-0.387,0.118,0.422,-0.611,0.851,0.422,0.35,0.495,0.753,0.645,0.07,0.052,-0.804,0,0.642,0.575,0.873,-0.497,-0.876,-0.948,-0.641,0.736
"EURJPY",0.975,0.204,-0.777,0.864,0.32,0.732,0.961,-0.8,0.271,-0.056,0.943,0.977,0.937,0.997,-0.232,0.648,-0.861,0.642,0,0.988,0.861,0.214,-0.683,-0.412,0.069,0.89
"GBPJPY",0.965,0.285,-0.778,0.826,0.397,0.738,0.968,-0.776,0.204,-0.041,0.958,0.986,0.871,0.989,-0.301,0.689,-0.788,0.575,0.988,0,0.806,0.252,-0.63,-0.35,0.12,0.878
"EURCAD",0.805,0.132,-0.778,0.722,-0.072,0.524,0.717,-0.721,0.617,0.34,0.673,0.734,0.922,0.863,0.087,0.331,-0.929,0.873,0.861,0.806,0,-0.01,-0.938,-0.729,-0.33,0.839
"AUDCAD",0.313,-0.197,0.134,0.209,0.657,0.685,0.406,-0.021,-0.643,-0.256,0.477,0.287,0.093,0.209,0.022,0.473,-0.004,-0.497,0.214,0.252,-0.01,0,0.125,0.645,0.72,-0.023
"CADCHF",-0.626,-0.114,0.719,-0.438,0.271,-0.34,-0.504,0.574,-0.72,-0.569,-0.456,-0.524,-0.762,-0.704,-0.248,-0.114,0.866,-0.876,-0.683,-0.63,-0.938,0.125,0,0.839,0.546,-0.696
"AUDCHF",-0.313,-0.2,0.631,-0.227,0.565,0.111,-0.168,0.436,-0.905,-0.576,-0.092,-0.249,-0.538,-0.431,-0.174,0.166,0.667,-0.948,-0.412,-0.35,-0.729,0.645,0.839,0,0.812,-0.552
"NZDCHF",0.117,0.032,0.169,0.227,0.824,0.603,0.336,-0.172,-0.922,-0.667,0.36,0.227,-0.076,0.044,-0.452,0.667,0.259,-0.641,0.069,0.12,-0.33,0.72,0.546,0.812,0,-0.046
"EURUSD",0.767,0.552,-0.96,0.794,0.339,0.613,0.822,-0.861,0.355,0.092,0.77,0.844,0.852,0.886,-0.469,0.691,-0.786,0.736,0.89,0.878,0.839,-0.023,-0.696,-0.552,-0.046,0

using the last 200 daily candles, CLOSE, I can make any period over 1h, and any number of days, just let me know what we need

you are amazing mate, just let’s keep everything on the same time horizont!!

So to recap, we need:

  1. column with all highs
  2. column with all lows
  3. column with all open
  4. column with all close
  5. correlation table

all of these 5 things are needed with datas from 1/1/2012->31/12/2012

You are being of real help :))

No problem, I dont really know what numbers to get, but if you give me the different numbers we need, Ill be happy to run them and see the results :wink:

Ill be busy tonight, but Ill be back at it tomorrow :slight_smile:

if you want to try out R and make some of the numbers yourself, here is the code
[C] Forex Portfolio test - Pastebin.com

the only interesting part is in the bottom, where I run through the symbols and generate the correlation table :slight_smile:

what you mean with “I dont really know what numbers to get, but if you give me the different numbers we need, Ill be happy to run them and see the results” ?

I just wrote above the 5 things we need :smiley:
And yea I’d be glad to do it by myself but i’m really ignorant in this kind of stuff lol

hehe,okay, what kind of variances do we need, just standard deviation, or variance, or both on all close/high/love/open and on all pairs?

as I said, the main issue is that datas must be on the same time horizont (1/1/2012->31/12/2012) and analysis made on DAILY chart.

You can even calculate variances already?! xD That would be great

the X in the standard deviation formula should be X=high-low

We need variance of each pair with this set of data. And I need correlation table, just chanigng the time horizont that must be the one written above, and not the previous 200 days :wink: (daily chart, close is fine)

let me know

Hi, I have fixed the data, so now I only use data from 2012, and I have done standard deviation from high,low,open,close and sd(High - Low) :wink:

check this out, tab seperated, so can be easily opened in Excel, do you want the raw daily data to?

anyway, let me know what else to do…

Just looked at the data again, and this did not come out as planed :confused: let me take a look at this again

The correlation table is correct, right?
Only the variance table, is not a variance table hehe

Keep it going :wink:

Wait, also the correlation table seems to have some issue: it’s supposed to be like a double entry matrix right? But then you should have a correlation +1 in correspondance of the same weight (eg: eurchf on the row and eurchf on the column) which appear to be the opposite, ie 0

let me know

Hi, yeah, thats just me, I filled the matrix with 0’s when I started, and didnt to a correlation on the equal pairs…

anyway, the variances had a pretty stupid bug, so its fixed, here is the updated table:

So whats next? :slight_smile:

So wait, the correlation table is correct? I just have to substitue the 0’s with 1’s ?

And the variance table, you calculated the variance for different inputs? (eg: first colum is the variance usign open values).
And did you used the formula that I posted in page 1 just without the square root, right?