© Ed Seykota, 2003 - 2009 ... Write for permission to reprint.

Ed Seykota's FAQ

(formerly: Frequently Appearing Questions)

Home  ...  FAQ Index & Ground Rules  ...  Tribe Directory - How to Join

TTP - The Trading Tribe Process  ...  Rocks  ...  Glossary

  TTP Workshop  ...  Resources  ...  Site Search  ...  The Trading Tribe Book

TSP: Trading System Project  ...  Breathwork ...  Levitator

EcoNowMics  ...  Contact Us  ...  The Whipsaw Song ...  Music

 

 

The Ways of Delays

 

by Nick Louca, August, 2009

Revision: September 2009

(c) 2009 by Ed Seykota

 

 

Delays are Like Bathtubs with Flows In and Out.

 

Other names for delay are “lag,” “smoother,”

“controller,” “tracker,” “average” and “regulator.”

Clip: http://www.boston.com/bostonglobe/ideas/articles/2008/06/15/surprising_insights_from_the_social_sciences/

 

Delays are among the most important system elements. They are inherent in most systems and have a major influence on dynamic behavior.  Other names for delay are “lag,” “smoother,” “controller,” “tracker,” “average” and “regulator.”

 

In this paper I develop models of delays by hand and in Excel and then experiment with them.  I share my process and insights below.  My  experiments include measuring the responses to Step, Pulse, Ramp and Sine inputs.

 

I enjoy the process of developing the models in Excel;  I find it is like solving puzzles.  It also helps me comprehend what really goes on behind the scenesI make some interesting discoveries during this process as I continue my education in System Dynamics and start to see the role of "averages" in trading systems.

 

1.     Using Driver Functions to Study Systems

 

At the start of this project, Ed introduces me to various types of Driver Functions (standard inputs that Engineers use to drive systems in order to study their responses).  The standard driver functions are: Step, Pulse, Ramp and Sine.  Ed sketches each input and the behavior it induces in a delay.  Each input excites a different responseEd suggests that I examine these responses in more detail.  I plan a series of tests on two types of systems:

 

1)  A Simple Accumulation System: one Rate feeds one Level with no feedback.

 

 

 

 

The Simple Accumulation System: One Rate and One Level with no Feedback

 

 

 

The Simple Accumulation System:

The Inflow Rate can flow in and out of the Level.

 

Note: In a Simple Accumulation System when I drive the Inflow rate with the Sine Function (+1 to -1) the Rate flows in and out of the Level.

 

 

Note: In Simple Accumulation System we have no feedback from the Level to the Rate.  Technically this is a first order (single Level) no feedback system.

 

Example: You turn on the water faucet to your bath and leave the room.  As you are not there to receive information about the Level of water – you do not turn it off, even if the tub flows over.

 

 

2)  A First Order Negative Feedback System.

 

 

 

First Order Negative Feedback System

 

 

Note: A First Order Negative Feedback system is a system with a single Level and a single Rate; the Level controls the Rate through feedback.

 

Example: You get feedback information about the Level and use this information to adjust the water drain rate from the tub.  In particular, you pull out the drain stopper when water approaches the top of the tub and allow water to drain out of the tub.

 

You might also turn off the faucet and stop the water from flowing into the Level. This particular action does not correspond to the above model.  See more on First Order Negative Feedback in Section 2, below.

 

The Target, Gap and Time Constant are part of the "Policy" for managing the rate in response to the Level.

 

1.2    Defining the Driver Functions

 

A driver function is an equation that controls the input to a system.  For example, the driver function might deliver a Step, Pulse, Ramp or Sine Wave input to a system.  We observe the system output for each driver function.

 

In our EcoNowMics work, we confirm our understanding of a system by explaining how the system  generates its response to each of the driver functions.

 

1.2.1  The Driver Functions: Getting More Specific

 

I look on the internet and in several books on System Dynamics.  I feel some frustration as I am unable to find exact definitions of these functions and how they actually drive rates in systems.

 

I have a general idea about how these functions operate and how they might apply in the field of engineering but not much about how these apply to System Dynamics.  I am still not clear or happy with my knowledge on these functions.

 

