approaches to calibrating a Heston model

Discussion in 'Options' started by stochastix, Mar 2, 2023.

  1. Damn! You're way ahead of Soy. He only spent 3 and a half days there, and he never actually even left El Paso. You just need a real Bentley and you'll be ahead of MB as well.
     
    #21     Mar 3, 2023
  2. destriero

    destriero


    Cheap trip. $14.95 for a month's VPN on the Big Island.
     
    #22     Mar 3, 2023
    M.W. likes this.
  3. who the hell is soy and MB? i caught my first wave it was cool and a bit of a personal milestone given the back and neck surgeries..i even had a secret graffiti artist collective writing my name and the particular number 777 i had posted in some code System.exit(777) on my github before i went there. never figured out who did it but the letter e in Steve was written as a summation symbol so i dunno what other Steve(Stephen) that does math would be haunting the writable surfaces of Honolulu and a subset of the inhabitants of said place
     
    #23     Mar 3, 2023
  4. Soy is SoyElGanador who recently took a virtual vacation with his virtual winnings. MB is Mark Brown, who, at various times in the past, has owned an imaginary Bently (sic), a Lambo, and a Cray.

    Q) Why should you know this already?
    A) Because you should be following the ongoing skew arb discussion and to do that you need to follow Destriero's posts. And ET's search facility is not good enough to filter out his interactions with fools from the listing of his posts. So if you were following those posts, you'd know about Soy and MB.

    And the reason you need to be following the skew discussion is because of your stated interest in rough stoch vol models (like, e.g. the Rough Heston Model). In stoch vol models, the parameter rho is the correlation between the vol process W and the spot process Z (it's the R in SABR mentioned previously in this thread).

    RHO IS THE SKEW! See the first few pages of Gatheral's 2017 presentation "Intro to Rough Vol." However, rough vol models don't fit short expiry skew very well -- see Gatheral et al "Short-Term At-the-
    Money Asymptotics under Stochastic Volatility Models" 2019 for a discussion of this failing. Now this is very important, so pay attention -- the etymology of this failure is explained by the structure of the skewlock.

    So the lesson here is that you can improve your models' calibrations on short-dated options curves by following the skew discussions here on ET.
     
    #24     Mar 3, 2023
    Adam777, Snuskpelle and stochastix like this.
  5. born to be wild starts playing as he tips his hat to agent Schmit
     
    #25     Mar 4, 2023
  6. lariati

    lariati

    Here is what it thinks is a working Heston model in python that it wrote. Trying to calibrate it though to a pandas series of S&P returns with maximum likelihood it went off the rails trying to rewrite the whole thing and blew up into nonsense. I have never had good results if it hits the limit of lines for the chat window. "continue" I don't think has ever worked one time for me without giving nonsense results. I don't think the for i in range(1, N+1) loop will be indented properly either below.

    import numpy as np
    import matplotlib.pyplot as plt
    from scipy.stats import norm

    # Define the Heston model parameters
    S0 = 100.0 # initial stock price
    mu = 0.05 # expected return
    kappa = 1.5 # mean-reversion speed of the variance
    theta = 0.04 # long-run average of the variance
    sigma = 0.3 # volatility of the variance
    rho = -0.5 # correlation between the stock and variance processes
    T = 1.0 # time horizon
    N = 252 # number of time steps

    # Set the random seed for reproducibility
    np.random.seed(123)

    # Define the time grid
    dt = T / N
    t = np.linspace(0, T, N+1)

    # Define arrays to store the stock and variance paths
    S = np.zeros(N+1)
    V = np.zeros(N+1)

    # Set the initial values for the stock and variance processes
    S[0] = S0
    V[0] = theta

    # Simulate the stock and variance processes
    for i in range(1, N+1):
    # Generate two independent standard normal random variables
    z1 = norm.rvs()
    z2 = norm.rvs()

    # Update the stock and variance processes using the Heston model equations
    S = S[i-1] * np.exp((mu - V[i-1]/2) * dt + np.sqrt(V[i-1] * dt) * z1)
    V = V[i-1] + kappa * (theta - V[i-1]) * dt + sigma * np.sqrt(V[i-1] * dt) * (rho * z1 + np.sqrt(1 - rho**2) * z2)

    # Plot the stock price and volatility paths
    fig, ax = plt.subplots(2, 1, figsize=(8, 6))
    ax[0].plot(t, S)
    ax[0].set_xlabel('Time')
    ax[0].set_ylabel('Stock Price')
    ax[1].plot(t, V)
    ax[1].set_xlabel('Time')
    ax[1].set_ylabel('Variance')
    plt.tight_layout()
    plt.show()
     
    #26     Mar 4, 2023
  7. OK, that is a reasonable first cut at a Heston implementation in python. But that is easy. 30 seconds of googling will get you links to better versions.


    Usually you'd calibrate to a smoothed arb-free options price curve instance, not an underlying price path instance. The latter is difficult and requires a few tricks to do well. That is where chatgpt fails most -- when confronted with difficult problems. Rather than admitting ignorance it generates a bullshit answer. At least when google can't find any relevant web content it doesn't respond with made-up links.

    I just tried the following prompt:

    Code:
    create a causal polyadic graph for financial time series based on partial renyi transfer
    entropy of order 0.1 for USD, BTC, ETH, and EUR return time series data and generate
    a python trading model based on same using a predictor/response segregation of the
    graph
    
    The query is complex but not really difficult. Anyone who can program in python and knows what a causal graph is could probably knock out a prototype in a couple of hours.

    Chatgpt responded with extremely long-winded total nonsense. But for a domain non-expert the response might sound plausible. That is the danger of chatgpt in its current state, it might be taken seriously to considerable financial ill effect.
     
    Last edited: Mar 5, 2023
    #27     Mar 5, 2023
    lariati likes this.
  8. lariati

    lariati

    Personally, I have no use for a Heston model but I do think it is cool chatGPT can write these up even with poor quantitative reasoning skills. I am pretty much trying to use chatGPT whenever I run across any problem just to see what happens.

    Even to say something can be easily Googled I have got to the point that almost anything is better in chatGPT because chatGPT can explain line by line what is going on and then you can ask further questions based on those responses.

    For code generation, it crushes writing React components but I think part of that is from the over representation in the training data and a functional style works well as a constraint on it. The farther out towards the edge you get the more nonsense it seems to produce.

    I think it is also interesting how while you have to take chatGPT with a grain of salt, all non-falsifiable human knowledge is probably just as much full of nonsense. While there are dangers in a non-domain expert using a Heston model foolishly is that more dangerous than someone trading options based on some useless books and gut feelings? At least someone attempting to use chatGPT to create a Heston model would get a feel for how deep the water is before diving in head first.

    This is actually quite a good exercise really with having very limited knowledge in a domain to see how possible it is to push into a domain I really have no business being in. I think this is probably a good mix of representation in the training data along with lots of nice trap doors and pitfalls to learn to avoid.

     
    #28     Mar 5, 2023
    stochastix likes this.
  9. M.W.

    M.W.

    I am surprised you still criticize chatgpt for something it's creators have not even begun to tune the model to do. I am one of the code contributors to several of OpenAI's projects but one should not even need to have a CS degree or know coding to understand that chatgpt is at best in its alpha. First to market is of absolutely top priority (and of course the handcuffs in order to appease the woke crowd). Give it a year and it will amaze you. In case anyone has not grasped what is happening: search has been reinvented and will change forever. Microsoft already embedded a modified bot in its search on Windows 11. That's a few months after the original release. The pace at which things are moving forward is truly amazing.

    I along many others are currently working on versions of multi-actor-critic models that have the core predictions exposed to differently biased critics which learn a qfunction to correct and guide the core algorithm in its search for minimum biased search results. Short story is that thousands currently work on exactly your complaint, bias, which often leads to inaccurate or severely incorrect results. "in the search for truth" if you want...

     
    Last edited: Mar 5, 2023
    #29     Mar 5, 2023
  10. The Heston model is a stochastic volatility model that assumes the volatility of an underlying asset follows a mean-reverting process. The characteristic function of the Heston model is given by:

    Ψ(ω,t) = exp[C(t,ω)Θ + D(t,ω)Θ₀ + iωln(S₀exp(rt))]

    where Θ₀ is the initial variance, Θ is the long-term average variance, S₀ is the initial stock price, r is the risk-free interest rate, ω is the frequency variable, and C(t,ω) and D(t,ω) are functions of time t and frequency ω.

    We can provide a general formula for the characteristic function:

    C(t,ω) = [M(ω) - 2ln((1 - g(ω,1)f(ω,τ))/(1 - g(ω,0)))],

    where M(ω) and g(ω,n) are defined as before, and f(ω,τ) = exp(-d(ω)τ).

    D(t,ω) = M(ω)/σ² * (1 - f(ω,τ))/(1 - g(ω,1)f(ω,τ)),

    where M(ω) and g(ω,n) are defined as before, and f(ω,τ) = exp(-d(ω)τ).

    In the expressions for C(t,ω) and D(t,ω), we have factored out the term exp(-d(ω)τ) into the function f(ω,τ).

    We can also factor out the term iρσω from the expression for d(ω):

    d(ω) = √((I(ω) - B(ω))² + σ²(2iω - ω²)),

    where B(ω) = λθ + A(ω), A(ω) = 1/2g(ω,1)d(ω) - I(ω) + λ, and I(ω) = iρσω.

    The function B(ω) represents the shift in the mean of the variance process due to the presence of the stochastic volatility process. We can use B(ω) in place of λθ + iρσω in various expressions.

    The variable a = λθ plays a crucial role in determining the long-term behavior of the variance process in the Heston model. It represents the equilibrium level of variance that the model reverts to in the long run.

    To calculate the characteristic function of the Heston model, we first need to compute the functions M(ω), g(ω,n), f(ω,τ), d(ω), and B(ω). We can then use these functions to compute C(t,ω) and D(t,ω). Finally, we can substitute the expressions for C(t,ω) and D(t,ω) into the characteristic function formula to obtain the final result.
     
    #30     Mar 6, 2023