September 26th, 2015, 5:47 pm
I have written the following python code to price a european call option. I get reasonable agreement with an online option calculator for the price, but the delta is quite a bit off. As far as I understand, I simulate a random walk, calculate the pay-off, present value the payoff, and then do lots of such simulations and take the average to get the price of the option. In order to calculate the delta, I simulate two paths, where the second path starts at a price [$] S + \Delta S [$], but the random number has to be the same. Can anyone confirm the correctness of the following pseudo python code? This is not the exact code, it just contains the essence of the algorithm. strike = 105r = 0.05sigma = 0.2time_to_expiry = 2time_step = 0.01N = time_to_expiry/time_stepdS = 0.5S[0] = 100S2[0] = S[0] + 2*dSfor i in xrange(1, N): S_current = S[i-1] S2_current = S2[i-1] #Draw a random number from a normal distribution with mean 0 and variance 1 rand = np.random.normal(loc=0.0, scale=1.0) #Euler discretisation of risk-neutral random walk S = S_current*(1 + dt*r + sigma*np.sqrt(dt)*rand) S2 = S2_current*(1 + dt*r + *sigma*np.sqrt(dt)*rand) S_call_payoff = max(S[N-1] - strike, 0) S_put_payoff = max(strike - S[N-1], 0) #Calculate greeks S2_call_payoff = max(S2[N-1] - strike,0)S2_put_payoff = max(strike - S2[N-1],0)call_delta = (S2_call_payoff - S_call_payoff)/(2*dS)put_delta = (S2_put_payoff - S_put_payoff)/(2*dS) call_price = np.exp(-r*(time_to_expiry))*S_call_payoffput_price = np.exp(-r*(time_to_expiry))*S_call_payoffThen one must average over many such simulations. Have I calculated the delta correctly? For the above parameters, an online option calculator gives:Call price: 13.6537, Put price: 8.6486Call delta: 0.6266, Put Delta: -0.3734In contrast, my Monte-Carlo code with 10,000 samples gives:Call price: 14.05, Put price: 8.57Call delta: 0.71, Put Delta: -0.4They're in the right ball-park, but I'm not confident enough to say the code is working correctly. Any help much appreciated.
Last edited by
barny on September 25th, 2015, 10:00 pm, edited 1 time in total.