Close Navigation
Learn more about IBKR accounts
Trend-Following Filters – Part 5

Trend-Following Filters – Part 5

Posted February 16, 2022
Henry Stern - via Alpha Architect Blog
Alpha Architect

The article “Trend-Following Filters – Part 5” first appeared on Alpha Architect Blog.

Excerpt

1. Introduction

Previous articles in this series examine, from a digital signal processing (DSP) frequency domain perspective, various types of digital filters used by quantitative analysts and market technicians to analyze and transform financial time series for trend-following purposes.

  1. An Introduction to Digital Signal Processing for Trend Following
  2. Trend-Following Filters – Part 1
  3. Trend-Following Filters – Part 2
  4. Trend-Following Filters – Part 3
  5. Trend-Following Filters – Part 4

Part 4 of this series, along with this article, examines the application of the Kalman filter to financial time series. The Kalman filter is a statistics-based algorithm used to perform estimation of random processes(1). Estimation of processes in noisy environments is a critical task in many fields, such as communications, process control, track-while-scan radar systems, robotics, and aeronautical, missile, and space vehicle guidance. The Kalman filter is a real-time algorithm that operates iteratively in the discrete-time domain and is used in a variety of complex random process estimation applications.

There are two general types of Kalman filter models: steady-state and adaptive. A steady-state filter assumes that the statistics of the process under consideration are constant over time, resulting in fixed, time-invariant filter gains. The gains of an adaptive filter, on the other hand, are able to adjust to processes that have time-varying dynamics, such as financial time series which typically display volatility and non-stationarity.

2. Two State Noise-Adaptive Kalman Filter

This article assumes familiarity with Part 4, which includes an overview of the Kalman filter and describes an adaptive covariance matching method originally proposed by Myers and Tapley (2) and re-stated with some modification by Stengel (3). The Stengel version is employed in both articles. The method estimates the process and measurement noise covariances directly from the Kalman filter algorithm, replacing, for example, the need for assumed or externally-derived noise covariance estimates.

To more easily illustrate adaptive filter concepts and calculations, the Kalman filter algorithm described in Part 4 has one state variable, x(t), modeled on a first-order process that has a locally constant mean value a contaminated by additive random noise ε(t)~N(0, σε2):

y(t) = a + ε(t)

The filter described in this article has two state variables, x1(t) and x2(t), modeled on a second-order process that has mean value a and locally constant linear trend b contaminated by additive random noise:

y(t) = a + b*t + ε(t)

More specifically, the process models in both articles are based on the assumption that financial asset prices follow the general Newtonian equation of motion (4):

where p is the position (analogous to a financial asset price), v is the velocity (analogous to what is commonly called “momentum” by quantitative analysts and market technicians), a is the acceleration (change in velocity), j is the jerk (change in acceleration), etc. State variable x1(t) is equivalent to the second-order process mean value a as well as to Newtonian position p. State variable x2(t) is equivalent to second-order process linear trend b as well as to Newtonian velocity v (i.e., it is assumed that acceleration a = 0, jerk j = 0, etc.).

The two-state noise-adaptive Kalman filter process and measurement model equations, variable initialization, algorithm steps, and noise estimate calculations are shown in Appendix 1 where:

  • the number of state variables n = 2,
  • the two state variables are position x1(t) and velocity x2(t),
  • the number of measurements m = 1 since only position (i.e., price) measurements z(t) are assumed to be available,
  • the time step is 1 trading day,
  • since the Newtonian motion equations that include only position p and velocity v are p(t) = p(t-1) + v*Δt and v(t) = v(t-1), respectively, the state transition matrix is:

where Δt = 1-time step

  • the process noise inputs g1 = ½ and g2 = 1, based on the process model assumption that the velocity is locally constant and subject to random acceleration noise (5),
  • the state measurement input vector H = (1 0) since only position is measured,
  • the filter gains k1(t) and k2(t) range between 0 and 1, and
  • the number of process and measurement noise samples N in the sliding time window is 10 trading days.

The noise-adaptive method estimates the measurement and process noise covariances simultaneously with the state estimates. Since only measurements z(t) of position are available, the noise-adaptive method uses a set of measurement noise samples r(t), also called “residuals”, where:

r(t) = z(t) – x1(t)

made over a sliding time window of length N time steps (N > 1) to estimate the measurement noise mean r’(t) and variance R(t). That is, the most recent set of N noise samples made over time steps t-N+1 to t is used in the calculations at each time step t. It uses sets of approximate position and velocity process noise samples q1(t) and q2(t), respectively, where:

q1(t) = [x1+(t) – (x1+(t-1) + x2+(t-1))] / g1

q2(t) = [x2+(t) – x2+(t-1)] / g2

