diff --git a/Programming for Finance/Lecture 4/Seminar 4.py b/Programming for Finance/Lecture 4/Seminar 4.py index e251de4..c9baa8e 100644 --- a/Programming for Finance/Lecture 4/Seminar 4.py +++ b/Programming for Finance/Lecture 4/Seminar 4.py @@ -3,6 +3,7 @@ import pandas as pd import numpy as np import matplotlib.pyplot as plt import urllib.request as urr +import datetime as dt #The URL's for our datasets es_url = "https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt" #This one has a problem with semicolons @@ -28,7 +29,38 @@ new_file.close() # new_lines = open("es50.txt", "r").readlines() -pdl = pd.read_csv("es50.txt", sep = ";") +es = pd.read_csv("es50.txt", sep = ";", parse_dates=True, dayfirst=True, index_col=0) # print(pdl.ix[0:4,:]) # A look before we delete the DEL column -del pdl["DEL"] # This removes the column we're talking about. -print(pdl.tail()) # Now we have a normal ass data frame. +del es["DEL"] # This removes the column we're talking about. +print(es.head()) # Now we have a normal ass data frame. + +#Read in our other file. +vs = pd.read_csv("vs.txt", sep = ",", parse_dates=True, header = 2, index_col=0) +print(vs.head()) + +data1 = pd.DataFrame({"EUROSTOXX":es['SX5E'][es.index > dt.datetime(1999, 1, 1)]}) +data1 = pd.DataFrame({"EUROSTOXX":data1['EUROSTOXX'][data1.index < dt.datetime(2016,2,13)]}) + +data2 = pd.DataFrame({"VSTOXX":vs["V2TX"][vs.index > dt.datetime(1999, 1, 1)]}) +data2 = pd.DataFrame({"VSTOXX":data2["VSTOXX"][vs.index < dt.datetime(2016, 2, 13)]}) + +print(data1.head()) +print(data2.head()) + +""" +The tutor recommends using .fillna('ffill') to pull down the +previous day's values, though that doesn't seem right to me. + +The code for the recommended thing is as follows, though from +here the seminar tutor and I have diverged substantially. +If you want to revert to the "actual" method, remove +the inner join argument from the joiner below, and uncomment +the statement below the join. + +It may also be that it's more 'realistic', but I would have +to know more about VSTOXX. I have no idea what it represents. +""" +data = data1.join(data2, how = "inner") +#data = data.fillna(method = 'ffill') + +print(data.head())