-
Notifications
You must be signed in to change notification settings - Fork 2
/
OBC_Example_1_Expected_Loss.m
73 lines (50 loc) · 1.67 KB
/
OBC_Example_1_Expected_Loss.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
%OBC Example 1 in the paper: solution 'by hand'. Based on Example 2 from Holden (2022, ReStat).
%Written by Michael Hatcher ([email protected]). Any errors are my own.
clc, clear
%Calibration
r = 0.005;
phi = 2;
psi = 0.93;
pi_0 = 0.005;
%Find stable root
p = [-1 phi -psi]; coefs = roots(p);
omeg = min(abs(coefs));
omega_check = 1-sqrt(1-psi) - omeg;
%Loss function
T_sim = 5000; %Time horizon
betta = 0.99; %Discount factor
pi = NaN(T_sim,1); pi_bind = pi; int = pi; int_bind = pi; int_star = pi; int_bind_star = pi;
pi_series = pi; pi_bind_series = pi;
Time = 0:T_sim;
%Period 1
pi(1) = omeg*pi_0;
pi_bind(1) = -r/omeg;
int(1) = r + phi*pi(1) - psi*pi_0;
int_bind(1) = 0;
int_star(1) = int(1);
int_bind_star(1) = r + phi*pi_bind(1) - psi*pi_0;
pi_series(1) = pi(1)^2;
pi_bind_series(1) = pi_bind(1)^2;
%Periods 2 onwards
for t=2:T_sim
pi(t) = omeg*pi(t-1);
int(t) = r + phi*pi(t) - psi*pi(t-1);
pi_bind(t) = omeg*pi_bind(t-1);
int_bind(t) = r + phi*pi_bind(t) - psi*pi_bind(t-1);
int_star(t) = int(t);
int_bind_star(t) = int_bind(t);
pi_series(t) = betta^(t-1)*pi(t)^2;
pi_bind_series(t) = betta^(t-1)*pi_bind(t)^2;
end
n_prob = 100;
prob = linspace(0,1,n_prob);
Loss = NaN(n_prob,1);
for i=1:n_prob
Loss(i) = prob(i)*sum(pi_series) + (1-prob(i))*sum(pi_bind_series);
%Line1(i) = omeg^2*pi_0^2/(1-betta*omeg^2);
%Line2(i) = (r/omeg)^2/(1-betta*omeg^2);
end
figure(1)
subplot(1,2,1), plot(prob,Loss,'k'), xlabel('Pr(Solution 1): p_1'),ylabel('E_0[L]'), hold on,
title('Expected loss')
%plot(prob,Line1,'--k'), plot(prob,Line2,'--k')