and g1 and g2 are the position and velocity process noise input scalars, respectively, made over the sliding time window to estimate the process noise means q1’(t) and q2’(t) and covariances Q11(t), Q12(t), Q21(t), and Q22(t). The measurement and process noise means and covariances are re-estimated each time the window is shifted forward by one time step.

3. Two State Noise-Adaptive Kalman Filter Examples

The following charts illustrate the application of the two-state noise-adaptive Kalman filter method to the daily closing values of a stock index, a bond index, a currency, a commodity index, and a volatility index for the year 2020. The upper chart of each example shows the index or FX rate input z(t) and the state estimate measurement update outputs x1+(t) and x2+(t), the middle chart shows the filter gains k1(t) and k2(t), and the lower chart shows the associated Q(t) and R(t) covariances.

S&P 500 Stock Index

For the three charts above:
The results are hypothetical results and are NOT an indicator of future results and do NOT represent returns that any investor actually attained. Indexes are unmanaged, do not reflect management or trading fees, and one cannot invest directly in an index.

Bloomberg U.S. Aggregate Bond Index

For the three charts above:
The results are hypothetical results and are NOT an indicator of future results and do NOT represent returns that any investor actually attained. Indexes are unmanaged, do not reflect management or trading fees, and one cannot invest directly in an index.

Euro

For the three charts above:
The results are hypothetical results and are NOT an indicator of future results and do NOT represent returns that any investor actually attained. Indexes are unmanaged, do not reflect management or trading fees, and one cannot invest directly in an index.

Notes:

  • The filter equations in Appendix 1 are shown in non-matrix form for clarity.
  • Because the measurement noise variance R(t) and process noise covariance Q(t) may in actual practice become negative definite when performing the estimate calculations, the absolute values of the summation terms of R(t), Q11(t), and Q22(t) are used (6).
  • In order to minimize potential problems in the initialization process, an expanding time window, i.e., including noise samples at time steps 1 to t, is used to calculate the process noise and measurement noise mean and covariance estimates for time steps 1 through N-1, after which the sliding time window of length N is used.
  • In order to minimize potential roundoff errors, the Joseph stabilized form of the state estimate covariance measurement update P+(t) equations is used.

References

1. Kalman, R. E., “A New Approach to Linear Filtering and Prediction Problems”, Journal of Basic Engineering, 82 (1), 35-45, March 1960.

2. 6. Myers, K. A. and Tapley, B. D., “Adaptive Sequential Estimation with Unknown Noise Statistics”, IEEE Transactions on Automatic Control, AC-21 (4), 520-523, August 1976.

3. Stengel, R. F., Optimal Control and Estimation, Dover Publications, Inc., 1994.

4. Lopez de Prado, M. and Rebonato, R., “Kinetic Component Analysis”, Journal of Investing, 25 (3), 142-154, Fall 2016.

5. Kalata, P. R., “The Tracking Index: A Generalized Parameter for α-β and α-β-γ Target Trackers”, IEEE Transactions on Aerospace and Electronic Systems, AES-20 (2), 174-182, March 1984.

Disclosure: Alpha Architect

The views and opinions expressed herein are those of the author and do not necessarily reflect the views of Alpha Architect, its affiliates or its employees. Our full disclosures are available here. Definitions of common statistics used in our analysis are available here (towards the bottom).

This site provides NO information on our value ETFs or our momentum ETFs. Please refer to this site.

Disclosure: Interactive Brokers

Information posted on IBKR Campus that is provided by third-parties does NOT constitute a recommendation that you should contract for the services of that third party. Third-party participants who contribute to IBKR Campus are independent of Interactive Brokers and Interactive Brokers does not make any representations or warranties concerning the services offered, their past or future performance, or the accuracy of the information provided by the third party. Past performance is no guarantee of future results.

This material is from Alpha Architect and is being posted with its permission. The views expressed in this material are solely those of the author and/or Alpha Architect and Interactive Brokers is not endorsing or recommending any investment or trading discussed in the material. This material is not and should not be construed as an offer to buy or sell any security. It should not be construed as research or investment advice or a recommendation to buy, sell or hold any security or commodity. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.

Disclosure: Forex

There is a substantial risk of loss in foreign exchange trading. The settlement date of foreign exchange trades can vary due to time zone differences and bank holidays. When trading across foreign exchange markets, this may necessitate borrowing funds to settle foreign exchange trades. The interest rate on borrowed funds must be considered when computing the cost of trades across multiple markets.

IBKR Campus Newsletters

This website uses cookies to collect usage information in order to offer a better browsing experience. By browsing this site or by clicking on the "ACCEPT COOKIES" button you accept our Cookie Policy.