If you would like to start playing with the code from this blog and write your own, you need to setup a development environment first. I've already put a summary of tools and software packages on the tools page and to make it even easier, here are the steps you'll need to follow to get up and running:
1. Install PythonXY. : this includes Python 2.7 and tools Spyder, Ipython etc.
2. Install Tortoise SVN. This is a utility that you need to pull the source code from Google Code
3. Install Pandas (time series library)
This is all you need for now.
To get the code, use 'Svn Checkout' windows explorer context menu that is available after installing Tortoise SVN. Checkout like this (change Checkout directory to the location you want, but it should end with tradingWithPython):
If all goes well, the most recent version of the files will be downloaded. I'll be writing more code and improving current one, you'll be able to stay in sync with my code by using 'svn update' context menu.
The final step is to launch Spyder (through pythonXY launcher or start menu) and add the directory just above the 'tradingWithPython' (in my example C:\Users\jev\Desktop') dir to python path . Do this with 'tools'->'PYTHONPATH manager'.
Ok, all done, now you can run the examples from \cookbok dir.
Friday, November 4, 2011
Friday, October 28, 2011
kung fu pandas will solve your data problems
I love researching strategies, but sadly I spend too much time on low-level work like filtering and aligning datasets. In fact, about 80% of my time is spent on this mind numbing work. There had got to be a better way than hacking all the filtering code myself, and there is!
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:
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.
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.
Monday, October 17, 2011
Tools & Cookbook
Saturday, October 15, 2011
How to download a bunch of csv files
I'll be analyzing VIX futures data, so to start with, I need all the files from CBOE. They use a consistent format for file names, which is easy to generate. The following script creates a data directory and then downloads all csv files for the period 2004-2011. As you can see, not much coding is required, less than 30 lines!
from urllib import urlretrieve
import os
m_codes = ['F','G','H','J','K','M','N','Q','U','V','X','Z'] #month codes of the futures
dataDir = os.getenv("USERPROFILE")+'\\twpData\\vixFutures' # data directory
def saveVixFutureData(year,month, path):
''' Get future from CBOE and save to file '''
fName = "CFE_{0}{1}_VX.csv".format(m_codes[month],str(year)[-2:])
urlStr = "http://cfe.cboe.com/Publish/ScheduledTask/MktData/datahouse/{0}".format(fName)
try:
urlretrieve(urlStr,path+'\\'+fName)
except Exception as e:
print e
if __name__ == '__main__':
if not os.path.exists(dataDir):
os.makedirs(dataDir)
for year in range(2004,2012):
for month in range(12):
print 'Getting data for {0}/{1}'.format(year,month)
saveVixFutureData(year,month,dataDir)
print 'Data was saved to {0}'.format(dataDir)
Friday, October 14, 2011
Sunday, September 25, 2011
Getting Started
First of all, I must admit that it took me quite some time even to consider switching from Matlab to Python. I've been working with Matlab for more than ten years, and I must say that it is an excellent tool for research. However, both in my professional and private work there where quite some cases where Matlab was not the best tool to do the job. This forced me to learn things like Labwindows and C# for gui programming, php for website building. Not to forget that Matlab is not a free (not as in speech, nor as in beer) product.
Still, the main reason for me trying to make the switch, is Python being a 'swiss knife of programming'. It can be used to make excellent GUIs with Qt, conduct research with SciPy, program dynamic websites and so on.
All posts on this blog will be based on the following tooling:
Still, the main reason for me trying to make the switch, is Python being a 'swiss knife of programming'. It can be used to make excellent GUIs with Qt, conduct research with SciPy, program dynamic websites and so on.
All posts on this blog will be based on the following tooling:
Subscribe to:
Posts (Atom)

