Unanswered question about incorrect code

Coming back the question from the Options Volatility Trading: Concepts and Strategies.



Section 15 unit 18



garch = 







the for log likelihood function:

 

# Define the GARCH(1,1) log-likelihood function

def garch_likelihood(parameters, returns, parkinson):
    gamma = parameters[0]
    alpha = parameters[1]
    beta = parameters[2]

    # Initialize the log-likelihood and initial volatility
    log_likelihood = 0

    # Calculate the log-likelihood
    for t in range(1, len(returns)):

        # Calculate sigma2 using GARCH(1,1) equation
        sigma2 = gamma * parkinson[-1] + alpha * \
            returns[t-1]**2 + beta * parkinson[t-1]

        # Substitute the sigma2 values in log-likelihood function and take sum
        log_likelihood += -np.log(sigma2) - returns[t]**2 / sigma2

    return log_likelihood


gamma * parkinson[-1] represents the following two terms from the GARCH function:
  • V is the long-term variance of the time series which is the historical volatility estimated by the Parkinson estimator.
  • γ is the weight given to the long-term variance V.

​​​
gamma = γ
parkinson[-1] = V

Since V is the long-term variance of the time series and we're looping of the returns as follows:
for t in range(1, len(returns)):

for every return we set out V term to the last value of our parkinson values. This doesn't make sense in 2 ways.
1. Suppose our returns and parkinson series range from day t to day t+20. We start looping over our returns and we are at day t+2. using parkinson[-1] we set the V term to the volatility at day t+20. (which is in the future at this point in time at t+2, aka we're leaking future data). Clearly this is incorrect.

2. V represents some single value of long-term variance. How is it possible to assume a single value at the end of our series (parkinson[-1]) is in any way representative of the long-term variance? Suppose by chance the day at parkinson[-1] was a holliday where markets closed early. Well, now we use a low volatility holliday as our term for long-term variance (or a huge market crash in a day for high vol day). Clearly this is unwanted as it is not representative.

I hope this shows the implementation of the code is not representative of what we're trying to achieve. Furthermore I'd love to get a response either telling me how/where I'm wrong or how we can fix the code. This implementation is used throughout the course so if it indeed is wrong I think it needs to be updated in other places too.

Thanks for reading and I'm eagerly waiting for a response!
​​​​​​​

 

Hi Oliver,

I believe you are referring to this query, which has already been addressed. You are absolutely correct, there should indeed be a 't-1' in this loop. Rest assured, we will make the necessary adjustments to the notebooks. Thank you for bringing this to our attention.