Difference between revisions of "Manipulating Financial Data in Python"

From Quantitative Analysis Software Courses
Jump to navigation Jump to search
Line 48: Line 48:
 
* Compare SPY vs XOM, with SPY vs GLD scatter plots
 
* Compare SPY vs XOM, with SPY vs GLD scatter plots
  
==Lesson 7: Computing statistics on a portfolio==
+
==Lesson 7: Sharpe ratio & other portfolio statistics==
 
*Speed up reading data by memoizing
 
*Speed up reading data by memoizing
 
*Average daily return
 
*Average daily return

Revision as of 14:17, 21 April 2015

Lesson 1: Reading, slicing and plotting stock data

  • Overview of the data we'll be working with (from Yahoo!)
  • Introduction to our primary library: Pandas
  • Reading CSV data into Pandas
  • Filtering to specific dates
  • Plotting

Reading: "Python for Finance", Chapter 6: Financial time series

Assignment: MC1-Homework-1 Write a function in Python to find the Nth prime number.

Lesson 2: Working with many stocks at once

  • Our target data frame structure
  • Address reverse order issue
  • Reading data for multiple stocks into the structure
  • Date slicing
  • Symbol slicing
  • Plotting
  • Normalizing

Lesson 3: The power of Numpy

  • What is Numpy and how it relates to Pandas
  • Why is Numpy powerful/important?
  • Creating Numpy arrays
  • Indexing and slicing Numpy arrays
  • Important data processing on Numpy arrays
  • Example use with pandas too

Reading: "Python for Finance", Chapter 4: Data types and structures

Lesson 4: Statistical analysis of time series

  • Gross statistics on dataframes
  • Rolling statistics on dataframes
  • Plotting a technical indicator (Bollinger Bands)

Lesson 5: Incomplete data

  • How incomplete data arises in financial data
  • Different approaches to dealing with it

Assignment: MC1-Homework-2 Install and test a Python environment.

Lesson 6: Histograms and scatter plots

  • Histogram of daily returns
  • Compare SPY with XOM
  • Scatter plots
  • Correlation is not slope!
  • Compare SPY vs XOM, with SPY vs GLD scatter plots

Lesson 7: Sharpe ratio & other portfolio statistics

  • Speed up reading data by memoizing
  • Average daily return
  • Volatility: stddev of daily return (don't count first day)
  • Cumulative return
  • Relationship between cumulative and daily

script

  • Statistics we'll look at:
    • Average daily return
    • Stddev of daily return: volatility
    • Total return
    • Sharpe ratio
  • Buy and hold: SPY, GLD, GOOG, XOM, $100K each
  • Show how to read assets, normalize so each starts at $100K, goes forward.
  • [quiz: compute total daily portfolio value and daily rets for portfolio]
  • Show how to compute, avg daily rets, stdev, total ret, Sharpe ratio

Assignment: MC1-Project-1 Analyze a portfolio.

Lesson 8: Optimizers: Building a parameterized model

  • Problem statement for an optimizer (inputs, outputs, assumptions)
  • How to build a parameterized model from real data using an optimizer

script

  • What does an optimizer do?
  • Show syntax of optimizer use
  • Create fake data
  • Try to fit it using an optimizer
  • [quiz: add another type of curve to fit (e.g., sine)]

Lesson 9: Optimizers: How to optimize a portfolio

  • Framing the portfolio problem for an optimizer
  • Constraints for an optimizer
  • Optimizing a portfolio

script

  • Frame the portfolio optimization problem for the optimizer
  • Add target return
  • Plug the parts together in code for 4 assets
  • [quiz: Add constraints on holdings]

Assignment: MC1-Project-2 Analyze a portfolio.