Gathering the EUROX STOXX 50 Index and VSTOXX data

STOXX Limited publishes the historical daily end-of-day index prices on their website at http://www.stoxx.com/data/historical/historical_benchmark.html.

The "STOXX Europe 600 (all regions)" historical daily data can be obtained at http://www.stoxx.com/download/historical_values/hbrbcpe.txt under Benchmark Indices of the Historical Data category of the website. The EURO STOXX 50 Index can be found within this data file.

The VSTOXX historical daily data can be obtained at http://www.stoxx.com/download/historical_values/h_vstoxx.txt. The EURO STOXX 50 Volatility link is found under Strategy Indices of the Historical Data category of the website.

The Python module urllib can be used to interact with the web resources through the urlretrieve function to download data from an external source onto our local disk.

The following Python code lets us download the required data text files onto our destination directory defined by the data_folder variable. In this example, the folder named data is used. If this folder does not exist in your working directory, create one now before running the codes:

from urllib import urlretrieve

url_path = 'http://www.stoxx.com/download/historical_values/'
stoxxeu600_url = url_path + 'hbrbcpe.txt'
vstoxx_url = url_path + 'h_vstoxx.txt'

data_folder = 'data/'  # Save file to local target destination.

stoxxeu600_filepath = data_folder + "stoxxeu600.txt"
vstoxx_filepath = data_folder + "vstoxx.txt" 

Now, we will run the following command to download the STOXX Europe 600 Index data file:

>>> urlretrieve(stoxxeu600_url, stoxxeu600_filepath)
('data/stoxxeu600.txt', <httplib.HTTPMessage instance at 0x105b47290>)

We can do the same to download the VSTOXX data file:

>>> urlretrieve(vstoxx_url, vstoxx_filepath)
('data/vstoxx.txt', <httplib.HTTPMessage instance at 0x105c764d0>)

To check whether our data has been downloaded successfully to our hard disk, run the following command:

>>> import os.path
>>> os.path.isfile(stoxxeu600_filepath)
True
>>> os.path.isfile(vstoxx_filepath)
True

That's right, the file now exists in our directory. Otherwise, the output will be False.

With the STOXX Europe 600 data file in hand, let's see what the first five lines of the text file might look like:

>>> with open(stoxxeu600_filepath, 'r') as opened_file:
...     for i in range(5):
...         print opened_file.readline(),
Price Indices - EURO Currency
Date    ;Blue-Chip;Blue-Chip;Broad    ; Broad   ;Ex UK    ;Ex Euro Zone;Blue-Chip; Broad
        ;  Europe ;Euro-Zone;Europe   ;Euro-Zone;         ;            ; Nordic  ; Nordic
        ;  SX5P   ;  SX5E   ;SXXP     ;SXXE     ; SXXF    ;    SXXA    ;    DK5F ; DKXF
31.12.1986;775.00 ;  900.82 ;   82.76 ;   98.58 ;   98.06 ;   69.06 ;  645.26  ;  65.56

From the previous output, we can see that semicolons separate the data in the STOXX Europe 600 text file. In the last of the top four rows of information lie our headers of interest, being Date, SX5P, SX5E, SXXP, SXXE, SXXF, SXXA, DK5F, and DKXF. With this information, we can begin to parse the data with pandas into a DataFrame object, as explained in the following code:

import pandas as pd

columns = ['Date', 'SX5P', 'SX5E', 'SXXP', 'SXXE',
           'SXXF', 'SXXA', 'DK5F', 'DKXF', 'EMPTY']
stoxxeu600 = pd.read_csv(stoxxeu600_filepath,
                 index_col=0,
                 parse_dates=True,                 
                 dayfirst=True,
                 header=None,
                 skiprows=4, 
                 names=columns,
                 sep=';'
                 )  
del stoxxeu600['EMPTY']

Here, we added an extra EMPTY column to the account for the trailing semicolons found at certain rows in the data. The extra column information is deleted after the parsing is done.

