-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stock_market_shorting_tax_SIMS_FAST_insert.m
176 lines (132 loc) · 5.33 KB
/
Stock_market_shorting_tax_SIMS_FAST_insert.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
%Stock market model with short-selling tax and endogenous shares: simulations
%Insert for simulations using the file 'Stock_market_shorting_tax_BIFURC.m'
%Last updated: March 9, 2024. Written by Michael Hatcher (m.c.hatcher@soton.ac.uk)
%------------------
%Parameter values
%------------------
%H = 100;
%betta = 2;
r = 0.1; a = 1;
dbar = 10; sigma = 1; Zbar = 0.1;
pf = (dbar - a*sigma^2*Zbar)/r; %Fundamental price
Tax = 0.1; %Short-selling tax
Tax_add = (1+r)*Tax/(a*sigma^2);
%----------------
%Coding choices
%----------------
%T = 100; %no. of periods
No_Tax = 0; %Set No_Tax = 1 to simulate without short-selling tax (or set Tax = 0);
Fixed = 0; %Fixed = 1: Pick fixed rather than time-varying (fitness-based) population shares.
Naive = 0; %runs naive algorithm (Algo 1): starts from 1 non-buyer
%----------------------
%Preallocate matrices
%----------------------
U = NaN(H,1); Bind = NaN(T,1); Dlag2 = NaN(H,1); x = NaN(T,1); k_tot = x; k_tax = x;
Beliefs = NaN(H,1); AllNeg = zeros(T,1); AllZero = AllNeg; AllElse = AllNeg;
Check1 = inf(T,1); Check11 = Check1; %pop = NaN(H,T);
for t=1:T
%Beliefs = NaN(H,1);
if t==1
Beliefs = b + g*x0;
n = n_init;
elseif t==2
Beliefs = b + g*x(t-1);
n = n_init;
elseif t>=3
Beliefs = b + g*x(t-1);
if t==3
Dlag2 = (b + g*x0 + a*sigma^2*Zbar - (1+r)*x(t-2))/(a*sigma^2);
else
Dlag2 = (b + g*x(t-3) + a*sigma^2*Zbar - (1+r)*x(t-2))/(a*sigma^2);
end
R = ones(length(Dlag2),1).*(x(t-1) + a*sigma^2*Zbar + shock(t-1) - (1+r)*x(t-2));
if Bind(t-2) == 1
if AllZero(t-2) == 1
Dlag2(Dlag2<0 & Dlag2+Tax_add >=0) = 0;
elseif AllNeg(t) == 1
Dlag2(Dlag2+Tax_add<0) = Dlag2(Dlag2+Tax_add<0) + Tax_add;
elseif AllElse(t) == 1
Dlag2(Dlag2<0 & Dlag2+Tax_add >=0) = 0;
Dlag2(Dlag2+Tax_add<0) = Dlag2(Dlag2+Tax_add<0) + Tax_add;
end
R(Dlag2<0) = R(Dlag2<0) + (1+r)*Tax;
end
U = exp(betta*( R.*Dlag2 - C) );
n = transpose(U)/sum(U);
%if Fixed==1
% n = n_init;
%end
end
%pop(:,t) = n;
%------------------------------
%Trial unconstrained solution
%------------------------------
xstar = n*Beliefs/(1+r);
if n*Beliefs - min(Beliefs) <= a*sigma^2*Zbar || No_Tax == 1
x(t) = xstar; %Solution when taxes irrelevant or ignored
%Bind(t) = 0;
else
Bind(t) = 1;
[Beliefs_sort,I] = sort(Beliefs);
n_adj = n(I);
%Sort beliefs when there are ties (uncomment to use, not essential)
%if length(unique(Beliefs)) ~= H
% run Stock_market_shorting_sort_insert
%end
%--------------------------------------------
%Obtain initial guess for no. non-buyers
%--------------------------------------------
Demand_star = (Beliefs_sort + a*sigma^2*Zbar - (1+r)*xstar)/(a*sigma^2);
Demand_star(Demand_star<0 & Demand_star+Tax_add >=0) = 0;
%Stock_market_shorting_tax_k_update
%Uncomment to use
k_sub = 0; %Relevant when using 'Stock_market_shorting_tax_k_update'; else can set at 0
k_init = max(sum(Demand_star<=0)-k_sub,1);
if Naive == 1
k_init = 1;
end
%--------------------------------------------------
%Measures of belief dispersion (Cases 2(i)-(ii))
%--------------------------------------------------
sum_n = sum(n_adj(k_init:end));
disp0 = n_adj(k_init:end)*Beliefs_sort(k_init:end) - sum_n*Beliefs_sort(k_init);
disp_hat = n_adj*Beliefs_sort - Beliefs_sort(k_init);
Stock_market_shorting_disp_insert
%--------------------------------------------------------------
%Find the equilibrium no. of short-sellers and zero positions
%--------------------------------------------------------------
if AllZero(t)+AllNeg(t)==0
k_init(k_init==1) = 2;
Stock_market_shorting_tax_cases_FAST
%%Stock_market_shorting_tax_cases
end
end
%-----------------------
%Check market clearing
%-----------------------
Demands = (Beliefs + a*sigma^2*Zbar - (1+r)*x(t))/(a*sigma^2);
if Bind(t) == 1
Demands_adj = (Beliefs_sort + a*sigma^2*Zbar - (1+r)*x(t))/(a*sigma^2);
if AllZero(t) == 1
Demands(Demands<0 & Demands+Tax_add>=0)=0;
Demands_adj(Demands_adj<0 & Demands_adj+Tax_add >=0)=0;
elseif AllNeg(t) == 1
Demands(Demands+Tax_add<0) = Demands(Demands+Tax_add<0) + Tax_add;
Demands_adj(Demands_adj+Tax_add<0) = Demands_adj(Demands_adj+Tax_add<0) + Tax_add;
elseif AllElse(t) == 1
Demands(Demands<0 & Demands+Tax_add>=0) = 0;
Demands(Demands+Tax_add<0) = Demands(Demands+Tax_add<0) + Tax_add;
Demands_adj(Demands_adj<0 & Demands_adj+Tax_add >=0) = 0;
Demands_adj(Demands_adj+Tax_add<0) = Demands_adj(Demands_adj+Tax_add<0) + Tax_add;
end
end
Check1(t) = abs(n*Demands - Zbar);
if Bind(t) == 1
Check11(t) = abs(n_adj*Demands_adj - Zbar);
else
Check11(t) = Check1(t);
end
if sum(isnan(Demands))>0
break %break simulation if explosive path
end
end