Calculating the VSTOXX main index

From the vstoxx.csv file saved earlier, we can use these values to calculate the VSTOXX index values. The formula to calculate the index is given as follows:

Calculating the VSTOXX main index

Here,

Calculating the VSTOXX main index and Calculating the VSTOXX main index is the number of seconds in one year and 30 days respectively.

Calculating the VSTOXX main index is the time left to the expiry of the nearest OESX in seconds.

Calculating the VSTOXX main index is the time left to the expiry of the second nearest OESX in seconds.

The implementation of the preceding formula is given in the calculate_vstoxx_index method:

import math

def calculate_vstoxx_index(dataframe, col_name):    
    secs_per_day = float(60*60*24)
    utility = OptionUtility()
    
    for row_date, row in dataframe.iterrows():
        # Set each expiry date with an 
        # expiration time of 5p.m
        date = row_date.replace(hour=17)  
        
        # Ensure dates and sigmas are in legal range
        expiry_date_1 = utility.get_settlement_date(date)
        expiry_date_2 = utility.fwd_expiry_date(date, 1)
        days_diff = (expiry_date_1-date).days
        sigma_1, sigma_2 = row["V6I1"], row["V6I2"]        
        if -1 <= days_diff <= 1:
            sigma_1, sigma_2 = row["V6I2"], row["V6I3"]        
        if days_diff <= 1:
            expiry_date_1 = expiry_date_2
            expiry_date_2 = utility.fwd_expiry_date(date, 2)   
            
        # Get expiration times in terms of seconds
        Nti = (expiry_date_1-date).total_seconds()
        Nti1 = (expiry_date_2-date).total_seconds()
        
        # Calculate index as per VSTOXX formula in seconds
        first_term = 
            (Nti1-30*secs_per_day)/ 
            (Nti1-Nti)*(sigma_1**2)*Nti/ 
            (secs_per_day*365)
        second_term = 
            (30*secs_per_day-Nti)/ 
            (Nti1-Nti)*(sigma_2**2)*Nti1/ 
            (secs_per_day*365)
        sub_index = math.sqrt(365.*(first_term+second_term)/30.)    
        dataframe.set_value(row_date, col_name, sub_index)
        
    return dataframe

Note that the function requires the use of the OptionUtility class discussed earlier to calculate the settlement date. Adjustments are made if the calculation date is one or less than one day to expiry. If the calculation date falls beyond the expiry date of the same month, the values of the following month are used.

To see how our calculated values can be compared to the VSTOXX actual values, we can take a sample from the VSTOXX data file and feed it into our calculate_vstoxx_index function. The following Python code demonstrates this. Since the data file dates a long time back, we will just take a sample of the last 100 sub-index values:

>>> sample = vstoxx.tail(100)  # From the previous section
>>> sample = calculate_vstoxx_index(sample, "Calculated")
>>>
>>> vstoxx_df = sample["V2TX"]
>>> calculated_df = sample["Calculated"]
>>> df = pd.DataFrame({'VSTOXX' : sample["V2TX"],
...               'Calculated' : sample["Calculated"]})
>>>  df.plot(figsize=(10, 6), grid=True, style=['ro','b'])

This gives us the following output:

<matplotlib.axes.AxesSubplot at 0x10c971f90>
Calculating the VSTOXX main index

The calculated values in red dots appear to be very close to the actual VSTOXX values.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset