Fintech Noir

Should we adjust drift-diffusion models to account for momentum?

NTTP
12 min readFeb 13, 2024
Photo by Filip Mroz on Unsplash

It was a dark and stormy NASDAQ. My partner and I were puzzled over the fact that our forecasts were all outta wack, see, so we went down to the VAX room and set up a new run to recompute parameters. While the minicomputer was doing its thing, we stepped outside for a breath of fresh air. I grabbed a coffee from the vending machine on the way. Strong, with powdered creamer to take off the edge, “poker hand” paper cups… “for entertainment purposes only.”

Opening the door, our colleague from the math department — not entirely unlike a situation that the musician Prince described in song — was walking in as we were walking out.

“Still fiddling with my grandmother’s pension fund?” he jocularly asked, per his usual harassment of us applied mathematicians.

While partly accurate, the barb was rich coming from someone who was comfortably tenured and living in an Arts and Craft bungalow on a leafy street in the historic part of town. Some of us need to keep on earning our money and can’t rest on any leaves, laurel or otherwise.

“Still trying to square the circle? Or no, was it: Prove Fermat’s para-penutimate theorem?” my quick-witted partner ricochet’d back at him.

Non-plussed, our equation-minded associate kept walking and concluded, as the glass door gently closed behind him, “Learn to push some symbols, boys…”

As we stood under the awning — not talking after a long session of piling up monetary losses in the unexpected bear market, our recent code corrections being an attempt to remedy this, me sipping my coffee while watching the heavy rain… we tried to stay out of the rain proper, but the occasional horizontal gust made this attempt only an approximation — my partner took out his clay pipe and proceeded to pack it and then light it with a match, using one of his strike-anywhere Ohio Blue Tips that he always had at-the-ready.

“One of these days, that box of Blue Tips is going to rattle around in your briefcase, and all of your genius work is going to go up in smoke, poof!”

He just grunted as he attempted to get the pipe lit in the damp air.

“And, you shouldn’t smoke,” I added dutifully.

“I know,” he finally agreed, while taking care not to perform any corrective actions related to my remonstrance. In this, he emanated a premonition of his future career in politics and corporate management, in addition to emanating clouds of cherry-wood tinged smoke. The downpour continued as we waited for the output of our run to be deposited in the output bin, online-printed fanfold, tu-tone.

There seems to be at least some agreement that markets are not completely efficient, and that some predictability may be had, in terms of direction. You must bear in mind, though, that — when you see any models or methods that claim to predict the direction that particular asset prices will take — these predictions are often in direct violation of the Efficient Market Hypothesis (EMH). With this caution in mind, we proceed.

In our drift/diffusion model forecasts that are based on empirical actual returns [described in our earlier articles], not constrained by normality or log-normality, a natural drift bullish or bearish often occurs based upon prior return tendencies. We do not compute a drift term like we would have to do if we had built this model analytically. It just shows up from the aggregate of random walks that are in turn based on actual prior returns, unhindered by the need to squeeze this data into an artificially analytic distribution.

Figure 1: 100 day bulk backtest in the software MCarloRisk3D, with realized median forecast (black) compared to model forecast (bright green).

For this model (GE, General Electric, started by Tom Edison, antihero versus N. Tesla? Or was it Westinghouse?) we do a bulk backtest of 100 days for some recent time period and see the bright green line, the model’s median forecast, showing up as notably more bullish than the actual blue curve. This green curve is essentially the drift of the drift/diffusion model as projected forward in time (into the withheld chunk of 100 bulk backtest days).

So we thought: What if we were to estimate the actual drift over this period, but constrain it to the probability model that we have built?

We can do this by moving the top slider on the yellow probability plot sideways until the realized percentile is close to 50%. In the resolution of this model, the closest we got was 49%. Good enough. Now see that the thin black model curve approximately follows the actual blue curve, because about 50% of the blue curve is above this black curve, and about 50% of it is below. This is shown in Figure 1 above.

Reading the number on the top graph, we see that this is an apparent model-based probability of 13%. E.g. the actual price has been running at about the 13th percentile of our probability model over the last 100 days, not at the 50th percentile. This may indicate that our model is too bullish. Perhaps we have some model tuning to do?

Hold the thought on model tuning for now. We are not going to tune the model in this example.

Now recall from our prior articles that we can also do exhaustive backtests and step this bulk backtest one day at a time, back in time, to see what happens. Let’s do this now, but also let’s have this “realized 50th percentile” offset be computed during the backtest. We have coded this up so you don’t need to do it manually at every step of the backtest.

Figure 2: Comparing 50th percentile (realized, black curve) to 50th percentile modeled (green curve). All versus blue curve actual. This is not really a backtest for the adjusted black curve, because it uses the actual price data from the backtest withheld data to compute the realized 50th percentile value. The switch for activating this feature is noted. The small legend annotations on the upper left with the percentiles are also switches to shut off curves. We shut off most of the other curves for this screenshot because they get in the way of understanding (1%, 5%, etc). The (i) button next to the “Validate versus realized 50th %ile” switch explains in detail what this black curve during the validation process is, to remind both end users and software writers what this switch does.

