tsmoothie: Time-Series Smoothing, Outliers and Block Bootstraps
Citation. Marco Cerliani. tsmoothie: "A python library for time-series smoothing and outlier detection in a vectorized way". cerlymarco/tsmoothie, version 1.0.5, read at commit 6eede02. The last push to the repository was on 23 November 2023. Under the MIT licence. It is software, with no paper.
Status. Not applicable. The project already has block bootstraps that follow Politis and Romano (1994), with a seeded random source (open_familyoffice/bootstrap.py). tsmoothie's bootstraps resample a smoother's residuals, and its "stationary bootstrap" is a different scheme. Most of its smoothers are two-sided, so they look ahead. Don't depend on it. Its one causal smoother, the exponential, is a few lines.
Read. Read on 2026-11-28 at commit 6eede02, through the GitHub API. I read tsmoothie/bootstrap.py in full. In tsmoothie/smoother.py, I read the class list, WindowWrapper, KalmanSmoother and the exponential and convolution smoothers. In tsmoothie/utils_func.py, I read the four bootstrap index functions and create_windows. I didn't read the other smoothers' code, the notebooks or the tests, and I didn't run it.
Summary
Claim. Smoothing and outlier detection "in a vectorized way", for many series at once.
What the code does.
BootstrappingWrapper. It "generates new timeseries samples" by smoothing a series and taking "the residuals of the smoothing operation". It resamples them in blocks, and adds them back "to the original smoothing curve". The schemes are non-overlapping (nbb), moving (mbb), circular (cbb) and stationary (sb). The user setsblock_length, which "must be an integer in [3, timesteps)".- The stationary bootstrap.
_id_s_bootstrapdraws block lengths fromnp.random.poisson(block_length, n_obs)and sets any below 3 to 3. It draws every block's start uniformly from 0 ton_obsminus the longest block, with no wrap-around. - The other bootstraps.
cbbwraps around the end.mbbdraws starts withnp.random.randint(0, n_obs - block_length), whose upper bound is exclusive, so the last possible block is never drawn. - Randomness. All four use the global
np.random, with no seed or generator argument. WindowWrapper. It "smooths timeseries partitioning them into equal sliding segments and treating them as new standalone timeseries", with astepthat defaults to 1.KalmanSmoother. It callskf.smooth(data)from simdkalman, the forward–backward pass.ExponentialSmoother. A convolution with weights (1 − α)^k over the lastwindow_lenpoints, so each value uses only that point and earlier ones.ConvolutionSmoother. It makes the window odd, so it is centred on each point. It builds the window witheval('np.' + self.window_type + '(window_len)').
Findings. It is a library, with no study.
Where the claims go beyond the evidence
The bootstrap isn't a bootstrap of returns. It keeps the smoothed curve fixed and resamples the residuals around it. For returns, most smoothers give a curve near zero, so the result is close to a block bootstrap of the demeaned returns. For prices, it holds the trend fixed, so it can't show the range of trends that a new history might have. Its spread is the spread around one fitted curve.
Its "stationary bootstrap" is not Politis and Romano's. Politis and Romano draw geometric block lengths and wrap the series into a circle. So the resampled series is stationary, and every observation is equally likely. tsmoothie's Poisson lengths are bunched near their mean, and the floor at 3 changes the mean further. Its starts stop short of the end, so the last observations are drawn less often. The results will differ from a reference implementation.
No seed. Without a seed, a bootstrap's error bars change from run to run. That breaks the project's rule that a result can be reproduced from its record.
Most smoothers look ahead. The Kalman smoother's backward pass uses later data. A centred convolution uses as many points after t as before. Splines, LOWESS, Gaussian smoothing, Fourier smoothing and seasonal decomposition fit the whole series. A feature or an outlier flag built from any of them leaks the future into a backtest.
WindowWrapper removes the look-ahead only at each window's end. Each window is smoothed on its own, so a value inside the window still uses the window's later points. Only the last value of each window uses past data alone, and that value sits at the smoother's edge, where most smoothers are least reliable.
eval on a parameter. The convolution smoother passes its window_type string to eval. A value that comes from outside, such as a config file, would run as code.
Credit. The library is small, vectorised and MIT-licensed. Its exponential smoother is causal. Its bootstrap wrapper refuses WindowWrapper and too-long blocks with clear errors.
Use in this repo
Keep the project's own bootstraps. bootstrap.circular and bootstrap.stationary resample returns directly. Their blocks are geometric with a circular wrap, and they take a seeded random source. metrics.bootstrapped uses them for any metric's error (#8). Choose the block length from the returns' serial correlation, such as a few days for daily equity returns, and report it with the result.
Smooth only with causal filters. A feature for a backtest, or an outlier check in the tick, must use data up to t only. The causal choices are an exponential moving average, a trailing window, and the Kalman filter's forward pass. statsmodels' state-space models give the filtered states directly (statsmodels.md, #315). The same rule applies to regime states (hmmlearn.md).
An outlier check must not hide a crash. A sigma band around a trailing average flags a bad tick, but it flags a real crash the same way. A data check should flag a value only when another source or the next values contradict it, not just because it is extreme (#181, #151). Flag the value and keep it. Never drop it silently.
Smoothing before a causal test can make false links. Two series smoothed with the same window share the smoother's lag structure. A Granger or PCMCI test on them can find links that the raw series don't have (#187).