# Recently in Python Category

## Python's NLTK Module

Whenever I have a few minutes I've been fooling around with Python's Natural Language Toolkit (NLTK) and have found it to be incredibly fascinating, powerful, and easy to use.  Mostly I've been following the examples from the NLTK Book as I learn to navigate around.  There is a section in the book about classifying text data, which I still need to dig through, but I found the section on "tagging" word data fascinating.

The goal for me is to use Python to scrape the data together and then let Rapidminer mine the data.  For ease of use of powerful operators, Rapidminer wins hands down.  If only they can extend Rapidminer with Python, like what the did for R, then I'll be happy as a nerd in new data!

## Hello Python

I finally managed to get Python up and running on my server, and managed to run the Hello World test script.  I know its lame, but its a big deal for me.

## Learning Python helps me with Excel

I use Excel extensively at work and I've always wished to write intricate macros but never understood the complexities of Visual Basic. Â After spending a few weeks learning Python, I've managed to build an Excel formula in VB that creates an "IF" statement formula if a hammer candlestick formation hasÂ occurred. Â I use this as a macro function and apply it automatically to my downloaded data using TraderXl. The formula is generates a 1 if a hammer has formed or a 0 if not.Â Assuming you've downloaded 153 rows of a stock's date, open, high, low, close, volume in the A, B, C, D, E and F columns respectively. The output is in column P; you may modify it as you see fit. Whoop-de-doo, right? Well here it is: ```Range("P1").Select ActiveCell.FormulaR1C1 = "Hammer Formula" Range("P2").Select ActiveCell.FormulaR1C1 = _ "=IF(AND((RC[-13]-RC[-12])>(3*(RC[-14]-RC[-11])),(((RC[-11]-RC[-12])/(0.001+(RC[-13]-RC[-12])))>0.6),(((RC[-14]-RC[-12])/(0.001+(RC[-13]-RC[-12])))>0.6)),1,0)" Range("P2").Select Selection.Copy Range("P3:P154").Select ActiveSheet.Paste``` Secret link to my trading code/strategy.

## Particle Swarm Optimization in Python

I found and installed the ECSPY evolutionary computation package and fiddled around with it. Â Considering I learned how to define and use functions in Python now, the example code (txt) for this Particle Swarm Optimiztation (PSO) chart below is beginning to make sense.

Long time Neural Market Trends readers might be wondering why I'm suddenly posting about Python and not Rapidminer? It's a valid question and I do have answers. First off, I always wanted to learn a programming language because I've felt that not knowing a programming language has held me back career wise, especially when I'm manipulating and data mining oodles of financial data. Second, Python is a great way to get my feet wet learning programming! Its Â fun and easy so far! Â Ultimately the goal is to learn Java so I can truly extend Rapidminer by creating custom operators, but learning Java at this stage of the game is like swallowing a whole elephant at once; not going to happen! Â So I'll start with eating a Python first.

## A Not So Simple GOOG Chart

What I am about to post is a simple \$GOOG chart created by a python script that I grabbed off Trainee Trader's site. Â While creating a line chart of GOOG's stock price is really basic finance, it does represent something very important to me. Â It means that I'm learning and troubleshooting python at a fast pace. I just started learning python about a week ago with absolutely no knowledge in programming (except for Frotran 77 a long time ago), but I am armed with an engineer's logic and enthusiam. I've worked on about 15 exercises in a training course I'm taking, and have read up on all the neat things python can do. Â  I installed python 2.6, matplotlib, and the ystockquote module from Cory Golberg on my development machine and configured the correct paths. Â Then I then tried to copy and paste TT's google chart python script to see if I could recreate his chart. Â I typed it verbatim and fired it up in python hoping to see the chart! Instead of seeing a nice GOOG chart, it crashed on me!!! Yep, it failed and I had no idea what the error messages were telling me. Fast forward one week and I'm picking up this language quick. Â So I took TT's code again, checked out theÂ documentationÂ for the matplotlib module, troubleshot it, and got the damn thing to plot! Â Go me!

Of course a sophisticated programmer would laugh at my silly plot, but to me it's awesomeness. Update: Here's the revised python script (txt): GOOGChart2.txt

## Learning Python - The Hard Way?

I'm teaching myself, through hand's on exercises, how to code Â (script) in Python. Â So far its been a breeze, but that's because I've found a great course for free. Â I'm reading and following along with "Learn Python the Hard Way," written by Zed Shaw. Â Zed made his book available for free download in PDF and I highly recommend it to programming novices, such as myself.

## Poking Python

So I'm finally getting around to poking around with Python again, and I created a scatter plot for Google. Â I'm pretty impressed with the modules they have for this language. Perhaps I should sit down and spend some time learning it, not just dream about it.

## Python Examples By Max

Long time linker (and reader hopefully) Max Dama maintains a great blog on automated trading and provides lots of great examples on how to do this.  I recently discovered that he has quite a few Python programming examples as well.  I'll have to spend more time there again digging through his posts and I suggest my readers do too.

## Trying Out Python

With the encouragement of @W0nk0, I've decided to start fooling around with the scripting language Python.  It appears to be an easy script language to learn and I hope to build various routines that will help me with my Automated Trading System.  There's also an open source ANN library for Python (and others) that I plan on fooling around with too.  That, coupled with ibPY, will let me finally build my ATS over the course of the year(s) and hook it up to Interactive Brokers.

## Machine Learning With Python Code

I'm recently came across some Python Code snippets for Machine Learning maintained by Stephen Marsland. I'm not a programmer or coder but I know several of my readers are.Â  Follow the link and enjoy.