This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in range(1,num_steps+1): | |
# fill out the first value with our initial stock price value and firm value | |
term_stock_val[i-1][0] = (np.full((num_simulations*i), S_0),np.full((num_simulations*i), S_0)) | |
for j in range (1,num_of_months): | |
# update current month to reflect the monthly simulation we are currently in | |
current_month = (j-1)/12 | |
corr_matrix = np.array([[1,correlation],[correlation,1]]) | |
norm_matrix = norm.rvs(size = np.array([2,num_simulations*i])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in range(1,num_steps+1): | |
# fill out the first value with our initial stock price | |
term_val[i-1][0] = np.full((num_simulations*i), S_0) | |
for j in range (1,num_of_months): | |
# update current month to reflect the monthly simulation we are currently in | |
current_month = (j-1)/12 | |
norm_array = norm.rvs(size = num_simulations*i) | |
term_val[i-1][j] = terminal_shareprice(term_val[i-1][j-1],risk_free,sigma,norm_array,dT) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
np.random.seed(0) | |
num_simulations = 1000 | |
# the number of steps represent the times we simulate the process, with each step comprising | |
# 1000*i steps so we get simulations from 1000 to 50000 | |
num_steps = 50 | |
num_of_months = 13 | |
# terminal price is an array of size 13 to account for the 12 months plus initial value | |
# it is timed by the number of steps | |
term_val = [[None]*num_of_months]*num_steps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_barrier_price(strike_num): | |
for i in range(1,num_steps+1): | |
# fill out the first value with our initial stock price | |
term_val[i-1][0] = np.full((num_simulations*i), S_0) | |
for j in range (1,num_of_months): | |
# update current month to reflect the monthly simulation we are currently in | |
current_month = (j-1)/12 | |
norm_array = norm.rvs(size = num_simulations*i) | |
term_val[i-1][j] = terminal_shareprice(term_val[i-1][j-1],risk_free,sigma,norm_array,dT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in range(1,num_steps+1): | |
# fill out the first value with our initial stock price | |
term_val[i-1][0] = np.full((num_simulations*i), S_0) | |
for j in range (1,num_of_months): | |
# update current month to reflect the monthly simulation we are currently in | |
current_month = (j-1)/12 | |
norm_array = norm.rvs(size = num_simulations*i) | |
term_val[i-1][j] = terminal_shareprice(term_val[i-1][j-1],risk_free,sigma,norm_array,dT) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
np.random.seed(0) | |
num_simulations = 1000 | |
# the number of steps represent the times we simulate the process, with each step comprising | |
# 1000*i steps so we get simulations from 1000 to 50000 | |
num_steps = 50 | |
num_of_months = 13 | |
# terminal price is an array of size 13 to account for the 12 months plus initial value | |
# it is timed by the number of steps | |
term_val = [[None]*num_of_months]*num_steps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in range(1,num_steps+1): | |
# fill out the first value with our initial stock price | |
term_val[i-1][0] = np.full((num_simulations*i), S_0) | |
for j in range (1,num_of_months): | |
# update current month to reflect the monthly simulation we are currently in | |
current_month = (j-1)/12 | |
norm_array = norm.rvs(size = num_simulations*i) | |
term_val[i-1][j] = terminal_shareprice(term_val[i-1][j-1],risk_free,sigma,norm_array,dT) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
np.random.seed(0) | |
num_simulations = 1000 | |
# the number of steps represent the times we simulate the process, with each step comprising | |
# 1000*i steps so we get simulations from 1000 to 50000 | |
num_steps = 50 | |
num_of_months = 13 | |
# terminal price is an array of size 13 to account for the 12 months plus initial value | |
# it is timed by the number of steps | |
term_val = [[None]*num_of_months]*num_steps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def terminal_shareprice(S_0, risk_free_rate, sigma, Z, T): | |
""" | |
Generates the terminal share price given some random normal values, z | |
""" | |
# It returns an array of terminal stock prices. | |
return S_0*np.exp((risk_free_rate-sigma**2/2)*T+sigma*np.sqrt(T)*Z) | |
def discounted_call_payoff(S_T, K, risk_free_rate, T): | |
""" | |
Function for evaluating the discounted payoff of a call option |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pandas as pd | |
from scipy.stats import norm | |
import matplotlib.pyplot as plt | |
import math as m | |
import random as r | |
#Market information | |
risk_free = 0.08 |
NewerOlder