Python for Finance


University of Kentucky MSF Seminar
Spring 2019
Joseph Farizo

What is Python?

What is Python?

Python is a popular and versatile computer programming language with numerous applications.

It is among the fastest growing programming languages in the world.

Simple things you can do with Python...

  • Get data from the web (scraping)
  • Pull text from PDFs
  • Send emails and schedule tasks
  • Edit spreadsheets and documents
  • Organize files

From The Economist

“...the Central Intelligence Agency has used it for hacking, Google for crawling webpages, Pixar for producing movies and Spotify for recommending songs.”

Python Applications for Finance

Python Applications for Finance

Python's ease-of-use, flexibility, and power have made it an attractive tool for a number of financial applications:

  • Data analysis & visualization
  • Asset valuation
  • Derivative pricing
  • Risk assessment
  • Portfolio optimization
  • Algorithmic trading

Today, we will retrieve and plot stock performance data and calculate a stock's $\beta$ and $\alpha$ using Python.

Getting Started with Python

Getting Started with Python

We will use the Anaconda distribution to run Python programs on our computer, which you can download here.

Within the Anaconda Navigator a number of applications are available, but we will just be using Spyder and Jupyter.

Note that Python is the programming language, Anaconda delivers the software we need to run Python code on our computer, and Spyder and Jupyter are places where we write Python code.

Spyder

An integrated development environment (IDE) which interprets and executes the Python code you write. It is useful for in-depth data analysis as it shows the "dataframes" and variables you create.

Jupyter

Like Spyder, Jupyter executes the code we write. There is an emphasis on taking notes on our code and sharing the Python scripts we write with others.

Today, we will focus on Jupyter as its strength is in sharing and documenting code.

Lastly, we use the Anaconda Prompt to download libraries that include functions and code to complete different tasks. You can access the Anaconda Prompt by searching for it in your computer's applications.

Lessons & Examples

Lessons

Lesson 1: An Introduction to Python

Click the links above to access the .ipynb (Jupyter) or .py (Spyder) code. All code is also available on GitHub.

Lesson 2: Graphing Stock Returns

Click the links above to access the .ipynb (Jupyter) or .py (Spyder) code. All code is also available on GitHub.

Lesson 3: Calculating a Stock's Beta and Alpha

Click the links above to access the .ipynb (Jupyter) or .py (Spyder) code. All code is also available on GitHub.

Quantopian

Quantopian

A crowd-sourced hedge fund that lets users write algorithms to compete for funds.

A large number of lectures and tutorials on using Python to design and test your own trading algorithms are available (and free!)

Summary

Summary

Python is a popular and versatile programming language, particularly useful for data and financial analysis.

To learn more, visit:

...and most important of all: Google. The best way to learn Python is to complete a project!

Thank You!