Some time ago I've come across a data analysis toolkit pandas especially suited for working with financial data. After just scratching the surface of its capabilities I'm already blown away by what it delivers. The package is being actively developed by Wes McKinney and his ambition is to create the most powerful and flexible open source data analysis/manipulation tool available. Well, I think he is well on the way!
Let's take a look at just how easy it is to align two datasets:
from tradingWithPython.lib import yahooFinance startDate = (2005,1,1) # create two timeseries. data for SPY goes much further back # than data of VXX spy = yahooFinance.getHistoricData('SPY',sDate=startDate) vxx = yahooFinance.getHistoricData('VXX',sDate=startDate) # Combine two datasets X = DataFrame({'VXX':vxx['adj_close'],'SPY':spy['adj_close']}) # remove NaN entries X= X.dropna() # make a nice picture X.plot()Two lines of code! ( this could be even fit to one line, but I've split it for readability)
Here is the result:
Man, this could have saved me a ton of time! But it still will help me in the future, as I'll be using its DataFrame object as a standard in my further work.