4
$\begingroup$

I am using the lm() and princomp() functions in R to perform regressions on foreign exchange time series. I would like to weight the regressions (and PCA) such that 50% of the influence on the regression comes from the past 3 months, 25% from the previous 3 months, etc, but in a smooth fashion. Both functions take such a weighting series. What is a simple formula for generating a decaying weights series with a half life of 3 months (or any other period, for that matter), in R?

Ideally the sum of the weights will equal 1, although I don't think this is mandatory in lm().

$\endgroup$
4
+25
$\begingroup$

To be general, let us consider a time series with arbitrary steps. Therefore, let $k$ be the number of steps in three months and write $\omega_1$ for the weight for the immediately preceding time, $\omega_2$ for the weight preceding it, and so on, so that the sequence of weights

$$(\omega_1, \omega_2, \ldots, \omega_k)$$

is applied to the preceding three months. The total weight for those three months is the sum of these.

Assumption I: It is natural to hope that the next sequence of weights starting at $\omega_{k+1}$ be in proportion to the first sequence; the question specifies that the constant of proportionality be $1/2$, entailing

$$\frac{1}{2}(\omega_1, \omega_2, \ldots, \omega_k) = (\omega_{k+1}, \omega_{k+2}, \ldots, \omega_{2k}).$$

The requirement of "smoothness," together with the natural idea of a monotonic decrease in weights over time, suggests that $\omega_{k+1} \lt \omega_k$. This leads to

Assumption II: We might hope that the sequence of weights could be arranged in geometric proportion, say with constant of proportionality $\rho$, whence

$$\frac{1}{2}\omega_1 = \omega_{k+1} = \rho^k \omega_1.$$

The unique solution is

$$\rho = 2^{-1/k}.$$

Summing these weights over $n$ time steps and requiring them to sum to unity gives

$$1 = \omega_1 + \omega_2 + \cdots + \omega_n = \omega_1(1 + \rho + \rho^2 + \cdots + \rho^{n-1}) = \omega_1 \frac{1-\rho^n}{1-\rho}.$$

It follows that

$$\omega_1 = \frac{1-\rho}{1-\rho^n} = \frac{1-2^{-1/k}}{1-2^{-n/k}}$$

and

$$\omega_i = \rho^{i-1}\omega_1 = 2^{(1-i)/k}\omega_1, \quad i=1, 2, \ldots, n.$$

For example, with $k=3$ (monthly data) and $n=6$ (giving two full three-month periods), $\rho = 2^{-1/3} = 0.793701$, $\omega_1 = 0.275066$, and the sequence of weights for the first three-month period is $0.275066$, $0.21832$, $0.173281$ followed by half these weights for the second three-month period, $0.137533$, $0.10916$, $0.0866403$.


Other solutions to the problem are possible; in particular, there are infinitely many available when we do not make Assumption II. But Assumption II has the particularly nice property that if you were to combine the data into sequential groups, taking $m$ of them at a time (such as combining daily data into monthly data, with $m \approx 30$), and recalculate the weights, then the sum of the weights for each group will equal the recalculated group weights.

$\endgroup$
2
  • $\begingroup$ (+1) Better explanation than mine! (as usual...) $\endgroup$
    – jbowman
    Jan 6 '12 at 18:48
  • $\begingroup$ Thanks--but the "as usual" is incorrect, IMHO, seeing that you already have posted plenty of superb answers to many questions. Let's not lose sight of the fact that we make a tradeoff between speed and thoroughness and sometimes speed is valued more. Regardless, as a community we hope that all correct replies will undergo a process of continual improvement (by their authors and community members) so that eventually each thread will offer at least one great answer to the question. $\endgroup$
    – whuber
    Jan 6 '12 at 18:53
2
$\begingroup$

Let us assume that you want such a decaying weight to take place over intervals of T time periods, e.g., 91 days in your example (there are 91 days in three months, so you want the weight on day 91 to equal 1/2 the weight on day 0.) Solve $\exp\{-\lambda T\} = 0.5$ to get $\lambda = -\log(0.5)/T$. In your case, $\lambda = -0.007617$. Then the weight assigned to a given time period $t$, $w(t)$, is equal to $\exp\{-\lambda t\}$.

You can see this works, as $w(t+T) = w(T)w(t) = 0.5w(t) \space \forall t$, so $\sum_{t=0}^{T-1}w(t) = 0.5\sum_{t=T}^{2T-1}w(t)$.

The weights can be normalized to sum to one after calculation as above.

$\endgroup$

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .