{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import dautil as dl\n",
    "import ch7util\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "context = dl.nb.Context('simple_log_rets')\n",
    "lr = dl.nb.LatexRenderer(chapter=7, context=context)\n",
    "lr.render(r'r=\\frac{V_f - V_i}{V_i}')\n",
    "lr.render(r'R = \\ln\\left(\\frac{V_f}{V_i}\\right)')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "ohlc = dl.data.OHLC()\n",
    "sp500 = ohlc.get('^GSPC')['Adj Close']\n",
    "rets = sp500[1:]/sp500[:-1] - 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "dl.options.mimic_seaborn()\n",
    "_, ax = plt.subplots()\n",
    "cp = dl.plotting.CyclePlotter(ax)\n",
    "cp.plot(sp500.index, rets, label='Simple')\n",
    "cp.plot(sp500.index[1:], ch7util.log_rets(sp500), label='Log')\n",
    "ax.set_title('Simple and Log Returns')\n",
    "ax.set_xlabel('Date')\n",
    "ax.set_ylabel('Return')\n",
    "ax.legend(loc='best')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.4.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
