Massive Python Weekend

I thought I would just summarize some of my early Python experiences.

Let me start by saying it hasn’t been as easy as many of the reviews would have you believe. To begin with the current version in production is 3.4.3 which is built on a completely new framework to the version 2 productions. So to begin with you encounter a debate about whether to start learning with version 2 or 3. You encounter this issue with many of the learning tutorials and video’s.

Once you have made your choice about version and download the Python program you are faced with the issue of an IDE or to stick with the raw “Shell” console. This reminded me of my earlier days with R where you also got a simple console, very similar to the DOS command prompt. The next big issue comes with downloading and installing libraries that are not shipped with the standard python installation.

With R there is no longer the issue with the IDE as RStudio is now accepted as the default IDE and installing new libraries is simply done the CRAN distribution hub doing all the heavy lifting with the built-in RStudio installation tools. Python libraries are typically shipped as binaries and need to be compiled into the base python programme. These are all big obstacles to getting going as a novice. Fortunately there is a great piece of software called Anaconda which updates and compiles most of the library’s in the broader ecosystem making it easier to work with.

So far I have chosen PyCharm as my IDE and code editor of choice. I have also found IPython Notes to be an awesome way to share code and explain each step in a markdown text so there are great editing solutions it just takes some time to get a grip on as there is so much choice.

I have to say I have been struggling a little to unlearn some of the R syntax to handle simple data manipulation and plotting. The literature seems to say that R syntax is very non-intuitive compared to much easier more natural Python syntax. As R was my first language I learned I am finding things the complete opposite.  As a quant it seems to be an essential to work with Numpy and Panda libraries as these guys seem to do all the heavy lifting in terms of standard functions for our industry. Because there is so much buy in to these libraries I plan on focusing a lot of my learning around these functions and not bother learning how to do things from the native library that can be doing with the call of a simple function in Pandas.

One of my biggest weaknesses and strengths is by nature I don’t like to ask for instructions, I am the kind of guy who likes to learn by myself on my own terms – excuse the arrogane. I almost never read instruction manuals when purchasing new appliances. I simply dive in like the proverbial bull in a china shop and try and work it out. That is how I learned my way around R and that is kind of how I started with Python.

Then it dawned on me I am not a computer science graduate with a good understanding of high level coding, and the different language environments, etc. To this end I have started to go down the more passive and slower approach of going through video tutorials by experts. This was indeed a good move as it has filled in many blanks and given me a far greater context to the subject and stronger building blocks.

The big find for me was Udemy which is an online “university” where teaching is broken into tiny ~5 minute type modules. I have been peppered with discount offerings and bought some excellent courses for $19 a piece some of which typically go for $279. So while this goes against my nature of diving in head first I have spent many hours over the last week “attending” lectures. In order to keep me sane though every couple of hours, I try and solve a real life problem that I have already mastered in R. This is still the best way to learn as it engraves the steps into ones memory far better than passively sitting and watching a lecture.

In conclusion I am starting to feel like I am getting somewhere but know I have a very long road ahead. As a further point of mention I must add that the reason for me wanting to learn a language like Python is that I know I will never be the sharpest quant in the house as many of the complex math problems are simply too difficult for me to master. However Python is far more than just a quant tool it has excellent Web building and general purpose capability that one cannot do well in R and it is these more general capabilities that I am hoping to add to my toolkit.

PS:

Last night I was running some code in R which was doing quite an involved VaR calculation over 1yr of daily data. The calculation was not running on the time series of the equity curve but on the open positions at each point in time and was taking my computer about ~1hr to run. I am very interested to know how long it would take to run in Python. I suspect it will be quicker, however as Python and R are not compiled languages they will still run much slower than say C++ or other compiled languages. All of this for another day, I would be happy to simply achieve “Hello World” in Python for now  😉

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s