{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Data Set Construction\n", "\n", "**Functions**\n", "\n", "`pd.read_csv`, `pd.read_excel`, `np.diff` or `DataFrame.diff`, `DataFrame.resample`\n", "\n", "### Exercise 1\n", "\n", "1. Download all available daily data for the S&P 500 and the Hang Seng Index from Yahoo! Finance. \n", "2. Import both data sets into Python. The final dataset should have a `DateTimeIndex`, and the date\n", " column should not be part of the `DataFrame`.\n", "3. Construct weekly price series from each, using Tuesday prices (less likely to be a holiday).\n", "4. Construct monthly price series from each using last day in the month.\n", "5. Save the data to the HDF file \"equity-indices.h5\".\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 2\n", "\n", "Write a function that will correctly aggregate to weekly or monthly respecting the\n", "aggregation rules\n", "\n", "* High: `max`\n", "* Low: `min`\n", "* Volume: `sum`\n", "\n", "The signature should be:\n", "\n", "```python\n", "def yahoo_agg(data, freq):\n", " \n", " return resampled_data\n", "```\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 3\n", "\n", "1. Import the Fama-French benchmark portfolios as well as the 25 sorted portfolios at both the\n", " monthly and daily horizon from [Ken French\"s Data Library](http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/data_library.html).\n", " **Note** It is much easier to clean to data file before importing than to find the precise\n", " command that will load the unmodified data.\n", "2. Import daily FX rate data for USD against AUD, Euro, JPY and GBP from the [Federal Reserve Economic Database (FRED)](http://research.stlouisfed.org/fred2/categories/94). Use Excel (xls) rather than csv files.\n", "3. Save the data to the HDF files \"fama-french.h5\" and \"fx.h5\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 3 (Alternative method)\n", "\n", "1. Install and use `pandas-datareader` to repeat the previous exercise.\n", "\n", "#### Preliminary Step\n", "\n", "You must first install the module using \n", "\n", "```\n", "pip install pandas-datareader\n", "``` \n", "\n", "from the command line. Then you can run this code. **Note**: Running this code requires access\n", "to the internet." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 4\n", "Download data on 1 year and 10 year US government bond rates from FRED, and \n", "construct the term premium as the different in yields on 10 year and 1 year\n", "bonds. Combine the two yield series and the term premium into a `DataFrame`\n", "and save it as HDF." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.5" }, "pycharm": { "stem_cell": { "cell_type": "raw", "metadata": { "collapsed": false }, "source": [] } } }, "nbformat": 4, "nbformat_minor": 4 }