1) Please clearly mention questions (a)or(b) in your solution word not to be confused. 2) Please add explanation/sentences to understand equations. 3) Please use the following equation typing function...

Stochastic calculus/Brownian motion/Ito calculus/Digital Option (Finance product)


1) Please clearly mention questions (a)or(b) in your solution word not to be confused. 2) Please add explanation/sentences to understand equations. 3) Please use the following equation typing function of MS-WORD below (NOT other one such as Math equation 6.0), otherwise I cannot edit the equations of MS-WORD. You send me some of your equation samples to see if I edit them or not. Again, please use this MS-WORD equation function. import numpy as np import matplotlib.pyplot as plt #-------------------- The normal forward step with forward Euler -------------------- def forwardStep( Fk, dt, dx): """Take one forward Euler time step for the heat equation. \partial_t F + (1./2) \partial_x^2 F = 0 Fk = solution at time t_k, a numpy array with Fk[0] and Fk[n+1] boundary values dx = space step size dt = time step size. Must have dt <= dx^2="" return="" values:="" f_km1="solution" at="" time="" t_{k-1}="t_k-dt" """="" a=".5*dt/(dx**2)" #="" random="" walk="" probabilities="" ...="" b="1." -="" dt/(dx**2)="" #="" ...="finite" difference="" weights.="" c="a" #="" week="" 3="" notes="" derive="" these="" formulas="" if="" (="" b="">< 0 ): print("violated the time step constraint") return fkm1 = np.zeros([n+2]) # n internal values plus two boundary values fkm1[0] = fk[0] # copy boundary conditions fkm1[n+1] = fk[n+1] for j in range(1,(n+1)): fkm1[j] = a*fk[j-1] + b*fk[j] + c*fk[j+1] return fkm1 #------------------ the main program --------------------------------------------------- # collect all constants and parameters in one place # number of grid points and plot color or symbol for each run run1 = { 'n': 8, 'symbol': "o"} run2 = { 'n': 14, 'symbol': "g"} run3 = { 'n': 29, 'symbol': "r"} runlist = [ run1, run2, run3] l = 12. # length of the space interval t = 1.25 # integrate from time t back to time 0 lam = .5 # cfl ratio = dt/(dx^2) plotfile = "finitedifference.pdf" # filename for plot file # do a separate solve for each n in the list fig, ax = plt.subplots() # put the results into a single plot. title = "value function for payout at time {t:7.2f} with lambda = {lam:7.2f}" title = title.format(t=t, lam = lam) ax.set_title(title) for run in runlist: # do all these runs n = run["n"] # the specs for this run symbol = run["symbol"] dx = l/(n+1) # n+1 = number of intervals for n internal points dt = lam*dx*dx # cfl formula for the time step, see week 3 notes nt = int(t/dt) + 1 # number of time steps between t and 0, rounded up dt = t/nt # possibly adjust dt down to have nt equal size time steps x = np.linspace( 0., l, n+2) # x values, for plotting only. # set up the final condition v = np.zeros([n+2]) # zero boundary values for j in range(1,(n+1)): v[j] = 1. # all ones in the interior. # time step loop to compute the time zero value function fk = v # fk = value function at time t_k = k*dt for ntmk in range(nt): # ntmk = nt - k = "nt minus k" fk = forwardstep( fk, dt, dx) f0 = fk # value funcion at t=0, save for plotting # add this computation to the figure legendtext = "n = {n:4d}" legendtext = legendtext.format( n = n) ax.plot( x, f0, symbol, label= legendtext, ) #ax.plot( x, f0, label= legendtext, symbol) ax.legend() ax.grid() ax.set_ylabel('f') ax.set_xlabel('x') plt.savefig(plotfile) # save a good copy of the plot plt.show() 0="" ):="" print("violated="" the="" time="" step="" constraint")="" return="" fkm1="np.zeros([n+2])" #="" n="" internal="" values="" plus="" two="" boundary="" values="" fkm1[0]="Fk[0]" #="" copy="" boundary="" conditions="" fkm1[n+1]="Fk[n+1]" for="" j="" in="" range(1,(n+1)):="" fkm1[j]="a*Fk[j-1]" +="" b*fk[j]="" +="" c*fk[j+1]="" return="" fkm1="" #------------------="" the="" main="" program="" ---------------------------------------------------="" #="" collect="" all="" constants="" and="" parameters="" in="" one="" place="" #="" number="" of="" grid="" points="" and="" plot="" color="" or="" symbol="" for="" each="" run="" run1="{" 'n':="" 8,="" 'symbol':="" "o"}="" run2="{" 'n':="" 14,="" 'symbol':="" "g"}="" run3="{" 'n':="" 29,="" 'symbol':="" "r"}="" runlist="[" run1,="" run2,="" run3]="" l="12." #="" length="" of="" the="" space="" interval="" t="1.25" #="" integrate="" from="" time="" t="" back="" to="" time="" 0="" lam=".5" #="" cfl="" ratio="dt/(dx^2)" plotfile="FiniteDifference.pdf" #="" filename="" for="" plot="" file="" #="" do="" a="" separate="" solve="" for="" each="" n="" in="" the="" list="" fig,="" ax="plt.subplots()" #="" put="" the="" results="" into="" a="" single="" plot.="" title="Value function for payout at time {T:7.2f} with lambda = {lam:7.2f}" title="title.format(T=T," lam="lam)" ax.set_title(title)="" for="" run="" in="" runlist:="" #="" do="" all="" these="" runs="" n="run["n"]" #="" the="" specs="" for="" this="" run="" symbol="run["symbol"]" dx="L/(n+1)" #="" n+1="number" of="" intervals="" for="" n="" internal="" points="" dt="lam*dx*dx" #="" cfl="" formula="" for="" the="" time="" step,="" see="" week="" 3="" notes="" nt="int(T/dt)" +="" 1="" #="" number="" of="" time="" steps="" between="" t="" and="" 0,="" rounded="" up="" dt="T/nt" #="" possibly="" adjust="" dt="" down="" to="" have="" nt="" equal="" size="" time="" steps="" x="np.linspace(" 0.,="" l,="" n+2)="" #="" x="" values,="" for="" plotting="" only.="" #="" set="" up="" the="" final="" condition="" v="np.zeros([n+2])" #="" zero="" boundary="" values="" for="" j="" in="" range(1,(n+1)):="" v[j]="1." #="" all="" ones="" in="" the="" interior.="" #="" time="" step="" loop="" to="" compute="" the="" time="" zero="" value="" function="" fk="V" #="" fk="value" function="" at="" time="" t_k="k*dt" for="" ntmk="" in="" range(nt):="" #="" ntmk="nt" -="" k="nt minus k" fk="forwardStep(" fk,="" dt,="" dx)="" f0="Fk" #="" value="" funcion="" at="" t="0," save="" for="" plotting="" #="" add="" this="" computation="" to="" the="" figure="" legendtext="n = {n:4d}" legendtext="legendText.format(" n="n)" ax.plot(="" x,="" f0,="" symbol,="" label="legendText," )="" #ax.plot(="" x,="" f0,="" label="legendText," symbol)="" ax.legend()="" ax.grid()="" ax.set_ylabel('f')="" ax.set_xlabel('x')="" plt.savefig(plotfile)="" #="" save="" a="" good="" copy="" of="" the="" plot="">
Nov 19, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here