# Portfolio calculation for 20 currency pairs

I'm trying to find a way to compute an optimized basket of n currency pairs based on 2 properties.

Let's say i have 50 pairs * 2 (long/short) = 100 possible items. A basket has 2 properties to optimize: correlation and property X. I want to have an optimized basket with configurable: - maximum correlation between all items - minimum X - minimum basket size (like 10 or 20)

Computing every combination results in much too many combinations so I need some other strategy to go about this.

So far I've come up with this:

• Start with a basket which includes all 60 items.
• Then iterate over all items and for each item compute the basket with that item excluded.
• Then keep the "best" basket which meets requirements.
• repeat until minimum basket size reached.

How to determine which is best? maybe use a value which includes correlation and X somehow? I would then want to be able to configure the importance/weight of correlation and X.

Maybe you know better ways?

thank you!

• As long as you do not specify anything about 'property X', there is no method of optimization other than exhaustive enumeration, i.e. trying all possible combinations. May 24, 2019 at 16:07
• Sorry, I can't understand what you are trying to do, normally I like to look at the optimisation questions but it not clear to me..
– Attack68
May 24, 2019 at 21:09

Firstly, I think you need to quantify a single score function - e.g. a combination of the correlation and X, that way you can rank solution A with some correlation and X value vs some solution B with a different correlation and X.

There may be more direct ways of finding baskets with particular properties; for example finding a basket closest to some particular sensitivities (i.e. a hedge of some instrument) can be done by first decomposing the sensitivities of the available instruments via PCA, and then rebuilding a portfolio from the now orthogonal components.

Also the basket with the maximum correlation between items is just a basket of 1 thing (or if you force it to be 10 things, amounts 1, 0, 0, 0, 0, 0, 0, 0, 0, 0...).

• These are helpful suggestions. I will research these concepts. May 31, 2019 at 12:17

Still failing to see what you actually doing let me describe an optimisation process in general for a minimisation problem:

For a starting point $$x$$ and function value $$f(x)$$, find a search direction $$p$$ and traverse that direction with some appropriate step size $$\alpha$$ to hopefully find $$f(x+\alpha p)

Thats it for pretty much all algorithms. While different algorithms do it better (faster) than others in certain circumstances and also offer nice properties such as "guarantees to converges to the (local/global) optimum point" you may find that you are happy with something that just improves.

The Expectation-Maximisation is a good example of an algorithm that fits this property, it guarantees to do better each iteration but offers no guarantees on speed of convergence or if it will indeed get to the optimum, but this approach is often practical and good enough.

@PhilH has provided some good ideas, and I would suggest that in the absence of being able to exhaustively test all combinations you identify a method of taking a starting state and identifying some test of finding a change to that state that improves matters.

Taking the "greedy" approach of finding the state change that provides the maximal improvement at each stage might also be a good start, this is commonly used in many AI and Machine Learning algorithms, without necessarily guaranteeing to be the best solution (or even a good solution) in all cases.

If you care most about selecting the assets, then I would suggest a (stochastic) Local Search. This is very much in the spirit of what Attack68 described, but very simple when it comes to search direction.

In essence it works like this: start with a random basket, and call it your "current solution". Then randomly select an asset, and if it is not in the basket, add it; otherwise, remove it. If this new basket is better than the old one, make the new basket the "current solution". Repeat this process many times.

If you suspect local minima in your model, the algorithm can be made less strict, and solutions that are not better than the current solution may get accepted. In this way, the algorithm may walk away from local minima. (This is what methods such as Simulated Annealing or Threshold Accepting do.)

If you can use R: in implementation of such a Local Search is in the NMOF package (which I maintain); the function is called LSopt. There is also example code for asset selection included in the package; a more recent examples are in Optimization Heuristics: A Tutorial.

Two more remarks. First, you cannot minimise two objectives at once. You can either include one objective as a constraint, i.e. minimise objective 1, provided objective 2 is not worse than some specified value, which is the approach used for Pareto-efficient frontiers. Or you can minimize some combination of the two objectives.

Second, with currency pairs, you might want to check for redundant pairs, e.g. if you are long EURUSD and long USDJPY, you are actually long EUR and short JPY.

Your problem explanation is confusing.

A couple initial thoughts:

(1) You don't need to consider going long v. short as two separate assets provided you're able to take short positions and you allow negative weights in your optimizaiton--number of assets cut in half.

(2) The approach you describe is called a brute force optimization, among other monikers. It can get you to a correct answer, but it's about as inefficient as it gets.

Generally, I (and I think we) understand that you don't want to give away your special sauce, so you're omitting big chunks of your problem, but the result is that your problem doesn't make much sense and there aren't many ways to help given the details you have provided. For instance, it's possible you don't even need to incorporate correlation in your objective function, but can instead include it in a constraint depending on what you're trying to do, which, again, isn't clear. Consider editing to provide additional detail.

• regarding (1): I'm looking at swap also which is different long vs short so I consider long and short different "assets" May 31, 2019 at 12:18