Skip to content Skip to footer

Time Series and Trend Analysis Challenge Inspired by Real World Datasets


Time Series and Trend Analysis Challenge
Image by Author | Canva

 

Introduction

 
Time series data is everywhere. Stock prices jump daily. Temperatures shift. Website traffic spikes and crashes. Most people plot a line. Then they stop.

But here’s what a single chart won’t tell you: Is the trend speeding up? Slowing down? About to reverse completely?

In this article, we’ll analyze real inflation expectations using three complementary techniques: moving averages, year-over-year changes, and Bollinger Bands.

 

Time Series and Trend Analysis Challenge
Image by Author

 

Each method answers a different question about the same data. Moving averages uncover the trend direction, year-over-year changes highlight momentum shifts, and Bollinger Bands expose periods of extreme movement.

We’ll use those techniques to analyze the 5-year inflation data trend, from October 2020 to October 2025.

 

Understanding Our Dataset: Decoding the 10-Year Breakeven Inflation Rate

 
To understand our dataset, we first need to understand the metric it’s built on: the 10-Year Breakeven Inflation Rate (T10YIE).

The T10YIE represents the market’s inflation expectations over the next decade. Simple math: subtract inflation-protected Treasury yields from regular Treasury yields.

 

// What Does It Mean?

If T10YIE = 2.5%, the market expects 2.5% average annual inflation over 10 years. Higher values imply stronger inflation expectations. Lower values imply weaker inflation or deflation fears.

 

// Why Economists and the Fed Watch This Rate Like Hawks

The Federal Reserve watches this metric closely. Rising breakeven rates signal inflation concerns that might trigger the Federal Reserve’s interest rate hikes. Sharp drops can indicate recession fears or deflationary pressures.

 

// Our Data at a Glance: 5 Years of Inflation Expectations (2020–2025)

Now we’ll use this dataset.

 

Time Series and Trend Analysis Challenge
Screenshot | FRED

 

Click on “Download” to save the file to your machine.

If you’re interested in exploring similar real-world datasets and practicing data analysis and visualization, check out StrataScratch. It’s a platform for accessing authentic datasets used across finance, technology, and public data sources.

 

// Getting Familiar with the Data: Structure, Source, and Summary Stats

Here is some information about our dataset:

  • Source: Federal Reserve Economic Data (FRED).
  • Time Period: October 2020 – October 2025 (5 years).
  • Frequency: Daily observations.
  • Total Observations: 1,305 data points.
  • Range: 1.64% to 3.02%.
  • Average: 2.33%.

Let’s read this dataset and see the first few rows. Here is the code:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

df= pd.read_csv("T10YIE.csv")
df.head()

 

Here is the output:

 
Time Series and Trend Analysis Challenge
 

It is a simple dataset, consisting of only two columns: observation_date and T10YIE.

 

Trend Analysis: Three Techniques for Time Series Insight

 
We will begin with the moving averages technique.

 

// Technique 1: Moving Averages

Moving averages smooth short-term fluctuations. They reveal underlying trends. Take a 30-day moving average. It calculates the mean of the last 30 days. The result? A smoother line that filters daily noise.

Financial markets are chaotic. Daily rates spike on news headlines. They drop on earnings reports. Geopolitical events send them sideways. Moving averages cut through all of this. They show you the actual trend direction underneath the chaos.

Types:

  • Short-term MA (30 days): Captures recent shifts.
  • Long-term MA (90 days): Shows broader trend direction.
    • Crossovers: When short MA crosses above long MA = uptrend signal.

Here is the code:

df['T10YIE'] = df['T10YIE'].ffill()
df['MA_30'] = df['T10YIE'].rolling(window=30).mean()
df['MA_90'] = df['T10YIE'].rolling(window=90).mean()

plt.figure(figsize=(15, 7))

plt.plot(df.index, df['T10YIE'], label="Daily Rate", alpha=0.4, linewidth=0.8, color="gray")
plt.plot(df.index, df['MA_30'], label="30-Day MA", linewidth=2, color="blue")
plt.plot(df.index, df['MA_90'], label="90-Day MA", linewidth=2, color="red")

plt.axvspan(0, 200, color="palegreen", alpha=0.3, label="Phase 1: Recovery")
plt.axvspan(200, 500, color="lightcoral", alpha=0.3, label="Phase 2: Volatility")
plt.axvspan(500, 1000, color="lightblue", alpha=0.3, label="Phase 3: Decline")
plt.axvspan(1000, df.index[-1], color="plum", alpha=0.3, label="Phase 4: Stabilization")

plt.title('Breakeven Inflation Rate with Highlighted Phases', fontsize=14, fontweight="bold")
plt.ylabel('Inflation Rate (%)')
plt.xlabel('Date')
plt.grid(True, alpha=0.3)

plt.legend(loc="upper right")

plt.tight_layout()
plt.show()

 

Here is the output:

 
Time Series and Trend Analysis Challenge
 

// Results & Interpretation

The moving averages reveal distinct patterns across five years of inflation expectations.

