RSS Feed

Setting up The Perfect Python Development Environment

0

I am sure most of you by now have heard about the awesomeness of Python. Python is a lightweight programming / scripting language that is very simple to learn yet powerful. As you know if you have been reading this blog you would know I am looking to test and develop automated trading strategies and the for the most part I have been using C++, Matlab, Excel and MetaTrader.

I have kept my head in the sand as I hear readers and colleagues constantly extol the virtues of working with Python. I am for the most part happy with Matlab for strategy evaluation, however it is not very good when it comes to the execution side of a strategy. So this weekend I have decided to get in touch with my inner Python. I like the idea of being able to develop, test and implement a strategy all in the same development environment. The best part about using Python is it’s Open Source and has a number of useful packages available.

The Zen of Python

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren’t special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one– and preferably only one –obvious way to do it.
Although that way may not be obvious at first unless you’re Dutch.
Now is better than never.
Although never is often better than right now.
If the implementation is hard to explain, it’s a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea — let’s do more of those!
—Tim Peters

To get this gem of wisdom simply type import this at the interactive python prompt. After a little research I have decided to use iPython as my interactive development environment at this stage I am not sure what I will use to write my static python code. For the moment I will just use emacs while I look into WingIDE.

Setting up Python

If you are not experienced with a UNIX like environment you may have a few issues with setting up all the libraries that are required. For the most part is smooth sailing. As I am running OS X I decided to take the easy / lazy option and just use mac ports.

At the moment I am experimenting with the following packages:

I tested matplotlib with the different back ends and in the end went with TkAgg backend. I have written a few simple shell scripts so I can launch IBTWS and Ipython from the desktop.

Hint: If you are running OS X you can simply save your shell scripts as .command files and chmod +x and they are executable from finder.

Now I am going to work through learning the programming language over the coming weeks. The language is very simple and easy to understand and coming from C++ I don’t think it will be to hard to pick up.


0 comments

Sorry, comments are closed.

Trading Wisdom

I have noticed that everyone who ever told me that the markets are efficient is poor. — Larry Hite