Skip to main content

What is economic indicator backtesting? How does it help?

Problem: Financial analysts and economists need to forecast key economic indicators like CPI, unemployment, and market indices. Univariate models can miss important relationships between economic variables, leading to less accurate predictions. Further, analysts need a way to perform what-if scenario analysis by testing different assumptions about future economic conditions. Our approach: We show how to use Synthefy’s multi-variate forecasting API to leverage relationships between economic indicators (GDP, Federal Funds Rate, Unemployment, CPI, S&P 500) to improve forecast accuracy through backtesting on historical data. We demonstrate three scenarios: univariate baseline, multivariate with macroeconomic indicators, and multivariate with “leaked” indicators (known future values) to enable powerful what-if forecasting. Outcome: Multi-variate models show significant improvement over univariate forecasts, and we show that Synthefy’s what-if forecasting is even more powerful, showing further improvements over the baseline univariate forecasting.

1. Setup and Data Loading

This example demonstrates forecasting CPI (Consumer Price Index) using macroeconomic indicators from FRED and Haver APIs. First, let’s set up our imports and API keys:
API Keys Required: You’ll need API keys from FRED and Haver Analytics to run this example.

2. Data Collection Functions

Let’s create functions to fetch economic indicators from FRED and Haver:

3. Combine and Aggregate Data

Now let’s combine all economic indicators and aggregate to quarterly frequency:
The combined dataset contains quarterly percent changes for all economic indicators:
Quarterly Aggregation: We aggregate monthly data to quarterly frequency using .resample("QE").mean() to align with GDP reporting cycles and reduce noise. Each row represents one quarter with percent changes for all economic indicators.

4. Visualize Historical Data

Let’s visualize the historical CPI percent change over time:

Example Output: Historical CPI Data

Historical CPI Percent Change The plot shows the quarterly percent change in CPI from 1990 to present, revealing economic cycles and inflation trends.

5. Run Backtesting Scenarios

Now let’s run three forecasting scenarios to compare performance:
  1. Univariate: Forecast using only CPI history
  2. Multivariate (No Leak): Add other economic indicators as context
  3. Multivariate (With Future Leak): Include future variables (e.g., Fed Funds Rate)

6. Compare Results

Let’s print the comparison of all three scenarios:
Example output:

7. Visualize Forecast Comparison

Create a comprehensive visualization showing all forecast scenarios:

Example Output: Forecast Comparison

Forecast Comparison: All Scenarios

8. Metrics Comparison

Finally, let’s create a bar chart comparing the performance metrics:

Example Output: Metrics Comparison

Metrics Comparison The bar charts clearly show the performance differences between the three approaches, with multivariate models leveraging economic relationships for better predictions.

Key Insights

From this analysis, you can answer critical questions:
  1. How much does context help? → Compare MAPE across scenarios to quantify improvement
  2. What If Forecasting Variables known in advance (like Fed Funds Rate) can be included as leak columns

Complete Code

Here’s the full working example you can run:

Next Steps

  1. Try different target variables: Forecast unemployment, S&P 500, or other economic indicators
  2. Adjust forecast horizon: Change NUM_BACKTEST_ROWS to change the backtesting period
  3. Add more economic data: Include additional indicators from FRED or Haver, or your own