Phase 1: Sharp Recovery (Days 0-200)
Both averages climb steeply from 1.7% to 2.4%. The 30-day MA rises faster. This period captures the post-COVID economic reopening. Massive fiscal stimulus drove inflation expectations upward.

Phase 2: High Volatility Period (Days 200-500)
Daily rates spike to 3.0% around day 400. The 30-day MA reaches 2.9%. This matches the 2022 inflation surge. Supply chain disruptions hit. Russia invaded Ukraine. Energy prices exploded.

Phase 3: The Decline (Days 500-1000)
The 30-day MA trends downward sharply, dropping to 2.2% near day 1000. The Fed hiked rates aggressively throughout 2022 and 2023. Inflation expectations cooled as policy worked.

Phase 4: Recent Stabilization (Days 1000-1300)
The 30-day MA hovers around 2.3% to 2.4%. Minimal fluctuation. Markets show confidence that inflation is normalizing near the Fed’s 2% target. Rate hikes paused.

Key Insight
The 30-day MA caught every turning point early. When it climbed sharply in early 2021, the inflation surge followed. When it dropped in mid-2022, cooling began. Current stability suggests markets believe the inflation shock has passed.

 

// Technique 2: Year-Over-Year Change

Year-over-year (YoY) change compares today’s value to the same day one year ago. It answers: “Are inflation expectations higher or lower than they were 12 months ago?”

This removes seasonal noise and shows pure directional momentum. Positive values = expectations rising year-over-year. Negative values = expectations falling year-over-year. Zero = flat trend.

Here is the formula for calculating YoY change, where \( V_t \) is the current value and \( V_{t-365} \) is the value from one year (approx. 252 trading days) ago:

$$
\text{YoY Change} = V_t – V_{t-365}
$$

In the code, it looks like this:

import pandas as pd
import matplotlib.pyplot as plt

df['T10YIE'] = df['T10YIE'].ffill()
# Calculating diff based on trading days (approx 252 per year)
df['YoY_Change'] = df['T10YIE'].diff(252)

fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(14, 10), sharex=True)

ax1.plot(df.index, df['T10YIE'], color="blue", linewidth=1)
ax1.set_ylabel('Inflation Rate (%)')
ax1.set_title('Breakeven Inflation Rate (Original)', fontsize=12, fontweight="bold")
ax1.grid(True, alpha=0.3)

ax2.plot(df.index, df['YoY_Change'], color="darkred", linewidth=1.5)
ax2.axhline(y=0, color="black", linestyle="--", linewidth=1.5, alpha=0.7)

ax2.fill_between(df.index, df['YoY_Change'], 0,
    where=(df['YoY_Change'] > 0), color="green", alpha=0.3, label="Rising YoY")
ax2.fill_between(df.index, df['YoY_Change'], 0,
    where=(df['YoY_Change'] <= 0), color="red", alpha=0.3, label="Falling YoY")
ax2.set_ylabel('YoY Change (%)')
ax2.set_xlabel('Date')
ax2.set_title('Year-over-Year Change in Inflation Expectations', fontsize=12, fontweight="bold")
ax2.grid(True, alpha=0.3)

# First Green Zone (Days 250-500)
ax1.axvspan(250, 500, color="palegreen", alpha=0.4, label="First Green Zone")
ax2.axvspan(250, 500, color="palegreen", alpha=0.4)

# Red Zone (Days 500-1000)
ax1.axvspan(500, 1000, color="lightcoral", alpha=0.4, label="Red Zone")
ax2.axvspan(500, 1000, color="lightcoral", alpha=0.4)

# Second Green Zone (Days 1000-1300)
ax1.axvspan(1000, df.index[-1], color="mediumaquamarine", alpha=0.4, label="Second Green Zone")
ax2.axvspan(1000, df.index[-1], color="mediumaquamarine", alpha=0.4)

ax1.legend(loc="upper left")
ax2.legend(loc="upper left")

plt.tight_layout()
plt.show()

 

Here is the output:

 
Time Series and Trend Analysis Challenge
 

// Results & Interpretation

The YoY change chart splits inflation expectations into green and red zones. Green means accelerating. Red means decelerating. This reveals that momentum shifts the original rate chart completely missed.

First Green Zone (Days 250-500)
Inflation expectations climbed fast. Year-over-year changes peaked at +1.0%. This period? 2021 to 2022. Supply chains collapsed. Stimulus checks flooded the economy. Russia invaded Ukraine. Energy prices exploded.

Red Zone (Days 500-1000)
Expectations crashed. They fell to -0.75% year-over-year. The Federal Reserve hiked rates aggressively throughout 2022 and 2023. Markets believed inflation would cool. They were right.

Second Green Zone (Days 1000-1300)
Small positive changes returned. They oscillated between +0.1% and +0.3%. Expectations stopped falling. They began stabilizing above previous year levels. This signals normalization, not panic.

Signal for the Future
Recent green patches are mild compared to the 2022 surge. YoY changes below +0.25%? Expectations remain anchored. Sustained movement above +0.5%? That would flag renewed inflation concerns worth watching.

 

// Technique 3: Bollinger Bands (Volatility Envelope)

