Monday, 23 November 2026

Fitting blunt instrument weights

 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:

7 Structural breaks (failure)

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

After a lot of playing round with shrinkage calibration, I decided that if you have at least five years of daily returns data then SR shrinkage of 0.5 and correlation shrinkage of 0.75 made sense (with stronger shrinkage with less data) for forecast weights, but also that the surface was quite flat and generally as long as you did some kind of shrinkage the results would be ok. 

In fact we're likely to end up with quite similar instrument p&l SR, which could support a less severe shrinkage on SR. However I'm biased towards equal (ignoring correlation) instrument weights anyway, and I also don't want to risk doing meta in sample fitting of optimal shrinkage on instrument weights when I've already arguably done it on forecast weights. Also, I can't be bothered.

So in conclusion I'm going to stick to the same shrinkage policy as used for forecast weights.

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
As intended this is very similar to forecasts, except of course there is no pooling and no reverse weights wrapper, nor do we remove assets that are too expensive to trade (there won't be any, due to rules with a SR cost of 0.13 being dropped).


The test data

To do some testing for this blog post, I used the following set of instruments:

SP500, US10, US5, VIX, DAX, NASDAQ, GOLD, CORN, BUND, BOBL, BITCOIN, ETHEREUM, CRUDE_W, GAS_US, WHEAT, MILK, SILVER, EUR, JPY, GBP, GBPEUR, V2X, BRENT_W, SHATZ, BUXL, KR10, CAD10, EDOLLAR

Obviously they have been selected to give a reasonable cross section across asset classes. I've also deliberately chosen one dead instrument - Eurodollar. This has no price after June 2023.

The trading rules I've chosen are:
  • 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 
To ensure I can test corner cases I also manually borked the data as follows:
  • 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

Let's skip to the weights first. Here are the final weights:


They are the final weights, so we have nothing for the stale and artifically stale instruments EDOLLAR and (E)THEREUM. Bitcoin doesn't even appear here since it never gets a weight it never makes it to the dataframe. Note we have a genuine zero weight for V2X, more of that in a second:

They are reasonably spread over asset classes:




Note there are more bonds (7) than say equities (3) or metals (1); so we'd expect more but clearly less than equal weighting would suggest.

How do weights vary over time:



Early markets get more weight initially as you'd expect. How stable are weights? Let's zoom in on the last 10 years or so:



That's kind of OK. And here is an uncapped IDM:



Account curves

Now, how about some account curves? First of all let's see the 'true out of sample' instrument account curves. Here we're using the forecast weights available at the start of each year to calculate combined forecasts:

Here are the net SR over the whole period for each instrument:


=

Bearing in mind how strict we are being here (nothing forward looking, allowing both negative and positive weights on everything so no implicit fitting except in the choice of trading rules) I'm quite pleased with that. V2X remember is the only instrument that gets a zero weight. 

How does this shape up for an overall account curve?

So that looks pretty good (SR gross in blue is 0.99, net is 0.93); but shouldn't we compare it against a benchmark?

Note those costs are underestimates due to the application of SR caps of 0.01; but anything with a SR over that won't be traded after dynamic optimisation.

A benchmark that is pretty close to what I do now is:
  • 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.
Note that using no reverse rules means we've got tacit fitting information (we know trend, breakout and carry work) so let's also consider a benchmark where we do allow reverse rules. That might be worse (as it hasn't got the advanced knowledge) or better (as it has the option to go short certain forecasts in certain instruments where they lose money).

First let's consider the two benchmark results. If we don't allow the use of reverse weights, and hence incorporate tacit fitting information, we get the blue line with the best performance; a net SR of 1.02. If on the other hand we permit reverse weights, we get the green line with SR 0.91. Finally, if we bring to bear all our fitting technology we do slightly better, the orange line with SR 0.93. 

Tacit fitting then adds 11 units of SR that we can't actually get without a time machine. Without tacit fitting- using reverse weights- the full machinery of robust fitting adds about 2 SR units compared to a very simple alternative. 

None of this is proof of anything, as we'd need to look at more than one combination of instruments to get. Remember that the robust fitting results are based on extensive . However, allowing tacit fitting will on average add to performance, assuming our rules have been chosen to be profitable. 

It's also worth noting that the results are a little different if we exclude the pre 1990 period, when trend following did exceptionally well:
In fact, focusing just on the last 30 years the benchmark is 9 SR units worse than the robust fit, with bench_negative falling between the two stools. We get a 3bp improvement from reverse weights - tacit fitting actually harms us here- and a 6 SR bump from fancier fitting.


Summary

That's it, I've now fully defined the 'gold standard' of fitting.

Subsequent posts around this topic will be how this fits into an 'autofitter' concept, which will prevent all the kinds of overfitting: implicit, tacit and explicit.



Monday, 16 November 2026

AI for systematic traders - this is the least stupid way to do it.

 Anyone who has spent more than 5 nano seconds following me on social media or listening to me waffle on during podcasts will know there are a few things that I am not a fan of. One is crypto. The other is AI. 

These two things have at least one thing in common. They are terrible for the environment, increasing the usage of energy at a time when we aren't using 100% renewable energy, and using other resources as well. 

Both Donald Trump and Elon Musk also like them, and they also sit firmly inside my personal 'not a fan of' box.

And yet, in my fifth book that is being released very shortly, that word 'crypto' is on the cover. Why? Let me explain myself in my own words from the book:

"I should state my own prejudices up front: I am not a fan of cryptocurrencies, which are used primarily for gambling and criminal activities such as money laundering, and which consume a great deal of electrical power, with obvious implications for the climate crisis. In an ideal world I would ignore them completely. Although I am retained as a research advisor for a crypto hedge fund, and I trade Bitcoin and Ethereum futures, I do not hold any crypto in my personal portfolio.

But the point of this book is to guide traders into using certain scientific rules to reduce their chances of losing money, and nobody needs those rules more than those trading crypto. The message of this book as it pertains to crypto can be summarised as “I would not do this stupid thing if I were you, but if you insist, this is the least stupid way to do it.”


In a similar vein, I am not a fan of AI, although unlike crypto I will admit to using it in a very limited way. Mostly for LOLs and making silly pictures, but yes ocassionally for more serious purposes. But I do appreciate that there are a lot of other people out there who are using AI; and perhaps more to the point unlike crypto I do believe AI is useful although it is clearly IMHO massively overhyped in terms of what it can achieve in the quant finance space specifically. But there are an awful lot of people using it in very stupid ways. Hence the subtitle of this post.


A silly picture - thanks chatgpt. See Appendix for prompts and transcript.


The 1st past of this post will be a brief and breezey criticism of the current use cases of AI by people who do similar things to me (develop trading strategies that can then be automated). Then I'll briefly explain the limited set of things I would trust AI to do. Finally I will outline a framework for using AI in a systematic trading strategy reserach process. 


Some bad ways to use AI 

Let's begin with the dumbest way to use AI for trading purposes, with a prompt like "Tell me what stocks to buy" on a generic public model. I hope I don't need to elucidate to the wise and educated people on this blog why that would be a bad idea. 

One level about that would be using the same prompt on a model that has been locally trained on some financial data. Generic machine learning classification tends to do very badly on financial data, mainly due to non stationarity. It's not clear to me why LLMs should do any better. 

Going up another level, would be a prompt like "Tell me what trading strategy to use, and why". Congratulations, you have just invented in sample fitting but in a completely opaque way! Plus you can't trust the code that's been used to produce the back test you have just been shown. Interestingly, AIs don't seem to be as good at the insample research loop (develop model -> test-> change model -> retest) that humans do so well.

That brings me to the writing of code. Any code that you use to handle your money and/or other people's money should be 100% trustworthy and fully understood by you, whether it be backtesting or production code. You can never say that is true of AI code.

Agentic AI? Well..





(The second image is a real screen shot from someone I know, who - for obvious reasons - will remain anonymous)

I am expecting this part of the post to get a lot of replies, mostly critical and starting with "Ok boomer..." (typical AI mistake, I am gen-X). I will ignore ones that say "Ah but that is because you should be using model XYZ" or "No you should be using a different prompt" or "Ah but you just need to do X, Y and Z". LLMs have inherent flaws that can never be completely fixed by prompting or using different models or using an agentic framework; and will always be opaque - a very bad thing indeed.

Some good ways to use AI 

Idea generation: I am not averse to using AI for idea generation. This could work with eithier a publically trained AI or a local model. 

Summarising research: Next after idea generation, it makes a lot of sense if you are doing a lot of research to have an AI summarise for you all the academic papers in field X (you shouldn't ask it to sumarise book Y, since the contents of that book will have been stolen from it's hard working authors). Of course AI's writing style is bloody irritating so I'm not sure how much of it you could read without screaming. I find that asking it do summarys in bullet points removes a lot of the pain. The other obvious problem is hallucinating, so you need to be prepared to get your metaphorical hands dirty and read the underyling research yourself. Still it's a good starting point, and better than just typing "phrase" into google scholar.


There are another ten pages of this, and in fairness although there were a few minor errors it pointed me to some papers I wasn't aware of

Finding data sources: arguably this is something a search engine could do, but we're pretty much at the point where AI is better at search than a search engine is. But don't just say 'give me the data', find out where the date comes from and get it yourself.

Writing small amounts of code: I've used AI to write small bits of code. Small bits because you can easily verify they are correct. It's particularly useful in a situation where the code is relatively isolated from everything else, and it's not a big deal if it fails. A recent example would be that for the framework described at the end of the post, I wanted a configuration file that could only be added to and not otherwise edited, and decided to implement this using hashes (yeah I know that makes the file like a single node blockchain, the irony isn't lost on me). 


I could have easily written this myself in an hour or so, but I was in a hurry and got AI to write it. It ran perfectly and although the style of the code wasn't something I would have written myself, it's small enough that I can easily check it's correctness in much less than an hour (so net time saved), and if it goes wrong it isn't going to result in me accidentally buying 10,000 contracts of Bund futures.

Checking code: In theory at least, I don't have a big problem with AI checking your code and suggesting changes. I've had other people check my code with AI, and to be fairness it did find some issues. The downsides here is that the language of code checking in AI is bloody awful (as is obvious from the AI contributions to pysystemtrade), and you often need another AI to interpret what it is saying, which seems to be a net waste of time. 

You should absolutely not merge the changes from the AI without checking them. The same code check someone did for me resulted in the AI unintentionally introducing an absolutely massive bug. So what I am suggesting here is definitely not a 'write code with AI', 'check code with AI' doom loop without human intervention; or using AI so extensively that you can't actually properly check all the code written or suggested changes. That would be insane, and it's incredible to me that there are people doing it.

Writing tests: I hate writing tests, as anyone involved in my open source psystemtrade project will know. Tests are small bits of code with a well defined objective that if they go wrong won't affect the rest of your codebase - perfect for AI. Note that I wouldn't extend this to writing documentation, another thing I am really lazy at (although unlike tests, I do actually do it), since AI writing isn't something I am a fan of; and there is a real benefit to writing your own in my opinion.

Stealing code: Like crypto, AI is also good for doing crime and stuff.


A framework for using AI (and also human brains)

With the above in mind, what is a safe framework for using AI in trading research? In fact this is exactly the same framework that should be used in an ideal environment for testing human generated ideas. We still have the same three versions of overfitting we're trying to avoid: explicit, implicit and tacit. It's just that the overfitting is wrapped in an opaque blob so we don't even know if it's happening or not. 

Idea generation, data scoping, initial research: As noted above this could be done by AI, or by a person. It's fine.

The end point of this exercise will be the following:

  • Some trustworthy data. To be trustworthy the data must have come direct from the source not via the AI. You should have checked the specs of the data to make sure there is no in-sample fitting hidden inside it (this is a problem often for sell-side produced 'strength indices', and more recently I've had this issue with certain Glassnode crypto data) and no forward looking data (a problem for eg macro data published with a lag and then revised, and company earnings that certainly don't come on the final day of the quarter they relate to).
  • A piece of parameter-isable code implementing the strategy idea (i.e. producing a forecast) given the data as an input and incorporating parameters that require calibration like the fast_span and slow_span below:


(As an aside, the code produced here was a bit rubbish as it also included some backtesting fluff and didn't just produce the forecast but this is a 'skill issue' that better prompting or a skill.md file can probably solve).

Note that the parameter-isable code is small and therefore it's correctness can be verified. However it may well incorporate tacit fitting.

That is the last time we will touch AI in this process. Everything else that happens will happen in a robust testing framework. Importantly that robust framework must not have been written with AI or be run be agents (with the caveat that small parts of the code may be AI written, AI may have been used to suggest improvements, and the tests may be written with AI).

A good way of explaining this is to think about the harness+AI that produces AI agents, something like this:


From https://www.bankofengland.co.uk/speech/2026/november/jon-hall-speech-at-cf-imperial-workshop which I attended actually

Instead of a model inside a harness (and inside a sandbox here) the model only gets to play with one thing; the parameter-isable python code that ends up getting tested as a forecasting rule. Everything else in the robust framework around it is off limits to the AI.

The list of requirements for the robust tester is again not different from what a proper tester would have for human generated ideas or strategies:

  • Generating the parameter fitting space eithier by using a very limited amount of real "burn in" data, fake data or theory. If real data is used, performance isn't considered, only correlation and turnover.
  • As alluded to above when I discussed the config file hash key thing, an add only system where new forecasting rules once tested can't be removed from the backtest. This avoids implicit fitting in the form of 'research loops' where the results of backtests are used to refine forecasting rules, or remove them entirely. As we're not ever going to remove or drop a rule, we don't need to worry about nonsense like Whites Reality Check and we're not at risk of dropping rules that may work but whose natural profitability is too low to pass an arbitrary statistical hurdle.
  • Backward looking explicit fitting of the combination of optimal parameters and forecasting rules.
  • The fitting is robust - it knows about statistical significance and trading costs (as discussed in my recent series of posts, the last one is here).
  • Both positive and negative versions of a strategy to avoid tacit in sample fitting. This avoids the problem that both smart humans and AI already know what's worked, eg medium speed trend following.

What I haven't done of course is specify exactly how this robust fitting engine will work. That is something I am currently working on; and will be spelt out more in (a) future blog post(s). It will also be the subject of my next (6th) book, title to be confirmed, publication date probably at least 2 years away...


Appendix: chat transcript for image

Me: I want a picture of renowned systematic trading author robert carver sat at his computer swearing because AI has just deleted all his files

Chat:







Me: that doesn't look like him and that book cover is completely wrong

Chat: You're right — the likeness and the book cover both need correcting. The image invented a generic older author rather than capturing Robert Carver. Let's get it right this time. Could you upload: 1. A photograph of Robert Carver that you'd like me to use as the likeness reference. 2. The actual cover of his book, Systematic Trading.

I'll recreate the scene with: - A much closer facial resemblance. - The genuine book cover, not an AI-invented version. - Robert visibly furious, shouting and swearing at his computer. - A screen displaying: "AI HAS DELETED ALL YOUR FILES".

Would you prefer photorealistic comedy or an exaggerated satirical caricature?

Me: <Attached Images> I am robert carver and I have the copyright to these images. photorealistic

Chat:








Me: WTF is going on with my hands, they look like those of an 80 year old man? What OS is that - should be linux? And why is my book so big - should be smaller

Chat:

Much better on the Linux front! This version has: - Ubuntu-style Linux desktop, with Tux visible. - A smaller, more realistic-sized book on the bookshelf. - A ThinkPad rather than a generic desktop monitor. - More natural-looking hands and gestures. - Your actual appearance and clothing as the reference. The AI has still managed to delete everything. At least it hasn't deleted your book. 😄

NOTE: Smiley face was inserted by AI not me. I am not that whimsical

Wednesday, 4 November 2026

Why optimising for the left tail of outcomes is like playing chess...

A short one today.

Suppose I offer you N trading strategies to choose between. We can run some kind of bootstrap of their historical returns to get a final distribution of CAGR, with all the caveats implied by that. Or suppose I ask you to pick the correct level of leverage on a trading strategy. Again we can bootstrap historical returns at different leverage levels, giving us a series of N discrete possible leverage levels. How do we do that? Both are equivalent to choosing which of N distributions of possible outcomes we prefer.

The strict expectation method is to pick the option with the distribution that has the best median value, eg 50% distribtional point. As I've discussed before, that is equivalent to the Kelly optimal.

The gambling addict method would be to pick the one with a very good right tail. We might go for the option that has the best 1% right tail. That would be a high leverage option, something with high natural risk like crypto, or a short gamma strategy that doesn't manage to blow up in the best possible alternative histories that generated the bootstrap. Nobody should be a gambler, except sometimes.

The conservative method, which I favour, is the opposite. We might go for the option that has the best 1%, 10% or 25% tail; eg the option that will have the best outcome if bad things happen. 

We can imagine an extreme version of the conservative method where we pick the option with the best worst outcome, i.e. the best minimum value. In fact if we're bootstrapping enough times the lower bound of all distributions will be a final portfolio value very close to zero (with compounded returns and absolute returns>-100% we can't mathemtically below zero) and hard to distinguish; so in practice the most realistic extreme version would be something like picking the option with the most optimal 1% left tail point. Given that is likely to be negative, that would be the option with the least worst 1% tail.

(Frankly more extreme outcomes are highly uncertain, and will probably go beyond what a historical bootstrapping exercise could predict)

The least worst option? That is also the MinMax of game theory, Nash equilibria and all chess playing software.


Credit: Chatgpt, authors own prompt

If you view the market as your adversary, you want to have the least bad outcome in the worst possible state.

Now I am not suggesting you optimise for the 1% point, but they do say that there are no old, bold traders. Good traders know how to quantify and when to take risks, but they also understand the importance of keeping their capital mostly intact in the future. So somewhere around the 10% or 25% point seems appropriate to me.