At this point I have a conference with Ed.  He tells me he has the same experience and that clarity is essential to moving forward.  He suggests we can move toward clarity by thinking about these matters until they become clear.  The definitions below arise through this thinking process.

 

i)     Step Function

A Step is a value that changes and then stays there.  Example: You turn the volume knob on your stereo from 3 to 5.  The knob steps from 3 to 5 and then stays at 5.

ii)    Pulse Function

A Pulse is a value that changes and then stays there for a short duration – and then changes back to its original value.  Example: You press down on your gas pedal, hold it down for a short duration, and then release it.  Note: You can also see a Pulse as two opposite steps occurring in sequence.

iii)   Ramp Function

The Ramp is a value that changes linearly.  Example: You gradually and consistently open the valve that controls the flow to your garden hose.  As you turn the valve, the flow increases. The graph of a Ramp function appears as an increasing line or "ramp."

iv)   Sine Function

The Sine is a regularly oscillating value, namely one that traces the height of a dot on a spinning wheel.  Example: A pendulum traces out a sinusoidal curve as it swings back and forth.  Note: For high amplitudes the oscillation is not exactly sinusoidal (see my report on oscillating systems, later in this series).

 

 

 

Sine Function in Relationship to the Circle

Source: http://mathworld.wolfram.com/Sine.html

 

1.2.2  Graphing The Driver Functions

 

My next step is to graph the driver functions.  I graph the Step, Pulse, Ramp and Sine Wave which I use to drive the Rate in the Simple Accumulation and the First Order Negative Feedback systems that I test in this paper.

 

 

 

Step, Pulse, Ramp and Sine Functions

I use these functions to drive the Rate in the Simple Accumulation System.

 

1.3    Sketching the Simple Accumulation System Responses By Hand

 

Ed advises me to first sketch out my best guess of how the Simple Accumulation System responds to the various driver functions.  I find that doing this requires that I think about how the system responds to the different inputs.

 

 

 

Step Response

 

I think about turning on a faucet (Inflow Rate) and leaving it on.

I guess that the Level keeps rising and making a ramp.

 

Note: I use two Y-axes for the Level and the Inflow Rate.

 

 

 

Pulse Response

 

I think about opening the faucet (Inflow Rate), for a

short period and then releasing it.  I guess that the

Level keeps rising for a while and then remains constant.

For very short pulses, the output appears to be a step. 

 

 

 

 

Ramp Response

 

The Simple Accumulation System response to a Ramp is a quadratic curve.

I gradually and consistently open the faucet that controls the flow into the cup.

The output appears to be a Quadratic.

 

 

 

Sine Response

The Simple Accumulation System response to a Sine is a “negative” Cosine.

Note: In the example in section 1.2.1, iv, the x-axis is in ∏ radians (polar coordinate)

whereas in the above example the x-axis is in time (cartesian coordinate).

 

 

I think of a tide that rises and falls and connects to a sound (lake) through a narrow inlet.  When the tide in the ocean is higher than the sound, water flows into the sound and when it is lower, water flows out of the sound. The water level in the sound rises and falls (oscillates) according to the tide.

 

Technically this system involves two Levels. The cloud at the end of the Inflow Rate in the system structure denotes the boundary of our system.

 

To get a feel for how this works and occurs in nature you may research Harrington Sound, Flatts Village in Bermuda.

 

1.4     Modeling the Simple Accumulation System with Excel

 

At this point, I have a good intuitive sense of the basic driver functions and how they drive the Simple Accumulation System.  I decide to check my intuitive sense by running some tests with Excel.

 

 

Simple Accumulation System

 

 

I formalize the model as a set of equations:

 

 

Equations  .
Level (cups) = Level (cups) + Inflow Rate (cups/sec) * dt
Inflow Rate (cups/sec)  = Driver Function (cups/sec)
Solution Interval, dt (secs) = 0.1 (secs)

 

 

In these equations, dt is the solution interval and represents a small interval of time.  For example, say the Inflow Rate is one cup per second. Then after one small interval of 1/10 second (dt), the increment is 1 cup/sec * 1/10 sec = 0.1 cups and the Level increases by this increment over the dt time interval.

I arrange an Excel spreadsheet to facilitate simulating the behavior of the system.

 

 

Time

Start Level