The thin black line in Figure 2 matches the blue actual curve much better than the bright green median curve that is emergent from the diffusion process which occurs at each backstep. But before we start popping champagne, let us recall that we are essentially fitting the blue curve during each back step, fitting a “constant probability flowline” that emanates from the diffusion process, to the actual blue line price data. So of course it is going to look closer to reality than the bright green line, which is purely a forward forecast.

Now the question becomes: Can we use this “median as fit” constant probability flowline to do any true predictions out of sample, and how good might these predictions be?

A full backtest of this we do not have coded up yet, but our code is set up so we can go one window of time ahead, and at least make a forecast. It may be possible to do a manual backtest in this manner with our software as-is. We are thinking about it. Stay tuned to this Medium channel for updates!

The process is: Make a bulk backtest of a basic drift diffusion model, however many days we want (how many days we bulk backtest will affect this newly solved for “apparent 50th percentile” flowline). Adjust the top yellow graph probability slider so that the bottom price curve best matches the blue actual curve. You can use the small percentage notation under “actual %” annotation on the upper left of the lower graph to guide this.

Figure 2: This value gives a hint about how the thin black constant probability flowline fits the actual blue price series. You may not be able to get it to exactly 50% due to the resolution of the model, especially with smaller days forward counts.

Make a note of the probability in the diffusion model where this occurs (yellow graph output; the yellow graph black line shows a CDF = cumulative distribution, empirical from the Monte Carlo generated model). In the above example, this occurred at the 13th percentile of the model. Now we can stop withholding data for the bulk backtest and just project this diffusion model into the future, and look at the 13th percentile probability flowline to see where it shows up at the investment horizon and all points before.

Figure 3: 13th percentile OOS = thin black curve.

Figure 3 shows the plot of this 13th percentile flowline, forward in time past our known data. This is the estimated median / 50th percentile / “expected value” of our adjusted model at the 13th percentile. The blue curve is now a flat line, last known actual price. This snapshot is 100 days ahead, so we can see that the flowline drops a bit below the last known price of GE (blue) and then after 30 or so trading days starts to rise, finally ending up at the end of our investment horizon of 100 trading days at $146.71. This is versus our original “free” untuned drift (bright green) at $171.48, the most probable value of the original model. The black adjusted line is actually a forward forecast here; there is no cheating and looking at future data, because we have no future data. We had fit at the 13% level before we projected forward into the future.

This fit-to-bulk-backtest curve is one departure or one adjustment from/to the raw drift-diffusion model, which is based on pure random walk theory, albeit enhanced by our use of empirical returns which allow for fat tails and all other non-normalities. But should we have calculated this adjustment from 100 days backwards, or should we have used 200 days… 50 days? Or what? At this point we do not know. This technique is presented as one possible way that we can adjust drift-diffusion models to try to correspond to reality better, but it needs copious verification and checks before using it. However, it does give food for thought.

Is this… momentum?

What the model seems to be doing is accounting for recent time period “momentum” that a raw drift/diffusion model does not account for, while fitting this momentum curve in the context of a probabilistic random walk model rather than an arbitrary curve or straight line. This may or may not be a good idea. As we noted in earlier articles, the price behavior of an asset in the past is a rough way to forecast the price of the asset in the future. Why? Because the future could be far different from the past. Next week, the actual blue curve may start to run at 70% of the forecasted probability distribution instead of 13%. So more testing is required. But we present this idea of adjusting via probability “flowlines” as we call them (curves of constant probability) as an alternative to some other backwards looking metrics that try to draw arbitrary curves through price series or otherwise smoothly filter price series. This model represents merely a probability shift (one parameter) from modeled 50th percentile to observed 50th percentile (in this example, ending up at the 13th percentile of the model). The smoothing is constrained by the drift diffusion constant probability curves. It is more than a one parameter adjustment, because we also have to account for how big of a bulk backtest we do to make this correction.

Let’s do a 252 trading day fit (1 year correction, 100 days forward) as a counter-example:

Figure 4: Withholding 252 trading days (1 year) shows an entirely different story. Now the actual is running at the 86.5th percentile of the model. Uh oh. Conflict. Note also that the green most probable expected value is just about flat in this case, close to what the EMH says it should be. Imagine that… a model that agrees with theory…

