1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
|
###########################################################################################################
################################# Définition des paramètres de simulation #################################
###########################################################################################################
NbreScen = 500
Horizon = 16
NbActif = 3
compteur = 0
###########################################################################################################
############################### 2. Taux nominaux ##########################################################
###########################################################################################################
Swaption = read.table("/Volumes/Zone de travail/Sauvegardes stagiaires/Quentin Bazoge (2016)/Données/SwaptionPrix 31122015.csv")
Courbe_ref = read.table("/Volumes/Zone de travail/Sauvegardes stagiaires/Quentin Bazoge (2016)/Données/Courbe des Taux EIOPA 31122015.csv",sep=";")
Courbe_ref$V2 = log(1+Courbe_ref$V2)
forward_marche = read.table("/Volumes/Zone de travail/Sauvegardes stagiaires/Quentin Bazoge (2016)/Données/forward2.csv",sep=";")
Prix_ref = Courbe_ref
Prix_ref$V2 = exp(-Prix_ref$V1*Prix_ref$V2)
forward_marche = forward_marche$V2[-((Horizon+2):length(forward_marche$V2))]
PrixZC_ref = Prix_ref$V2[-((Horizon+1):length(Prix_ref$V2))]
CourbeZC_ref = Courbe_ref$V2[-((Horizon+1):length(Courbe_ref$V2))]
############################# 2. Formule pour les prix ZC######################
# Formule fermée pour les prix ZC donnant P(t,T), le paramètre option sert à l'évaluation des caplet.
B1 =function(t,alpha1)
{
out = (1-exp(-alpha1 * t))/alpha1
return(out)
}
B2 =function(t,alpha1,alpha2)
{
out = (alpha1/(alpha1 - alpha2))*(((1-exp(-alpha2*t))/alpha2)-((1-exp(-alpha1 * t))/alpha1))
return(out)
}
a =function(TauxLong,sigma1,alpha2)
{
out = TauxLong - ((sigma1^2)/(2*alpha1^2))
return(out)
}
b =function(t,sigma1,alpha1)
{
out = (sigma1^2*B1(t,alpha1)^2)/(4*alpha1)
return(out)
}
c1 =function(t,alpha2)
{
out = t/(alpha2^2)
return(out)
}
d =function(t,alpha1,alpha2)
{
out = 2*(B1(t,alpha1)+B2(t,alpha1,alpha2))/(alpha2^2)
return(out)
}
e =function(t,alpha1,alpha2)
{
out = (1-exp(-2*alpha1*t))/(2*alpha1*(alpha1-alpha2)^2)
return(out)
}
f =function(t,alpha1,alpha2)
{
out = (2*alpha1*(1-exp(-t*(alpha1+alpha2))))/(alpha2*(alpha1-alpha2)^2*(alpha1+alpha2))
return(out)
}
g =function(t,alpha1,alpha2)
{
out = (alpha1^2*(1-exp(-2*alpha2*t)))/(2*alpha2^3*(alpha1-alpha2)^2)
return(out)
}
A =function(t,alpha1,alpha2,TauxLong,sigma1,sigma2)
{
out = (B1(t,alpha1)-t)*a(TauxLong,sigma1,alpha2)+B2(t,alpha1,alpha2)*TauxLong-b(t,sigma1,alpha1)+(sigma2^2/2)*(c1(t,alpha2)-d(t,alpha1,alpha2)+e(t,alpha1,alpha2)-f(t,alpha1,alpha2)+g(t,alpha1,alpha2))
return(out)
}
PrixZC = function(t,Horizon,rt,mt,TauxLong,alpha1,alpha2,sigma1,sigma2)
{
PrixZC = exp(A((Horizon-t),alpha1,alpha2,TauxLong,sigma1,sigma2)-B1((Horizon-t),alpha1)*rt-B2((Horizon-t),alpha1,alpha2)*mt)
}
PrixSwaption=function(Maturite,Tenor,K,PrixZC_sto,rt)
{
Taux_swap = vector("numeric",NbreScen)
SommeActu = vector("numeric",NbreScen)
Payoff = vector("numeric",NbreScen)
for(j in 1:NbreScen)
{
Taux_swap[j] = (1-PrixZC_sto[[j]][[Maturite+1]][Tenor])/sum(PrixZC_sto[[j]][[Maturite+1]][1:Tenor])
SommeActu[j] = sum(PrixZC_sto[[j]][[Maturite+1]][1:Tenor])
Payoff[j] = (((Taux_swap[j] - K)>=0)*1)*(Taux_swap[j] - K)*SommeActu[j] * exp(-sum(rt[1:Maturite,j]))
}
PrixSwaption = Payoff
}
Test = function(Num, PrixZC_sto,rt)
{
Test = PrixSwaption(Swaption$Maturite[Num],Swaption$Tenor[Num], Swaption$Strike[Num],PrixZC_sto,rt)
}
############################# 3. Calibrage à la main ######################
# Paramètres Initiaux
#Paramétrage pour le swaption 6 ans
alpha1 =0.14
alpha2 = 0.62
TauxLong = 0.042
sigma1 = 0.033
sigma2 = 0.014
r0 = -0.00157
m0 = 0.005
para = c(alpha1,alpha2,sigma1,sigma2)
minimum = function(para)
{
somme = 0
alpha1 = para[1]
alpha2 = para[2]
sigma1=para[4]
sigma2=para[5]
############################# 4. Génération des scénarios économiques ######################
print(1)
Brownien1 = matrix(nrow = Horizon+1, ncol = NbreScen)
Brownien2 = matrix(nrow = Horizon+1, ncol = NbreScen)
mt = matrix(nrow = Horizon+1, ncol = NbreScen)
rt = matrix(nrow = Horizon+1, ncol = NbreScen)
moyenne_rt = vector("numeric",Horizon+1)
moyenne_mt = vector("numeric",Horizon)
for(j in 1:NbreScen)
{
for(i in 1:(Horizon+1))
{
Brownien1[i,j] = rnorm(1, 0, 1)
Brownien2[i,j] = rnorm(1, 0, 1)
}
}
for(j in 1:NbreScen)
{
mt[1,j] = m0
rt[1,j] = r0
}
for(j in 1:NbreScen)
{
for(i in 2:(Horizon+1))
{
mt[i,j] = alpha2 * TauxLong + mt[i-1,j]*(1-alpha2) + sigma2*Brownien2[i,j]
rt[i,j] = alpha1 * mt[i-1,j]+rt[i-1,j]*(1-alpha1) + sigma1*Brownien1[i,j]
}
}
#############################################
#############################################
#############################################
# Calcul de l'ensemble des prix zéros coupons stochastiques.
PrixZC_sto = list()
for( j in 1 : NbreScen)
{
x = list()
for(t in 0 : 8)
{
P = vector("numeric", (Horizon-t))
for(i in (t+1) : Horizon)
{
P[i-t] = PrixZC(t,i,rt[t+1,j],mt[t+1,j],TauxLong,alpha1,alpha2,sigma1,sigma2)
}
x[[t+1]] = P
}
PrixZC_sto[[j]] = x
}
############################# 7. Pricer de swaption ######################
Prix = vector("numeric", 20)
ListePrix = NULL
for(i in 1:20)
{
ListePrix[[i]] = Test(i,PrixZC_sto,rt)
Prix[i] = mean(ListePrix[[i]])
}
for (i in 4:18)
{
somme = somme + (Prix[i] - Swaption$Prix[i])^2
}
compteur = compteur +1
print(2)
return(somme)
}
u = matrix(c(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),4,4)
c= matrix(c(0,0,0,0))
Calibrage = constrOptim(para, minimum, ui = u, ci = c,method = "SANN" |
Partager