Inflow Rate

End Level

(secs)

(cups)

(cups/sec)

(cups)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1.4.1  Simple Accumulation System Response to a Step in the Inflow Rate

 

I program the Step response in Excel.  Here I use a Step to drive the Inflow Rate (Column C).  The Rate steps from 0 to 5 at time = 2.00 seconds.  The output (driven variable) is the end Level (Column D).  Note: the end Level for each time interval carries forward and becomes the start Level (column B) for the next time interval.

 

The Excel program confirms my earlier guess about the  response.  The Step response of the  Simple Accumulation System is a Ramp.

 

 

 

 

Note how the Rate jumps from 0 to 5 cups per second at time = 2.00 seconds.  This is how I implement the Step function as the driver function.  See the Excel File.

 

I also notice that in Excel, I cannot get a perfectly square Step to drive the system.  I discuss this with Ed.  He says the smaller the dt the more accurate the step.  I try various dt's and notice that with a much smaller dt I do indeed get a much steeper Step.

 

 

 

Simple Accumulation System - Step Response

 

The Rate steps from 0 to 5 cups per second at t = 2 seconds.

The ascending part of the Step does not appear to go “straight up.”

 

 

1.4.2 Simple Accumulation System Response to a Pulse in the Inflow Rate

 

Again, the program confirms my hunch.  The Pulse response is a Step.  See the Excel file.

 

 

 

 

Simple Accumulation System - Pulse Response

 

The Rate goes from 0 to 20 cups per second at t = 2 seconds.

It remains at 20 cups for a duration of 1 second and then returns to 0.

Note: You can see a Pulse as two opposite Steps occurring in sequence.

 

 

1.4.3  Simple Accumulation System Response to a Ramp in the Inflow Rate

 

The Ramp response is a quadratic curve.  See Excel.

 

 

 

 

Simple Accumulation System - Ramp Response

 

The Ramp function drives the Inflow Rate.

 The flow rate: X = a * (t-1.9) , where a = 3 cups/sec/sec.

 

The Level: Y = 1/2 * (t-1.9)2 * a.

 

You might notice that in the Excel spreadsheet the equation

for the Level = Level + ((Inflow Rate + Inflow Rate -1) * dt)/2.

The Level becomes an average as we attempt

to achieve greater accuracy.

 

Note: In this simulation t is not less than 1.9.

 

 

 

 

1.4.4       Simple Accumulation System Response to a Sine Wave in the Inflow Rate

 

The Sine response in the Excel model exhibits oscillation.

 

 

 

Simple Accumulation System - Sine Response

 

Sine begins at t = 0 minutes.

Note: One cycle occurs every 6.28 minutes = (2 * ∏) minutes.

 

1.4.5  Summary Chart of the Simple Accumulation Response Experiments

 
 

 

 

 

Simple Accumulation System Responses to Various Driver Functions

 

 

At this point, I feel that I understand more about the behavior of the Simple Accumulation System.  I decide to proceed and take a look at a more complex system, namely, the delay (First Order Negative Feedback system).

 

2.               First Order Negative Feedback System

 

The First Order Negative Feedback system is similar to the Simple Accumulation System with the addition of feedback from the Level back to the Rate.

 

 

 

The Level Feeds Information Back to the Rate

 

 

In the chart above, feedback appears as a single information line from the Level to the Rate  - that indicates the policy for controlling the Rate as a function of the Level.

 

We may wish to explore some details of this Policy.  We might notice that it includes various elements:

  • a Target or Goal for the Level;

  • the delta or Gap: the difference between the Target and the Level; and

  • a Time Constant - the time it takes the Rate to move the Level to the Target.

Negative Feedback loops may occur in various places in systems, for example in the system below, the negative loop includes the Outflow Rate, the Level and the feedback from the Level to the Rate.

 

 

 

First Order Negative Feedback System

showing details of the feedback loop

 

 

Equations

Level (units)

= Level (units) + (Inflow Rate (units/time) - Outflow Rate (units/time)) * dt

Inflow Rate (units/time)

= Driver Function (units/time)

Outflow Rate (units/time) = Gap (units) / Time Constant (time)
Gap (units) = Level  (units) - Target  (units)

Target (units)

