#Nathan Fox #Homework 12 #I give permission for this work to be posted online #Read packages with(`combinat`): #Read procedures from class read(`C12.txt`): #Help procedure Help:=proc(): print(` OP2scr(S1, S2, D11, D12, D13, D21, D22, D23, r, T, C1, C2, C3) `): print(` OP2nice(S1, S2, D11, D12, D13, D21, D22, D23, r, T, C1, C2, C3) `): print(` ExpBuyer2(S1, S2, D11, D12, D13, D21, D22, D23, r, T, C1, C2, C3, q1, q2) `): print(` ExpSeller2(S1, S2, D11, D12, D13, D21, D22, D23, r, T, C1, C2, C3, q1, q2) `): end: ##PROBLEM 2## #OP2scr(S1, S2, D11, D12, D13, D21, D22, D23, r, T, C1, C2, C3) #There are two stocks, 1 and 2, whose current prices are S1 and S2. #Their values in time T in the future depends whether the economy #will be really bad, OK, or really good (there are only three #scenarios). #-If the economy will be really bad, the prices of stock 1 and stock #2 will be D11 and D21 respectively #-If the economy will be OK, the prices of stock 1 and stock 2 will #be D12 and D22 respectively #-If the economy will be great, the prices of stock 1 and stock 2 #will be D13 and D23 respectively # #This procedure calculates the FAIR price (no arbitrage!) of an #option that pays C1 dollars if the economy is bad, C2 dollars if #the economy is OK, and C3 dollars if the economy is great, #assuming inerest rate r. OP2scr:=proc(S1, S2, D11, D12, D13, D21, D22, D23, r, T, C1, C2, C3) local x1, x2, x3, eq, var, P: eq:={x1*exp(r*T)+x2*D11+x3*D21=C1, x1*exp(r*T)+x2*D12+x3*D22=C2, x1*exp(r*T)+x2*D13+x3*D23=C3}: var:={x1, x2, x3}: var:=solve(eq, var): x1:=subs(var, x1): x2:=subs(var, x2): x3:=subs(var, x3): P:=x1+x2*S1+x3*S2: return normal(P), x2, x3: end: ##PROBLEM 3## #OP2nice(S1, S2, D11, D12, D13, D21, D22, D23, r, T, C1, C2, C3): #outputs the same thing as OP2scr, but does it with martingales OP2nice:=proc(S1, S2, D11, D12, D13, D21, D22, D23, r, T, C1, C2, C3) local q1, q2, eq, var: eq:={q1*D11+q2*D12+(1-q1-q2)*D13=exp(r*T)*S1, q1*D21+q2*D22+(1-q1-q2)*D23=exp(r*T)*S2}: var:={q1, q2}: var:=solve(eq, var): q1:=subs(var, q1): q2:=subs(var, q2): return normal(q1*(exp(-r*T)*C1) + q2*(exp(-r*T)*C2) + (1-q1-q2)*(exp(-r*T)*C3)): end: #This gives something equivalent to OP2scr ##PROBLEM 4## #The expected gain to the buyer of the option #if she believes that the probability of the economy going down is #q1, the probability of ok is q1, and the probability of going up #is 1-q1-q2 ExpBuyer2:=proc(S1, S2, D11, D12, D13, D21, D22, D23, r, T, C1, C2, C3, q1, q2) local P: P:=OP2scr(S1, S2, D11, D12, D13, D21, D22, D23, r, T, C1, C2, C3)[1]: return q1*(C1*exp(-r*T)-P)+q2*(C2*exp(-r*T)-P)+(1-q1-q2)*(C3*exp(-r*T)-P): end: #The expected gain to the seller of the option #if he believes that the probability of the stock going up is q #following the do nothing portfolio ExpBuyer2:=proc(S1, S2, D11, D12, D13, D21, D22, D23, r, T, C1, C2, C3, q1, q2) local P: P:=OP2scr(S1, S2, D11, D12, D13, D21, D22, D23, r, T, C1, C2, C3)[1]: return q1*(P-C1*exp(-r*T))+q2*(P-C2*exp(-r*T))+(1-q1-q2)*(P-C3*exp(-r*T)): end: #Yes, they add up to zero