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?


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) (8.66 KB)


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:


symbols <- c("USD/JPY",

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:

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


con = gzcon(url('', 'rb'))

# Lets load some symbols
symbols <- c(

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)

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

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: (833 KB)

[EDIT]Here is D-pips post:

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


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 -

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?