% Author: Daniel Nathan
% Date: 30/10/2025
filename = '..\_data\basis\basis_markus_v3.xlsx';
data = readtable(filename, 'Sheet', 'data');

% Extract date (col A) and variable (col V)
dates = data{:,1};
values = data{:,9};

% Convert to datetime if necessary
if ~isdatetime(dates)
    try
        dates = datetime(dates, 'ConvertFrom', 'excel');
    catch
        dates = datetime(dates);
    end
end

% Clear any variable conflicts
clear xlim ylim

% Extend axis to avoid clipping
date_min = min(dates);
date_max = max(dates);
buffer = calmonths(1);  % Add one month of padding

% Plot settings
figure('Units', 'pixels', 'Position', [100, 100, 800, 600]);
plot(dates, values, 'k', 'LineWidth', 1.5);
yline(0, '--', 'Color', [0.5 0.5 0.5], 'LineWidth', 1);

% Format axes
set(gca, 'FontName', 'Times New Roman', ...
    'FontSize', 14, ...
    'LineWidth', 1.2, ...
    'Box', 'off');

xlim([date_min, date_max + buffer]);  % Extend RHS buffer
grid on;
set(gca, 'GridLineStyle', ':', 'GridAlpha', 0.25);

xlabel('Date', 'FontSize', 16, 'FontWeight', 'normal', 'FontName', 'Times New Roman');
ylabel('Cross-Currency Basis (in %)', 'FontSize', 16, 'FontWeight', 'normal', 'FontName', 'Times New Roman');

% Remove excess margins
set(gca, 'LooseInset', [0 0 0 0]);
set(gcf, 'Color', 'w');

% Create output directory if it doesn't exist
output_dir = '..\_results\Figure I1';
if ~exist(output_dir, 'dir')
    mkdir(output_dir);
    fprintf('Created directory: %s\n', output_dir);
end

% Use exportgraphics for clean output
output_file = fullfile(output_dir, 'ccy_markus.pdf');
exportgraphics(gcf, output_file, 'ContentType', 'vector', 'BackgroundColor', 'white');

fprintf('Figure saved to: %s\n', output_file);