HOMEWORK 6 2024 SPRING

docx

School

Illinois Institute Of Technology *

*We aren’t endorsed by this school

Course

503

Subject

Economics

Date

Apr 3, 2024

Type

docx

Pages

7

Uploaded by BarristerInternet1945

Report
MSF 503: HOMEWORK 6 Name: Tanvi Patil 1.) Create a Python program that: Generates 100 price paths using geometric Brownian motion with parameters μ and σ , and initial price S 0 . Each path should be 252 days long. import numpy as np import matplotlib.pyplot as plt # Parameters mu = 0.1 # drift coefficient n = 252 # number of steps T = 1 # time in years M = 100 # number of sims S0 = 100 # initial stock price sigma = 0.3 # volatility dt = T / n # simulation using numpy arrays St = np.exp( (mu - sigma ** 2 / 2) * dt + sigma * np.random.normal(0, np.sqrt(dt), size=(M, n)).T ) # include array of 1's St = np.vstack([np.ones(M), St]) # multiply through by S0 and return the cumulative product of elements along a given simulation path (axis=0). St = S0 * St.cumprod(axis=0) # Define time interval correctly time = np.linspace(0, T, n + 1) # Require numpy array that is the same shape as St tt = np.full(shape=(M, n + 1), fill_value=time).T plt.plot(tt, St) plt.xlabel("Years $(t)$") plt.ylabel("Stock Price $(S_t)$") plt.title(
"Realizations of Geometric Brownian Motion\n $dS_t = \\mu S_t dt + \\sigma S_t dW_t$\n $S_0 = {0}, \\mu = {1}, \\sigma = {2}$".format(S0, mu, sigma) ) plt.show() Assuming a put option with strike price X , calculates the value of the option at the end (i.e. expiration) of each price path that ends up “in the money” (i.e. the option has a value of greater than zero). import numpy as np def calculate_put_option_value(stock_price, strike_price): return max(strike_price - stock_price, 0) def simulate_price_paths(initial_price, drift, volatility, num_paths, num_steps): dt = 1 / 252 # Assuming trading days in a year paths = [] for _ in range(num_paths): price_path = [initial_price] for _ in range(num_steps): z = np.random.normal() price_change = drift * price_path[-1] * dt + volatility * price_path[-1] * np.sqrt(dt) * z price_path.append(price_path[-1] + price_change) paths.append(price_path) return paths def calculate_put_option_values(price_paths, strike_price): option_values = []
for path in price_paths: final_price = path[-1] if final_price < strike_price: option_value = calculate_put_option_value(final_price, strike_price) option_values.append(option_value) return option_values def main(): initial_price = 100 strike_price = 95 drift = 0.05 # 5% annual drift volatility = 0.2 # 20% annual volatility num_paths = 1000 num_steps = 252 # Number of trading days in a year price_paths = simulate_price_paths(initial_price, drift, volatility, num_paths, num_steps) option_values = calculate_put_option_values(price_paths, strike_price) if len(option_values) == 0: print("No price paths ended up in the money.") else: print("Option values at expiration for price paths ending up in the money:") for i, value in enumerate(option_values): print(f"Path {i+1}: ${value:.2f}") if __name__ == "__main__": main() Calculates the average of these option values. # List of option values option_values = [14.01, 1.18, 41.29, 12.90, 9.52, 21.35, 3.22, 1.04, 4.17, 10.92, 7.48, 12.62, 6.72, 4.78, 24.61, 1.14, 1.50] # Calculate the total sum of the values total_sum = sum(option_values) # Calculate the average average = total_sum / len(option_values) # Print the average print("The average of the option values is: ${:.2f}".format(average)) The average of the option values is: $10.50
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Answer the following questions in words: If you move S 0 up or down $1, what happens to this average value? If you move S0 up or down $1, the average value, also known as the equilibrium price, changes. For Instance, if S0 is moved up, it represents an increase in the cost of production or supply, which leads to a higher equilibrium price. Similarly, if S0 is moved down, it represents a decrease in the cost of production or supply, which leads to a lower equilibrium price. This concept is a fundamental principle in understanding the relationship between supply and price in a market economy. 2.) Create a Python program that implements an ARCH(1) simulation. Use whatever values you want for the gamma and alpha parameters. Your program should graph the price path, the returns, and the volatility forecasts as in the GARCH example. import numpy as np import matplotlib.pyplot as plt # Parameters T = 1000 alpha = 0.1 gamma = 0.05 # Generate ARCH(1) process np.random.seed(42) epsilon = np.random.normal(0, 1, T) sigma_sq = np.zeros(T) returns = np.zeros(T) for t in range(1, T): sigma_sq[t] = alpha + gamma * returns[t-1]**2 returns[t] = np.sqrt(sigma_sq[t]) * epsilon[t] # Plotting plt.figure(figsize=(12, 8)) plt.subplot(3, 1, 1) plt.plot(returns, color='b') plt.title('Returns') plt.subplot(3, 1, 2) plt.plot(sigma_sq, color='r') plt.title('Volatility Forecasts')
plt.subplot(3, 1, 3) price_path = np.cumsum(returns) plt.plot(price_path, color='g') plt.title('Price Path') plt.tight_layout() plt.show() 3.) Here is some data on MCD. Date Open High Low Close Adj Close Volume 1/3/201 9 175.45 176.45 174.41 174.9 157.572 5 372820 0 1/4/201 9 176.03 179.2 175.69 178.28 160.617 6 319430 0 Create a Python program that estimates the volatility for January 4 th using the close-to-close, Parkinson, Garman-Klass, DVOL, Rogers and Satchell, and Yang and Zhang formulas. Print out the estimates from lowest to highest
import numpy as np # Given data close_price = 178.28 high_price = 179.2 low_price = 175.69 # Close-to-close volatility close_to_close_volatility = close_price / (close_price - 1) - 1 # Parkinson volatility parkinson_volatility = (1 / (4 * np.log(2))) * np.sqrt((np.log(high_price / low_price))**2) # Garman-Klass volatility garman_klass_volatility = np.sqrt((0.5 * np.log(high_price / low_price))**2 - (2 * np.log(2) - 1) * (np.log(close_price / high_price) * np.log(close_price / low_price))) # DVOL volatility dvol_volatility = np.log(high_price / low_price) # Rogers and Satchell volatility rs_volatility = np.sqrt((np.log(high_price / close_price) * np.log(close_price / low_price)) + (0.5 * (dvol_volatility ** 2))) # Yang and Zhang volatility yz_volatility = np.sqrt((np.log(high_price / close_price) ** 2) + (np.log(low_price / close_price) ** 2) - (2 * np.log(2) - 1) * (np.log(high_price / low_price) ** 2)) # Put all volatilities in a list volatility_list = [close_to_close_volatility, parkinson_volatility, garman_klass_volatility, dvol_volatility, rs_volatility, yz_volatility] # Sort the list sorted_volatility = sorted(volatility_list) # Print the sorted volatilities print("Volatility Estimates (sorted from lowest to highest):") for volatility in sorted_volatility: print(volatility) Volatility Estimates (sorted from lowest to highest):
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
0.005640794223826795 0.007134639914385576 0.00946024542154047 0.01126604269001614 0.01646138356100762 0.019781422163867246