Duffing Oscillator
Motivated by e-mail from Dan M.

Once upon a time I looked at identifying periodic variations in stock prices ... here.

>That was a LONG time ago!!
Uh ... yes, it was ... and it was fun.
I assumed that stock price changes depended upon their deviation from some magic price which I called Po.

>Po could be a moving average?
Sure, why not?
Anyway, suppose successive prices at times t = n-1, t = n, t = n+1 are P(n-1), P(n) and P(n+1).
Then the rates of change are P(n) - P(n-1) and P(n+1) - P(n)
... and the rate at which this changes is: [ P(n+1) - P(n) ] - [ P(n) - P(n-1) ] which we assumed is proportional to P(n) - Po.
This is a rate of change of a rate of change ... let's call it RCRC.
If P were distance travelled, then P(n) - P(n-1) would be speed and our RCRC would be acceleration.

>Acceleration is the rate of change of speed, right?
Right. So we now have:

[1]       RCRC = [ P(n+1) - P(n) ] - [ P(n) - P(n-1) ] = - β [ P(n) - Po ] ... where β is some positive constant

Note that, when P(n) is greater than Po, the right-side, hence the rate of change of slope ... it's negative.
That means the price change is decreasing. That means the P vs n chart is concave down ... like so

>But that's not even smooth. It jiggles about and ...
We're talking mathematical idealization ... and that's how we do it. Avoid the complexity of reality.


This proportionality makes this a linear system, so let's make things a bit sexier and assume nonlinearity.

>Nonlinear? That seems the trend these days, eh?
It does, doesn't it?
Anyway, we'd still like the chart or Price vs Time, that is P vs n, to be concave down when P is larger than Po.
So we can introduce nonlinearity by assuming that the rate of change of [ P(n) - P(n-1) ] goes like so:

[2]       RCRC = [ P(n+1) - P(n) ] - [ P(n) - P(n-1) ] = - β [ P(n) - Po ] + α [ P(n) - Po ]3 ... where α>0 and β>0 are constants
Note that the right-side is still negative when P is greater than Po
... until P becomes quite large.
.... then it can go negative

>x? What's x, in the diagram?
Oh ... I forgot. We'll let x(n) = P(n) - Po.


To make things even sexier, we'll assume that the slope of the P vs n graph ...

>Huh? Slope? What slope?
P(n) - P(n-1) is the slope. Didn't you recognize that? When P > Po, the slope decreases and when P < Po, it increases. That's what we're talking about and ...

>Okay! Please continue!
We're going to make the rate of change of slope depend not only upon the deviation of price from some magic price Po, but upon how quickly the price is changing.

>How quickly the price is changing? Isn't that P(n) - P(n-1)?
Exactly! When the rate of change is positive, meaning the price is increasing, we want our RCRC to be even more concave down.
That is, we want RCRC to be even more negative ... so we're now at:

[3]       RCRC = [ P(n+1) - P(n) ] - [ P(n) - P(n-1) ] = - β [ P(n) - Po ] + α [ P(n) - Po ]3 - δ [ P(n) - P(n-1) ] ... where α, β and δ are positive constants

>Why more negative?
When the P > Po and the price is increasing (so that P(n) - P(n-1) > 0), the magic Po attracts the price.
When the price finally starts heading South (so that P(n) - P(n-1) < 0) then the attraction eases off.

Okay, if we wave our magic wand and change this from a difference equation to a differential equation, we'd get:

[4]      d2x/dt2 = - β x + α x3 - δ dx/dt ... where x(t) = P(t) - Po

>You're kidding. Can you do that?
Of course. Didn't I mention my magic wand?

Of course, there are other unmentionables that'll affect the stock price ... perhaps seasonal variations, periodic changes in interest rates, etc., so ...

>Don't tell me ... you're going to add something else, right?
Yes. Equation [4] describes an autonomous system that runs on its own, disregarding outside influences ... so we'll add an outside influence, like so:
d2x/dt2 + δ dx/dt + β x - α x3 = A cos( ωt)
>I assume that A cos( ωt) is the outside influence.
Yes, indeed. Looks pretty, eh? It's called the Duffing oscillator and you won't believe the sexy things it can do.


a Fun Spreadsheet

We'll let dx/dt = y so we get a pair of neat differential equations with the following form:
[Duffing]
dx/dt = y
dy/dt = -B*x - A*x^3 - D*y+E*sin(w*t)

Then we can solve 'em using this spreadsheet: Click the picture to download:

>Huh? What's all that about?
Patience ... there's an Explain sheet:

>Ha! You spelled clikc wrong!

Pay attention!
The solution is plotted, like so.

I should point out some things:

  • We assumed that Po was a constant.
  • Alas, for arbitrary function, Po(t), it's awkward.
  • To make life simple, we solve [Duffing] for x(t) ... then we just add in Po(t)
>You can do that?
Didn't I tell you about my magic wand?
That's mathmanship. You start with a complex system, then you ignore the hard parts so the problem is amenable to a mathematical analysis, then you solve the simpler problem, then ...
>Then you pray that it's a reasonable approximation to the original, complix problem.
You got it!

By the way, you spelled complix wrong.


The properties exhibited by the Duffing Oscillator are often associated with Chaos.

>Yeah, I know about chaos. I once invested in a stock that ...
Pay attention!
Chaos is usually associated with nonlinear systems that are unpredictable and change radically when the initial conditions are changed just a bit.

>Huh? But the solution satisfies a differential equation. Doesn't that mean it's predictable? I just solve the equation and ...
Uh ... you'd think so, but remember that small changes in the system can generate HUGE changes in the solution.
Perhaps the most famous well known is the butterfly effect

>That's gotta be one HUGE butterfly, eh?
Remember that we're talking mathematical idealization ... a mathematical model of the real world.
If this simplified model behaves chaotically, just imagine ...

>Just imagine how the real world behaves!
You got it.

>So where did you get that spreadsheet?
I used the one here, with modifications.
Remember, once upon a time I was interested in Ordinary Differential Equations. That was a long, long time ago: CLICK!

>Mamma mia! That's ancient!
Well ... yes.