September 24th, 2004, 11:49 am
Thanks Aaron. I have some problem calculating 'theta' of HW model. Frankly I dont know how to calculate it. I tried out in VBA. I am not sure where am I going wrong. Can anyone help me?Here is the main code without declations etc.,'------------------------------------Function max2(in1 As Double, in2 As Double) As Double' A function to calculate the maximum value between two given inputs in1 and in2 If (in1 >= in2) Then max2 = in1 Else max2 = in2 End IfEnd Function'------------------------------------Function dr1(fn_plus As Double, fn_minus As Double, delta As Double) As Double' A function to calculate the first derivative value at given point dr1 = (fn_plus - fn_minus) / 2 * deltaEnd Function'------------------------------------Sub mix_mc() Const num_yield = 50 dt = maturity / time_nodes sdt = Sqr(dt) 'Calculation of 1 Year forwardrate(0,t) from yield y(i) For i = 1 To num_yield - 1 fwd(i) = (i + 1) * y(i + 1) - i * y(i) Next i 'Calculation of theta(i) theta(1) = mr_mean / mr_rate For i = 1 To num_yield - 1 ' # NOTE: have to add the derivative of forward rate later theta(i + 1) = mr_rate * fwd(i) + (hw_vol ^ 2 * (1 - Exp(-2 * mr_rate * i))) / 2 * mr_rate Next i 'Calculation of mc_hw(i,j) For i = 1 To num_sim For j = 1 To time_nodes randns = Application.NormSInv(Rnd) If j = 1 Then mc_hw(i, 1) = ini_int_rate Else mc_hw(i, j) = mc_hw(i, j - 1) + (theta(j) - mr_rate * mc_hw(i, j - 1)) * dt + randns * hw_vol * sdt 'mc_hw(i, j) = mc_hw(i, j - 1) + mr_rate * ((mr_mean / mr_rate) - mc_hw(i, j - 1)) * dt + randns * hw_vol * sdt End If Next j Next i 'Calculation of mc_mix(i,j) For i = 1 To num_sim For j = 1 To time_nodes randns = Application.NormSInv(Rnd) If j = 1 Then mc_mix(i, 1) = ini_sto_prc Else ' substituting hw rate in GBM mc_mix(i, j) = mc_mix(i, j - 1) * Exp((mc_hw(i, j) * dt) + randns * gbm_vol * sdt) End If Next j call_payoff(i) = max2((mc_mix(i, time_nodes) - str_pr), 0) put_payoff(i) = max2(0, (str_pr - mc_mix(i, time_nodes))) Next i 'Calculation of Call Value call_temp = 0 For i = 1 To num_sim call_temp = call_temp + call_payoff(i) Next i call_value = Exp(-1 * ini_int_rate * maturity) * (call_temp / num_sim) 'Calculation of Put Value put_temp = 0 For i = 1 To num_sim put_temp = put_temp + put_payoff(i) Next i put_value = Exp(-1 * ini_int_rate * maturity) * (put_temp / num_sim)End Sub'------------------------------------