clear; clc; close all;

[~, ~, raw] = xlsread("twse_all.xlsx");

prices = [raw{4 : end, 2}];
volumes = [raw{4 : end, 3}];
dates = datetime(raw(4 : end, 1), "format", "yyyy/MM/dd");

fig1 = figure;
plot(dates, prices); grid on;
xlabel("Date"); ylabel("TWSE Index");
annotation(fig1, 'arrow', [0.4 0.88], [0.28 0.65]);
print(gcf, "-djpeg", "twse_idx.jpg", "-r300");

figure;
bar(dates, volumes); grid on;
xlabel("Date"); ylabel("Traded volume");
print(gcf, "-djpeg", "twse_volume.jpg", "-r300");

figure;
yyaxis left;
plot(dates, prices); grid on;
yyaxis right;
bar(dates, volumes); grid on;

return_rates = diff(prices) ./ prices(1 : end - 1);
figure; grid on;
plot(dates(2 : end), return_rates);

figure;
histogram(return_rates * 100, "binmethod", "integer", ...
                              "normalization", "probability");
xlabel("Return rate (%)");
ylabel("Probability");
grid on;

