{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Stock Analysis Using Stocker \n", "\n", "This notebook will walk through a basic example of using the Stocker class to analyze a stock. The Stocker class is built on the quandl financial library and the fbprophet additive model library but hides all that code behind the scenes so you can focus on making sense of the data! " ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Command for plotting in the notebook\n", "import matplotlib.pyplot as plt\n", "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Import the Class\n", "\n", "Make sure to run this notebook in the same directory as stocker.py" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from stocker import Stocker" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Instantiate a Stocker Object\n", "\n", "An object is an instance of a Python class. To create a stocker object, we call the Stocker class with a valid stock ticker (there are over 3000 available). We will be using Microsoft throughout this example. If successful, the call will display that the data was retrieved and the date range. " ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "MSFT Stocker Initialized. Data covers 1986-03-13 to 2018-01-22.\n" ] } ], "source": [ "microsoft = Stocker('MSFT')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The Stocker object contains a number of attributes, or pieces of data, and methods, functions that act on that data. \n", "One attribute is the stock history, which is a dataframe. We can assign this to a variable and then look at the dataframe." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", " | Date | \n", "Open | \n", "High | \n", "Low | \n", "Close | \n", "Volume | \n", "Ex-Dividend | \n", "Split Ratio | \n", "Adj. Open | \n", "Adj. High | \n", "Adj. Low | \n", "Adj. Close | \n", "Adj. Volume | \n", "ds | \n", "y | \n", "Daily Change | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "1986-03-13 | \n", "25.50 | \n", "29.25 | \n", "25.5 | \n", "28.00 | \n", "3582600.0 | \n", "0.0 | \n", "1.0 | \n", "0.058941 | \n", "0.067609 | \n", "0.058941 | \n", "0.064720 | \n", "1.031789e+09 | \n", "1986-03-13 | \n", "0.064720 | \n", "0.005779 | \n", "
1 | \n", "1986-03-14 | \n", "28.00 | \n", "29.50 | \n", "28.0 | \n", "29.00 | \n", "1070000.0 | \n", "0.0 | \n", "1.0 | \n", "0.064720 | \n", "0.068187 | \n", "0.064720 | \n", "0.067031 | \n", "3.081600e+08 | \n", "1986-03-14 | \n", "0.067031 | \n", "0.002311 | \n", "
2 | \n", "1986-03-17 | \n", "29.00 | \n", "29.75 | \n", "29.0 | \n", "29.50 | \n", "462400.0 | \n", "0.0 | \n", "1.0 | \n", "0.067031 | \n", "0.068765 | \n", "0.067031 | \n", "0.068187 | \n", "1.331712e+08 | \n", "1986-03-17 | \n", "0.068187 | \n", "0.001156 | \n", "
3 | \n", "1986-03-18 | \n", "29.50 | \n", "29.75 | \n", "28.5 | \n", "28.75 | \n", "235300.0 | \n", "0.0 | \n", "1.0 | \n", "0.068187 | \n", "0.068765 | \n", "0.065876 | \n", "0.066454 | \n", "6.776640e+07 | \n", "1986-03-18 | \n", "0.066454 | \n", "-0.001734 | \n", "
4 | \n", "1986-03-19 | \n", "28.75 | \n", "29.00 | \n", "28.0 | \n", "28.25 | \n", "166300.0 | \n", "0.0 | \n", "1.0 | \n", "0.066454 | \n", "0.067031 | \n", "0.064720 | \n", "0.065298 | \n", "4.789440e+07 | \n", "1986-03-19 | \n", "0.065298 | \n", "-0.001156 | \n", "