用python Price discrete-monitored barrier options (e.g. at the closing of the last day of each month or each day), and compare with the price under the continuous-time version.
时间: 2024-02-25 16:55:53 浏览: 111
Python库 | dftintegrate-0.0.40.tar.gz
To price discrete-monitored barrier options in Python, we can use the Monte Carlo simulation method. Here are the steps to do so:
1. Define the parameters of the option, such as the strike price, barrier level, expiration date, and risk-free interest rate.
2. Generate a large number of random stock price paths using a geometric Brownian motion model.
3. For each stock price path, check if the barrier is breached at any of the monitoring dates. If the barrier is breached, the option expires worthless. Otherwise, the option pays off according to its payoff function (e.g. European call or put option).
4. Calculate the average payoff of all the simulated paths to obtain the option price.
To compare the price of the discrete-monitored barrier option with the continuous-time version, we can repeat the above steps but with a different model for the stock price. Instead of using geometric Brownian motion, we can use a continuous-time model such as Black-Scholes. We can then compare the prices obtained from the two models.
Here is an example Python code for pricing a discrete-monitored barrier option using Monte Carlo simulation:
```python
import numpy as np
from scipy.stats import norm
# Option parameters
s0 = 100
k = 110
b = 120
T = 1
r = 0.05
sigma = 0.2
n = 12 # Number of monitoring dates per year
# Monte Carlo simulation parameters
num_paths = 100000
num_steps = int(T * n)
# Generate stock price paths
dt = T / num_steps
drift = (r - 0.5 * sigma**2) * dt
volatility = sigma * np.sqrt(dt)
z = np.random.normal(size=(num_paths, num_steps))
s = s0 * np.exp(np.cumsum(drift + volatility * z, axis=1))
# Check barrier breach at monitoring dates
is_breached = np.any(s > b, axis=1)
# Calculate option payoff
payoff = np.maximum(0, s[:, -1] - k) * (1 - is_breached)
# Discounted expected payoff
discount_factor = np.exp(-r * T)
option_price = discount_factor * np.mean(payoff)
print("Discrete-monitored barrier option price:", option_price)
```
To price the continuous-time version using Black-Scholes, we can use the following code:
```python
from scipy.stats import norm
d1 = (np.log(s0/k) + (r + 0.5 * sigma**2) * T) / (sigma * np.sqrt(T))
d2 = d1 - sigma * np.sqrt(T)
n1 = norm.cdf(d1)
n2 = norm.cdf(d2)
call_price = s0 * n1 - k * np.exp(-r * T) * n2
put_price = k * np.exp(-r * T) * (1 - n2) - s0 * (1 - n1)
print("Continuous-time Black-Scholes call price:", call_price)
print("Continuous-time Black-Scholes put price:", put_price)
```
We can then compare the prices obtained from the two models to see how much difference the discrete monitoring makes.
阅读全文