Someone, not so long time ago, turned my attention from Matlab coding towards Python programming. He used a strong argument on the enormous flexibility of the language and equally dynamic capabilities as contrasted with Matlab. Well, not mentioning a zero-dollar cost and the power behind the art of computing. That got my attention. When I did my own in-depth research on Python’s applications to the quantitative finance and risk modeling, I came back to my friend saying: Pal, you got my attention but now you have my curiosity. It’s difficult to divide a heart between two women and love them both the same way. Matlab and Python. However, since Python enters the saloons of financial coding with a full splendour, it deserves more respect than initially one would consider.
With this article, my wish is to commence a new thread at Quant At Risk pertaining a tutorial for all quants and financial risk managers wishing to pick up the language’s fundamentals, tastes, and all ingredients backed by a number of useful examples on the way. As this is a new path of wisdom for me too, I hope we will enjoy this journey together.
Assuming that Apple, Inc. and its powerful computers will continue to keep the pace of becoming increasingly popular among financial applications, let me put an extra ground standing behind the motivation of this post. We will set up a complete quant programming Python environment in Apple’s OS X 10.9 Mavericks operating system.
Steps to Success
Let me provide you with a complete list of steps you need to take to download, install, and setup Python on Mac. I will limit all descriptions to a required minimum. The whole process should take no longer than thirty minutes depending on your Internet connection.
- 1.Download .dmg file with Python 2.7.5 for Mac OS X 64-bit/32-bit from here.
- Execute and install on you hard drive.
- 2. XCode
- If you don’t have it, just visit Mac App Store for a free download. It may require you to register first as a developer but that comes will all privileges for your programming career in the future. Once installed, open XCode, go to Preferences… and click on the Downloads tab. We will need to have downloaded and installed Command Line Tools, therefore if you don’t have it, follow that path.
Open Terminal for next steps.
- 3. sudo easy_install virtualenv
- This command installs and allows us to set up a temporary environment assisting within the further installation process.
- 4. mkdir -p ~/Python/env; virtualenv ~/Python/env
- 5. pip install mpmath
- 6. pip install numpy
- 7. pip install scipy
- 8. /usr/bin/ruby -e “$(curl -fsSkL raw.github.com/mxcl/homebrew/go)”
- 9. brew install pkg-config
- 10. brew install freetype
- 11. brew install libpng
- 12. brew install ffmpeg
- 13. pip install matplotlib
- 14. brew install zeromq
- 15. pip install pyzmq
- 16. pip install Tornado
- 17. pip install readline
- 18. pip install azure
- 19. pip install curses
- 20. pip install cython
- 21. pip install jinja2
- 22. pip install pexpect
- 23. pip install pygments
- 24. pip install pymongo
- 25. pip install sphinx
- 26. pip install sqlite3
- 27. pip install wx
- 28. pip install zmq
- 29. pip install sympy
- 30. pip install patsy
- 31. pip install scikit_learn
- 32. pip install statsmodels
- 33. pip install pandas
- 34. pip install ipython
All these packages we will be using extensively, separately or in a combined version. They all supplement each other and make us equipped with a powerful weapon of sophisticated coding in Python.
- 35.export PY_ENV_DIR=~/Python/env
- Add this line into ~/.bash_profile file.
By typing a command which python we shoud get: ~/Python/env/bin/python. If so, it looks like that we went through the storm smoothly and we are ready to give go-and-go for launch!
- In the next post, we will setup a nice and cosy Integrated Development Environment (IDE) which should be sufficient for our early stages of scripting in Python.