= Constant Value  (units)

Time Constant (time)

= Constant Value (time)

Solution Interval, dt (time)

= Constant Value (time)

 

Model Equations

 

 

A First Order Negative Feedback System may have an Inflow Rate only, an Outflow Rate only or both an Inflow Rate and an Outflow Rate. The Level may feed information back to one or both of the Rates.

 

2.1    Driving the First Order Negative Feedback Loop

 

I would again like to find out how a First Order Negative Feedback system responds to the various driver functions.  In addition, I would also like to find out how it responds to sinusoidal driver function of various frequencies (frequency response study).

 

 

 

In the next series of  tests, I use the system above.

I drive the Inflow Rate and / or the Target with the driver functions

and I monitor the Level and Outflow Rates for their responses.

 

2.1.2  Sketching By Hand

 

Once again, I sketch my guesses of the First Order Negative Feedback system responses to the driver functions by hand on graph paper.  I find that, as I gain experience, sketching the curves by hand becomes more intuitive.

 

 

 

 

Response of Level and Outflow Rate

to a Step in the Inflow Rate.

 

 

 

Response to Step in the Target.

 

 

 

Response of Level and Outflow Rate

to a Pulse in the Inflow Rate.

 

 

 

Response of Level and Outflow Rate

to a Ramp in the Inflow Rate.

 

2.2    Studying the First Order Negative Feedback System with Excel

 

I program the system in Excel and carry out further experiments.  I also notice the programming task becomes much easier.

 

 

2.2.1  First Order Negative Feedback Loop Response to a Step in the Inflow Rate

 

The first driver function I use for the First Order Negative Feedback model is the Step.

 

 

 

First Order Negative Feedback System Structure

 

 

I formulate the model in the spreadsheet as per the below. See the model in Excel. Notice the Step in the Inflow Rate at time = 2.00 seconds.

 

 

 

 

 

System Response to Step in the Inflow Rate

 

The Inflow Rate steps from 0 to 5 cups per second at t = 2 seconds.

Note: the Level increases until the outflow rate rises

to equal the inflow rate.

 

This test confirms my sketch. The Step response is an asymptotic rise in the Outflow Rate as it approaches the Inflow Rate.   We can think of this response as the Outflow Rate "tracking" the Inflow Rate.  We can also see a "delay" between the input and the output.  Later, we can see how we can use the Outflow Rate to take an "average" of the Inflow Rate.

 

 

2.2.2   First Order Negative Feedback Loop Response to a Step in the Target

 

I continue to experiment with the Step function.  In the above experiment, I Step the Inflow Rate.  In this experiment I hold the Inflow Rate constant and Step the Target.

 

 

 

First Order Negative Feedback System Structure

Target as Driver

 

 

 

System Response to Step in the Target

 

The Target steps from 0 to 5 cups per second at t = 2 seconds.

Note: the Level increases by the value of the Target i.e. 5 cups.

 

The Gap decreases from a value of 8 cups to 3 cups at time = 2 seconds

and then grows asymptotically by 5 cups to its initial value of 8 cups. 

 

Note: The Gap and the Outflow Rate follow the same path.

The Gap refers to the left axis (cups) whereas the the Outflow Rate

refers to the right axis (cups/sec)

 

 

The Outflow Rate decreases as soon as the Target steps from 0 to 5 cups at time = 2 seconds.  It gradually increases asymptotically as it tracks the Inflow Rate that remains constant throughout the simulation.  The Level tracks the Target and increases from the steady state of 8 cups at the start of the simulation to 13 cups at the end of the simulation, an increase of 5 cups which is equal to the Target.  See Excel.

 

 

2.2.3   First Order Negative Feedback Loop Response to a Pulse in the Inflow Rate

 

To see how the First Order Negative Feedback loop responds to a Pulse, I  experiment with the Pulse response as driver for the Inflow Rate and observe the behavior of the Outflow Rate and the Level.

 

 

 

First Order Negative Feedback System Structure

Inflow Rate as Driver

 

 

 

 

System Response to a Pulse input in the Inflow Rate

 

The Inflow Rate steps from 0 to 5 cups per second at t = 2 seconds.

It remains at 5 cups for a duration of 1 second.

 