Here the approximate best fit adjustment of the median is at the 86.5% probability flowline. Observe how the actual curve seems to fit so well to this black square-root-like curve which is computed from prior historical data and the random diffusion process. It is not an analytic curve fit, a power law equation, or a filtering of the raw data with any simple or complex filtering mechanism. It is a completely empirical curve from prior return data resampled, remixed, and projected forward as we always do in our drift diffusion models. The only thing we have to do to get it to fit is adjust the probability level on the yellow graph by dragging the slider back and forth. Now that we have specified the 252 day backtest, it is truly a one parameter fit. It seems remarkable that a one parameter model fits so well to a complicated price series, and, that the model is based on prior data and not arbitrary equations, filters, or manual line drawing. Granted, we are manually adjusting the probability level to get this single parameter flowline to fit… “optimization by looking,” as my colleague used to say. But still: This procedure is automated in the backtest, and we have a secret button in the app to do this fitting manually.

Figure 4A: Mystery button “find min |mean|” shows up during a bulk backtest on the lower right of the probability graph. This will automatically find the probability flowline level that best fits the actual withheld data. These buttons are hidden in the case of a forecast, since there is no withheld data to fit. The other similar buttons marked “find realized” do similar things, but target the upper and lower percentiles (5% from each edge) instead of the median 50th percentile.

If we forecast forward now for 100 trading days again, we get a forecast price at this 86.5% flowline of $202.04, much higher now than the unadjusted $172.45 median forecast (recall that our prior adjustment was lower than the default 50th percentile forecast).

Figure 5: 100 day forecast but using the “momentum” adjusted median at 86.5% (from the 252 day bulk backtest). Thin black curve above bright green curve. What a difference 152 days make when doing momentum estimates.

Which one to believe? The original 13th percentile flowline from the 100 day momentum-like fit? The “as modeled” 50th percentile? Or the 252 day momentum-like fit at the 86.5th percentile? No doubt there are many more alternatives.

Hence, this illustrates the issue of following momentum of price series (even if adjusted by this simple probabilistic method): How far back should you go to compute the so-called momentum is the critical issue in our case, and, will the adjusted trend continue? Clearly this is a model with an unsolved-for degree of freedom, this “how far back to do the bulk backtest” to adjust this probability value. But the concept of having a two-parameter model to estimate momentum by adjusting a probabilistic forecast model is interesting enough that we leave it in our MCarloRisk3D software for user’s experimentation and mulling, with cautions as we note here, and with the always apropos recommendation of “consult a financial professional before making trades”… to be heard in your mind right before you press the buy button in your Robinhood app, of course.

Hey, there’s an idea: A “consult your financial adviser” button in the Robinhood app! Live stream chat! Maybe it already exists…?

Ok, back to our reality: We know that even in basic analytic drift diffusion models, the standard deviation of returns follows the square root of time as we project this volatility into the future, so it seems reasonable that other probability levels should follow a similar power-type function into the future (square root being the one half power of course). Our software attempts a fit of these power-law type of functions to these constant probability curves, but we won’t get into that here too much, as it is another step removed from these constant probability empirical curves. If you want to try it, there is a switch on the lower right of this screen of the app. Switching this on adds some delays to the user interface currently, so we leave it off by default. The screenshots below give you a little preview/taste of this feature. However, we think it is more important to focus on backtesting this concept first before arriving at analytic forms. Why bother with an analytic form until we know that the concept backtests okay?

Figure 6: Power function fit switch. With this on, the application will generate a power function fit for the black selected probability curve and show the equation on screen on the upper left of the envelope graph.
Figure 7: Example power function fit output, price as a function of days forward for the selected probability level. This is just for an arbitrary example, not specific to the earlier examples. Note that instead of 0.5 (square root), this particular constant probability curve is at a power of about 0.65.

We will have more to say on probabilistic model adjustment soon, but if you want a preview, consult our detailed training slides for this app at:

https://diffent.com/mcrtrain/mcrtrain.html

As we trudged bleary-eyed up from the machine room back to our offices after retrieving our printouts from the N-th run of our code, we ran into — let’s call him Professor Smith — from our economics department.

“You boys ready to accept the Efficient Market Hypothesis yet? I heard the financial news on the radio…” His eyes were sparkling as he said this behind Bakelite-rimmed spectacles, barely holding back his glee.

“No comment,” my future politician friend said as we gumshoed our way back to our offices at the end of the hall. I just shrugged sheepishly and smoothed down my rain-dampened hair in the general direction of our elder as he looked after us, shaking his head as he gently closed his office door and started on his way home, carrying his well-worn tan leather satchel of mysterious pre-published papers pending.

Software links

The MCarloRisk3D app with these features may be found on the Apple app stores for macOS and iPad, but alas not for the VAX.

An older edition is available on store.microsoft.com for MS Windows machines. That edition has the manual adjustment of this constant probability flowline, but not the exhaustive validate of it. We have limited development resources for free software.

A lite version is also available for iPhone (MCarloRisk3DLite) and under the same name on Google Play and store.windows.com, and a large screen desktop/laptop lite version for browsers on the web is at:

https://mcr3d.diffent.com/

Screenshot of lite web version MCarloRisk3DLite. More limited features but you can do manual momentum experiments as we describe here.

--

--