```html
Home | Command Reference | Run Example
The LOGDIFF command converts a time series into continuously compounded percentage changes. It is one of the most commonly used transformations in finance and economics because it converts a level series into a growth-rate series.
Main idea: rather than analyzing the level of a variable, analyze how quickly it is changing through time.
logdiff(sp500)
This example transforms the S&P 500 Index into continuously compounded daily returns. The resulting series is often more suitable for volatility analysis, regression modeling, Hidden Markov Models, GARCH estimation, and spectral analysis.
logdiff(series)
For a time series X, the logarithmic difference is defined as:
LOGDIFF(X)t = ln(Xt / Xt-1)
For small changes, the logarithmic difference closely approximates a percentage change:
ln(Xt / Xt-1) ≈ (Xt - Xt-1) / Xt-1
Unlike simple percentage changes, logarithmic differences are additive through time and provide a natural framework for financial return calculations.
Many economic and financial time series exhibit trends that make direct analysis difficult. Stock prices, retail sales, industrial production, employment, and GDP often grow over long periods of time.
Applying LOGDIFF removes much of this trend and focuses attention on changes rather than levels. The resulting series often displays more stable statistical properties and is easier to model.
logdiff(RSAFSNA)
Instead of examining the level of retail sales, this transformation focuses on monthly growth rates. Seasonal effects, business cycle dynamics, and unusual economic events often become easier to identify after converting the series to growth rates.
sales = logdiff(RSAFSNA)
plot(sales)
The LOGDIFF command is one of the foundational transformations used throughout RainbowStats and serves as the starting point for many financial and economic modeling workflows.