This is ... pauses to check... post #12 in my 2026 series on portfolio optimisation. And it will be the last! But don't be sad, I'll be following it up with some posts on my new 'autofitter' project which I've briefly hinted at a few times. The autofitter code will implement the 'best practice' of my work on optimisation.
Since it's the last post, let's summarise the previous 11 posts:
And in the last post I put together my 'gold standard' for fitting forecasting weights. Feel free to (re)read that but since it's germane to this post here's a very brief summary:
We do rolling pure out of sample optimisation, rerunning each year on a 30 year expanding then rolling window. For each year we take an average of three optimisations for each instrument with different sets of gross returns, but using the costs of the actual instrument: the gross returns of the instrument, pooled returns across the asset class, and finally pooled across all instruments. Each of those optimisations uses a remove high trading cost rules (SR costs>0.13) and reverse weights wrapper. The reverse weights wrapper finds assets with negative gross p&l and reverses the sign on them. Once the weights are found, it puts a minus sign in front of the weights. Inside the wrapper is a clustering algo. Finally within each cluster we use shrinkage of gross returns for SR and correlation, deducting costs from the shrunk SR.
... and breath.
With that in mind we now move on to optimising instrument weights. Mostly we'll be following on from the work above, but there are some wrinkles and differences. This will be a longish post, since it's compressing everything I currently think about instrument fitting into one place. Apologies but otherwise I'd have to keep erecting mental scaffolding for each sub-post - a pain for you to read, and even more of a pain for me to write.
Finally, you may be wondering what is 'blunt' about these instrument weights. Not very much. I just liked the pun. I also think James Blunt is bloody hilarious, which isn't relevant eithier.
Prior art
In terms of prior art on optimising instrument weights, there are surprisingly few posts of mine:
- A very old post on the basics of optimising
- Here's a random post on clustering, albeit of underlying instrument returns not subsystem returns
- This post on costs also looked at how we'd handle instrument costs
- The handcrafting series (my heuristic cluster based method) final post is here with links to previous posts
What I actually do now for my current weights is a fully heuristic handcrafting which ignores SR and costs, and just requires manually putting instruments into a hierarchy of groupings. But what I would recommend for someone who actually wants to do an optimisation, well check out relevant part of the default config file for pysystemtrade. You can see that it uses proper handcrafting with equalised SR (so don't use gross returns SR or costs at all), and shrinking correlation by 0.5. That will end up producing very similar results to my fully manual handcrafted, unless correlations are radically different from my subjective labelling.
In terms of what we need to consider; it's not dissimilar to what we have with forecast returns:
- We're using past returns of trading different instruments using the combined forecast that comes from our fitted forecast weights; so it's not the underlying returns that are important here
- We know that the key moments of those returns (correlation, SR) are going to be hard to predict, and their predictability is worse than we'd expect with a stable distribution.
- We know that small differences in moment estimators can cause havoc in the form of sparse weights when used with classical optimisation, so we need to get robust - clustering, shrinkage, pooling...
- We have the classic trade off between using more data (robust!) and using less data (adapts to distributional changes, eventually)
- We need to think about how we handle costs, that are more predictable than gross returns.
Considering all my previous work in forecast weights, my prior for instruments is going to be to do exactly the same, unless there is a really obvious reason why this wouldn't make sense.
A novel gotcha
Before we begin, there is a bit of a 'gotcha'. Something I should have noticed before, but despite doing this sort of thing for 20 years it has never occured to me before.
Let's start from scratch; suppose we have two forecasting rules X and Y, and two instruments A and B. After we get a year of returns, we fit forecast weights w_ to both instruments, calculate an FDM, and then calculate the combined forecast C:
C_A = FDM*(w_a_x * a_x + w_a_y * a_y)
... and the same for instrument B:
C_B = FDM*(w_b_x * b_x + w_b_y * b_y)
(there will be forecast clipping at 20, but we can ignore that)
We then calculate the p&l for instrument A and B, which will be a function of the combined forecast (and their price):
P(A) = f(C_A)
P(B) = f(C_B)
... and from that we calculate the instrument weights, w_a and w_b. We can then use those weights for the following year to calculate the p&l we'd get from trading this little system.
Now let's suppose after that year we then refit the trading system again. We'll get four new forecast weights w_*_* that are unlikely to be . Up until now what I've done is use those forecast weights to calcuate the following . That means the year 1 combined forecasts are using the year 1 forecast weights, and the year 2 combined combined forecasts are using the year 2 forecast weights. Those combined forecasts are then used to calculate instrument p&l for both years, and that's used to estimate instrument weights.
But this is incorrect - and it's taken me 20 years to notice it. When it comes to calculating the combined forecasts for p&l calculation, and then year 2 instrument weight fitting, we should be using the year 2 instrument weights for the entire history. Whilst this may be a small problem when we only had positive forecast weights, now with the appearance of the reverse weights wrapper we can have negative forecast weights, it's a big problem.
Let's make this concrete. Suppose that X is trend, and Y is carry. To keep it simple suppose we always have a zero weight to carry in both assets for both years. But in year one trend does really well in A, and really badly in B. The forecast weights will be X_A>0 and Y_A<0. Then in year two things are the same for A but switch around for B, such that over the two years trend is now also positive for B; we get year two weights X_A>0 and X_B>0.
If we use the forecast weights for each year to calculate the combined forecast and then p&l for each year, then we'll think that the subsystem B starts off as a mean reversion then becomes trend, with obvious weird results for estimating SR and correlations. When in fact what we're actually trying to optimise over at the end of year two is two trend subsystems, A and B. We need to use the final forecast weights to calculate the combined forecast for both years, and then to use that for p&l calculations and instrument weight fitting.
This makes the calculation of rolling instrument weights a little trickier (and slower), since we're not just multiplying out data frames. It also means we have to be careful about interpreting the two different account curves we'd get for a given instrument:
- the 'true out of sample' curve which would use the forecast weights available at the start of each year to calculate the following years p&l
- the current 'point in time forecast weights' curves used at each stage of the optimisation for fitting ('fitting p&l'), which will be much better performing since it's effectively all in sample.
A reverse wrapper probably doesn't make sense
Remember, the reverse wrapper means that we put negative weights on poorly performing assets. This is done by switching the sign from negative to positive before the optimisation, hence avoiding the nasty hedging like behaviour we'd expect in an optimisation with assets that have negative returns especially if positively correlated with other assets, and then multiply the resulting weights by -1.
The logic of this is that if we only include the 'positive' version of a forecasting rule, then (a) we're committing in sample tacit fitting and (b) we're not opening ourselves up to the option of the best option being the negative version of a rule (eg mean reversion working at a given time scale for certain instruments).
One implication of the use of reverse wrapper on forecast weight optimisation, and then using 'point in time' calculated forecast weights to calculate instrument p&l for fiting purposes, is that it's very unlikely that you'll end up with instruments that have a negative fitting p&l before costs.
That makes a reverse wrapper redundant; and means we'd never allocate a negative weight to an instrument. In fact, given the upwardly biased SR of fitting p&l, it's unlikely we'll allocate a zero weight to an instrument if we were only using pre-cost returns.
This makes sense; when we construct a subsystem for an instrument we're trying to come up with a way to do the best job we can to forecast a given instrument. It makes no sense to short the resulting subsystem by giving it negative weights.
Pooling doesn't make sense
Now, what about pooling? Remember for forecast weights, we pooled the gross returns together before optimising, eithier within an asset class, or across the whole universe. This was in the name of getting more data. But it makes no sense here.
If we pooled all subsystem returns together, that would be equivalent to full shrinkage on correlations and SR. Which is eithier silly, or a very complicated way of achieving the result of allocating equal weights (at least pre-costs - after costs we'd give more to cheaper instruments).
If we pooled all subsystem returns together within an asset class, that would be like shrinking within assset classes. That's slightly less weird, but still not worth doing.
No pooling for instrument weights.
Clustering makes a lot of sense
Clustering is designed to work with large portfolios. I have ~50 trading rules in my portfolio right now. 50 is pretty large. But I also have 200+ instruments I've allocated instrument weights to. So clustering makes even more sense here.
In the post on clustering before, I opted for an optimal cluster size of 6. That's roughly the number of asset classes I trade (stocks, bonds&rates, energies, agri, metals, fx, vol - that's 7; but vol is small and similar to equities with a minus sign in front). For 200 instruments I would have about 3 levels (6*6*6=216) of heirarchy. That all feels about right.
Shrinkage makes sense
Costs
We need to think about how we handle costs, as discussed here, given the use of a dynamic optimiser that drops positions in instruments which currently have costs greater than SR=0.01:
- Should we apply trading costs to instrument performance, so we end up allocating less to (expensive) Cheese and more to (cheap) S&P?
- How does that work with (very expensive) Sugar, where we would probably end up negative SR after costs even if the forecast weights were just 100% in the slowest system?
- Given I am going to apply cost penalties to (expensive) Milk anyway, does it matter if we apply trading costs?
- Given we won't actually trade (very expensive) Sugar because of it's trading costs, it's instrument weight will just determine how it influences the positions we do actually trade. So what implications does that have for applying costs?
In the end I decided to repeat the method used for forecast weight optimisation:
- If using dynamic optimisation, I cap SR cost estimates at 0.01
- I subtract costs from gross SR after shrinkage has happened, reflecting as with forecast weights that I have more certainty about costs than gross SR.
- I will end up with lower instrument weights for expensive instruments, although this will be ameliorated by the fact that expensive instruments will trade slower due to lower allocations to faster forecasts.
- If using DO, instruments that currently have SR cost>0.01 will be excluded from the final portfolio.
As I noted in the previous post, this makes the "cliff edge" effect of excluding expensive instruments less problematic. I change my instrument overrides based on current costs much more frequently than my forecast or instrument weights. Consider something (instrument A) which has SR cost of 0.02 when I do the forecast weight optimisation, and instrument B with SR 0.005 at that time. We will end up trading the former as if it has a SR cost of 0.01 - so a little too quickly. Instrument A will also get a lower instrument weight, although higher than if it's true SR cost was used. However since we're using dynamic optimisation, we won't actually hold positions in A; instead it's optimal positions will influence our position in B.
Then suppose A and B swap, so B has SR 0.02 costs and A has 0.005. At this point we're going to be trading A a little too slowly, but fine; and B too quickly. Once I update my overrides though B will be excluded from the dynamic optimisation. I'm still 'trading' it too quickly, but I'm not actually trading it so I can relax. B will now be overweight in the instrument weight optimisation and A underweight, but again this isn't such a big deal.
Duplicates and high correlations
Before allocating forecast weights, there is a unspecified step we don't talk about which is deciding that e.g. the pool of trading rule variations for EWMAC should be EWMAC2,8; EWMAC4,16 ... EWMAC64,256. Basically what is the granularity and boundaries of the parameter space. Boundaries are important, because trading really slowly is boring; trading too quickly is expensive. Granularity is important because there is no point trying to trade both EWMAC 2,8 and EWMAC 2,9 as they are 99% correlated, and more to the point portfolio optimisation with very highly correlated things is hard, even if we shrink the correlations.
To choose those we need (i) the correlation between forecasts of different parameters (to weed out parameters that are too close to each other), and (ii) the trading costs (to determine the boundary limits). We do not use pre-cost returns. That decision can be made in a number of ways, using fake data, maths where possible, or using a limited amount of real 'burn in' data - normally a year (since we need a year to get estimates of forecast and instrument weights).
In instrument weight fitting space we don't need to select the assets we're optimising, they are given. However that doesn't mean we can't worry about highly correlated assets. The US 5 year and 10 year bond future are pretty correlated; although their subsystem correlations will be lower than those of the underlying instruments. And in fact in the instrument space I trade there are instruments that are likely to be 100% correlated. That's because there are often multiple instruments trading the same price: different contract sizes, or on different exchanges.
My open source trading system, pysystemtrade, deals with this by dropping duplicate instruments in favour of just one for each underlying price. This means we'd need to do that substitution before we did instrument weight optimisation. It makes most sense to pick the instrument in a given group with the longest history; even if we end up substituting a different instrument again before we trade.
(Another 'gotcha' is that we'd need to keep a record of substitutions that happened in the past, even if we're not currently trading the relevant instrument, since under the rules of 'no out of sample fitting, ever' we have to retain old instruments in our backtest).
A summary of the proposed instrument weights method
OK, so for instrument weights we:
- Remove highly correlated subsystems, by picking the one with the longest history from a series of duplicated instruments.
- If using dynamic optimisation, cap instrument cost estimates at SR=0.01
- Do rolling pure out of sample optimisations, rerunning the optimisation each year and using the last 30 years of rolling returns (as for forecast weights).
- We don't remove 'dead' or 'stale' instruments as that would be in-sample fitting, instead they get a zero weight for a given year if in the last 6 months they have no price or forecast data (I do a similar thing for forecasts).
- For each annual optimisation we use the last (current) set of forecast weights to calculate 'point in time' combined forecasts, and instrument p&l for fitting.
- Each optimisation is a clustering algo, with a desired cluster size of 6.
- Within each cluster we use shrinkage of SR and correlations according to the boilerplate numbers for forecast weights; with more extreme shrinkage with less data.
- We deduct the instrument costs from the shrunk SR estimate
The test data
- EWMAC2,8; 4,16; 8,32; 16,64; 32,128; 64,256
- Carry with smooth of 10,20,40,80
- Breakout with lookbacks 10, 20,40,80,160,320
- Broke the carry rule for bunds and bobls; and for Shatz before the year 2020, and for Buxl for after the year 2020 (as I explain in AFTS, carry is a bit weird on German bonds so why not)
- Deliberately broke Bitcoin so it has no price
- Removed the price from Ethereum from 2023 onwards, making it look like a stale instrument. Remember Eurodollar is already stale.
The instrument weights




Account curves
- Forecasting weights: remove expensive rules (SR>0.13), cluster with equal weights within clusters, no reverse rules. Note this means we ignore SR, only using correlation for clustering.
- Instrument weights: cluster with equal weights within cluster. Note this means we ignore SR, only using correlation for clustering.
