The read_csv function is a nifty pandas function that parses and converts a file into a pandas DataFrame object. A DataFrame object is a two-dimensional data structure very much like a table. The extra arguments tells us to treat the first column values as date objects, ignore the top four rows, parse the data with semicolon separators, and introduce the column names as defined in our columns variable. The stoxx50 variable now takes on the pandas DataFrame data type. To view more details about our new DataFrame object, we can use the info function of Pandas as follows:

>>> stoxxeu600.info()
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 7189 entries, 1986-12-31 00:00:00 to 2014-11-17 00:00:00
Data columns (total 8 columns):
SX5P    7189 non-null float64
SX5E    7189 non-null float64
SXXP    7189 non-null float64
SXXE    7189 non-null float64
SXXF    7189 non-null float64
SXXA    7189 non-null float64
DK5F    7189 non-null float64
DKXF    7189 non-null float64
dtypes: float64(8)

The column definitions of the STOXX Europe 600 data file are given in the following table:

Abbreviation

Benchmark index

SX5P

STOXX Europe 50

SX5E

Euro STOXX 50 Index

SXXP

STOXX Europe 600

SXXE

EURO STOXX

SXXF

STOXX Europe 600 ex UK

SXXA

STOXX Europe 600 ex Eurozone

DK5F

STOXX Nordic 30

DKXF

STOXX Nordic

Now, let's do the same for the VSTOXX data file:

>>> with open(vstoxx_filepath, 'r') as opened_file:
...     for i in range(5):
...         print opened_file.readline(),
EURO STOXX 50 Volatility Indices,,,,,,,,,
,VSTOXX,Sub-Index 1M,Sub-Index 2M,Sub-Index 3M,Sub-Index 6M,Sub-Index 9M,Sub-Index 12M,Sub-Index 18M,Sub-Index 24M
Date,V2TX,V6I1,V6I2,V6I3,V6I4,V6I5,V6I6,V6I7,V6I8
04.01.1999,18.2033,21.2458,17.5555,31.2179,33.3124,33.7327,33.2232,31.8535,23.8209
05.01.1999,29.6912,36.6400,28.4274,32.6922,33.7326,33.1724,32.8457,32.2904,25.0532

From the preceding output information, we can see that the VSTOXX data file is slightly different from the STOXX Europe 600 data file. Data in the VSTOXX text file is separated by commas with the first two rows carrying the additional information, which we will discard.

In the same fashion, we will do the same for the STOXX Europe 600 data file. We will parse the VSTOXX data text file to a pandas DataFrame object:

vstoxx = pd.read_csv(vstoxx_filepath,
                 index_col=0, 
                 parse_dates=True, 
                 dayfirst=True,
                 header=2)

In the later sections of this chapter, we will read the VSTOXX data again. For easy access to the VSTOXX data, let's save the data file as a CSV file in the data folder of our working directory with the name vstoxx.csv:

>>> vstoxx.to_csv('data/vstoxx.csv')

The vstoxx variable is now a pandas DataFrame object type, and we can use the info function of pandas to peek at its properties:

>>> print vstoxx.info()
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 4046 entries, 1999-01-04 00:00:00 to 2014-11-17 00:00:00
Data columns (total 9 columns):
V2TX    4046 non-null float64
V6I1    3625 non-null float64
V6I2    4046 non-null float64
V6I3    3995 non-null float64
V6I4    4046 non-null float64
V6I5    4046 non-null float64
V6I6    4031 non-null float64
V6I7    4046 non-null float64
V6I8    4035 non-null float64
dtypes: float64(9)

The column definitions of the VSTOXX data file are given in the following table:

Abbreviation

Index

V2TX

The actual EURO STOXX 50 Volatility values

V6I1

VSTOXX 1 month

V6I2

VSTOXX 2 months

V6I3

VSTOXX 3 months

V6I4

VSTOXX 6 months

V6I5

VSTOXX 9 months

V6I6

VSTOXX 12 months

V6I7

VSTOXX 18 months

V6I8

VSTOXX 24 months

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

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