{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Purpose: Investigate Additional Exchanges"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "What other stock exchange databases besides WIKI will work with Stocker? The main issue is making sure the data is daily and finding the right column to analyze."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# BSE and NSE\n",
    "import quandl\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import fbprophet\n",
    "import pytrends\n",
    "from pytrends.request import TrendReq\n",
    "\n",
    "# matplotlib pyplot for plotting\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "import matplotlib"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "stock = quandl.get('NSE/TECHM')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Open</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Last</th>\n",
       "      <th>Close</th>\n",
       "      <th>Total Trade Quantity</th>\n",
       "      <th>Turnover (Lacs)</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2006-08-28</th>\n",
       "      <td>521.0</td>\n",
       "      <td>569.0</td>\n",
       "      <td>502.00</td>\n",
       "      <td>553.00</td>\n",
       "      <td>554.25</td>\n",
       "      <td>15166163.0</td>\n",
       "      <td>83717.60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2006-08-29</th>\n",
       "      <td>555.0</td>\n",
       "      <td>563.9</td>\n",
       "      <td>535.55</td>\n",
       "      <td>536.10</td>\n",
       "      <td>539.30</td>\n",
       "      <td>3929113.0</td>\n",
       "      <td>21515.30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2006-08-30</th>\n",
       "      <td>537.0</td>\n",
       "      <td>542.9</td>\n",
       "      <td>521.50</td>\n",
       "      <td>529.00</td>\n",
       "      <td>528.10</td>\n",
       "      <td>2034983.0</td>\n",
       "      <td>10776.30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2006-08-31</th>\n",
       "      <td>525.0</td>\n",
       "      <td>544.0</td>\n",
       "      <td>515.00</td>\n",
       "      <td>539.35</td>\n",
       "      <td>538.45</td>\n",
       "      <td>1670990.0</td>\n",
       "      <td>8904.46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2006-09-01</th>\n",
       "      <td>539.0</td>\n",
       "      <td>549.0</td>\n",
       "      <td>535.10</td>\n",
       "      <td>541.35</td>\n",
       "      <td>541.85</td>\n",
       "      <td>1176195.0</td>\n",
       "      <td>6380.39</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             Open   High     Low    Last   Close  Total Trade Quantity  \\\n",
       "Date                                                                     \n",
       "2006-08-28  521.0  569.0  502.00  553.00  554.25            15166163.0   \n",
       "2006-08-29  555.0  563.9  535.55  536.10  539.30             3929113.0   \n",
       "2006-08-30  537.0  542.9  521.50  529.00  528.10             2034983.0   \n",
       "2006-08-31  525.0  544.0  515.00  539.35  538.45             1670990.0   \n",
       "2006-09-01  539.0  549.0  535.10  541.35  541.85             1176195.0   \n",
       "\n",
       "            Turnover (Lacs)  \n",
       "Date                         \n",
       "2006-08-28         83717.60  \n",
       "2006-08-29         21515.30  \n",
       "2006-08-30         10776.30  \n",
       "2006-08-31          8904.46  \n",
       "2006-09-01          6380.39  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "stock2 = quandl.get('BSE/CPSE')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Open</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Close</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2008-07-08</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1415.09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2008-07-09</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1471.62</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2008-07-10</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1486.05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2008-07-11</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1446.56</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2008-07-14</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1460.94</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            Open  High  Low    Close\n",
       "Date                                \n",
       "2008-07-08   NaN   NaN  NaN  1415.09\n",
       "2008-07-09   NaN   NaN  NaN  1471.62\n",
       "2008-07-10   NaN   NaN  NaN  1486.05\n",
       "2008-07-11   NaN   NaN  NaN  1446.56\n",
       "2008-07-14   NaN   NaN  NaN  1460.94"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock2.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "\n",
    "path_to_stocker = 'C:/Users/Will Koehrsen/Documents/Data-Analysis/stocker'\n",
    "sys.path.insert(0, path_to_stocker)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "from stocker import Stocker"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "%load_ext autoreload"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "%autoreload 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPSE Stocker Initialized. Data covers 2008-07-08 to 2018-01-31.\n"
     ]
    }
   ],
   "source": [
    "cpse = Stocker(ticker = 'CPSE', exchange='BSE')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Top Related Queries: \n",
      "\n",
      "            query  value\n",
      "0     india times    100\n",
      "1  times of india     94\n",
      "2   bank of india     81\n",
      "3   india cricket     78\n",
      "4      news india     67\n",
      "\n",
      " Rising Related Queries: \n",
      "\n",
      "                         query  value\n",
      "0  india national cricket team  69000\n",
      "1      india vs sri lanka 2017  11550\n",
      "2           rio olympics india   9250\n",
      "3    samsung j2 price in india   8700\n",
      "4      india vs australia 2017   7550\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 90272 characters]\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x22bb990e748>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cpse.changepoint_date_analysis(search='India')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "TECHM Stocker Initialized. Data covers 2006-08-28 to 2018-01-31.\n"
     ]
    }
   ],
   "source": [
    "techm = Stocker('TECHM', 'NSE')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Maximum Adj. Close = 2921.65 on 2015-03-11.\n",
      "Minimum Adj. Close = 209.30 on 2009-01-23.\n",
      "Current Adj. Close = 612.65 on 2018-01-31.\n",
      "\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 51124 characters]\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x22bbb227ef0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "techm.plot_stock()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 187908 characters]\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x22bb241c7b8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "techm.changepoint_prior_analysis()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "MSFT Stocker Initialized. Data covers 1986-03-13 to 2018-01-30.\n"
     ]
    }
   ],
   "source": [
    "msft = Stocker('MSFT')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 118012 characters]\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x22bb9a0df60>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "msft.changepoint_prior_analysis()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Top Related Queries: \n",
      "\n",
      "              query  value\n",
      "0        msft stock    100\n",
      "1        msft price     43\n",
      "2  msft stock price     35\n",
      "3              aapl     25\n",
      "4              amzn     14\n",
      "\n",
      " Rising Related Queries: \n",
      "\n",
      "                    query  value\n",
      "0              snap stock  39500\n",
      "1                alphabet  23750\n",
      "2  amzn stock price today  18900\n",
      "3       msft connect test  16150\n",
      "4          snapchat stock  13700\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 105796 characters]\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x22bbafc9da0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "msft.changepoint_date_analysis(search='MSFT')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "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.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
