MC1-Project-1

From Quantitative Analysis Software Courses
Revision as of 19:45, 19 May 2015 by Arpan987 (talk | contribs)
Jump to navigation Jump to search

Overview

A portfolio is a collection of stocks (or other investment options) and corresponding allocations of money to each of them. In order to evaluate and compare different portfolios, we first need to compute certain metrics, based on available historical data.

The primary goal of this assignment is to introduce you to this form of portfolio analysis. We will use pandas for reading in data, calculating various statistics and plotting a comparison graph.

Task

We are given the following inputs for analyzing a portfolio:

  • A date range to select the historical data to use (specified by a start and end date)
  • Symbols for equities (e.g., GOOG, AAPL, GLD, XOM)
  • Allocations to the equities at the beginning of the simulation (e.g., 0.2, 0.3, 0.4, 0.1)
  • Total starting value of the portfolio (e.g. $1,000,000)

These are passed to a Python function named assess_portfolio(). This function will be provided to you.

Example call:

assess_portfolio('2010-01-01', '2010-12-31', ['GOOG','AAPL','GLD','XOM'], [0.2,0.3,0.4,0.1], 1000000)

It uses three helper functions to simulate and assess the performance of the stock portfolio. Your job is to implement these three functions:

get_portfolio_value(prices, allocs, start_val)
Compute daily portfolio value given stock prices, allocations and starting value.
get_portfolio_stats(port_val, daily_rf, samples_per_year)
Calculate statistics on given portfolio values.
plot_normalized_data(df, title, xlabel, ylabel)
Normalize given stock prices and plot for comparison.

TODO: Include detailed function descriptions here

The function should return:

  • Standard deviation of daily returns of the total portfolio
  • Average daily return of the total portfolio
  • Sharpe ratio of the total portfolio (Assume you have 252 trading days in an year. And risk free rate = 0)
  • Cumulative return of the total portfolio

Also, create a chart that illustrates the value of your portfolio over the year and compares it to SPY. The portfolio and SPY should be normalized to 1.0 at the beginning of the period.

TODO: Include example chart here

Suggestions

Here is a suggested outline for your code:

  • Read in adjusted closing prices for the 4 equities.
  • Normalize the prices according to the first day. The first row for each stock should have a value of 1.0 at this point.
  • Multiply each column by the allocation to the corresponding equity.
  • Sum each row for each day. That is your cumulative daily portfolio value.
  • Compute statistics from the total portfolio value.

Here are some notes and assumptions:

  • When we compute statistics on the portfolio value, we do not include the first day.
  • We assume you are using the data provided. If you use other data your results may turn out different from ours. Yahoo's online data changes every day. We could not build a consistent "correct" answer based on "live" Yahoo data.
  • Assume 252 trading days/year.

Make sure your assess_portfolio() function gives correct output. Check it against the examples below.

Example output

Here's an example output for your function. These are actual correct examples that you can use to check your work.

TODO: example 1

TODO: example 2

Start Date: January 1, 2010
End Date: December 31, 2010
Symbols: ['AXP', 'HPQ', 'IBM', 'HNZ']
Optimal Allocations:  [0.0, 0.0, 0.0, 1.0]
Sharpe Ratio: 1.29889334008
Volatility (stdev of daily returns): 0.00924299255937
Average Daily Return: 0.000756285585593
Cumulative Return: 1.1960583568

Minor differences in float values may arise due to different implementations.

What to turn in

Via t-square turn in attachments only:

  • Your code as submission.py
  • Your chart as chart.pdf