B. Stochastic Interest Rate Model 115
B.4. Stock Price Dynamics
For the dynamics of stock price, we introduce a two-dimensional setup, because in most asset pricing models we have that there are underlying processes which affect each other, such as price processes for a different asset, i.e. a bond’s price dynamics.
Adding the time-setting adds a second standard Brownian motion. In our system, we consider two assets, a bond and a stock whereBtand St is the notation for each, respectively. Let:
dBt
Bt =µBtdt+σB,1tdz1,t+σB,2tdz2,t dSt
St =µStdt+σS,1tdz1,t+σS,2tdz2,t
where z1 = (z1t) and z2 = (z2t) are independent Brownian motions. And µSt = r+ψσS, whereψ is the Sharpe Ratio. Firstly, we want to investigate the correlation between the two stochastic processes, so we derive the covariance function of these two as follows:
Cov(X, Y) = E(XY)−E(X)E(Y)
Substitute in our processes:
Covt(dBt, dSt) = E[dBt·dSt]−E[dBt]·E[dSt]
=Eh
(µBtdt+σB1tdzz1+σB2tdz2t)·(µStdt+σS1tdzz1+σS2tdz2t)i
−E[µBtdt+σB1tdzz1 +σB2tdz2t]·E[µStdt+σS1tdz1z +σS2tdz2t] After multiplying
Covt[dBt, dSt] =Eh
µBµSdt2+µBdtσS1tdz1t+µBdtσB2tdz2t +σB1tdz1tµS1tdt+σB1tσS1tdz1t2 +σB1tdz1tσS1tdz2t
+σB2tdz2tµStdt+σB2tdz2tσS1tdz1t+σB2tσS2tdz2t2i
−µBtµSdt2
Imposing the rules of stochastic calculus, where we remember the rules of stochastic calculus:
dt2 = 0 dz·dt = 0 and (dzt)2 =dt Using the rules below
Covt[dBt, dSt] =Eh
µBµSdt2
| {z }
=0
+µBdtσS1tdz1t
| {z }
=0
+µBdtσB2tdz2t
| {z }
=0
+σB1tdz1tµS1tdt
| {z }
=0
+σB1tσS1tdz1t2 +σB1tdz1tσS1tdz2t
| {z }
=0
+σB2tdz2tµStdt
| {z }
=0
+σB2tdz2tσS1tdz1t
| {z }
=0
+σB2tσS2tdz2t2i
−µBtµSdt2
| {z }
=0
.
Now we can further reduce the expression to:
Covt[dBt, dSt] =E[σB1tσS1tdz1t2 +σB2tσS2tdz22t] Using the rule(dz)2 =dt again, and taking expectations, we get:
Covt[dBt, dSt] =σB1tσS1tdt+σB2tσS2tdt.
So the covariance function for the two processes is:
Cov[dB , dS] = (σ σ +σ σ )dt
In order to find the correlation function, we must first find the variances of the two processes,dBt and dSt. Applying the variance formula to each process:
V ar[X] =E[(X−E[X])2] =E[X2]−(E[X])2 FordBt:
V art[dBt] =E[dBt2]−(E[dBt])2
=E[µ2Btdt2+σB2
1tdz1,t2 +σB2
2tdz2,t2 ]−[E[µBtdt+σB,1tdz1,t+σB,2tdz2,t]]2 Again taking expectations and using the rules of stochastic calculus:
dt2 = 0 dz·dt = 0 and (dzt)2 =dt Then we get:
V art[dBt] =E[µ2Btdt2
| {z }
dt2=0
+σB,12 tdt+σ2B,2tdt]−[E[µBtdt+σB,1tdz1,t
| {z }
=0
+σB,2tdz2,t
| {z }
=0
]]2
=σB,12 tdt+σ2B,2tdt−µ2Btdt2
| {z }
=0
= (σ2B2t +σB22t)dt
This is the variance for for the bond price process. Now we want to carry out the same procedure for the variance of the stock price:
V art[dSt] =E[µ2Stdt2+σS21tdz1t2 +σS22tdz22t]−[E[µStdt+σS1tdz1t+σS2tdz2t]]2
=E[µ2Stdt2
| {z }
=0
+σS21tdt+σS22tdt]−[E[µStdt+σS1tdz1t
| {z }
=0
+σS2tdz2t
| {z }
=0
]]2
=σ2S1tdt+σ2S2tdt−µ2Stdt2
| {z }
=0
= (σ2S1t+σS22t)dt
Now that we have the variances for each processes, and the covariance between them, we are now able to find the correlation function of the two processes. The
correlation function is given as:
Corrt[dBt, dSt] = Covt[dBt, dSt] pV art[dBt]·V art[dSt]
= (σB1tσS1t +σB2tσS2t)dt q
[(σB22t+σB22t)dt]·[(σ2S1t +σS22t)dt]
= σB1tσS1t +σB2tσS2t
q (σ2B
2t+σB2
2t)·(σS2
1t+σS2
2t)
However, from this derivation of the correlation of the two stochastic processes, we can see that when specifying the two-dimensional process [dBt, dSt], and character-izing the first-order local and second-order local moments, which are:
• The first-order local moments are µBt and µSt.
• The second-order local moments are the volatility coefficients (shock) coeffi-cients σB1t,σB2t, σS1t, and σS2t, which defines the two instantaneous variances and the instantaneous correlation coefficient.
From the above derivation, it was evident that the four volatility (shocks) coefficient would give rise to the same variances and the same correlation. This implies, that we have one degree of freedom extra by fixing the coefficients, which mean that we choose to fix one of the volatility (shock) coefficients for the process of the bond price, specific σB2t = 0, since we want to see how the stock price dynamics are affected the bond price dynamics. So we can simplify our two processes as such:
dBt
Bt =µBtdt+σBtdz1t dSt
St µStdt+σSt(ρtdz1t+p
1−ρ2dz2t) whereρt is the correlation between the market returns of stock and bond. Now we can again define the new instantaneous variances and the instantaneous covariance of the newly defined stochastic processes. Now using prior definition of µSt = r+ ψσS, we can obtain the same stock price dynamics as in Munk (2013), which are represented by the following process:
dSt
St = (r+ψσS)dt+σSt(ρtdz1t+p
1−ρ2dz2t)
This shows the dynamics of the stock price, where the drift term is defined as a mean return with addition of the Sharpe ratio with risk adjustment term, and the
Further, in this appendix we want show the relationship between the processes.
Firstly, we consider the instantaneous variance ofdBt is:
V art[dBt] =E[(µBtdt+σBtdz1t)2]−[E[µBtdt+σBtdz1t]]2
=E[µ2Btdt2
| {z }
=0
+σ2Btdz1t2]−[E[µBtdt+σBtdz1t
| {z }
=0
]]2
=σB2tdt−µ2Btdt2
| {z }
=0
=σB2tdt
And the same is done for the instantaneous variance of dSt: V art[dSt] =E[[µStdt+σSt(ρtdz1t+p
1−ρ2dz2t)]2]
−[E[µStdt+σSt(ρtdz1t+p
1−ρ2dz2t)]]2
=E[µ2S
tdt2
| {z }
=0
+σS2
t(ρtdz1t+p
1−ρ2tdz2t)2
−[E[µStdt+σSt(ρtdz1t
| {z }
=0
+p
1−ρ2dz2t)
| {z }
=0
]]2
=σS2t(ρtdz1t+p
1−ρ2tdz2t)2−µ2Stdt2
| {z }
=0
=V arth
σS2t(ρtdz1t+p
1−ρ2tdz2t)2i
=σS2tV arth
(ρtdz1t+p
1−ρ2tdz2t)2i
=σS2th
(ρ2tdz1t2 + (1−ρ2t)dz22ti
=σS2t h
(ρ2tdt+ (1−ρ2t)dt i
=σS2tdt
Next, we can also find the instantaneous covariance under this new specification:
Covt[dBt, dSt] =E[dBt·dSt]−E[dBt]·E[ESt]
=E[(muBtdt+σBtdz1t)(µStdt+σSt(ρtdz1t+p
1−ρ2dz2t))]
−E[muBtdt+σBtdz1t
| {z }
=0
]·E[µStdt+σSt(ρtdz1t
| {z }
=0
+p
1−ρ2dz2t
|{z}=0
)]
=Eh
µBtµStdt2
| {z }
=0
+µBtσSt(ρtdz1tdt
| {z }
=0
+p
1−ρ2dz2tdt
| {z }
=0
) +σBtµStdz1tdt
| {z }
=0
+σBtσSt(ρtdz1t2 +p
1−ρ2dz1tdz2t)i
−µBtµStdt2
| {z }
=0
=σBtσSt(ρtdz21t+p
1−ρ2dz1tdz2t)
=Covt
h
σBtσSt(ρtdz1t2 +p
1−ρ2dz1tdz2t) i
=σBtσStCovth
z1t, ρtdz1t2 +p
1−ρ2dz1tdz2t)i
This is the instantaneous covariance between the two stochastic processes, dBt and dSt. However, we can transform the embedded covariance, which are inside the instantaneous covariance to an embedded correlation in the following way:
Covt[dBt, dSt] =
σBtσStCovt
h
z1t, ρtdz1t2 +p
1−ρ2dz1tdz2t) i q
σB2tdt·σS2tdt
=σBtσStρtdt
From this expression of the instantaneous covariance, we can see if σBt and σSt are both positive or both negative, this implies that the instantaneous correlation is ρt between the two processesdBt and dSt, while if they have opposite signs, then the correlation will be−ρt.
Appendix C
Justification for Numerical Integration
In Section 7.4.2 it is chosen to use numerical integration to estimate the loss from choosing a suboptimal allocation. The numerical integration of A00 is done by the Trapez-formula
Z t0 t
A00(s)ds= (t0−t)A00(t) +A00(t0)
2 ,
where t0 > t. To have a high precision of the estimation of the integral, the size of the subintervals is set to t0 −t = 0.01. To verify the precision, the two functions A1(τ) andA2(τ)have been estimated by the Trapez-formula and then compared to the correct, closed-form solution. Estimation of the value at time t = 3 has been done for several sizes of the subinterval. As seen from Table C.1 the marginal effect from a smaller size of subintervals i decreasing. At t = 3 the formula estimates 98.0511% of the actual value of A2(τ). For t= 30 the estimation finds 98.0506% of the actual value ofA2(τ). Even for a long time horizon, the precision is high, and it does not even seem to decrease very much as time increases. ForA1(τ)for precision at 30 years is 99.5066%.
Subunit 1 0.75 0.5 0.25 0.15 0.1 0.05 0.01
Estimated 31.6% 38.1% 47.9% 65.3% 76.2% 83.0% 90.8% 98.1%
Table C.1: The table illustrates for 8 different subintervals,t0−t, how much of the correct value is estimated by use of numerical integration fort= 3.
Appendix D R-code
All R-programs and Excel files used for this thesis can be provided upon request.
Below is the full R-code provided. We apologise in advance for the length.
Listing D.1: R-code
########################
# PROGRAM 1 TABLE 2.1#
########################
#Load packages r e q u i r e(s t a r g a z e r)
#Set working d i r e c t o r y getwd( )
setwd("C:/Users/d i t l e/Desktop/")
#Load Excel f i l e AUM_DK_WW AUM.df < data.frame(AUM_DK_WW)
#Use s t a r g a z e r
s t a r g a z e r(AUM.df, t y p e = " l a t e x ", summary = F A L S E)
##################################################
# PROGRAM 2 MEAN VARIANCE ANALYSIS : FIGURE 3 . 1 #
##################################################
#CONTENT:
#Plot : E f f i c i e n t F r o n t i e r o f only r i s k y a s s e t
#Plot : E f f i c i e n t F r o n t i e r o f a l l a s s e t s
#Load Excel Mean_Variance
mean.v a r i a n c e.df < data.frame(mean_v a r i a n c e) h e a d(mean.v a r i a n c e.df)
t a i l(mean.v a r i a n c e.df)
g e o m_l i n e(aes(x = SD_2 , y = Exp_ret_2 , c o l = " red ") , s i z e = 1) + g e o m_p o i n t(aes(x = SD_tan, y = Exp_ret_tan) , s i z e = 3) +
g e o m_p o i n t(aes(x = SD_GMV, y = Exp_ret_GMV) , s i z e = 3) + g e o m_p o i n t(aes(x = A1_SD, y = A1_ret) , s i z e = 3) + g e o m_p o i n t(aes(x = A3_SD, y = A3_ret) , s i z e = 3) + s c a l e_x_c o n t i n u o u s(" Standard Deviation (%)") + s c a l e_y_c o n t i n u o u s(" Expected Return (%)") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c( " E f f i c i e n t F r o n t i e r o f r i s k y ← -a s s e t s ", " E f f i c i e n t F r o n t i e r o f a l l a s s e t s ") ,
v a l u e s = c(" blue ", " red ") ) + t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = e l e m e n t_b l a n k( ) , a x i s.t e x t.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t i t l e.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t e x t.y=e l e m e n t_t e x t(s i z e=9) , a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=9) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=8, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n= c( 0 . 4 8 , 0 . 8 5 ) , legend.key.s i z e = u n i t( 0 . 3 ,"cm") , legend.t e x t = e l e m e n t_t e x t(s i z e = 11) , legend.d i r e c t i o n = " v e r t i c a l ",
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=a l p h a(' white ', 0 . 4 ) ) )
mv.p l o t + g e o m_t e x t(aes(x = SD_tan, y = Exp_ret_tan, l a b e l = "Tangency P o r t f o l i o "← -) , h j u s t=1.1 , v j u s t=0, s i z e = 3) +
g e o m_t e x t(aes(x = SD_GMV, y = Exp_ret_GMV, l a b e l = "GMV P o r t f o l i o ") , h j u s t←
-= 0 . 1 , v j u s t=0, s i z e = 3)
##########################################
# PROGRAM 3 INTEREST RATES: FIGURE 5 . 1 #
##########################################
#'===========================================================================
#' Varies i n t e r e s t r a t e s f o r the y e a r s 1986 to 2016
#'===========================================================================
#i n s t a l l . packages (" t s e r i e s ") ; i n s t a l l . packages (" quantmod ") ; i n s t a l l . packages ("← -gg p lot 2 ")
#' Neded packages
# '
l i b r a r y(t s e r i e s) ; l i b r a r y(q u a n t m o d) ;l i b r a r y(g g p l o t 2) r e q u i r e(t s e r i e s) ; r e q u i r e(q u a n t m o d) ;r e q u i r e(g g p l o t 2)
# '
# ' 1 0 Year Treasury Constant Maturity Rate
# '
g e t S y m b o l s( c("DGS10") , src="FRED") a d j y e a r 1 0 < D G S 1 0[ 6 2 9 7 :nrow(D G S 1 0) , ]
# '
#'3 month Treasury i n t e r e s t r a t e
# '
g e t S y m b o l s( c("DTB3") , src="FRED") a d j m o n t h 3 < D T B 3[ 8 3 8 3 :nrow(D T B 3) , ]
# '
#'30 y e a r s Treasury i n t e r e s t r a t e
# '
g e t S y m b o l s( c("DGS30") , src="FRED") a d j y e a r 3 0 < D G S 3 0[ 2 3 5 2 :nrow(D G S 3 0) , ]
#' Due to data i s s u e s we w i l l have a time p e r i o d with i n t e r e s t r a t e
#' with the value o f z e r o . This i s because the 3 0 year t r e a s u r y bond
#' was d i s c o n t i n e d on February 19 , 2002 and r e i n t r o d u c e d February 9 , 2006.
u t i l s: :V i e w(a d j y e a r 3 0)
a d j y e a r 3 0[i s.na(a d j y e a r 3 0) ] < 5 #Just using a random number to avoid ommiting ← -l a t e r
#Combine a l l t h r e e i n t e r e s t r a t e s
c o m b i n e d < cbind(a d j y e a r 1 0, a d j m o n t h 3, a d j y e a r 3 0)
#Rename the columns
colnames(c o m b i n e d) < c(" Tenyear ", "Threemonth", " Thirtyyear ")
#I n s p e c t data
u t i l s: :V i e w(c o m b i n e d)
#We s t i l l have a high number o f missing data : sum(i s.na(c o m b i n e d$T e n y e a r) )/nrow(c o m b i n e d)∗100
#This i s due to Federal h o l d i d a y s .
#The problem i s simply s o l v e d by removing days with missing v a l u e s c o m b i n e d < na.omit(c o m b i n e d)
d a t a f r a m e c o m b i n e d < data.frame(c o m b i n e d)
p < g g p l o t( ) +
g e o m_l i n e(data = d a t a f r a m e c o m b i n e d, aes(x = index(c o m b i n e d) , y = Tenyear, c o l o r←
-= "Ten year ") ) +
g e o m_l i n e(data = d a t a f r a m e c o m b i n e d, aes(x = index(c o m b i n e d) , y = T h r e e m o n t h, ← -c o l o r = " Three month") ) +
g e o m_l i n e(data = d a t a f r a m e c o m b i n e d[ 1 : 4 0 0 2 , ] , aes(x = index(c o m b i n e d[ 1 : 4 0 0 2 , ] ) , ← -y = T h i r t y y e a r, c o l o r = " Thirty year ") ) +
g e o m_l i n e(data = d a t a f r a m e c o m b i n e d[ 4 9 9 7 :nrow(d a t a f r a m e c o m b i n e d) , ] , aes(x = ← -index(c o m b i n e d[ 4 9 9 7 :nrow(c o m b i n e d) , ] ) , y = T h i r t y y e a r, c o l o r = " Thirty year←
-") ) +
#l a b s ( t i t l e =" I n t e r e s t r a t e s from 1986 to 2016" , x="Year " , y=" I n t e r e s t r a t e i n ←
-%", c o l o r ="Treasury type ") t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = _ ( ) ,
a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=7) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=9, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n= c( 1 , 0 . 7 5 ) , legend.key.s i z e = u n i t( 0 . 5 ,"cm") , legend.t e x t = e l e m e n t_t e x t(s i z e = 7) , legend.d i r e c t i o n = " v e r t i c a l ",
legend.key.s i z e = u n i t( 2 , "cm") ,
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=" t r a n s p a r e n t ") ) p
p+l a b s(x="Year", y=" I n t e r e s t r a t e in %", c o l o r=" Treasury type ")
# theme ( a x i s . l i n e = element_l i n e ( c o l o u r = " black ") ,
# #panel . g r i d . major = element_l i n e ( c o l o u r = " black ") ,
# #panel . g r i d . minor = element_l i n e ( c o l o u r = " black ") ,
# panel . border = element_blank ( ) ,
# panel . background = element_blank ( ) )
#'========================
#' I n t e r e s t r a t e v o l a t i l i t y
#'========================
r e t y e a r 1 0 < l o g(lag(a d j y e a r 1 0) ) l o g(a d j y e a r 1 0) r e t y e a r 1 0 < r e t y e a r 1 0[ 1 ]
p l o t(r e t y e a r 1 0)
r e t y e a r 1 0 < na.omit(r e t y e a r 1 0) p l o t(r e t y e a r 1 0)
r e t m o n t h 3 < l o g(lag(a d j m o n t h 3) ) l o g(a d j m o n t h 3) r e t m o n t h 3 < r e t m o n t h 3[ 1 ]
p l o t(r e t m o n t h 3)
r e t 3 < na.omit(r e t m o n t h 3) p l o t(r e t m o n t h 3)
r e t y e a r 3 0 < l o g(lag(a d j y e a r 3 0) ) l o g(a d j y e a r 3 0) r e t y e a r 3 0 < r e t y e a r 3 0[ 1 ]
p l o t(r e t y e a r 3 0)
r e t y e a r 3 0 < na.omit(r e t y e a r 3 0) p l o t(r e t y e a r 3 0)
##################################################
## PROGRAM 4 Simulate Sample Paths : FIGURE 5 . 2 #
##################################################
#Load packages r e q u i r e(g g p l o t 2)
#FUNCTION:
## Define model parameters r0 < 0 . 0 3
t h e t a < 0 . 1 0 k < 0 . 3 beta < 0 . 0 3
## s i m u l a t e s h o r t r a t e paths
n < 10 # MC s i m u l a t i o n t r i a l s T < 30 # t o t a l time
m < 200 # s u b i n t e r v a l s
dt < T/m # d i f f e r e n c e i n time each s u b i n t e r v a l
r < matrix( 0 ,m+1,n) # matrix to hold s h o r t r a t e paths r[ 1 , ] < r0
f o r(j in 1 :n) { f o r(i in 2 : (m+1) ) {
dr < k∗(theta r[i 1 ,j] )∗ dt + beta ∗ s q r t(dt)∗rnorm( 1 , 0 , 1 ) r[i,j] < r[i 1 ,j] + dr
} }
## Standard matplot : t < seq( 0 , T, dt)
rT.e x p e c t e d < t h e t a + (r0 t h e t a)∗exp( k∗ t) rT.s t d e v < s q r t( beta^2/(2∗k)∗( 1 exp( 2∗k∗ t) ) ) matplot(t, r[ , 1 : 1 0 ] , t y p e=" l ", lty=1, y l a b=" r t ") a b l i n e(h=theta, c o l=" red ", lty=2)
l i n e s(t, rT.e x p e c t e d, lty=2)
l i n e s(t, rT.e x p e c t e d + 2∗rT.stdev, lty=2) l i n e s(t, rT.e x p e c t e d 2∗rT.stdev, lty=2) p o i n t s( 0 ,r0)
#Set up f o r gg p l o t 2 p l o t r.df < data.frame(r) e x p e c t e d.r < rT.e x p e c t e d
up.l i m i t < rT.e x p e c t e d + 2∗rT.s t d e v d o w n.l i m i t < rT.e x p e c t e d 2∗rT.s t d e v
#ggpl ot 2 p l o t
g g p l o t(r.df, aes(x = t, y= X1) ) + g e o m_l i n e(aes(c o l=" darkpurple ") ) + g e o m_l i n e(aes(y=X2, c o l = " red ") ) + g e o m_l i n e(aes(y=X3, c o l = " green ") ) + g e o m_l i n e(aes(y=X4, c o l = " blue ") ) + g e o m_l i n e(aes(y=X5, c o l = " darkred ") ) + g e o m_l i n e(aes(y=X6, c o l = " darkblue ") ) + g e o m_l i n e(aes(y=X7, c o l = " orange ") ) + g e o m_l i n e(aes(y=X8, c o l = " darkgreen ") ) + g e o m_l i n e(aes(y=X9, c o l = " o l i v e ") ) + g e o m_l i n e(aes(y=X10, c o l = " purple ") ) + g e o m_l i n e(aes(y=up.l i m i t) , l i n e t y p e = 2) + g e o m_l i n e(aes(y=d o w n.l i m i t) , l i n e t y p e = 2) + g e o m_l i n e(aes(y=e x p e c t e d.r) , l i n e t y p e = 2) + s c a l e_x_c o n t i n u o u s(" Years ") +
s c a l e_y_c o n t i n u o u s("%") + t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") ,
panel.g r i d. = _ ( ) ,
a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=9) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=9, c o l o r=" black ") , legend.p o s i t i o n= "none")
#################################################################
## PROGRAM 5 CONSTANT AND STOCHASTIC INVESTMENT OPPORTUNITIES #
#################################################################
#CONTENT
#( i ) g g p l o t o f E f f i c i e n t Frontier , Figure 5 . 3
#( i i ) g g p l o t o f a l l o c a t i o n r e s u l t s , RA=2 and RA= 10 , Figure 5 . 6
#( i i i ) g g p l o t o f bond a l l o c a t i o n , constant and s t o c h a s t i c model , Figure 5 . 4
#( i v ) g g p l o t o f cash a l l o c a t i o n , constant and s t o c h a s t i c model , Figure 5 . 5
#Packages
r e q u i r e(g g p l o t 2) r e q u i r e(g r i d E x t r a)
#################################################
#Create dataframe from CSV. f i l e
f r o n t i e r.df < data.frame(F r o n t i e r_R c s v)∗100
#View data
h e a d(f r o n t i e r.df)
#E f f i c i e n t f r o n t i e r
f r o n t i e r.p l o t < g g p l o t(f r o n t i e r.df, aes(x = Con_Stddev, y = Con_ret) ) + g e o m_l i n e(aes(c o l = " black ") , s i z e = 1) +
g e o m_l i n e(aes(x = Sto_d e v 2. 5 , y = Sto_r e t 2. 5 , c o l= " blue ") , s i z e = 1) + g e o m_l i n e(aes(x = Sto_dev5, y = Sto_ret5, c o l= " green ") , s i z e = 1) + g e o m_l i n e(aes(x = Sto_dev30, y = Sto_ret30, c o l = " reed ") , s i z e = 1) + c o o r d_c a r t e s i a n(x l i m = c( 0 , 2 0 ) , y l i m = c( 0 , 1 0 ) ) +
s c a l e_x_c o n t i n u o u s(" Standard Deviation ") + s c a l e_y_c o n t i n u o u s(" Expected Return ") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c(" Constant ", "T=2.5", "T=5", "T←
-=30") ,
v a l u e s = c(" black ", " blue "," green ", " red ") ) + t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = e l e m e n t_b l a n k( ) , a x i s.t e x t.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t i t l e.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t e x t.y=e l e m e n t_t e x t(s i z e=9) , a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=9) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=8, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n= " r i g h t ", #c ( 1 . 0 2 4 9 , 0 . 8 4 5 ) legend.key.s i z e = u n i t( 0 . 5 ,"cm") ,
legend.t e x t = e l e m e n t_t e x t(s i z e = 9) , legend.d i r e c t i o n = " v e r t i c a l ",
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=a l p h a(' white ', 0 . 4 ) ) , legend.margin = u n i t( 0 . 5 , "cm") ,
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l = " black ", s i z e=0.5 , l i n e t y p e="← -s o l i d ",
c o l o u r =" black ") )
##### Bond , Cash and Hedge ###
#Load Excel f i l e
weights.df < data.frame(weights_csv)
#View date h e a d(weights.df)
#Plot o f a l l o c a t i o n r e s u l t , RA = 10
p l o t.r i s k 1 0 < g g p l o t(weights.df, aes(x = Time, y = B o n d_10) ) + g e o m_l i n e(aes(c o l = " blue ") , s i z e = 1) +
g e o m_l i n e(aes(y = C a s h_10 , c o l=" green ") , s i z e = 1) + g e o m_l i n e(aes(y = H e d g e_10 , c o l=" red ") , s i z e = 1) + c o o r d_c a r t e s i a n(x l i m = c( 0 , 2 0 ) , y l i m = c( 0 . 7 5 , 1 . 1 ) ) + s c a l e_x_c o n t i n u o u s(" Years ") +
s c a l e_y_c o n t i n u o u s(" Fraction o f Wealth") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c("Bonds", " Risk Free ", "Hedge" ) ,← -v a l u e s = c(" blue "," green ", " red ") ) +
l a b s(t i t l e=" ( b ) Risk Aversion = 10") + t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = e l e m e n t_b l a n k( ) , a x i s.t e x t.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t i t l e.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t e x t.y=e l e m e n t_t e x t(s i z e=9) , a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=9) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=9, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n= c( 0 . 3 4 5 , 0 . 7 5 ) , legend.key.s i z e = u n i t( 0 . 3 5 ,"cm") , legend.t e x t = e l e m e n t_t e x t(s i z e = 7) , legend.d i r e c t i o n = " v e r t i c a l ",
legend.key.s i z e = u n i t( 2 , "cm") ,
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=" t r a n s p a r e n t ") )
#Plot o f a l l o c a t i o n r e s u l t , RA = 2
p l o t.r i s k 2 < g g p l o t(weights.df, aes(x = Time, y = B o n d_2) ) + g e o m_l i n e(aes(c o l = " blue ") , s i z e = 1) +
g e o m_l i n e(aes(y = C a s h_2 , c o l=" green ") , s i z e = 1) + g e o m_l i n e(aes(y = H e d g e_2 , c o l=" red ") , s i z e = 1) + c o o r d_c a r t e s i a n(x l i m = c( 0 , 2 0 ) , y l i m = c( 0 . 7 5 , 1 . 1 ) ) + s c a l e_x_c o n t i n u o u s(" Years ") +
s c a l e_y_c o n t i n u o u s(" Fraction o f Wealth") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c("Bonds", " Risk Free ", "Hedge" ) ,← -v a l u e s = c(" blue "," green ", " red ") ) +
l a b s(t i t l e=" ( a ) Risk Aversion = 2") + t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") ,
panel.g r i d. = _ ( ) ,
a x i s.t e x t.y=e l e m e n t_t e x t(s i z e=9) , a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=9) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=9, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n= c( 0 . 3 4 5 , 0 . 7 5 ) , legend.key.s i z e = u n i t( 0 . 3 5 ,"cm") , legend.t e x t = e l e m e n t_t e x t(s i z e = 7) , legend.d i r e c t i o n = " v e r t i c a l ",
legend.key.s i z e = u n i t( 2 , "cm") ,
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=" t r a n s p a r e n t ") )
#Combine p l o t s
g r i d.a r r a n g e(p l o t.risk2, p l o t.risk10, n c o l=2)
#Bond a l l o c a t i o n , Constant and s t o c h a s t i c model , Figure 5 . 4
#Load e x c e l f i l e
s t o c h a s.df < data.frame(S t o c h a s t i c_a n a l y s i s)
#View data h e a d(s t o c h a s.df)
#Bond a l l o c a t i o n f o r constant model
b o n d.c o n s t a n t < g g p l o t(s t o c h a s.df, aes(x = Gamma, y = Con_B o n d) ) + g e o m_l i n e(aes(c o l = " blue ") , s i z e = 1 . 5 ) +
c o o r d_c a r t e s i a n(x l i m = c( 0 , 2 0 ) , y l i m = c( 0 . 7 5 , 1 . 1 ) ) + s c a l e_x_c o n t i n u o u s(" Risk Aversion ") +
s c a l e_y_c o n t i n u o u s(" Fraction o f Wealth") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c("Bonds") , v a l u e s = c(" blue ") ) ← -+
l a b s(t i t l e=" ( a ) Constant Model") + t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = e l e m e n t_b l a n k( ) , a x i s.t e x t.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t i t l e.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t e x t.y=e l e m e n t_t e x t(s i z e=9) , a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=9) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=9, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n= c( 0 . 3 , 0 . 8 7 ) , legend.key.s i z e = u n i t( 0 . 3 5 ,"cm") , legend.t e x t = e l e m e n t_t e x t(s i z e = 7) , legend.d i r e c t i o n = " v e r t i c a l ",
legend.key.s i z e = u n i t( 2 , "cm") ,
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=" t r a n s p a r e n t ") )
#Bond a l l o c a t i o n f o r s t o c h a s t i c model
b o n d.s t o 2 5 < g g p l o t(s t o c h a s.df, aes(x =Gamma, y = B o n d_2 . 5 ) ) + g e o m_l i n e(aes(c o l = " blue ") , s i z e = 1 . 5 ) +
g e o m_l i n e(aes(y = B o n d_5 , c o l = " darkred ") , s i z e = 1 . 5 , l i n e t y p e = 2) + c o o r d_c a r t e s i a n(x l i m = c( 0 , 2 0 ) , y l i m = c( 0 . 7 5 , 1 . 1 ) ) +
s c a l e_x_c o n t i n u o u s(" Risk Aversion ") + s c a l e_y_c o n t i n u o u s(" Fraction o f Wealth") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c("Bond , T=2.5", "Bond , T=5") , ← -v a l u e s = c(" blue "," darkred ") ) +
l a b s(t i t l e=" ( b ) S t o c h a s t i c Model") + t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = e l e m e n t_b l a n k( ) , a x i s.t e x t.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t i t l e.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t e x t.y=e l e m e n t_t e x t(s i z e=9) , a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=9) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=9, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n= c( 0 . 4 , 0 . 8 2 ) , legend.key.s i z e = u n i t( 0 . 3 5 ,"cm") , legend.t e x t = e l e m e n t_t e x t(s i z e = 7) , legend.d i r e c t i o n = " v e r t i c a l ",
legend.key.s i z e = u n i t( 2 , "cm") ,
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=" t r a n s p a r e n t ") )
#Combine p l o t s
g r i d.a r r a n g e(b o n d.c o n s t a n t, b o n d.sto25, n c o l=2)
#( i v ) g g p l o t o f cash a l l o c a t i o n , constant and s t o c h a s t i c model , Figure 5 . 5
#Cash a l l o c a t i o n f o r constant model
c a s h.c o n s t a n t < g g p l o t(s t o c h a s.df, aes(x = Gamma, y = Con_C a s h) ) + g e o m_l i n e(aes(c o l = " green ") , s i z e = 1 . 5 ) +
c o o r d_c a r t e s i a n(x l i m = c( 0 , 2 0 ) , y l i m = c( 0 . 7 5 , 1 . 1 ) ) + s c a l e_x_c o n t i n u o u s(" Risk Aversion ") +
s c a l e_y_c o n t i n u o u s(" Fraction o f Wealth") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c("Cash") , v a l u e s = c(" green ") ) + l a b s(t i t l e=" ( a ) Constant Model") +
t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = e l e m e n t_b l a n k( ) , a x i s.t e x t.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t i t l e.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t e x t.y=e l e m e n t_t e x t(s i z e=9) , a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=9) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=9, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n= c( 0 . 3 , 0 . 8 5 ) , legend.key.s i z e = u n i t( 0 . 3 5 ,"cm") , legend.t e x t = e l e m e n t_t e x t(s i z e = 7) , legend.d i r e c t i o n = " v e r t i c a l ",
legend.key.s i z e = u n i t( 2 , "cm") ,
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=" t r a n s p a r e n t ") )
g e o m_l i n e(aes(y = C a s h_5 , c o l = " darkgreen ") , s i z e = 1 . 5 ) + c o o r d_c a r t e s i a n(x l i m = c( 0 , 2 0 ) , y l i m = c( 0 . 7 5 , 1 . 1 ) ) + s c a l e_x_c o n t i n u o u s(" Risk Aversion ") +
s c a l e_y_c o n t i n u o u s(" Fraction o f Wealth") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c("Cash , T=2.5", "Cash , T=5") , ← -v a l u e s = c(" green "," darkgreen ") ) +
l a b s(t i t l e=" ( b ) S t o c h a s t i c Model") + t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = e l e m e n t_b l a n k( ) , a x i s.t e x t.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t i t l e.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t e x t.y=e l e m e n t_t e x t(s i z e=9) , a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=9) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=9, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n= c( 0 . 4 , 0 . 8 ) , legend.key.s i z e = u n i t( 0 . 3 5 ,"cm") , legend.t e x t = e l e m e n t_t e x t(s i z e = 7) , legend.d i r e c t i o n = " v e r t i c a l ",
legend.key.s i z e = u n i t( 2 , "cm") ,
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=" t r a n s p a r e n t ") )
#Combine p l o t s
g r i d.a r r a n g e(c a s h.c o n s t a n t, c a s h.sto25, n c o l=2)
#############################################################################
## PROGRAM 6 MAIN PROGRAM FOR ALLOCATION RESULTS, PLOTS AND LOSS FUNCTION #
#############################################################################
#CONTENT
#( i ) PORTFOLIO MODEL FOR BOTH MODEL 1 AND MODEL 2
#( i i ) TABLE 6 . 1 Bond decomposition
#( i i i ) PLOTS f o r Figure 6 . 1 , Figure 6 . 2 , cOMPARE MODEL1 AND MODEL 2
#( i v ) Loss FUNCTIONS BETWEEN CONSTANT MODEL AND MODEL 1
#### Required Packages #####
r e q u i r e(g g p l o t 2) r e q u i r e(s t a r g a z e r) ; r e q u i r e(g r i d E x t r a)
#############################################################################
#### I n t e r e s t Rate Simulation ####
## Define model parameters r0 < 0 . 0 1
r_bar < 0 . 0 1 #theta kappa < 0.4965 #k s i g m a_r < 0 . 0 5 #beta
## s i m u l a t e s h o r t r a t e paths n < 1 # MC s i m u l a t i o n t r i a l s T < 30 # t o t a l time
m < 30 # s u b i n t e r v a l s
dt < T/m # d i f f e r e n c e i n time each s u b i n t e r v a l
r < matrix( 0 ,m+1,n) # matrix to hold s h o r t r a t e paths r[ 1 , ] < r0
f o r(j in 1 :n) { f o r(i in 2 : (m+1) ) {
dr < kappa∗(r_bar r[i 1 ,j] )∗ dt + s i g m a_r∗ s q r t(dt)∗rnorm( 1 , 0 , 1 ) r[i,j] < r[i 1 ,j] + dr
} }
## p l o t paths t < seq( 0 , T, dt)
rT.e x p e c t e d < r_bar + (r0 r_bar)∗exp( kappa∗ t)
rT.s t d e v < s q r t( s i g m a_r^2/(2∗kappa)∗( 1 exp( 2∗kappa∗ t) ) ) matplot(t, r[ , 1 ] , t y p e=" l ", lty=1, y l a b=" r t ")
a b l i n e(h=r_bar, c o l=" red ", lty=2) l i n e s(t, rT.e x p e c t e d, lty=2)
l i n e s(t, rT.e x p e c t e d + 2∗rT.stdev, lty=2) l i n e s(t, rT.e x p e c t e d 2∗rT.stdev, lty=2) p o i n t s( 0 ,r0)
#### PORTFOLIO MODEL ####
#Function begin g a m m a L i s t = l i s t( )
g a m m a V e c = c( 0 . 5 , 1 , 2 , 5 , 10 , 20)
f o r(g in 1 :l e n g t h(g a m m a V e c) ) { gamma = g a m m a V e c[g]
#Parameters
l a m b d a_b a r 2 < 0.3650 #0.3650 #0.15 l a m b d a_t i l d e 2 < 0 . 0 6 #0 . 0 6 #8.925 rho < 0 . 2
s i g m a_s < 0.202
l a m b d a_b a r 1 < 0.109 #0.109 #0.05 l a m b d a_t i l d e 1 < 0.067 #0.067 #2.48 tau < t
b_tau < (1/kappa)∗( 1 exp( kappa∗ t) ) s i g m a_b < 0 . 1
mu_s < 0.087 mu_b < 0.021
#r < rep ( 0 . 0 1 , 3 1 )
#### #Model with s t o c h a s t i c i n t e r e s t and a f f i n e market p r i c e o f r i s k ####
#ODE' s
v < 2∗ s q r t( ( kappa + ( (gamma 1 )/gamma)∗s i g m a_r∗l a m b d a_t i l d e 1) ^2 + ( (gamma1 )/← -gamma)∗( (l a m b d a_t i l d e 1^2+l a m b d a_t i l d e 2^2)/gamma)∗s i g m a_r^2)
_ < (2∗( ( 1/gamma)∗( _ ^2+ _ ^2) )∗(exp( ∗ ) 1 ) )/( (v←
-( -( 1/gamma)∗(l a m b d a_t i l d e 1^2+l a m b d a_t i l d e 2^2) )∗A2_tau +(2/v)∗((1+(1/gamma)∗(← -l a m b d a_b a r 1∗l a m b d a_t i l d e 1+l a m b d a_b a r 2∗l a m b d a_t i l d e 2) )∗
(2∗(kappa+ ( ( 1 gamma)/gamma)∗s i g m a_r∗l a m b d a_t i l d e 1) )+
2∗( (kappa∗r_bar ( 1 gamma)/gamma)∗s i g m a_r∗l a m b d a_b a r 1)∗
( ( 1/gamma)∗(l a m b d a_t i l d e 1^2+l a m b d a_t i l d e 2^2) ) )∗ ( (exp( (v∗tau)/2) 1 ) ^2)/ ( (v+(2∗(← -kappa+ ( ( 1gamma)/gamma)∗s i g m a_r∗l a m b d a_t i l d e 1) ) )∗
(exp(v∗tau) 1 ) +2∗v)
A_f u n c t i o n s < data.frame(A1_tau, A2_tau, v)
#Stock Weight
pi_s2 < (1/gamma)∗( (l a m b d a_b a r 2+l a m b d a_t i l d e 2∗r)/(s q r t( 1 rho^2)∗s i g m a_s) )
#Bond Weight
pi_b2 < (1/(gamma∗s i g m a_b) )∗(l a m b d a_b a r 1+l a m b d a_t i l d e 1∗r rho/(s q r t( 1 rho^2) )←
-∗(l a m b d a_b a r 2+l a m b d a_t i l d e 2∗r) ) +(((gamma 1 )/gamma) ∗ (s i g m a_r/s i g m a_b) )∗(← -A1_tau +A2_tau∗r)
pi_b2. 1t e r m < (1/(gamma∗s i g m a_b) )∗(l a m b d a_b a r 1+l a m b d a_t i l d e 1∗r) mean(pi_b2. 1t e r m)
pi_b2. 2t e r m < (1/(gamma∗s i g m a_b) )∗( rho/(s q r t( 1 rho^2) )∗(l a m b d a_b a r 2+l a m b d a_← -t i l d e 2∗r) )
mean(pi_b2. 2t e r m)
#Hedge part
pi_b2_h e d g e < ( ( (gamma 1 )/gamma) ∗ (s i g m a_r/s i g m a_b) )∗(A1_tau +A2_tau∗r)
#Mean value o f p i_s2
mean_pi_s2 < rep(mean(pi_s2) , 31)
#### Model only s t o c h a s t i c i n t e r e s t r a t e #####
#Parameters :
l a m b d a 1 < (l a m b d a_b a r 1+l a m b d a_t i l d e 1∗mean(r) ) #0 . 1 1 l a m b d a 2 < (l a m b d a_b a r 2+l a m b d a_t i l d e 2∗mean(r) ) #0.3666
#Stock weight
pi_s1 < (1/gamma)∗(l a m b d a 2/(s q r t( 1 rho^2)∗s i g m a_s) ) s t o c k_weights_old < data.frame(pi_s1)
#Bond weight
pi_b1 < (1/gamma)∗( ( (l a m b d a 1)/s i g m a_b) ( (rho∗(l a m b d a 2) )/(s q r t( 1 rho^2)∗s i g m a← -_b) ) ) +((gamma 1 )/gamma)∗(s i g m a_r/s i g m a_b)∗b_tau
b o n d_weights_old < data.frame(pi_b1)
pi_b1_h e d g e < ( (gamma1 )/gamma)∗(s i g m a_r/s i g m a_b)∗b_tau
#F i l l a v e c t o r the constant s t o c k weight vac < rep(pi_s1, 3 1 )
#Hedging importance
h e d g e 1 < pi_b1 pi_b1_h e d g e h e d g e 2 < pi_b2 pi_b2_h e d g e
#Stock Bond Ratio r a t i o_1 < pi_b1/pi_s1 r a t i o_2 < pi_b2/pi_s2
r a t i o.df < data.frame(r a t i o_1 ,r a t i o_2)
#Cash f r a c t i o n
c a s h_1 < 1 pi_s1 pi_b1 check_1 < pi_s1 + pi_b1 + c a s h_1 c a s h_2 < 1 pi_s2 pi_b2 check_2 < pi_s2 + pi_b2 + c a s h_2
#Dataframe f o r s t o c k s
s t o c k_weights < data.frame(pi_s2)
#Dataframe f o r bonds
b o n d_weights < data.frame(pi_b2)
h e d g e_weights < data.frame(pi_b2_h e d g e)
b o n d_terms < data.frame(pi_b2. 1term,pi_b2. 2term, pi_b2_hedge, A1_tau,A2_tau)
### LOSS FUNCTION ###
g a i n_model < (1/gamma 1)∗( 1 gamma)/2 ∗ s i g m a_r^2 ∗ ( (kappa∗tau ( 1 exp( kappa∗tau) ) )/(kappa^3)
( 1 exp( kappa∗tau) ) ^2/(2∗kappa^3) ) l o s s_model < exp(g a i n_model∗r0) 1
#a s s i g n ( paste0 ("G" , g ) , s t o c k_weights )
g a m m a L i s t[ [p a s t e 0("G", g a m m a V e c[g] ) ] ] < s t o c k_weights g a m m a L i s t[ [p a s t e 0("A", g a m m a V e c[g] ) ] ] < s t o c k_weights_old g a m m a L i s t[ [p a s t e 0("B", g a m m a V e c[g] ) ] ] < b o n d_weights g a m m a L i s t[ [p a s t e 0("O", g a m m a V e c[g] ) ] ] < b o n d_weights_old g a m m a L i s t[ [p a s t e 0("H", g a m m a V e c[g] ) ] ] < h e d g e_weights g a m m a L i s t[ [p a s t e 0("T", g a m m a V e c[g] ) ] ] < b o n d_terms g a m m a L i s t[ [p a s t e 0("V", g a m m a V e c[g] ) ] ] < A_f u n c t i o n s g a m m a L i s t[ [p a s t e 0("L", g a m m a V e c[g] ) ] ] < l o s s_model g a m m a L i s t[ [p a s t e 0("C", g a m m a V e c[g] ) ] ] < c a s h_1 }
##############################################
##############################################
#Producing output
##############################################
##############################################
#S e t t i n g up dataframes
a v e r s i o n.df.s2 < data.frame(g a m m a L i s t$G0. 5 ,g a m m a L i s t$G1,g a m m a L i s t$G2,g a m m a L i s t$← -G5,g a m m a L i s t$G10,g a m m a L i s t$G20)
a v e r s i o n.df.s1 < data.frame(g a m m a L i s t$A0. 5 ,g a m m a L i s t$A1,g a m m a L i s t$A2,g a m m a L i s t$← -A5,g a m m a L i s t$A10,g a m m a L i s t$A20)
a v e r s i o n.df.b2 < data.frame(g a m m a L i s t$B0. 5 ,g a m m a L i s t$B1,g a m m a L i s t$B2,g a m m a L i s t$← -B5,g a m m a L i s t$B10,g a m m a L i s t$B20)
a v e r s i o n.df.b1 < data.frame(g a m m a L i s t$O0. 5 ,g a m m a L i s t$O1,g a m m a L i s t$O2,g a m m a L i s t$← -O5,g a m m a L i s t$O10,g a m m a L i s t$O20)
.df. < data.frame( $ . 5 , $ , $ ,←
-a v e r s i o n.df.A_f u n c t i o n s < data.frame(g a m m a L i s t$V0. 5 ,g a m m a L i s t$V1,g a m m a L i s t$V2, ← -g a m m a L i s t$V5,g a m m a L i s t$V10,g a m m a L i s t$V20)
a v e r s i o n.df.c a s h.m1 < data.frame(g a m m a L i s t$C0. 5 ,g a m m a L i s t$C1,g a m m a L i s t$C2, ← -g a m m a L i s t$C5,g a m m a L i s t$C10,g a m m a L i s t$C20)
new.df.A_f u n c t i o n s_g a m m a 2 < data.frame(a v e r s i o n.df.A_f u n c t i o n s$A1_tau. 2 ,a v e r s i o n← -.df.A_f u n c t i o n s$A2_tau. 2 ,a v e r s i o n.df.A_f u n c t i o n s$v. 2 )
new.df.b2 < data.frame(a v e r s i o n.df.b2)
# S e l e c t i n g time p e r i o d s
new.SW < a v e r s i o n.df.s2[c( 2 , 3 0 ) , 1 : 6 ] new.BW < a v e r s i o n.df.b2[c( 2 , 3 0 ) , 1 : 6 ] new.HE < a v e r s i o n.df.h e d g e[c( 2 , 3 0 ) , 1 : 6 ]
new.BT < a v e r s i o n.df.b o n d t e r m s[ (c( 1 , 1 0 , 2 0 , 3 0 ) ) , 1 : 5 ]
### NEW THINGS TABLE MODEL 1 ###
a v e r s i o n.df.b1[c( 2 , 3 0 ) , 1 : 6 ] a v e r s i o n.df.s1[c( 2 , 3 0 ) , 1 : 6 ] a v e r s i o n.df.c a s h.m1[c( 2 , 3 0 ) , 1 : 6 ]
# D e f i n i n g new dataframes RA.SW < new.SW[ 1 : 2 , ] RA.BW < new.BW[ 1 : 2 , ] RA.HE < new.HE[ 1 : 2 , ] RA.BT < new.BT[ 1 : 4 , ]
#Creating a Bond Table with decomposed terms BT. 0 5 < a v e r s i o n.df.b o n d t e r m s[ (c( 2 , 3 0 ) ) , 1 : 5 ] BT. 1 < a v e r s i o n.df.b o n d t e r m s[ (c( 2 , 3 0 ) ) , 6 : 1 0 ] BT. 2 < a v e r s i o n.df.b o n d t e r m s[ (c( 2 , 3 0 ) ) , 1 1 : 1 5 ] BT. 5 < a v e r s i o n.df.b o n d t e r m s[ (c( 2 , 3 0 ) ) , 1 6 : 2 0 ] BT. 1 0 < a v e r s i o n.df.b o n d t e r m s[ (c( 2 , 3 0 ) ) , 2 1 : 2 5 ] BT. 2 0 < a v e r s i o n.df.b o n d t e r m s[ (c( 2 , 3 0 ) ) , 2 6 : 3 0 ]
colnames(BT. 0 5 ) < c(" f i r s t ","2nd", " hedge ", "A1", "A2") colnames(BT. 1 ) < c(" f i r s t ","2nd", " hedge ", "A1", "A2") colnames(BT. 2 ) < c(" f i r s t ","2nd", " hedge ", "A1", "A2") colnames(BT. 5 ) < c(" f i r s t ","2nd", " hedge ", "A1", "A2") colnames(BT. 1 0 ) < c(" f i r s t ","2nd", " hedge ", "A1", "A2") colnames(BT. 2 0 ) < c(" f i r s t ","2nd", " hedge ", "A1", "A2")
#########################################################
#( i i ) TABLE 6 . 1 Bond decomposition
BT.t a b l e < rbind(BT. 0 5 ,BT. 1 ,BT. 2 ,BT. 5 ,BT. 1 0 ,BT. 2 0 )
# S t a r g a z e r t a b l e output
BT.t a b l e.l a t e x < s t a r g a z e r(BT.table, summary = F A L S E)
########################################################
#Creating a t a b l e f o r comparison between the models
#S e t t i n g up the t a b l e
dim(RA.SW) = c(l e n g t h(RA.SW) , 1) dim(RA.BW) = c(l e n g t h(RA.BW) , 1) dim(RA.HE) = c(l e n g t h(RA.HE) , 1)
SW.df < t(RA.SW) BW.df < t(RA.BW) HE.df < t(RA.HE)
SW.t1.df < data.frame(SW.df[ , 1 ] )
SW.t30.df < data.frame(SW.df[ , 2 ] ) colnames(SW.t1.df) < c(" Stocks ") colnames(SW.t30.df) < c(" Stocks ")
BW.t1.df < data.frame(BW.df[ , 1 ] ) BW.t30.df < data.frame(BW.df[ , 2 ] ) colnames(BW.t1.df) < c("Bonds") colnames(BW.t30.df) < c("Bonds")
HE.t1.df < data.frame(HE.df[ , 1 ] ) HE.t30.df < data.frame(HE.df[ , 2 ] ) colnames(HE.t1.df) < c("Hedge") colnames(HE.t30.df) < c("Hedge")
SW.rbind < rbind(SW.t1.df,SW.t30.df) BW.rbind < rbind(BW.t1.df,BW.t30.df) HE.rbind < rbind(HE.t1.df,HE.t30.df) C a s h.df < 1 SW.rbind BW.rbind colnames(C a s h.df) < c("Cash")
check.df < C a s h.df + SW.rbind + BW.rbind
new.t a b l e.PF < cbind(SW.rbind,BW.rbind,HE.rbind,C a s h.df)
################################################
#( i i i ) Table 6 . 2 f o r comparison new.t a b l e.PF.df < new.t a b l e.PF
#Table S o l u t i o n
PF.t a b l e.l a t e x < s t a r g a z e r(new.t a b l e.PF, summary = F A L S E)
##########################################################
#Labeling to p r i n t
rownames(BW.df) = colnames(RA.BW) rownames(SW.df) = colnames(RA.BW) rownames(HE.df) = colnames(RA.HE) rownames(SW.df) = c( 0 . 5 , 1 , 2 , 5 , 1 0 , 2 0 ) rownames(BW.df) = c( 0 . 5 , 1 , 2 , 5 , 1 0 , 2 0 ) rownames(HE.df) = c( 0 . 5 , 1 , 2 , 5 , 1 0 , 2 0 )
SW.df # Stocks at T= 1 and T=30 BW.df # Bonds
HE.df # Hegde term
########################################################
#( i i i ) PLOTS f o r Figure 6 . 1 , Figure 6 . 2 ###############
########################################################
h e a d(a v e r s i o n.df.b1) h e a d(a v e r s i o n.df.b2)
# Bond Plot f o r RA = 1 #
b o n d.p l o t. 1 < g g p l o t(a v e r s i o n.df.b1, aes(x = t, y = g a m m a L i s t$O1, c o l = " blue ") ,← -s i z e = 1 . 2 ) +
_ ( ) +
c o o r d_c a r t e s i a n(x l i m = c( 0 , 3 0 ) , y l i m = c( 0 . 2 5 , 0 . 7 5 ) ) + s c a l e_x_c o n t i n u o u s(" Years ") +
s c a l e_y_c o n t i n u o u s(" Fraction Of Wealth") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c("Bonds M1", "Bonds M2" ) , ← -v a l u e s = c(" blue ", " green ") ) +
l a b s(t i t l e=" ( a ) Risk Aversion = 1") + t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = e l e m e n t_b l a n k( ) , a x i s.t e x t.x=e l e m e n t_t e x t(s i z e=8) , a x i s.t i t l e.x=e l e m e n t_t e x t(s i z e=8) , a x i s.t e x t.y=e l e m e n t_t e x t(s i z e=8) , a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=8) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=9, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n= "none", # c ( 0 . 4 , 0 . 8 ) , legend.key.s i z e = u n i t( 0 . 3 5 ,"cm") , legend.t e x t = e l e m e n t_t e x t(s i z e = 7) , legend.d i r e c t i o n = " v e r t i c a l ",
legend.key.s i z e = u n i t( 2 , "cm") ,
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=" t r a n s p a r e n t ") ) b o n d.p l o t. 1
# Bond Plot f o r RA = 2 #
b o n d.p l o t. 2 < g g p l o t(a v e r s i o n.df.b1, aes(x = t, y = g a m m a L i s t$O2, c o l = " blue ") ,← -s i z e = 1 . 2 ) +
g e o m_l i n e( ) +
g e o m_l i n e(aes(y = g a m m a L i s t$B2, c o l = " green ") , s i z e = 1 . 2 ) +
g e o m_r i b b o n(aes(x = t, y m a x=g a m m a L i s t$B2, y m i n=g a m m a L i s t$O2, l i n e t y p e = NA) , ← -f i l l=" pink ", a l p h a=.3) +
c o o r d_c a r t e s i a n(x l i m = c( 0 , 3 0 ) , y l i m = c( 0 . 2 5 , 0 . 7 5 ) ) + s c a l e_x_c o n t i n u o u s(" Years ") +
s c a l e_y_c o n t i n u o u s(" Fraction Of Wealth") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c("Bonds M1", "Bonds M2" ) , ← -v a l u e s = c(" blue ", " green ") ) +
l a b s(t i t l e=" ( b ) Risk Aversion = 2") + t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = e l e m e n t_b l a n k( ) , a x i s.t e x t.x=e l e m e n t_t e x t(s i z e=8) , a x i s.t i t l e.x=e l e m e n t_t e x t(s i z e=8) , a x i s.t e x t.y=e l e m e n t_t e x t(s i z e=8) , a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=8) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=9, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n= "none", # c ( 0 . 4 , 0 . 8 ) , legend.key.s i z e = u n i t( 0 . 3 5 ,"cm") , legend.t e x t = e l e m e n t_t e x t(s i z e = 7) , legend.d i r e c t i o n = " v e r t i c a l ",
legend.key.s i z e = u n i t( 2 , "cm") ,
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=" t r a n s p a r e n t ") ) b o n d.p l o t. 2
# Bond Plot f o r RA = 5 #
b o n d.p l o t. 5 < g g p l o t(a v e r s i o n.df.b1, aes(x = t, y = g a m m a L i s t$O5, c o l = " blue ") ,← -s i z e = 1 . 2 ) +
g e o m_l i n e( ) +
g e o m_l i n e(aes(y = g a m m a L i s t$B5, c o l = " green ") , s i z e = 1 . 2 ) +
g e o m_r i b b o n(aes(x = t, y m a x=g a m m a L i s t$B5, y m i n=g a m m a L i s t$O5, l i n e t y p e = NA) , ← -f i l l=" pink ", a l p h a=.3) +
c o o r d_c a r t e s i a n(x l i m = c( 0 , 3 0 ) , y l i m = c( 0 . 5 , 1 ) ) + s c a l e_x_c o n t i n u o u s(" Years ") +
s c a l e_y_c o n t i n u o u s(" Fraction Of Wealth") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c("Bonds M1", "Bonds M2" ) , ← -v a l u e s = c(" blue ", " green ") ) +
l a b s(t i t l e=" ( c ) Risk Aversion = 5") + t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = e l e m e n t_b l a n k( ) , a x i s.t e x t.x=e l e m e n t_t e x t(s i z e=8) , a x i s.t i t l e.x=e l e m e n t_t e x t(s i z e=8) , a x i s.t e x t.y=e l e m e n t_t e x t(s i z e=8) , a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=8) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=9, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n="none", # c ( 0 . 4 , 0 . 8 ) , legend.key.s i z e = u n i t( 0 . 3 5 ,"cm") ,
legend.t e x t = e l e m e n t_t e x t(s i z e = 7) , legend.d i r e c t i o n = " v e r t i c a l ",
legend.key.s i z e = u n i t( 2 , "cm") ,
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=" t r a n s p a r e n t ") ) b o n d.p l o t. 5
# Bond Plot f o r RA = 10 #
b o n d.p l o t. 1 0 < g g p l o t(a v e r s i o n.df.b1, aes(x = t, y = g a m m a L i s t$O10, c o l = " blue "← -) , s i z e = 1 . 2 ) +
g e o m_l i n e( ) +
g e o m_l i n e(aes(y = g a m m a L i s t$B10, c o l = " green ") , s i z e = 1 . 2 ) +
g e o m_r i b b o n(aes(x = t, y m a x=g a m m a L i s t$B10, y m i n=g a m m a L i s t$O10, l i n e t y p e = NA) , ← -f i l l=" pink ", a l p h a=.3) +
c o o r d_c a r t e s i a n(x l i m = c( 0 , 3 0 ) , y l i m = c( 0 . 5 , 1 ) ) + s c a l e_x_c o n t i n u o u s(" Years ") +
s c a l e_y_c o n t i n u o u s(" Fraction Of Wealth") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c("Bonds M1", "Bonds M2" ) , ← -v a l u e s = c(" blue ", " green ") ) +
l a b s(t i t l e=" ( d ) Risk Aversion = 10") + t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") ,
panel.g r i d. = _ ( ) ,
a x i s.t e x t.y=e l e m e n t_t e x t(s i z e=8) , a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=8) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=9, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n= "none", # c ( 0 . 4 , 0 . 8 ) , legend.key.s i z e = u n i t( 0 . 3 5 ,"cm") , legend.t e x t = e l e m e n t_t e x t(s i z e = 7) , legend.d i r e c t i o n = " v e r t i c a l ",
legend.key.s i z e = u n i t( 2 , "cm") ,
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=" t r a n s p a r e n t ") ) b o n d.p l o t. 1 0
# Bond Plot f o r RA = 20 #
b o n d.p l o t. 2 0 < g g p l o t(a v e r s i o n.df.b1, aes(x = t, y = g a m m a L i s t$O20, c o l = " blue "← -) , s i z e = 1 . 2 ) +
g e o m_l i n e( ) +
g e o m_l i n e(aes(y = g a m m a L i s t$B20, c o l = " green ") , s i z e = 1 . 2 ) +
g e o m_r i b b o n(aes(x = t, y m a x=g a m m a L i s t$B20, y m i n=g a m m a L i s t$O20, l i n e t y p e = NA)← -, f i l l=" pink ", a l p h a=.5) +
c o o r d_c a r t e s i a n(x l i m = c( 0 , 3 0 ) , y l i m = c( 0 . 7 5 , 1 ) ) + s c a l e_x_c o n t i n u o u s(" Years ") +
s c a l e_y_c o n t i n u o u s(" Fraction Of Wealth") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c("Bonds M1", "Bonds M2" ) , ← -v a l u e s = c(" blue ", " green ") ) +
l a b s(t i t l e=" ( d ) Risk Aversion = 20") + t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = e l e m e n t_b l a n k( ) , a x i s.t e x t.x=e l e m e n t_t e x t(s i z e=8) , a x i s.t i t l e.x=e l e m e n t_t e x t(s i z e=8) , a x i s.t e x t.y=e l e m e n t_t e x t(s i z e=8) , a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=8) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=9, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n= "none", #c ( 0 . 4 , 0 . 8 ) , legend.key.s i z e = u n i t( 0 . 3 5 ,"cm") , legend.t e x t = e l e m e n t_t e x t(s i z e = 7) , legend.d i r e c t i o n = " v e r t i c a l ",
legend.key.s i z e = u n i t( 2 , "cm") ,
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=" t r a n s p a r e n t ") )
#A l l p l o t s
g r i d.a r r a n g e(b o n d.p l o t. 2 , b o n d.p l o t. 5 , nrow = 1 , n c o l = 2) g r i d.a r r a n g e(b o n d.p l o t. 1 0 , b o n d.p l o t. 2 0 , nrow = 1 , n c o l = 2)
g r i d.a r r a n g e(b o n d.p l o t. 1 , b o n d.p l o t. 2 , b o n d.p l o t. 5 , b o n d.p l o t. 1 0 , nrow = 2 , n c o l ←
-= 2)
##########################################################
### STOCKS ##############################################
##########################################################
#RA = 2
s t o c k.p l o t. 2 < g g p l o t(a v e r s i o n.df.s2, aes(x = t, y = g a m m a L i s t$G2) ) + g e o m_l i n e(aes(c o l = " red ") , s i z e = 1) +
g e o m_l i n e(aes(y = g a m m a L i s t$A2, c o l = " darkred ") , s i z e = 1 , l i n e t y p e = 2) +
c o o r d_c a r t e s i a n(x l i m = c( 0 , 3 0 ) ) + s c a l e_x_c o n t i n u o u s(" Years ") +
s c a l e_y_c o n t i n u o u s(" Fraction o f Wealth") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c(" Stocks M1", " Stocks M2" ) , ← -v a l u e s = c(" red ", " darkred ") ) +
l a b s(t i t l e=" ( a ) Risk Aversion = 2") + t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = e l e m e n t_b l a n k( ) , a x i s.t e x t.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t i t l e.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t e x t.y=e l e m e n t_t e x t(s i z e=8) , a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=8) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=9, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n= c( 0 . 4 , 0 . 6 5 ) , legend.key.s i z e = u n i t( 0 . 3 5 ,"cm") , legend.t e x t = e l e m e n t_t e x t(s i z e = 7) , legend.d i r e c t i o n = " v e r t i c a l ",
legend.key.s i z e = u n i t( 2 , "cm") ,
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=" t r a n s p a r e n t ") )
#RA = 5
s t o c k.p l o t. 5 < g g p l o t(a v e r s i o n.df.s2, aes(x = t, y = g a m m a L i s t$G5) ) + g e o m_l i n e(aes(c o l = " red ") , s i z e = 1) +
g e o m_l i n e(aes(y = g a m m a L i s t$A5, c o l = " darkred ") , s i z e = 1 , l i n e t y p e = 2) + c o o r d_c a r t e s i a n(x l i m = c( 0 , 3 0 ) ) +
s c a l e_x_c o n t i n u o u s(" Years ") +
s c a l e_y_c o n t i n u o u s(" Fraction o f Wealth") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c(" Stocks M1", " Stocks M2" ) , ← -v a l u e s = c(" red ", " darkred ") ) +
l a b s(t i t l e=" ( b ) Risk Aversion = 5") + t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = e l e m e n t_b l a n k( ) , a x i s.t e x t.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t i t l e.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t e x t.y=e l e m e n t_t e x t(s i z e=8) , a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=8) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=9, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n= c( 0 . 4 , 0 . 6 5 ) , legend.key.s i z e = u n i t( 0 . 3 5 ,"cm") , legend.t e x t = e l e m e n t_t e x t(s i z e = 7) , legend.d i r e c t i o n = " v e r t i c a l ",
legend.key.s i z e = u n i t( 2 , "cm") ,
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=" t r a n s p a r e n t ") )
g e o m_l i n e(aes(y = g a m m a L i s t$A10, c o l = " darkred ") , s i z e = 1 , l i n e t y p e = 2) + c o o r d_c a r t e s i a n(x l i m = c( 0 , 3 0 ) ) +
s c a l e_x_c o n t i n u o u s(" Years ") +
s c a l e_y_c o n t i n u o u s(" Fraction o f Wealth") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c(" Stocks M1", " Stocks M2" ) , ← -v a l u e s = c(" red ", " darkred ") ) +
l a b s(t i t l e=" ( c ) Risk Aversion = 10") + t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = e l e m e n t_b l a n k( ) , a x i s.t e x t.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t i t l e.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t e x t.y=e l e m e n t_t e x t(s i z e=8) , a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=8) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=9, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n= c( 0 . 4 , 0 . 6 5 ) , legend.key.s i z e = u n i t( 0 . 3 5 ,"cm") , legend.t e x t = e l e m e n t_t e x t(s i z e = 7) , legend.d i r e c t i o n = " v e r t i c a l ",
legend.key.s i z e = u n i t( 2 , "cm") ,
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=" t r a n s p a r e n t ") )
## RA = 20
s t o c k.p l o t. 2 0 < g g p l o t(a v e r s i o n.df.s2, aes(x = t, y = g a m m a L i s t$G20) ) + g e o m_l i n e(aes(c o l = " red ") , s i z e = 1) +
g e o m_l i n e(aes(y = g a m m a L i s t$A20, c o l = " darkred ") , s i z e = 1 , l i n e t y p e = 2) + c o o r d_c a r t e s i a n(x l i m = c( 0 , 3 0 ) ) +
s c a l e_x_c o n t i n u o u s(" Years ") +
s c a l e_y_c o n t i n u o u s(" Fraction o f Wealth") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c(" Stocks M1", " Stocks M2" ) , ← -v a l u e s = c(" red ", " darkred ") ) +
l a b s(t i t l e=" ( d ) Risk Aversion = 20") + t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = e l e m e n t_b l a n k( ) , a x i s.t e x t.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t i t l e.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t e x t.y=e l e m e n t_t e x t(s i z e=8) , a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=8) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=9, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n= c( 0 . 4 , 0 . 6 5 ) , legend.key.s i z e = u n i t( 0 . 3 5 ,"cm") , legend.t e x t = e l e m e n t_t e x t(s i z e = 7) , legend.d i r e c t i o n = " v e r t i c a l ",
legend.key.s i z e = u n i t( 2 , "cm") ,
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=" t r a n s p a r e n t ") )
g r i d.a r r a n g e(s t o c k.p l o t. 2 , s t o c k.p l o t. 5 , s t o c k.p l o t. 1 0 , s t o c k.p l o t. 2 0 , nrow = 2 , ← -n c o l = 2)
###############################################################
### ( i v ) Loss FUNCTIONS BETWEEN CONSTANT MODEL AND MODEL 1 ##
###############################################################
l o s s.f u n c t i o n < data.frame(g a m m a L i s t$L0. 5 ,g a m m a L i s t$L1,g a m m a L i s t$L2, g a m m a L i s t$← -L5,g a m m a L i s t$L10,g a m m a L i s t$L20)
### Risk Aversion = 2 ###
p l o t.l o s s.rv2 < g g p l o t(l o s s.function , aes(x = t, y = l o s s.f u n c t i o n $g a m m a L i s t.L2)← -) +
g e o m_l i n e(c o l= " red ", s i z e = 1) + c o o r d_c a r t e s i a n(x l i m = c( 0 , 3 0 ) ) + s c a l e_x_c o n t i n u o u s(" Years ") +
s c a l e_y_c o n t i n u o u s(" Welfare Loss (%)") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c(" Loss " ) , v a l u e s = c(" red ") ) + l a b s(t i t l e=" ( a ) Risk Aversion = 2") +
t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = e l e m e n t_b l a n k( ) , a x i s.t e x t.x=e l e m e n t_t e x t(s i z e=7) , a x i s.t i t l e.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t e x t.y=e l e m e n t_t e x t(s i z e=7) , a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=9) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=8, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n= c( 1 . 0 2 4 9 , 0 . 8 4 5 ) , legend.key.s i z e = u n i t( 0 . 3 ,"cm") , legend.t e x t = e l e m e n t_t e x t(s i z e = 6) , legend.d i r e c t i o n = " h o r i z o n t a l ",
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=a l p h a(' white ', 0 . 4 ) ) ) p l o t.l o s s.rv2
### Risk Aversion = 5 ###
p l o t.l o s s.rv5 < g g p l o t(l o s s.f unct ion , aes(x = t, y = l o s s.f u n c t i o n $g a m m a L i s t.L5)← -) +
g e o m_l i n e(c o l= " red ", s i z e = 1) + c o o r d_c a r t e s i a n(x l i m = c( 0 , 3 0 ) ) + s c a l e_x_c o n t i n u o u s(" Years ") +
s c a l e_y_c o n t i n u o u s(" Welfare Loss (%)") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c(" Loss " ) , v a l u e s =← -c(" red ") ) +
l a b s(t i t l e=" ( b ) Risk Aversion = 5") + t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5)← -,
a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = "← -dotted ") ,
panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = _ ( ) ,
a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=9) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=8, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n= c( 1 . 0 2 4 9 , 0 . 8 4 5 ) , legend.key.s i z e = u n i t( 0 . 3 ,"cm") , legend.t e x t = e l e m e n t_t e x t(s i z e = 6) , legend.d i r e c t i o n = " h o r i z o n t a l ",
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=a l p h a(' white ', 0 . 4 ) ) )
### Risk Aversion = 10 ###
p l o t.l o s s.r v 1 0 < g g p l o t(l o s s.function, aes(x = t, y = l o s s.f u n c t i o n $g a m m a L i s t.← -L10) ) +
g e o m_l i n e(c o l= " red ", s i z e = 1) + c o o r d_c a r t e s i a n(x l i m = c( 0 , 3 0 ) ) + s c a l e_x_c o n t i n u o u s(" Years ") +
s c a l e_y_c o n t i n u o u s(" Welfare Loss (%)") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c(" Loss " ) , v a l u e s = c(" red ") ) + l a b s(t i t l e=" ( c ) Risk Aversion = 10") +
t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = e l e m e n t_b l a n k( ) , a x i s.t e x t.x=e l e m e n t_t e x t(s i z e=7) , a x i s.t i t l e.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t e x t.y=e l e m e n t_t e x t(s i z e=7) , a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=9) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=8, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n= c( 1 . 0 2 4 9 , 0 . 8 4 5 ) , legend.key.s i z e = u n i t( 0 . 3 ,"cm") , legend.t e x t = e l e m e n t_t e x t(s i z e = 6) , legend.d i r e c t i o n = " h o r i z o n t a l ",
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=a l p h a(' white ', 0 . 4 ) ) )
### Risk Aversion = 20 ###
p l o t.l o s s.r v 2 0 < g g p l o t(l o s s.f unct ion, aes(x = t, y = l o s s.f u n c t i o n $g a m m a L i s t.← -L20) ) +
g e o m_l i n e(c o l= " red ", s i z e = 1) + c o o r d_c a r t e s i a n(x l i m = c( 0 , 3 0 ) ) + s c a l e_x_c o n t i n u o u s(" Years ") +
s c a l e_y_c o n t i n u o u s(" Welfare Loss (%)") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c(" Loss " ) , v a l u e s = c(" red ") ) + l a b s(t i t l e=" ( d ) Risk Aversion = 20") +
t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = e l e m e n t_b l a n k( ) , a x i s.t e x t.x=e l e m e n t_t e x t(s i z e=7) , a x i s.t i t l e.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t e x t.y=e l e m e n t_t e x t(s i z e=7) , a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=9) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=8, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n= c( 1 . 0 2 4 9 , 0 . 8 4 5 ) , legend.key.s i z e = u n i t( 0 . 3 ,"cm") , legend.t e x t = e l e m e n t_t e x t(s i z e = 6) , legend.d i r e c t i o n = " h o r i z o n t a l ",
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=a l p h a(' white ', 0 . 4 ) ) )
# A l l p l o t s
g r i d.a r r a n g e(p l o t.l o s s.rv2, p l o t.l o s s.rv5,p l o t.l o s s.rv10,p l o t.l o s s.rv20, nrow = ← -2 , n c o l = 2)
######################################################
#### Program 7 A l t e r n a t i v e S p e c i f i c a t i o n o f MPR ####
######################################################
#Content#
#( i ) Simulation o f models with a constant i n t e r e s t rate , i f r < rep ( 0 . 0 1 , 3 1 ) i s ← -a c t i v e .
#( i i ) Simulation o f models with a s t o c h a s t i c i n t e r e s t rate , i f r < rep ( 0 . 0 1 , 3 1 ) ← -i s d e a c t -i v e .
#( i i i ) Figure 6 . 3 and Fiure 6 . 4
#### Required Packages #####
r e q u i r e(g g p l o t 2) r e q u i r e(s t a r g a z e r) ; r e q u i r e(g r i d E x t r a)
#######################################################
#### I n t e r e s t Rate Simulation ####
## Define model parameters r0 < 0 . 0 1
r_bar < 0 . 0 1 #theta kappa < 0.4965 #k s i g m a_r < 0 . 0 5 #beta
## s i m u l a t e s h o r t r a t e paths n < 1 # MC s i m u l a t i o n t r i a l s T < 30 # t o t a l time
m < 30 # s u b i n t e r v a l s
dt < T/m # d i f f e r e n c e i n time each s u b i n t e r v a l
r < matrix( 0 ,m+1,n) # matrix to hold s h o r t r a t e paths r[ 1 , ] < r0
f o r(j in 1 :n) { f o r(i in 2 : (m+1) ) {
dr < kappa∗(r_bar r[i 1 ,j] )∗ dt + s i g m a_r∗ s q r t(dt)∗rnorm( 1 , 0 , 1 ) r[i,j] < r[i 1 ,j] + dr
} }
## p l o t paths
matplot(t, r[ , 1 ] , t y p e=" l ", lty=1, y l a b=" r t ") a b l i n e(h=r_bar, c o l=" red ", lty=2)
l i n e s(t, rT.e x p e c t e d, lty=2)
l i n e s(t, rT.e x p e c t e d + 2∗rT.stdev, lty=2) l i n e s(t, rT.e x p e c t e d 2∗rT.stdev, lty=2) p o i n t s( 0 ,r0)
#### PORTFOLIO MODEL ####
#Function begin g a m m a L i s t = l i s t( )
g a m m a V e c = c( 0 . 5 , 1 , 2 , 5 , 10 , 20)
f o r(g in 1 :l e n g t h(g a m m a V e c) ) { gamma = g a m m a V e c[g]
#Parameters
l a m b d a_b a r 2 < 0.301 #Base : 0.365 #A l t e r n a t i v e : 0.301 l a m b d a_t i l d e 2 < 6 . 5 #Base : 0 . 0 6 #A l t e r n a t i v e : 6 . 5 rho < 0 . 2
s i g m a_s < 0.202
l a m b d a_b a r 1 < 0 . 0 6 #Base : 0.109 #A l t e r n a t i v e : 0 . 0 6 l a m b d a_t i l d e 1 < 5 #Base : 0.067 #A l t e r n a t i v e : 5 tau < t
b_tau < (1/kappa)∗( 1 exp( kappa∗ t) ) s i g m a_b < 0 . 1
mu_s < 0.087 mu_b < 0.021
#r < rep ( 0 . 0 1 , 3 1 ) ######## IMPORTANT: i f ACTIVE: Simulation with constant ← -i n t e r e s t r a t e ####
#### #Model with s t o c h a s t i c i n t e r e s t and a f f i n e market p r i c e o f r i s k ####
#ODE' s
v < 2∗ s q r t( ( kappa + ( (gamma 1 )/gamma)∗s i g m a_r∗l a m b d a_t i l d e 1) ^2 + ( (gamma1 )/← -gamma)∗( (l a m b d a_t i l d e 1^2+l a m b d a_t i l d e 2^2)/gamma)∗s i g m a_r^2)
A2_tau < (2∗( ( 1/gamma)∗(l a m b d a_t i l d e 1^2+l a m b d a_t i l d e 2^2) )∗(exp(v∗tau) 1 ) )/( (v← -+(2∗(kappa + ( ( 1 gamma)/gamma)∗s i g m a_r∗l a m b d a_t i l d e 1) ) )∗(exp(v∗tau) 1 ) +2∗v)
A1_tau < (1+(1/gamma)∗(l a m b d a_b a r 1∗l a m b d a_t i l d e 1+l a m b d a_b a r 2∗l a m b d a_t i l d e 2) )/
( ( 1/gamma)∗(l a m b d a_t i l d e 1^2+l a m b d a_t i l d e 2^2) )∗A2_tau +(2/v)∗ ((1+(1/gamma)∗(l a m b d a_b a r 1∗l a m b d a_t i l d e 1+l a m b d a_b a r 2∗l a m b d a_←
-t i l d e 2) )∗
(2∗(kappa+ ( ( 1gamma)/gamma)∗s i g m a_r∗l a m b d a_t i l d e 1) )+
2∗( (kappa∗r_bar ( 1 gamma)/gamma)∗s i g m a_r∗l a m b d a_b a r 1)∗ ( ( 1/gamma)∗(l a m b d a_t i l d e 1^2+l a m b d a_t i l d e 2^2) ) )∗
( (exp( (v∗tau)/2) 1 ) ^2)/
( (v+(2∗(kappa+ ( ( 1gamma)/gamma)∗s i g m a_r∗l a m b d a_t i l d e 1) ) )∗(exp(v∗← -tau) 1 ) +2∗v)
A_f u n c t i o n s < data.frame(A1_tau, A2_tau, v)
#Stock Weight
pi_s2 < (1/gamma)∗( (l a m b d a_b a r 2+l a m b d a_t i l d e 2∗r)/(s q r t( 1 rho^2)∗s i g m a_s) )
#Bond Weight
pi_b2 < (1/(gamma∗s i g m a_b) )∗(l a m b d a_b a r 1+l a m b d a_t i l d e 1∗r rho/(s q r t( 1 rho^2) )←
-∗(l a m b d a_b a r 2+l a m b d a_t i l d e 2∗r) ) +(((gamma 1 )/gamma) ∗ (s i g m a_r/s i g m a_b) )∗(← -A1_tau +A2_tau∗r)
pi_b2. 1t e r m < (1/(gamma∗s i g m a_b) )∗(l a m b d a_b a r 1+l a m b d a_t i l d e 1∗r) mean(pi_b2. 1t e r m)
pi_b2. 2t e r m < (1/(gamma∗s i g m a_b) )∗( rho/(s q r t( 1 rho^2) )∗(l a m b d a_b a r 2+l a m b d a_← -t i l d e 2∗r) )
mean(pi_b2. 2t e r m)
#Hedge part
pi_b2_h e d g e < ( ( (gamma 1 )/gamma) ∗ (s i g m a_r/s i g m a_b) )∗(A1_tau +A2_tau∗r)
#Mean value o f pi_s2
mean_pi_s2 < rep(mean(pi_s2) , 31)
#### Model only s t o c h a s t i c i n t e r e s t r a t e #####
#Parameters :
l a m b d a 1 < (l a m b d a_b a r 1+l a m b d a_t i l d e 1∗mean(r) ) #0 . 1 1 l a m b d a 2 < (l a m b d a_b a r 2+l a m b d a_t i l d e 2∗mean(r) ) #0.3666
#Stock weight
pi_s1 < (1/gamma)∗(l a m b d a 2/(s q r t( 1 rho^2)∗s i g m a_s) )
s t o c k_weights_old < data.frame(pi_s1)
#Bond weight
pi_b1 < (1/gamma)∗( ( (l a m b d a 1)/s i g m a_b) ( (rho∗(l a m b d a 2) )/(s q r t( 1 rho^2)∗s i g m a← -_b) ) ) +((gamma 1 )/gamma)∗(s i g m a_r/s i g m a_b)∗b_tau
b o n d_weights_old < data.frame(pi_b1)
pi_b1_h e d g e < ( (gamma1 )/gamma)∗(s i g m a_r/s i g m a_b)∗b_tau
#F i l l a v e c t o r the constant s t o c k weight vac < rep(pi_s1, 3 1 )
#Hedging importance
h e d g e 1 < pi_b1 pi_b1_h e d g e h e d g e 2 < pi_b2 pi_b2_h e d g e
#Stock Bond Ratio r a t i o_1 < pi_b1/pi_s1 r a t i o_2 < pi_b2/pi_s2
r a t i o.df < data.frame(r a t i o_1 ,r a t i o_2)
#Cash f r a c t i o n
c a s h_1 < 1 pi_s1 pi_b1
check_1 < _ + _ + _1
#Dataframe f o r s t o c k s
s t o c k_weights < data.frame(pi_s2)
#Dataframe f o r bonds
b o n d_weights < data.frame(pi_b2)
h e d g e_weights < data.frame(pi_b2_h e d g e)
b o n d_terms < data.frame(pi_b2. 1term,pi_b2. 2term, pi_b2_hedge, A1_tau,A2_tau)
### LOSS FUNCTION ###
g a i n_model < (1/gamma 1)∗( 1 gamma)/2 ∗ s i g m a_r^2 ∗ ( (kappa∗tau ( 1 exp( kappa←
-∗tau) ) )/(kappa^3) ( 1 exp( kappa∗tau) ) ^2/(2∗kappa^3) ) l o s s_model < exp(g a i n_model∗r0) 1
#a s s i g n ( paste0 ("G" , g ) , s t o c k_weights )
g a m m a L i s t[ [p a s t e 0("G", g a m m a V e c[g] ) ] ] < s t o c k_weights g a m m a L i s t[ [p a s t e 0("A", g a m m a V e c[g] ) ] ] < s t o c k_weights_old g a m m a L i s t[ [p a s t e 0("B", g a m m a V e c[g] ) ] ] < b o n d_weights g a m m a L i s t[ [p a s t e 0("O", g a m m a V e c[g] ) ] ] < b o n d_weights_old g a m m a L i s t[ [p a s t e 0("H", g a m m a V e c[g] ) ] ] < h e d g e_weights g a m m a L i s t[ [p a s t e 0("T", g a m m a V e c[g] ) ] ] < b o n d_terms g a m m a L i s t[ [p a s t e 0("V", g a m m a V e c[g] ) ] ] < A_f u n c t i o n s g a m m a L i s t[ [p a s t e 0("L", g a m m a V e c[g] ) ] ] < l o s s_model }
############################################################
############################################################
#Producing output
############################################################
############################################################
#S e t t i n g up dataframes
a v e r s i o n.df.s2 < data.frame(g a m m a L i s t$G0. 5 ,g a m m a L i s t$G1,g a m m a L i s t$G2,g a m m a L i s t$← -G5,g a m m a L i s t$G10,g a m m a L i s t$G20)
a v e r s i o n.df.s1 < data.frame(g a m m a L i s t$A0. 5 ,g a m m a L i s t$A1,g a m m a L i s t$A2,g a m m a L i s t$← -A5,g a m m a L i s t$A10,g a m m a L i s t$A20)
a v e r s i o n.df.b2 < data.frame(g a m m a L i s t$B0. 5 ,g a m m a L i s t$B1,g a m m a L i s t$B2,g a m m a L i s t$← -B5,g a m m a L i s t$B10,g a m m a L i s t$B20)
a v e r s i o n.df.b1 < data.frame(g a m m a L i s t$O0. 5 ,g a m m a L i s t$O1,g a m m a L i s t$O2,g a m m a L i s t$← -O5,g a m m a L i s t$O10,g a m m a L i s t$O20)
a v e r s i o n.df.h e d g e < data.frame(g a m m a L i s t$H0. 5 ,g a m m a L i s t$H1,g a m m a L i s t$H2,← -g a m m a L i s t$H5,g a m m a L i s t$H10,g a m m a L i s t$H20)
a v e r s i o n.df.b o n d t e r m s < data.frame(g a m m a L i s t$T0. 5 ,g a m m a L i s t$T1,g a m m a L i s t$T2, ← -g a m m a L i s t$T5,g a m m a L i s t$T10,g a m m a L i s t$T20)
a v e r s i o n.df.A_f u n c t i o n s < data.frame(g a m m a L i s t$V0. 5 ,g a m m a L i s t$V1,g a m m a L i s t$V2, ← -g a m m a L i s t$V5,g a m m a L i s t$V10,g a m m a L i s t$V20)
new.df.A_f u n c t i o n s_g a m m a 2 < data.frame(a v e r s i o n.df.A_f u n c t i o n s$A1_tau. 2 ,a v e r s i o n← -.df.A_f u n c t i o n s$A2_tau. 2 ,a v e r s i o n.df.A_f u n c t i o n s$v. 2 )
new.df.b2 < data.frame(a v e r s i o n.df.b2)
# S e l e c t i n g time p e r i o d s
new.SW < a v e r s i o n.df.s2[c( 2 , 3 0 ) , 1 : 6 ] new.BW < a v e r s i o n.df.b2[c( 2 , 3 0 ) , 1 : 6 ] new.HE < a v e r s i o n.df.h e d g e[c( 2 , 3 0 ) , 1 : 6 ]
new.BT < a v e r s i o n.df.b o n d t e r m s[ (c( 1 , 1 0 , 2 0 , 3 0 ) ) , 1 : 5 ]
# D e f i n i n g new dataframes RA.SW < new.SW[ 1 : 2 , ] RA.BW < new.BW[ 1 : 2 , ] RA.HE < new.HE[ 1 : 2 , ] RA.BT < new.BT[ 1 : 4 , ]
#Creating a Bond Table with decomposed terms BT. 0 5 < a v e r s i o n.df.b o n d t e r m s[ (c( 2 , 3 0 ) ) , 1 : 5 ] BT. 1 < a v e r s i o n.df.b o n d t e r m s[ (c( 2 , 3 0 ) ) , 6 : 1 0 ] BT. 2 < a v e r s i o n.df.b o n d t e r m s[ (c( 2 , 3 0 ) ) , 1 1 : 1 5 ] BT. 5 < a v e r s i o n.df.b o n d t e r m s[ (c( 2 , 3 0 ) ) , 1 6 : 2 0 ] BT. 1 0 < a v e r s i o n.df.b o n d t e r m s[ (c( 2 , 3 0 ) ) , 2 1 : 2 5 ] BT. 2 0 < a v e r s i o n.df.b o n d t e r m s[ (c( 2 , 3 0 ) ) , 2 6 : 3 0 ]
colnames(BT. 0 5 ) < c(" f i r s t ","2nd", " hedge ", "A1", "A2") colnames(BT. 1 ) < c(" f i r s t ","2nd", " hedge ", "A1", "A2") colnames(BT. 2 ) < c(" f i r s t ","2nd", " hedge ", "A1", "A2") colnames(BT. 5 ) < c(" f i r s t ","2nd", " hedge ", "A1", "A2") colnames(BT. 1 0 ) < c(" f i r s t ","2nd", " hedge ", "A1", "A2") colnames(BT. 2 0 ) < c(" f i r s t ","2nd", " hedge ", "A1", "A2") BT.t a b l e < rbind(BT. 0 5 ,BT. 1 ,BT. 2 ,BT. 5 ,BT. 1 0 ,BT. 2 0 )
BT.t a b l e.l a t e x < s t a r g a z e r(BT.table, summary = F A L S E)
#Creating a t a b l e f o r comparison between the models dim(RA.SW) = c(l e n g t h(RA.SW) , 1)
dim(RA.BW) = c(l e n g t h(RA.BW) , 1) dim(RA.HE) = c(l e n g t h(RA.HE) , 1)
SW.df < t(RA.SW) BW.df < t(RA.BW) HE.df < t(RA.HE)
SW.t1.df < data.frame(SW.df[ , 1 ] ) SW.t30.df < data.frame(SW.df[ , 2 ] ) colnames(SW.t1.df) < c(" Stocks ") colnames(SW.t30.df) < c(" Stocks ")
BW.t1.df < data.frame(BW.df[ , 1 ] ) BW.t30.df < data.frame(BW.df[ , 2 ] ) colnames(BW.t1.df) < c("Bonds") colnames(BW.t30.df) < c("Bonds")
HE.t1.df < data.frame(HE.df[ , 1 ] ) HE.t30.df < data.frame(HE.df[ , 2 ] ) colnames(HE.t1.df) < c("Hedge") colnames(HE.t30.df) < c("Hedge")
SW.rbind < rbind(SW.t1.df,SW.t30.df) BW.rbind < rbind(BW.t1.df,BW.t30.df) HE.rbind < rbind(HE.t1.df,HE.t30.df) C a s h.df < 1 SW.rbind BW.rbind colnames( .df) < c("Cash")
new.t a b l e.PF < cbind(SW.rbind,BW.rbind,HE.rbind,C a s h.df) new.t a b l e.PF.df < new.t a b l e.PF
#Table S o l u t i o n
PF.t a b l e.l a t e x < s t a r g a z e r(new.t a b l e.PF, summary = F A L S E)
#Labeling to p r i n t
rownames(BW.df) = colnames(RA.BW) rownames(SW.df) = colnames(RA.BW) rownames(HE.df) = colnames(RA.HE) rownames(SW.df) = c( 0 . 5 , 1 , 2 , 5 , 1 0 , 2 0 ) rownames(BW.df) = c( 0 . 5 , 1 , 2 , 5 , 1 0 , 2 0 ) rownames(HE.df) = c( 0 . 5 , 1 , 2 , 5 , 1 0 , 2 0 )
SW.df # Stocks at T= 1 and T=30 BW.df # Bonds
HE.df # Hegde term
######################################################
####### ( i i i ) Figure 6 . 3 and Fiure 6 . 4 ###############
######################################################
h e a d(a v e r s i o n.df.b1) h e a d(a v e r s i o n.df.b2)
# Bond Plot f o r RA = 1 #
b o n d.p l o t. 1 < g g p l o t(a v e r s i o n.df.b1, aes(x = t, y = g a m m a L i s t$O1, c o l = " blue ") ,← -s i z e = 1 . 2 ) +
g e o m_l i n e( ) +
g e o m_l i n e(aes(y = g a m m a L i s t$B1, c o l = " darkblue ") , s i z e = 1 . 2 ) +
g e o m_r i b b o n(aes(x = t, y m a x=g a m m a L i s t$B1, y m i n=g a m m a L i s t$O1, l i n e t y p e = NA) , ← -f i l l=" pink ", a l p h a=.3) +
c o o r d_c a r t e s i a n(x l i m = c( 0 , 3 0 ) , y l i m = c( 0 . 2 5 , 0 . 7 5 ) ) + s c a l e_x_c o n t i n u o u s(" Years ") +
s c a l e_y_c o n t i n u o u s(" Fraction Of Wealth") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c("Bonds M1", "Bonds M2" ) , ← -v a l u e s = c(" blue ", " darkblue ") ) +
l a b s(t i t l e=" ( a ) Risk Aversion = 1") + t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = e l e m e n t_b l a n k( ) , a x i s.t e x t.x=e l e m e n t_t e x t(s i z e=8) , a x i s.t i t l e.x=e l e m e n t_t e x t(s i z e=8) , a x i s.t e x t.y=e l e m e n t_t e x t(s i z e=8) , a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=8) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=9, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n= "none", # c ( 0 . 4 , 0 . 8 ) , legend.key.s i z e = u n i t( 0 . 3 5 ,"cm") , legend.t e x t = e l e m e n t_t e x t(s i z e = 7) , legend.d i r e c t i o n = " v e r t i c a l ",
legend.key.s i z e = u n i t( 2 , "cm") ,
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=" t r a n s p a r e n t ") ) b o n d.p l o t. 1
# Bond Plot f o r RA = 2 #
b o n d.p l o t. 2 < g g p l o t(a v e r s i o n.df.b1, aes(x = t, y = g a m m a L i s t$O2, c o l = " blue ") ,← -s i z e = 1 . 2 ) +
g e o m_l i n e( ) +
g e o m_l i n e(aes(y = g a m m a L i s t$B2, c o l = " darkblue ") , s i z e = 1 . 2 ) +
g e o m_r i b b o n(aes(x = t, y m a x=g a m m a L i s t$B2, y m i n=g a m m a L i s t$O2, l i n e t y p e = NA) , ← -f i l l=" pink ", a l p h a=.3) +
c o o r d_c a r t e s i a n(x l i m = c( 0 , 3 0 ) , y l i m = c( 1 . 5 , 4 . 5 ) ) + s c a l e_x_c o n t i n u o u s(" Years ") +
s c a l e_y_c o n t i n u o u s(" Fraction Of Wealth") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c("Bonds M1", "Bonds M2" ) , ← -v a l u e s = c(" blue ", " darkblue ") ) +
l a b s(t i t l e=" ( a ) Risk Aversion = 2") + t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = e l e m e n t_b l a n k( ) , a x i s.t e x t.x=e l e m e n t_t e x t(s i z e=8) , a x i s.t i t l e.x=e l e m e n t_t e x t(s i z e=8) , a x i s.t e x t.y=e l e m e n t_t e x t(s i z e=8) , a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=8) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=9, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n= "none", # c ( 0 . 4 , 0 . 8 ) , legend.key.s i z e = u n i t( 0 . 3 5 ,"cm") , legend.t e x t = e l e m e n t_t e x t(s i z e = 7) , legend.d i r e c t i o n = " v e r t i c a l ",
legend.key.s i z e = u n i t( 2 , "cm") ,
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=" t r a n s p a r e n t ") ) b o n d.p l o t. 2
# Bond Plot f o r RA = 5 #
b o n d.p l o t. 5 < g g p l o t(a v e r s i o n.df.b1, aes(x = t, y = g a m m a L i s t$O5, c o l = " blue ") ,← -s i z e = 1 . 2 ) +
g e o m_l i n e( ) +
g e o m_l i n e(aes(y = g a m m a L i s t$B5, c o l = " darkblue ") , s i z e = 1 . 2 ) +
g e o m_r i b b o n(aes(x = t, y m a x=g a m m a L i s t$B5, y m i n=g a m m a L i s t$O5, l i n e t y p e = NA) , ← -f i l l=" pink ", a l p h a=.3) +
c o o r d_c a r t e s i a n(x l i m = c( 0 , 3 0 ) , y l i m = c( 1 . 5 , 4 ) ) + s c a l e_x_c o n t i n u o u s(" Years ") +
s c a l e_y_c o n t i n u o u s(" Fraction Of Wealth") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c("Bonds M1", "Bonds M2" ) , ← -v a l u e s = c(" blue ", " darkblue ") ) +
l a b s(t i t l e=" ( b ) Risk Aversion = 5") + t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = _ ( ) ,
a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=8) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=9, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n="none", # c ( 0 . 4 , 0 . 8 ) , legend.key.s i z e = u n i t( 0 . 3 5 ,"cm") ,
legend.t e x t = e l e m e n t_t e x t(s i z e = 7) , legend.d i r e c t i o n = " v e r t i c a l ",
legend.key.s i z e = u n i t( 2 , "cm") ,
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=" t r a n s p a r e n t ") ) b o n d.p l o t. 5
# Bond Plot f o r RA = 10 #
b o n d.p l o t. 1 0 < g g p l o t(a v e r s i o n.df.b1, aes(x = t, y = g a m m a L i s t$O10, c o l = " blue "← -) , s i z e = 1 . 2 ) +
g e o m_l i n e( ) +
g e o m_l i n e(aes(y = g a m m a L i s t$B10, c o l = " darkblue ") , s i z e = 1 . 2 ) +
g e o m_r i b b o n(aes(x = t, y m a x=g a m m a L i s t$B10, y m i n=g a m m a L i s t$O10, l i n e t y p e = NA) , ← -f i l l=" pink ", a l p h a=.3) +
c o o r d_c a r t e s i a n(x l i m = c( 0 , 3 0 ) , y l i m = c( 1 . 5 , 4 ) ) + s c a l e_x_c o n t i n u o u s(" Years ") +
s c a l e_y_c o n t i n u o u s(" Fraction Of Wealth") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c("Bonds M1", "Bonds M2" ) , ← -v a l u e s = c(" blue ", " darkblue ") ) +
l a b s(t i t l e=" ( c ) Risk Aversion = 10") + t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = e l e m e n t_b l a n k( ) , a x i s.t e x t.x=e l e m e n t_t e x t(s i z e=8) , a x i s.t i t l e.x=e l e m e n t_t e x t(s i z e=8) , a x i s.t e x t.y=e l e m e n t_t e x t(s i z e=8) , a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=8) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=9, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n= "none", # c ( 0 . 4 , 0 . 8 ) , legend.key.s i z e = u n i t( 0 . 3 5 ,"cm") , legend.t e x t = e l e m e n t_t e x t(s i z e = 7) , legend.d i r e c t i o n = " v e r t i c a l ",
legend.key.s i z e = u n i t( 2 , "cm") ,
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=" t r a n s p a r e n t ") ) b o n d.p l o t. 1 0
# Bond Plot f o r RA = 20 #
b o n d.p l o t. 2 0 < g g p l o t(a v e r s i o n.df.b1, aes(x = t, y = g a m m a L i s t$O20, c o l = " blue "← -) , s i z e = 1 . 2 ) +
g e o m_l i n e( ) +
g e o m_l i n e(aes(y = g a m m a L i s t$B20, c o l = " darkblue ") , s i z e = 1 . 2 ) +
g e o m_r i b b o n(aes(x = t, y m a x=g a m m a L i s t$B20, y m i n=g a m m a L i s t$O20, l i n e t y p e = NA) , ← -f i l l=" pink ", a l p h a=.5) +
c o o r d_c a r t e s i a n(x l i m = c( 0 , 3 0 ) , y l i m = c( 1 . 5 , 4 ) ) + s c a l e_x_c o n t i n u o u s(" Years ") +
s c a l e_y_c o n t i n u o u s(" Fraction Of Wealth") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c("Bonds M1", "Bonds M2" ) , ← -v a l u e s = c(" blue ", " darkblue ") ) +
l a b s(t i t l e=" ( d ) Risk Aversion = 20") +
t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = e l e m e n t_b l a n k( ) , a x i s.t e x t.x=e l e m e n t_t e x t(s i z e=8) , a x i s.t i t l e.x=e l e m e n t_t e x t(s i z e=8) , a x i s.t e x t.y=e l e m e n t_t e x t(s i z e=8) , a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=8) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=9, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n= "none", #c ( 0 . 4 , 0 . 8 ) , legend.key.s i z e = u n i t( 0 . 3 5 ,"cm") , legend.t e x t = e l e m e n t_t e x t(s i z e = 7) , legend.d i r e c t i o n = " v e r t i c a l ",
legend.key.s i z e = u n i t( 2 , "cm") ,
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=" t r a n s p a r e n t ") ) b o n d.p l o t. 2 0
#A l l p l o t s
g r i d.a r r a n g e(b o n d.p l o t. 2 , b o n d.p l o t. 5 , nrow = 1 , n c o l = 2) g r i d.a r r a n g e(b o n d.p l o t. 1 0 , b o n d.p l o t. 2 0 , nrow = 1 , n c o l = 2)
##########################################################
#( i i i ) Figure 6 . 3 and Fiure 6 . 4
g r i d.a r r a n g e(b o n d.p l o t. 2 , b o n d.p l o t. 5 , b o n d.p l o t. 1 0 , b o n d.p l o t. 2 0 , nrow = 2 , n c o l←
-= 2)
##########################################################
##########################################################
### STOCKS ###
##########################################################
#RA = 2
s t o c k.p l o t. 2 < g g p l o t(a v e r s i o n.df.s2, aes(x = t, y = g a m m a L i s t$G2) ) + g e o m_l i n e(aes(c o l = " red ") , s i z e = 1) +
g e o m_l i n e(aes(y = g a m m a L i s t$A2, c o l = " darkred ") , s i z e = 1 , l i n e t y p e = 2) + c o o r d_c a r t e s i a n(x l i m = c( 0 , 3 0 ) ) +
s c a l e_x_c o n t i n u o u s(" Years ") +
s c a l e_y_c o n t i n u o u s(" Fraction o f Wealth") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c(" Stocks M1", " Stocks M2" ) , ← -v a l u e s = c(" red ", " darkred ") ) +
l a b s(t i t l e=" ( a ) Risk Aversion = 2") + t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = e l e m e n t_b l a n k( ) , a x i s.t e x t.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t i t l e.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t e x t.y=e l e m e n t_t e x t(s i z e=8) , a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=8) ,
p l o t.t i t l e= _t e x t( =9, =" black ") ,
legend.t e x t = e l e m e n t_t e x t(s i z e = 7) , legend.d i r e c t i o n = " v e r t i c a l ",
legend.key.s i z e = u n i t( 2 , "cm") ,
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=" t r a n s p a r e n t ") )
#RA = 5
s t o c k.p l o t. 5 < g g p l o t(a v e r s i o n.df.s2, aes(x = t, y = g a m m a L i s t$G5) ) + g e o m_l i n e(aes(c o l = " red ") , s i z e = 1) +
g e o m_l i n e(aes(y = g a m m a L i s t$A5, c o l = " darkred ") , s i z e = 1 , l i n e t y p e = 2) + c o o r d_c a r t e s i a n(x l i m = c( 0 , 3 0 ) ) +
s c a l e_x_c o n t i n u o u s(" Years ") +
s c a l e_y_c o n t i n u o u s(" Fraction o f Wealth") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c(" Stocks M1", " Stocks M2" ) , ← -v a l u e s = c(" red ", " darkred ") ) +
l a b s(t i t l e=" ( b ) Risk Aversion = 5") + t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = e l e m e n t_b l a n k( ) , a x i s.t e x t.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t i t l e.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t e x t.y=e l e m e n t_t e x t(s i z e=8) , a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=8) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=9, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n= c( 0 . 4 , 0 . 6 5 ) , legend.key.s i z e = u n i t( 0 . 3 5 ,"cm") , legend.t e x t = e l e m e n t_t e x t(s i z e = 7) , legend.d i r e c t i o n = " v e r t i c a l ",
legend.key.s i z e = u n i t( 2 , "cm") ,
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=" t r a n s p a r e n t ") )
#RA = 10
s t o c k.p l o t. 1 0 < g g p l o t(a v e r s i o n.df.s2, aes(x = t, y = g a m m a L i s t$G10) ) + g e o m_l i n e(aes(c o l = " red ") , s i z e = 1) +
g e o m_l i n e(aes(y = g a m m a L i s t$A10, c o l = " darkred ") , s i z e = 1 , l i n e t y p e = 2) + c o o r d_c a r t e s i a n(x l i m = c( 0 , 3 0 ) ) +
s c a l e_x_c o n t i n u o u s(" Years ") +
s c a l e_y_c o n t i n u o u s(" Fraction o f Wealth") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c(" Stocks M1", " Stocks M2" ) , ← -v a l u e s = c(" red ", " darkred ") ) +
l a b s(t i t l e=" ( c ) Risk Aversion = 10") + t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = e l e m e n t_b l a n k( ) , a x i s.t e x t.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t i t l e.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t e x t.y=e l e m e n t_t e x t(s i z e=8) , a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=8) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=9, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n= c( 0 . 4 , 0 . 6 5 ) ,
legend.key.s i z e = u n i t( 0 . 3 5 ,"cm") , legend.t e x t = e l e m e n t_t e x t(s i z e = 7) , legend.d i r e c t i o n = " v e r t i c a l ",
legend.key.s i z e = u n i t( 2 , "cm") ,
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=" t r a n s p a r e n t ") )
## RA = 20
s t o c k.p l o t. 2 0 < g g p l o t(a v e r s i o n.df.s2, aes(x = t, y = g a m m a L i s t$G20) ) + g e o m_l i n e(aes(c o l = " red ") , s i z e = 1) +
g e o m_l i n e(aes(y = g a m m a L i s t$A20, c o l = " darkred ") , s i z e = 1 , l i n e t y p e = 2) + c o o r d_c a r t e s i a n(x l i m = c( 0 , 3 0 ) ) +
s c a l e_x_c o n t i n u o u s(" Years ") +
s c a l e_y_c o n t i n u o u s(" Fraction o f Wealth") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c(" Stocks M1", " Stocks M2" ) , ← -v a l u e s = c(" red ", " darkred ") ) +
l a b s(t i t l e=" ( d ) Risk Aversion = 20") + t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = e l e m e n t_b l a n k( ) , a x i s.t e x t.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t i t l e.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t e x t.y=e l e m e n t_t e x t(s i z e=8) , a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=8) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=9, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n= c( 0 . 4 , 0 . 6 5 ) , legend.key.s i z e = u n i t( 0 . 3 5 ,"cm") , legend.t e x t = e l e m e n t_t e x t(s i z e = 7) , legend.d i r e c t i o n = " v e r t i c a l ",
legend.key.s i z e = u n i t( 2 , "cm") ,
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=" t r a n s p a r e n t ") )
g r i d.a r r a n g e(s t o c k.p l o t. 2 , s t o c k.p l o t. 5 , s t o c k.p l o t. 1 0 , s t o c k.p l o t. 2 0 , nrow = 2 , ← -n c o l = 2)
##########################################################
######################################################################
### Program 8 Loss f u n c t i o n f o r constant investment o p p o r t u n i t i e s ##
######################################################################
#Content
#( i ) Loss f u n c t i o n f o r r i s k a v e r s i o n f o r Figure 7 . 1
#( i i ) Loss f u n c t i o n f o r time h o ri zo n f o r Figure 7 . 1
#Packages
r e q u i r e(g g p l o t 2)
####################################################################
#Loss f u n c t i o n Gamma
l o s s.f u n c t i o n.gamma.df < data.frame(l o s s_f u n c t i o n_c o n s t a n t 1) ( .f u n c t i o n.gamma.df)
g e o m_l i n e(aes(x = pi, y = gamma_2 , c o l = " red ") , s i z e = 1) + g e o m_l i n e(aes(x = pi, y = gamma_3 , c o l = " green ") , s i z e = 1) + g e o m_l i n e(aes(x = pi, y = gamma_6 , c o l = " purple ") , s i z e = 1) + s c a l e_x_c o n t i n u o u s(" Fraction o f Risky Assets ") +
s c a l e_y_c o n t i n u o u s(" Welfare Loss (%)") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c("RRA = 1", "RRA = 2","RRA = 3","← -RRA = 6") , v a l u e s = c(" blue ", " red ", " green ", " purple ") ) +
l a b s(t i t l e=" ( a ) Time = 10") + t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = e l e m e n t_b l a n k( ) , a x i s.t e x t.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t i t l e.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t e x t.y=e l e m e n t_t e x t(s i z e=9) , a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=9) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=9, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n= c( 0 . 1 4 , 0 . 5 ) , legend.key.s i z e = u n i t( 0 . 3 ,"cm") , legend.t e x t = e l e m e n t_t e x t(s i z e = 9) , legend.d i r e c t i o n = " v e r t i c a l ",
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=a l p h a(' white ', 0 . 4 ) ) )
#Loss f u n c t i o n Time
l o s s.f u n c t i o n.time.df < data.frame(l o s s_f u n c t i o n_c o n s t a n t 2) h e a d(l o s s.f u n c t i o n.time.df)
l o s s.con.time < g g p l o t(l o s s.f u n c t i o n.time.df) +
g e o m_l i n e(aes(x = pi, y = time_1 , c o l = " blue ") , s i z e = 1) + g e o m_l i n e(aes(x = pi, y = time_10 , c o l = " red ") , s i z e = 1) + g e o m_l i n e(aes(x = pi, y = time_20 , c o l = " green ") , s i z e = 1) + g e o m_l i n e(aes(x = pi, y = time_30 , c o l = " purple ") , s i z e = 1) + c o o r d_c a r t e s i a n(x l i m = c( 0 , 2 ) , y l i m = c( 0 , 1 ) ) +
s c a l e_x_c o n t i n u o u s(" Fraction o f Risky Assets ") + s c a l e_y_c o n t i n u o u s(" Welfare Loss (%)") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c("T = 1", "T = 10","T = 20","T = ← -30") , v a l u e s = c(" blue ", " red ", " green ", " purple ") ) +
l a b s(t i t l e=" ( b ) Risk Aversion = 2") + t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = e l e m e n t_b l a n k( ) , a x i s.t e x t.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t i t l e.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t e x t.y=e l e m e n t_t e x t(s i z e=9) , a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=9) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=9, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n= c( 0 . 1 3 , 0 . 5 ) , legend.key.s i z e = u n i t( 0 . 3 ,"cm") , legend.t e x t = e l e m e n t_t e x t(s i z e = 9) , legend.d i r e c t i o n = " v e r t i c a l ",
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=a l p h a(' white ', 0 . 4 ) ) ) g r i d.a r r a n g e(l o s s.con.gamma, l o s s.con.time, nrow = 2 , n c o l =1)
###########################################################
### Program 9 Loss f u n c t i o n between model 1 and model 2##
###########################################################
#Content
#( i ) Figure 7 . 2 Loss f u n c t i o n f o r model and model 2
#Packages
r e q u i r e(g g p l o t 2) r e q u i r e(g r i d E x t r a)
#Load Excel f i l e
l o s s.f u n c t i o n.df < data.frame(l o s s_f u n c t i o n_2) h e a d(l o s s.f u n c t i o n.df)
t a i l(l o s s.f u n c t i o n.df)
#Plot f o r RA=2
p l o t.l o s s.rv2 < g g p l o t(l o s s.f u n c t i o n.df, aes(x = time, y = l o s s_g2) ) + g e o m_l i n e(c o l= " red ", s i z e = 1) +
c o o r d_c a r t e s i a n(x l i m = c( 0 , 3 0 ) , y l i m = c( 0 , 8 0 ) ) + s c a l e_x_c o n t i n u o u s(" Years ") +
s c a l e_y_c o n t i n u o u s(" Welfare Loss (%) ") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c(" Loss " ) , v a l u e s = c(" red ") ) + l a b s(t i t l e=" ( a ) Risk Aversion = 2") +
t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = e l e m e n t_b l a n k( ) , a x i s.t e x t.x=e l e m e n t_t e x t(s i z e=7) , a x i s.t i t l e.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t e x t.y=e l e m e n t_t e x t(s i z e=7) , a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=9) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=8, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n= c( 1 . 0 2 4 9 , 0 . 8 4 5 ) , legend.key.s i z e = u n i t( 0 . 3 ,"cm") , legend.t e x t = e l e m e n t_t e x t(s i z e = 6) , legend.d i r e c t i o n = " h o r i z o n t a l ",
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=a l p h a(' white ', 0 . 4 ) ) )
#Plot f o r RA=5
p l o t.l o s s.rv5 < g g p l o t(l o s s.f u n c t i o n.df, aes(x = time, y = l o s s_g5) ) + g e o m_l i n e(c o l= " red ", s i z e = 1) +
c o o r d_c a r t e s i a n(x l i m = c( 0 , 3 0 ) , y l i m = c( 0 , 5 ) ) + s c a l e_x_c o n t i n u o u s(" Years ") +
s c a l e__ (" Welfare Loss (%)") +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = e l e m e n t_b l a n k( ) , a x i s.t e x t.x=e l e m e n t_t e x t(s i z e=7) , a x i s.t i t l e.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t e x t.y=e l e m e n t_t e x t(s i z e=7) , a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=9) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=8, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n= c( 1 . 0 2 4 9 , 0 . 8 4 5 ) , legend.key.s i z e = u n i t( 0 . 3 ,"cm") , legend.t e x t = e l e m e n t_t e x t(s i z e = 6) , legend.d i r e c t i o n = " h o r i z o n t a l ",
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=a l p h a(' white ', 0 . 4 ) ) )
#Plot f o r RA=10
p l o t.l o s s.r v 1 0 < g g p l o t(l o s s.f u n c t i o n.df, aes(x = time, y = l o s s_g10) ) + g e o m_l i n e(c o l= " red ", s i z e = 1) +
c o o r d_c a r t e s i a n(x l i m = c( 0 , 3 0 ) , y l i m = c( 0 , 1 . 5 ) ) + s c a l e_x_c o n t i n u o u s(" Years ") +
s c a l e_y_c o n t i n u o u s(" Welfare Loss (%)") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c(" Loss " ) , v a l u e s = c(" red ") ) + l a b s(t i t l e=" ( c ) Risk Aversion = 10") +
t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = e l e m e n t_b l a n k( ) , a x i s.t e x t.x=e l e m e n t_t e x t(s i z e=7) , a x i s.t i t l e.x=e l e m e n t_t e x t(s i z e=9) , a x i s.t e x t.y=e l e m e n t_t e x t(s i z e=7) , a x i s.t i t l e.y=e l e m e n t_t e x t(s i z e=9) ,
p l o t.t i t l e=e l e m e n t_t e x t(s i z e=8, c o l o r=" black ") , legend.j u s t i f i c a t i o n=c( 1 , 0 ) ,
legend.p o s i t i o n= c( 1 . 0 2 4 9 , 0 . 8 4 5 ) , legend.key.s i z e = u n i t( 0 . 3 ,"cm") , legend.t e x t = e l e m e n t_t e x t(s i z e = 6) , legend.d i r e c t i o n = " h o r i z o n t a l ",
legend.b a c k g r o u n d = e l e m e n t_r e c t(f i l l=a l p h a(' white ', 0 . 4 ) ) )
#Plot f o r RA=20
p l o t.l o s s.r v 2 0 < g g p l o t(l o s s.f u n c t i o n.df, aes(x = time, y = l o s s_g20) ) + g e o m_l i n e(c o l= " red ", s i z e = 1) +
c o o r d_c a r t e s i a n(x l i m = c( 0 , 3 0 ) , y l i m = c( 0 , 1 . 5 ) ) + s c a l e_x_c o n t i n u o u s(" Years ") +
s c a l e_y_c o n t i n u o u s(" Welfare Loss (%)") +
s c a l e_c o l o r_m a n u a l("Legend T i t l e \n",l a b e l s = c(" Loss " ) , v a l u e s = c(" red ") ) + l a b s(t i t l e=" ( d ) Risk Aversion = 20") +
t h e m e_bw( ) +
t h e m e(panel.b a c k g r o u n d = e l e m e n t_r e c t(c o l o u r = " black ", s i z e=1.5) , a x i s.t i c k s = e l e m e n t_l i n e(c o l o r = " black ") ,
panel.g r i d.m a j o r = e l e m e n t_l i n e(c o l o r = " grey ", l i n e t y p e = " dotted ") , panel.g r i d.m i n o r = e l e m e n t_b l a n k( ) ,
legend.t i t l e = e l e m e n t_b l a n k( ) ,