# C16.txt: March 25, 2013, Procedure DC corrected by Joey Reichert # Wall Street Gambling Help:= proc() print(`N(x); d1(S,t,r,sig,K,T); d2(S,t,r,sig,K,T); C(S,t,r,sig,K,T); PBS(); DC(S,t,r,sig,K,T,n);`): end: # The real error function int(exp(-t^2/2)/sqrt(2*Pi),t=-infinity..x) N:=proc(x) local t: (erf(x/sqrt(2.))+1)/2: end: # d1(S,t,r,sig,K,T) is the quantity featuring in Black-Scholes formula # S = price of stock at some time (t?), # t = time, r = interest rate for no-risk government bond, # sig = volatility, K = strike price (how much you can buy for at T), # T = end of game d1:=proc(S,t,r,sig,K,T) (ln(S/K) + (r+sig^2/2)*(T-t)) / (sig*sqrt(T-t)): end: # d2(S,t,r,sig,K,T) is the other quantity in Black-Scholes formula such that # d2 = d1 - sig*sqrt(T-t). d2:=proc(S,t,r,sig,K,T) d1(S,t,r,sig,K,T) - sig*sqrt(T-t): end: # C(S,t,r,sig,K,T): The value of a European Call option according to the # famous Black-Scholes formula. C:=proc(S,t,r,sig,K,T) N(d1(S,t,r,sig,K,T))*S - N(d2(S,t,r,sig,K,T))*K*exp(-r*(T-t)): end: # PBS(): A completely rigorous proof of the formula that won the Nobel prize PBS:=proc() local S,t,r,sig,K,T,V,BS: V:=C(S,t,r,sig,K,T): evalb(0= expand(diff(V,t) + 1/2 * sig^2 * S^2 * diff(V,S$2) + r*S*diff(V,S) - r*V)): end: # DC(S,t,r,sig,K,T,n): The approximate value (with n dicrete steps) # using the Cox-Ross-Rubinstein discrete version of Black Scholes # of a European Call option according to the # famous Black-Scholes formula. Discrete model. DC:=proc(S,t,r,sig,K,T,n) local u,d,p,i: u:=evalf(exp(sig*sqrt((T-t)/n))): d:=1/u: p:=(exp(r*(T-t)/n)-d)/(u-d): evalf(exp(-r*(T-t)) * add( binomial(n,i)*p^(n-i)*(1-p)^i*max(0,S*u^(n-i)*d^i-K), i=0..n )): end: