-
Notifications
You must be signed in to change notification settings - Fork 564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HestonModel.sample_paths returns variance converging to zero #42
Comments
Hi Shota, Thank you for reporting the issue. Let me take a look and come back to you. |
Thank you again for reaching out. I think this behavior is expected. If you run trajectories for longer they will "unstuck". In this case Feller condition is violated ( You will get a less dramatic picture if you use You can test sample paths quality by comparing Monte Carlo estimate for European option prices with Here is a code snippet: tf.random.set_seed(42)
dtype = tf.float64
kappa = 0.5
theta = 0.04
epsilon = 1.1 # make it a constant so that Atari approximation can be used
rho = 0.1
initial_log_spot = tf.constant(1.0, dtype=dtype)
initial_vol = tf.constant(0.04, dtype=dtype)
initial_state = np.array([initial_log_spot, initial_vol])
# Set up Heston model
heston = tff.models.HestonModel(
kappa=kappa, theta=theta, epsilon=epsilon, rho=rho, dtype=np.float64
)
# ATM European call option price seems to be valued correctly
maturity_time = 1.0
strike = tf.math.exp(initial_log_spot)
# Using Atari approximation
approximate_price = tff.models.heston.approximations.european_option_price(
variances=initial_vol,
strikes=strike,
expiries=maturity_time,
forwards=strike,
is_call_options=True,
kappas=kappa,
thetas=theta,
sigmas=epsilon,
rhos=rho,
dtype=tf.float64)
print("Atari approximation: ", approximate_price.numpy())
# Expected 0.1445071937036353
# Using Monte Carlo sampling
samples = heston.sample_paths(
times=[maturity_time / 2, maturity_time],
initial_state=initial_state,
time_step=0.01,
num_samples=1000000,
random_type=tff.math.random.RandomType.SOBOL,
seed=42)
log_spots = samples[:, -1, 0]
monte_carlo_price = (
tf.math.reduce_mean(tf.nn.relu(tf.math.exp(log_spots) - strike)))
print("Monte Carlo price (Andersen method): ", monte_carlo_price.numpy())
# Expected 0.1449164116664759 Please let me know if this all makes sense. Please feel free to add additional tests for correctness (e.g., check that the expected boundary hitting times are correct) |
Yes, that makes great sense. It really helps. |
I generated sample paths of HestonModel with parameters shown in the documentation.
However, variance eventually converges to zero and accordingly spot prices asymptotic to constant.
I attach the plot and a snippet to reproduce it.
Is this an expected behaviour?
I appreciate it if you could take a look at it.
The text was updated successfully, but these errors were encountered: