Comments (3)
Hi Shota,
Thank you for reporting the issue. Let me take a look and come back to you.
from tf-quant-finance.
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)
from tf-quant-finance.
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!
from tf-quant-finance.
Related Issues (20)
- New Release
- JointItoProcess
- Unable to import tf_quant_finance as tff in Colab notebook: Monte_Carlo_Euler_Scheme.ipynb
- Memory leak with TF.function HOT 2
- Discrete dividens for american options HOT 24
- Which precision should I use? float32 or float64 HOT 2
- case-sensitive paths on a case-insensitive filesystem HOT 4
- XLA compilation error of a TARF payoff with MC HOT 16
- IRS Delta HOT 1
- conda-forge package HOT 1
- Fair performance comparison with QuantLib HOT 9
- times grid bug (XLA) HOT 1
- Quant
- The mailing-list is set to Invite Only HOT 1
- Issue with running Bazel tests HOT 2
- Options at-expiration return `nan` HOT 2
- SOFR USD OIS curve
- Hull White Model - calibration not aligning to input prices HOT 3
- Negative price for barrier option
- TF 2.12 (and Python 3.11) support HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tf-quant-finance.