Closed ghost closed 3 years ago
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 (epsilon**2 > 2 * kappa * theta
) so the process hits zero eventually, but will also "unstuck" if you run it for longer.
You will get a less dramatic picture if you use RandomType.PSEUDO
instead (since Sobol numbers are not meant to be random at all).
You can test sample paths quality by comparing Monte Carlo estimate for European option prices with tff.models.heston.approximations.european_option_price
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. Feller condition is indeed violated and thus variance will eventually be zero. Interesting.
It really helps. Thank you so much for your time and kindness!
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.