# Calculations with an exponentially-weighted moving average

I need help figuring out the following formula:

Where:

CTLy = yesterdays CTL

TSS = current Training Stress Score

TC_c = your CTL Time Constant

Now I have TSS, thats a number between 20-500

CTL is calculated as an exponentially-weighted moving average of daily TSS values, with the default time constant set to 42 days. CTL can therefore be viewed as analogous to the positive effect of training on performance in the impulse-response model, i.e., the first integral term in Eq. 1, with the caveat that CTL is a relative indicator of changes in performance ability due to changes in fitness, not an absolute predictor (since the gain factor, ka (or k1), has been eliminated).

Can anyone make an example with lets say a TSS = 100 ?

So let's say every day from today on I have TSS = 100

 CTL_day_1 = 100 * (1-CTL_exp) + (CTL_start * CTL_exp)
CTL_day_2 = 100 * (1-CTL_exp) + (CTL_day_1 * CTL_exp)
CTL_day_3 = 100 * (1-CTL_exp) + (CTL_day_2 * CTL_exp)


But I'm not sure what exactly will CTL_exp and CTL_start be in numbers and how will they change?

Update

So I figured out that I can get the desired result like so:

public function ctlFilter($tss,$constant, $start){ return$tss * (1-(exp(-1/$constant))) +$start * exp(-1/$constant); }  calling the function like: $day1 = $this->ctlFilter(100, 42, 0);$day2 = $this->ctlFilter(100, 42,$day1);


But the question remains: I would like to know what is going on "behind the scene". So if anyone can explain, like Alfred Einstein sayd to a 6 year old, that would be much appreciated. Thank you.

## migrated from mathematica.stackexchange.comJan 30 '16 at 15:16

This question came from our site for users of Wolfram Mathematica.

• Welcome to Mathematica.SE. Are you sure you are posting on the right site? There is nothing in your question making it clear that it is concerned with Mathematica software. – m_goldberg Jan 30 '16 at 13:59
• I'm voting to close this question as off-topic because this question belongs on another site in the Stack Exchange network. It is not about using Mathematica. – Michael E2 Jan 30 '16 at 14:15
• @m_goldberg I thought so, but obviously I was at the wrong place. I just wanted some Mathematical knowledge. I didn't know about the Mathematica software till now .. :) thank you! – caramba Jan 30 '16 at 16:00

As you correctly mentioned, Chronic Training Load (CTL) is an exponential moving average (EMA) of the daily Training Stress Score (TSS). Your TSS can vary a lot with time so you need to average it (for example, with EMA) in order to see the trend. The equation for CTL would look like this

$CTL_t = \alpha \cdot TSS_t - (1-\alpha) \cdot TSS_{t-1}$

Now let's generate some random TSS data (between 25 and 100) for 100 days and apply ExponentialMovingAverage[] to it. I have chosen low alpha for large smoothing of the data. High alpha will result in small smoothing.

TSS = RandomInteger[{25, 100}, 100];
alpha = 0.1;
CTL = ExponentialMovingAverage[TSS, alpha];
ListLinePlot[{TSS, CTL}, PlotLegends -> {"TSS", "CTL"}]


• Thank you Pavlo! This looks very nice. Where/how did you programm this? Which environment, which coding language? And can you explain alpha in this case? – caramba Jan 30 '16 at 13:22
• @caramba Are you aware this site is about the software Mathematica by Wolfram Reseach and not about general math? – Sascha Jan 30 '16 at 13:37
• @caramba This code was written in the Wolfram Language and executed in the program Mathematica. When using EMA, the calculation of each point takes into account the values of all previous points. The degree to which previous points are accounted is defined by alpha. High alpha neglects previous points (decreases their weight) while low alpha takes them into account (increases their weight). – Pavlo Fesenko Jan 30 '16 at 13:45

using your CTL equation: assuming CTL_start = 10

here is some Mathematica code visualising the accumulation over 42 days with stress = 100

I'm not familiar with CTL yet but It looks like it works like compound interest or the Golden ratio?

CTL[CTLday1_] := CTLday1 + (100 - CTLday1)/42

accumulatingCTL = N[NestList[CTL, CTLstart, 42]]

CTLstart = 10

ListPlot[accumulatingCTL]


hope this is some use to you

Note: I just learned on Kahn academy that functions which take their previous output as their input: CTLday2 = CTLday1 + (100 - CTLday1)/42 are called "recursive functions". A famous example is Newton's Method. They usually produce a sequence in which element n+1 is generated from element n. We start with a base case. Every term is defined in terms of the term before it.

Sometimes an "explicit function" can be found which will give you any element you like if you know its index.

• Thank you, that looks very good. I still don't understand the equation really. Will post my working solution in a bit – caramba Jan 30 '16 at 12:47