Difference between revisions of "MC1-Project-1"
(Revised description with helper functions) |
|||
Line 1: | Line 1: | ||
==Overview== | ==Overview== | ||
− | The purpose of this assignment is to | + | |
+ | The purpose of this assignment is to | ||
* Introduce you to historical equity data | * Introduce you to historical equity data | ||
* Introduce you to Pandas | * Introduce you to Pandas | ||
Line 7: | Line 8: | ||
==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. | |
Inputs to the function include: | Inputs to the function include: | ||
Line 14: | Line 15: | ||
* Symbols for for equities (e.g., GOOG, AAPL, GLD, XOM) | * 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) | ||
+ | |||
+ | 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> | ||
+ | |||
+ | It calls three helper functions to complete the desired tasks. 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. | ||
+ | * <code>get_portfolio_stats(port_val, daily_rf, samples_per_year)</code>: Calculate statistics on given portfolio values. | ||
+ | * <code>plot_normalized_data(df, title, xlabel, ylabel)</code>: Normalize given stock prices and plot for comparison. | ||
+ | |||
+ | TODO: Include detailed function descriptions here | ||
The function should return: | The function should return: | ||
Line 20: | Line 32: | ||
* Sharpe ratio of the total portfolio (Assume you have 252 trading days in an year. And risk free rate = 0) | * 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 | * 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. | 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== | ==Suggestions== | ||
Line 49: | Line 57: | ||
Here's an example output for your function. These are actual correct examples that you can use to check your work. | 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 | Start Date: January 1, 2010 |
Revision as of 12:27, 19 May 2015
Overview
The purpose of this assignment is to
- Introduce you to historical equity data
- Introduce you to Pandas
- Give you a first look at portfolio assessment
Task
We provide you with a Python function named assess_portfolio()
that is designed to simulate and assess the performance of a stock portfolio.
Inputs to the function include:
- 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)
- Total starting value of the portfolio (e.g. $1,000,000)
Example call:
assess_portfolio('2010-01-01', '2010-12-31', ['GOOG','AAPL','GLD','XOM'], [0.2,0.3,0.4,0.1], 1000000)
It calls three helper functions to complete the desired tasks. 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