Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Python for Finance

You're reading from   Mastering Python for Finance Understand, design, and implement state-of-the-art mathematical and statistical applications used in finance with Python

Arrow left icon
Product type Paperback
Published in Apr 2015
Publisher Packt
ISBN-13 9781784394516
Length 340 pages
Edition 1st Edition
Languages
Arrow right icon
Toc

Table of Contents (12) Chapters Close

Preface 1. Python for Financial Applications FREE CHAPTER 2. The Importance of Linearity in Finance 3. Nonlinearity in Finance 4. Numerical Procedures 5. Interest Rates and Derivatives 6. Interactive Financial Analytics with Python and VSTOXX 7. Big Data with Python 8. Algorithmic Trading 9. Backtesting 10. Excel with Python 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...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime