import math
import numpy as np
import pandas as pd
from scipy import stats
import matplotlib as plt
T = 1 #Time to Expiry in Years
E = 100 #Strike
r = .05 #Risk Free Rate
SIGMA = .20 #Volatility
Type = True #Type of Option True=Call False=Put
NAS = 40 #Number of Asset Steps - Higher is more accurate, but more time consuming
ds = 2 * E / NAS #Asset Value Step Size
dt = (0.9/NAS/NAS/SIGMA/SIGMA) #Time Step Size
NTS = int(T / dt) + 1 #Number of
value_matrix = np.zeros((int(NAS+1), int(NTS)))
asset_price = np.arange(NAS*ds,-1,-ds)
value_matrix[:,-1]= np.maximum(asset_price - E,0)
for x in range(1,NTS):
value_matrix[-1,-x-1] = value_matrix[-1,-x]* math.exp(-r*dt)
for x in range(1,int(NTS)):
for y in range(1,int(N