Difference between revisions of "MC1-Project-1"

From Quantitative Analysis Software Courses
Jump to navigation Jump to search
(Revised description with helper functions)
m
Line 1: Line 1:
 
==Overview==
 
==Overview==
  
The purpose of this assignment is to
+
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.
* Introduce you to historical equity data
+
 
* Introduce you to Pandas
+
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.
* Give you a first look at portfolio assessment
 
  
 
==Task==
 
==Task==
  
We provide you with a Python function named <code>assess_portfolio()</code> that is designed to simulate and assess the performance of a stock portfolio
+
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)
Inputs to the function include:
+
* Symbols for equities (e.g., GOOG, AAPL, GLD, XOM)
* Start date
 
* End date
 
* Symbols for 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)
 
* 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)
 
* Total starting value of the portfolio (e.g. $1,000,000)
 +
 +
These are passed to a Python function named <tt>assess_portfolio()</tt>. This function will be provided to you.
  
 
Example call:
 
Example call:
<code>assess_portfolio('2010-01-01', '2010-12-31', ['GOOG','AAPL','GLD','XOM'], [0.2,0.3,0.4,0.1], 1000000)</code>
+
<pre>assess_portfolio('2010-01-01', '2010-12-31', ['GOOG','AAPL','GLD','XOM'], [0.2,0.3,0.4,0.1], 1000000)</pre>
  
It calls three helper functions to complete the desired tasks. Your job is to implement these three functions:
+
It uses three helper functions to simulate and assess the performance of the stock portfolio. Your job is to implement these three functions:
* <code>get_portfolio_value(prices, allocs, start_val)</code>: Compute daily portfolio value given stock prices, allocations and starting value.
+
; <tt>'''get_portfolio_value'''(prices, allocs, start_val)</tt>
* <code>get_portfolio_stats(port_val, daily_rf, samples_per_year)</code>: Calculate statistics on given portfolio values.
+
: Compute daily portfolio value given stock prices, allocations and starting value.
* <code>plot_normalized_data(df, title, xlabel, ylabel)</code>: Normalize given stock prices and plot for comparison.
+
; <tt>'''get_portfolio_stats'''(port_val, daily_rf, samples_per_year)</tt>
 +
: Calculate statistics on given portfolio values.
 +
; <tt>'''plot_normalized_data'''(df, title, xlabel, ylabel)</tt>
 +
: Normalize given stock prices and plot for comparison.
  
 
TODO: Include detailed function descriptions here
 
TODO: Include detailed function descriptions here

Revision as of 19:45, 19 May 2015

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