#March 23, 2015; Multiperiod Binary Model Help:=proc(): print(` FL(S0,Sd,Su,r,dt,C), FLv(S0,Sd,Su,r,dt,C)`): print(` RandH(S0,r,dt,k,UB) `): end: #FL(S0,Sd,Su,r,dt,C): inputs S0=current price of the stock #Sd, Su, the future price (in time dt) of the stock #Sd1 then print(`Either open a saving account or buy the stock`): print(`no point for options`): fi: print(`Just for your information (but you don't need it)`): print(`The so-called risk-neutral prob. of the stock going up`): print(` is `, q): P:=q*exp(-r*dt)*C[2]+ (1-q)*exp(-r*dt)*C[1]: print(`The fair price of the option is`, P): phi:=(C[2]-C[1])/(Su-Sd): psi:=P-phi*S0: print(`In order to guarantee meeting your claim you should`): print(`purchase`, phi, `units of stock, and`): if psi<0 then print(`borrow `, -psi, `dollars from the bank `): else print(`deposit `, psi, `dollars in the bank`): fi: [q,P,phi,psi]: end: #[t,a]: t time, and a is the code-word for the sequence of #d, u in binary #[t,a]->[t+1,2*a],[t+1,2*a+1] #generation 0 [0,0] #generation 1 [1,0],[1,1] #generation k, [k,0], ..[k, 2^k-1] #a stock history is a list of lists #[H[0],H[1],...,H[k]] #where H[i][j] is the price of the stock at time i #with history code-word j #RandH(S0,r,dt,k,UB) RandH:=proc(S0,r,dt,k,UB) local H,i,j,Sc,Sd,Su: H[0]:=[S0]: for i from 1 to k do H[i]:=[]: for j from 1 to nops(H[i-1]) do Sc:=H[i-1][j]: Sd:=rand(0..trunc(Sc*exp(r*dt))-1 )(): Su:=rand(trunc(Sc*exp(r*dt))+1.. UB*Sc)(): H[i]:=[op(H[i]), Sd,Su]: od: od: [seq(H[i],i=0..k)]: end: #PO(H,r,dt,C): inputs a possible stock-price history #r and dt as above and C the claims at the nops(H)-1 generation #and outputs the respective foursome #[q,P,phi,psi] For every node of the tree P0:=proc(H,r,dt) local i,P: end: