-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha002_b_Forecast.m
executable file
·83 lines (73 loc) · 2.92 KB
/
a002_b_Forecast.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
%% 2.b Forecast
clear
clc
load data.mat
%% core
% bench
M=5000; % number of simulated paths
N=60; % length of simulated paths
w=6; % average block length
% boostrapping row indices
[indices,~]=stationary_bootstrap_MC((1:size(returns,1))',M,w,N);
% compute ew portfolio
ewWeights = ones(1, size(returns,2))/size(returns,2);
ewReturns = returns*ewWeights';
benchSimReturns=zeros(N,M);
benchSimReturnsDefl=zeros(N,M);
ewSimReturns=zeros(N,M);
ewSimReturnsDefl=zeros(N,M);
for j=1:M
inflationRate = inflation(indices(:,j));
benchSimReturns(:,j)=cumprod(1+benchReturns(indices(:,j))./100);
benchSimReturnsDefl(:,j)=cumprod(1+benchReturns(indices(:,j))./100-inflationRate)./(inflationRate+1);
ewSimReturns(:,j)=cumprod(1+ewReturns(indices(:,j))./100);
ewSimReturnsDefl(:,j)=cumprod(1+ewReturns(indices(:,j))./100-inflationRate)./(inflationRate+1);
end
period = dm.dates(end) + calmonths(1:N);
C = linspecer(2);
figure
% EW plot
subplot(1,2,1);
Q=quantile(ewSimReturns',[0.05 0.5 0.95])';
Qd=quantile(ewSimReturnsDefl',[0.05 0.5 0.95])';
fill([period, fliplr(period)], [Q(:,1)', fliplr(Q(:,3)')], C(1,:), 'FaceAlpha',.2, 'EdgeAlpha',0);
hold on
fill([period, fliplr(period)], [Qd(:,1)', fliplr(Qd(:,3)')], C(2,:), 'FaceAlpha',.2, 'EdgeAlpha',0);
plot(period,Q(:,2),'-','Color', C(1,:), 'LineWidth',2);
plot(period,Q(:,1),'--','Color', C(1,:),'LineWidth',2);
plot(period,Q(:,3),'--','Color', C(1,:),'LineWidth',2);
plot(period,Qd(:,2),'-','Color', C(2,:),'LineWidth',2);
plot(period,Qd(:,1),'--','Color', C(2,:),'LineWidth',2);
plot(period,Qd(:,3),'--','Color', C(2,:),'LineWidth',2);
title('5 years EW monthly returns');
ylabel('Return');
legend({'EW returns', 'Deflated EW returns'});
grid on
% EW plot
subplot(1,2,2);
Q=quantile(benchSimReturns',[0.05 0.5 0.95])';
Qd=quantile(benchSimReturnsDefl',[0.05 0.5 0.95])';
fill([period, fliplr(period)], [Q(:,1)', fliplr(Q(:,3)')], C(1,:), 'FaceAlpha',.2, 'EdgeAlpha',0);
hold on
fill([period, fliplr(period)], [Qd(:,1)', fliplr(Qd(:,3)')], C(2,:), 'FaceAlpha',.2, 'EdgeAlpha',0);
plot(period,Q(:,2),'-','Color', C(1,:), 'LineWidth',2);
plot(period,Q(:,1),'--','Color', C(1,:),'LineWidth',2);
plot(period,Q(:,3),'--','Color', C(1,:),'LineWidth',2);
plot(period,Qd(:,2),'-','Color', C(2,:),'LineWidth',2);
plot(period,Qd(:,1),'--','Color', C(2,:),'LineWidth',2);
plot(period,Qd(:,3),'--','Color', C(2,:),'LineWidth',2);
title('5 years Bench monthly returns');
ylabel('Return');
legend({'Bench returns', 'Deflated Bench returns'});
grid on
%% Probability of positive return
lastVal = ewSimReturns(end,:);
ewProb=length(lastVal(lastVal>1))/length(lastVal);
lastVal = ewSimReturnsDefl(end,:);
ewDeflProb=length(lastVal(lastVal>1))/length(lastVal);
lastVal = benchSimReturns(end,:);
benchProb=length(lastVal(lastVal>1))/length(lastVal);
lastVal = benchSimReturnsDefl(end,:);
benchDeflProb=length(lastVal(lastVal>1))/length(lastVal);
Tab1=table({'P(Returns > 1)'},ewProb,ewDeflProb,benchProb,benchDeflProb);
Tab1