Bollinger Bands create an upper and lower boundary around a moving average using standard deviation. The bands expand during volatile periods and contract during calm periods.

It shows when inflation expectations are “normal” (inside bands) versus “extreme” (outside bands). When the rate touches the upper band, it’s unusually high. When it touches the lower band, it’s unusually low.

The Structure:

  • Middle Band: 20-day moving average.
  • Upper Band: Middle + (2 × standard deviation).
  • Lower Band: Middle – (2 × standard deviation).

The created range means 95% of the data should fall within the bands. This can be expressed formally as:

$$
\text{Upper} = \mu_{20} + (2 \times \sigma_{20})
$$
$$
\text{Lower} = \mu_{20} – (2 \times \sigma_{20})
$$

Here is the code:

df['T10YIE'] = df['T10YIE'].ffill()

window = 20
df['BB_Middle'] = df['T10YIE'].rolling(window=window).mean()
df['BB_Std'] = df['T10YIE'].rolling(window=window).std()
df['BB_Upper'] = df['BB_Middle'] + (2 * df['BB_Std'])
df['BB_Lower'] = df['BB_Middle'] - (2 * df['BB_Std'])

plt.figure(figsize=(15, 7))

plt.plot(df.index, df['T10YIE'], label="Daily Rate", color="black", linewidth=0.8)
plt.plot(df.index, df['BB_Middle'], label="20-Day MA", color="blue", linewidth=1.5)
plt.plot(df.index, df['BB_Upper'], label="Upper Band", color="red", linewidth=1, linestyle="--")
plt.plot(df.index, df['BB_Lower'], label="Lower Band", color="green", linewidth=1, linestyle="--")
plt.fill_between(df.index, df['BB_Upper'], df['BB_Lower'], alpha=0.1, color="gray")

plt.axvspan(350, 450, color="gold", alpha=0.3, label="Band Expansion (Volatility↑)")
plt.axvspan(800, 1200, color="lightblue", alpha=0.3, label="Band Contraction (Volatility↓)")

plt.axvspan(190, 210, color="lightcoral", alpha=0.5, label="Upper Breach (~Day 200)")
plt.axvspan(390, 410, color="lightcoral", alpha=0.5, label="Upper Breach (~Day 400)")

plt.axvspan(1040, 1060, color="palegreen", alpha=0.5, label="Lower Touch (~Day 1050)")

plt.title('Breakeven Inflation Rate with Bollinger Bands & Key Events', fontsize=14, fontweight="bold")
plt.ylabel('Inflation Rate (%)')
plt.xlabel('Date')
plt.grid(True, alpha=0.3)
plt.legend(loc="upper left")

plt.tight_layout()
plt.show()

 

Here is the output:

 
Time Series and Trend Analysis Challenge
 

// Results & Interpretation

The Bollinger Bands identify when inflation expectations were extreme versus normal.

Band Expansion (Days 350-450)
The bands widen dramatically as the daily rate repeatedly breaks the upper band, hitting 3.0%. This period captured the 2022 inflation panic during the Russia-Ukraine war when market volatility peaked.

Upper Band Breaches
Multiple touches of the upper band (days 200, 400) signal market panic, expectations jumped beyond normal ranges. Each breach warned that inflation fears were accelerating.

Band Contraction (Days 800-1200)
The bands narrow significantly with the rate staying inside. This shows volatility collapsed as Fed rate hikes worked and markets reached consensus.

Lower Band Touch (Day 1050)
The rate briefly hit the lower band at 2.05%, signaling unusual pessimism during late-2023 recession fears.

Signal for the Future
The current narrow bands and stable rate (2.35%) indicate normal market behavior. A new upper band breach above 2.5% would signal renewed inflation concerns.

 

Different Techniques, Different Stories

 
Trend analysis isn’t about predicting the future; it’s about understanding what the data is telling you. The 10-year breakeven inflation rate from 2020 to 2025 revealed different patterns using each technique.

Even though global events like the Russia-Ukraine invasion or the energy crisis affect all analyses, each technique interprets their impact differently. A moving average might show a gradual trend shift, a year-over-year change could highlight the sharp momentum swing, while Bollinger Bands might frame the same period as a spike in volatility.

That’s why choosing your trend analysis technique matters; it shapes how you see the story in your data. The same event can look like recovery, instability, or normalization depending on the analytical lens you use.

 

Conclusion

 
The real lesson isn’t which technique is best; it’s knowing when to use which one. These three approaches work on stock prices, web traffic, sales data, or anything that moves over time. The patterns are there. You just need the right tools to see them.

In other words, data rarely speaks with one voice. The method you choose determines the message you hear. That’s why trend analysis is as much about interpretation as it is about calculation.
 
 

Nate Rosidi is a data scientist and in product strategy. He’s also an adjunct professor teaching analytics, and is the founder of StrataScratch, a platform helping data scientists prepare for their interviews with real interview questions from top companies. Nate writes on the latest trends in the career market, gives interview advice, shares data science projects, and covers everything SQL.





Source link

Leave a comment

0.0/5