clear all; close all; clc;

%% FRED: Quarterly Nominal GDP (SAAR, billions USD) -> Annual
fred_url = 'https://fred.stlouisfed.org/graph/fredgraph.csv?id=GDP';
T = readtable(fred_url);        % columns: DATE, GDP

% Parse
dates_q = datetime(T.observation_date, 'InputFormat', 'yyyy-MM-dd');
gdp_q   = T.GDP;   % nominal, SAAR, billions


% Plot
figure;
plot(dates_q, gdp_q, '-o', 'LineWidth', 1.25); grid on;
xlabel('Year'); ylabel('GDP (current US$, billions, SA)');
title('Nominal GDP (FRED GDP series) — Quarterly');

% Save 
Time = dates_q; GDP = gdp_q; 
writetable(table(Time, GDP), 'gdp_quarterly.csv');
writetable(table(Time, GDP), 'gdp_quarterly.xlsx');