clear; clc; close all;

[~, ~, raw] = xlsread("y9999.xlsx");
raw = raw(4 : end, :);
dates = datetime(raw(:, 1), "format", "yyyy/MM/dd");
prices = [raw{:, 2}];

plot(dates, prices);
xlabel("Date (year)");
ylabel("Taiwan Weighted Stock Exchange Index");
title("TWSE from 2010 to 2020");
grid on;

hold on;
sma5 = movmean(prices, [4, 0]);
sma180 = movmean(prices, [179, 0]);
plot(dates, sma5);
plot(dates, sma180);
lg = legend("TWSE", "sma5", "sma180", "location", "best");
set(lg, "Position", [0.3581, 0.6320, 0.1685, 0.1214]);

print(gcf, "-djpeg", "twse.jpg", "-r300");

figure;
return_rates = diff(prices) ./ prices(1 : end - 1);
histogram(return_rates * 100, "normalization", "probability");
xlabel("Return rate (%)");
ylabel("Probability Density");
grid on;

hold on;
r2 = diff(sma5) ./ sma5(1 : end - 1);
histogram(r2 * 100, "normalization", "probability");
legend("Daily close", "SMA5");







