Book Image

Mastering Python for Finance

Book Image

Mastering Python for Finance

Overview of this book

Table of Contents (17 chapters)
Mastering Python for Finance
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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:

Here,

and is the number of seconds in one year and 30 days respectively.

is the time left to the expiry of the nearest OESX in seconds.

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...