How to Use l1 Trend Filtering in Julia
Overview
L1TrendFiltering.jl
is a Julia package that translates the trend filtering code originally implemented in MATLAB1. The finds the solution to the following optimization problem for the given time series data and 2.
Here, the matrix is a Toeplitz matrix designed to reflect the second-order difference.
Code
The result of applying trend filtering to the time series after importing the SNP 500 data is shown above.
using L1TrendFiltering
using Plots, CSV, DataFrames
y = snp500
result = l1tf(y, 50, verbose = true)
x = result.x
plot(ylabel = "log(price)")
plot!(y, label = "S&P500")
plot!(x, label = "l1tf")
Environment
- OS: Windows
- Julia: v1.11.1
Kim, S. J., Koh, K., Boyd, S., & Gorinevsky, D. (2009). \ell_1 trend filtering. SIAM review, 51(2), 339-360. https://stanford.edu/~boyd/l1_tf/ ↩︎