An App that presents a laest Square Monte Carlo based real Option Pricing model
Drop files here
or click to upload
import streamlit as st
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
st.title("Monte Carlo Option Pricing Model")
# Input parameters
S = st.number_input('Current Stock Price (S)', value=100.0)
K = st.number_input('Strike Price (K)', value=100.0)
T = st.number_input('Time to Maturity in Years (T)', value=1.0)
r = st.number_input('Risk-free Interest Rate (r)', value=0.05)
sigma = st.number_input('Volatility (σ)', value=0.2)
n = st.number_input('Number of Simulations', value=10000)
# Function to calculate option price
def monte_carlo_option_pricing(S, K, T, r, sigma, n):
# Generate random numbers
Z = np.random.normal(0, 1, n)
ST = S * np.exp((r - 0.5 * sigma ** 2) * T + sigma * np.sqrt(T) * Z)
payoff = np.maximum(ST - K, 0) # Call option payoff
option_price = np.exp(-r * T) * np.mean(payoff)
return option_price
if st.button('Calculate Option Price'):
option_price = monte_carlo_option_pricing(S, K, T, r, sigma, n)
st.write(f'The estimated option price is: ${option_price:.2f}')
# Optional: plot histogram
if st.checkbox('Show Histogram of Simulated Prices'):
Z = np.random.normal(0, 1, n)
ST = S * np.exp((r - 0.5 * sigma ** 2) * T + sigma * np.sqrt(T) * Z)
plt.hist(ST, bins=50, alpha=0.7)
plt.title('Histogram of Simulated Stock Prices at Maturity')
plt.xlabel('Stock Price')
plt.ylabel('Frequency')
st.pyplot(plt)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?