I notice that the response of the First Order Negative Feedback system to the Pulse in Inflow Rate is a rapid (Step) rise in the Level, and then an exponential decay back to the initial value.  The Outflow Rate and the Level gradually decline asymptotically.  I experiment with different Time Constants to examine this behavior.  I see that at higher Time Constant’s the lag is longer and the system does not reach equilibrium as fast as it does at lower Time Constants. 

 

 

2.2.4  First Order Negative Feedback Loop Response to a Ramp in the Inflow Rate

 

The next function I experiment with is the Ramp Function.

 

 

 

 

First Order Negative Feedback System Structure

Inflow Rate as Driver

 

 

 

 

System Response to a Ramp in the Inflow Rate

The Inflow Rate grows linearly starting at t = 2 seconds.

 

 

I notice the Ramp response has some similarities to how a moving average tracks a trending market.  The Outflow Rate tracks the Inflow Rate and lags behind it by one Time Constant.  I look further at the behavior and examine the numbers.  

 

 

2.2.5  First Order Negative Feedback Loop Response to a Sine in the Inflow Rate

 

The last function I use for a driver function is the Sine.  The Sine function  generates oscillating behavior.  My guess is that this behavior is relevant to most real world systems which revolve around cycles.

 

 

 

First Order Negative Feedback System Structure

Inflow Rate as Driver

 

 

Negative Feedback System - Sine Response

 

 

The Sine Function drives the Inflow Rate.  The response is, not surprisingly, oscillatory. I test the behavior of the model at different Time Constants.  From my experiments with the Time Constant I see that at smaller Time Constants the Outflow Rate tracks the Inflow Rate much closer; at longer Time Constants the Outflow Rate does not track the Inflow Rate as closely (see charts below).

 

 

 

Response with Time Constant = 0.5 months

The Outflow Rate tracks the Inflow Rate very closely.

 

 

 

Response with Time Constant = 5 months.

The Outflow Rate does not track the Inflow Rate closely.

(It has a low amplitude and it lags behind.)

 

 

2.2.6  Measuring the Frequency Response

 

During my experiments with the Sine Response, Ed advises me to make a frequency response curve from a table of the responses of the Outflow Rate to the Inflow Rate at different frequencies.  I agree to do this but I have no idea how to go about measuring the frequency response or how to derive a Frequency Response Curve.

 

I research the Frequency Response Curve and find out that the Frequency Response Curve shows how a system responds to the Sine Function at different frequencies.  The frequency response indicates the output amplitude and lag between the Inflow Rate and the Outflow Rate at different frequencies.

 

I drive the Inflow Rate at various frequencies and observe the responses.   I then derive the Gain = Outflow Rate Amplitude / Inflow Rate Amplitude at different frequencies.  I plot the Gain against the frequency to derive the Frequency Response Curve.

 

 

Frequency Factor

(rads)

Inflow Rate

(US$/month)

Outflow Rate

(US$/month)

Gain

(1/month )

0.25

1

0.90

0.90

0.50

1

0.72

0.72

0.75

1

0.56

0.56

1.00

1

0.46

0.46

1.25

1

0.38

0.38

1.50

1

0.32

0.32

1.75

1

0.28

0.28

2.00

1

0.25

0.25

2.25

1

0.22

0.22

2.50

1

0.20

0.20

2.75

1

0.18

0.18

3.00

1

0.17

0.17

3.25

1

0.16

0.16

3.50

1

0.15

0.15

3.75

1

0.14

0.14

4.00

1

0.13

0.13

 

Frequency Response Table

Gain = Inflow Rate/Outflow Rate

 

 

 

Frequency Response Curve

 

I notice that at lower frequencies the Outflow Rate tracks the Inflow Rate very closely whereas at higher frequencies the Outflow Rate does not track the Inflow Rate as well (see below).  Ed mentions that this property of exponential lags makes them useful in trading systems.  They track the lower frequencies (secular trends) and do not respond to the higher frequencies (whipsaws and noise).

 

 

 

At a Frequency of 0.25 radians per month the Outflow Rate tracks the Inflow Rate closely.

Note: 1 cycle = 2 * ∏ (radians)

Wavelength = 1 cycle / frequency = 2 * ∏ (radians) / 0.25 (radians/month) = 25.13 (months)

 

 

 

At a Frequency of 3 radians per month the Outflow Rate does not track the Inflow Rate.

 

2.2.7  Measuring the Phase Angle

Ed also advises me to measure the Phase Angle at the various frequencies to find out how synchronous the Inflow Rate and the Outflow Rate are at different frequencies.  This is another new one for me!  I do some more research and find out that a Phase Angle is the angle by which the system output (in this case the Outflow Rate) lags the system input i.e. the Inflow Rate. The Phase Angle indicates the degree of synchronicity between a system input and output.

 

To determine the Phase Angle I measure the angle by which the Outflow Rate lags the Inflow Rate at different frequencies.  I also measure the time it takes for one cycle to complete at these frequencies.  The Phase Angle = Lag time / Cycle time.

 

 

Frequency Factor

(rads)

Lag

(month)

Cycle

(month)

Phase Angle

(rads)

0.25

0.10

25.13

0.004

0.50

0.28

12.57

0.022

0.75

0.44

8.38

0.053

1.00

0.54

6.28

0.086

1.25

0.62

5.03

0.123

1.50

0.68

4.19

0.162

1.75

0.72

3.59

0.201

2.00

0.75

3.14

0.239

2.25

0.78

2.79

0.279

2.50

0.80

2.51

0.318

2.75

0.82

2.28

0.359

3.00

0.83

2.09

0.396

3.25

0.84

1.93

0.434

3.50

0.85

1.80

0.473

3.75

0.86

1.68

0.513

4.00

0.87

1.57

0.554

 

Phase Angle Table

Lag = time of peak Inflow Rate - time of peak Outflow Rate

(at different frequencies)

 

Note: at Frequency Factor 1 the cycle takes 6.28 months (2 * ∏) to complete

Notice how the phase angle increases at higher frequencies

 

 

 

Phase Angle Curve

 

 

I examine the data and the Phase Angle curve.  I observe from the data that at higher frequencies the Inflow Rate and Outflow Rate are out of phase.  This is consistent with the Frequency Response Curve.  At higher frequencies the Inflow Rate and Outflow Rate appear to be out of synch.

 

 

2.2.8  Summary Chart of the Five Feedback System Response Experiments

 

 

First Order Negative Feedback System Responses to Various Driver Functions

 

3.     Conclusion

 

I find that the experiments I conduct with the models I develop in Excel give me numerous insights about the workings of delays.  I also find that developing simple models by hand and later in Excel gives me a deeper understanding of what really goes on in the model.  Sketching by hand and using Excel gives me a much deeper understanding than I can get by using system modeling software that conducts the tests "under the hood." 

 

During the process of writing this paper I also recall the Exponential Lags paper on the Trading Systems Project page on Ed's site.  I review this paper and find that I can relate to the material much more easily. 

 

I develop a  simple exponential average model in Excel that I can use to track price trends.

 

 

 

Exponential Average System Structure

 

 

 

S&P 500 Exponential Average

Exponential Averages of 50 and 200 days

 

Notice how the Time Constant of 50 days tracks the price very closely and is more sensitive to noise in the market.  The result of this is whipsaws and high frequency trading as opposed to the Time Constant of 200 days which is more sluggish but does not respond to noise.  The slow average acts as a low pass filter that tracks secular trends.

 

The numerous experiments I carry out with the Time Constant and the response functions reinforce some system dynamics key lessons such as:

 

  1. The Time Constant is part of the Policy that relates a Rate to feedback from a Level.  In this case, Rate = Level/Time Constant.

  2. Rates change over time and a Rate cannot control another Rate without an intervening Level;

  3. Levels accumulate Rates and they change smoothly. There are no discontinuities or jumps in Levels;

  4. Delays influence the dynamic behavior of most systems and have a major impact on real life situations; and

  5. The use of a small solution interval (dt) gives a much smoother curve and generates a more accurate simulation particularly when experimenting with the Response curves.

 

back to menu

 

 

Clips: http://www.boston.com/bostonglobe/ideas/articles/2008/06/15/surprising_insights_from_the_social_sciences/

          http://mathworld.wolfram.com/Sine.html

 

e