"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%matplotlib inline\n",
"prices.Close.plot(figsize=(16,4), grid=True)\n",
"prices.tail()"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from pandas_datareader import get_data_google"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/markbaum/Python/python/lib/python3.6/site-packages/pandas_datareader/google/daily.py:41: UnstableAPIWarning: \n",
"The Google Finance API has not been stable since late 2017. Requests seem\n",
"to fail at random. Failure is especially common when bulk downloading.\n",
"\n",
" warnings.warn(UNSTABLE_WARNING, UnstableAPIWarning)\n"
]
},
{
"ename": "RemoteDataError",
"evalue": "Unable to read URL: https://finance.google.co.uk/bctzjpnsun/historical?q=KRX%3AKOSPI&startdate=Jan+01%2C+2010&enddate=Jun+08%2C+2018&output=csv\nResponse Text:\nb'\\n\\n \\n \\n Error 404 (Not Found)!!1\\n \\n \\n 404. That\\xe2\\x80\\x99s an error.\\n
The requested URL /bctzjpnsun/historical
was not found on this server. That\\xe2\\x80\\x99s all we know.\\n'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mRemoteDataError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mget_data_google\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'KRX:KOSPI'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m~/Python/python/lib/python3.6/site-packages/pandas_datareader/data.py\u001b[0m in \u001b[0;36mget_data_google\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 65\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 66\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mget_data_google\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 67\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mGoogleDailyReader\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 68\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 69\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/Python/python/lib/python3.6/site-packages/pandas_datareader/base.py\u001b[0m in \u001b[0;36mread\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 208\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msymbols\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mcompat\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstring_types\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 209\u001b[0m df = self._read_one_data(self.url,\n\u001b[0;32m--> 210\u001b[0;31m params=self._get_params(self.symbols))\n\u001b[0m\u001b[1;32m 211\u001b[0m \u001b[0;31m# Or multiple symbols, (e.g., ['GOOG', 'AAPL', 'MSFT'])\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 212\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msymbols\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mDataFrame\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/Python/python/lib/python3.6/site-packages/pandas_datareader/base.py\u001b[0m in \u001b[0;36m_read_one_data\u001b[0;34m(self, url, params)\u001b[0m\n\u001b[1;32m 82\u001b[0m \u001b[0;34m\"\"\" read one data from specified URL \"\"\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 83\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_format\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m'string'\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 84\u001b[0;31m \u001b[0mout\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_read_url_as_StringIO\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0murl\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mparams\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 85\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_format\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m'json'\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 86\u001b[0m \u001b[0mout\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_get_response\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0murl\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mparams\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mjson\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/Python/python/lib/python3.6/site-packages/pandas_datareader/base.py\u001b[0m in \u001b[0;36m_read_url_as_StringIO\u001b[0;34m(self, url, params)\u001b[0m\n\u001b[1;32m 93\u001b[0m \u001b[0mOpen\u001b[0m \u001b[0murl\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;32mand\u001b[0m \u001b[0mretry\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 94\u001b[0m \"\"\"\n\u001b[0;32m---> 95\u001b[0;31m \u001b[0mresponse\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_get_response\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0murl\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mparams\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 96\u001b[0m \u001b[0mtext\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_sanitize_response\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresponse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 97\u001b[0m \u001b[0mout\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mStringIO\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/Python/python/lib/python3.6/site-packages/pandas_datareader/base.py\u001b[0m in \u001b[0;36m_get_response\u001b[0;34m(self, url, params, headers)\u001b[0m\n\u001b[1;32m 153\u001b[0m \u001b[0mmsg\u001b[0m \u001b[0;34m+=\u001b[0m \u001b[0;34m'\\nResponse Text:\\n{0}'\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlast_response_text\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 154\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 155\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mRemoteDataError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmsg\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 156\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 157\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m_get_crumb\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mRemoteDataError\u001b[0m: Unable to read URL: https://finance.google.co.uk/bctzjpnsun/historical?q=KRX%3AKOSPI&startdate=Jan+01%2C+2010&enddate=Jun+08%2C+2018&output=csv\nResponse Text:\nb'\\n\\n \\n \\n Error 404 (Not Found)!!1\\n \\n \\n 404. That\\xe2\\x80\\x99s an error.\\n
The requested URL /bctzjpnsun/historical
was not found on this server. That\\xe2\\x80\\x99s all we know.\\n'"
]
}
],
"source": [
"get_data_google('KRX:KOSPI')"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"from googlefinance.get import get_data"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" code | \n",
" open | \n",
" high | \n",
" low | \n",
" close | \n",
" volume | \n",
"
\n",
" \n",
" date | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
" 2018-04-24 | \n",
" KRX:KOSPI | \n",
" 2478.47 | \n",
" 2479.32 | \n",
" 2454.44 | \n",
" 2464.14 | \n",
" 524280000 | \n",
"
\n",
" \n",
" 2018-04-25 | \n",
" KRX:KOSPI | \n",
" 2444.19 | \n",
" 2453.54 | \n",
" 2436.51 | \n",
" 2448.81 | \n",
" 466095000 | \n",
"
\n",
" \n",
" 2018-04-26 | \n",
" KRX:KOSPI | \n",
" 2460.62 | \n",
" 2484.09 | \n",
" 2456.20 | \n",
" 2475.64 | \n",
" 520917000 | \n",
"
\n",
" \n",
" 2018-04-27 | \n",
" KRX:KOSPI | \n",
" 2497.75 | \n",
" 2508.13 | \n",
" 2484.19 | \n",
" 2492.40 | \n",
" 464957000 | \n",
"
\n",
" \n",
" 2018-04-30 | \n",
" KRX:KOSPI | \n",
" 2502.29 | \n",
" 2515.38 | \n",
" 2500.22 | \n",
" 2515.38 | \n",
" 746291000 | \n",
"
\n",
" \n",
" 2018-05-03 | \n",
" KRX:KOSPI | \n",
" 2506.94 | \n",
" 2507.91 | \n",
" 2487.25 | \n",
" 2487.25 | \n",
" 614102000 | \n",
"
\n",
" \n",
" 2018-05-04 | \n",
" KRX:KOSPI | \n",
" 2486.47 | \n",
" 2487.77 | \n",
" 2461.38 | \n",
" 2461.38 | \n",
" 612024000 | \n",
"
\n",
" \n",
" 2018-05-08 | \n",
" KRX:KOSPI | \n",
" 2468.45 | \n",
" 2479.75 | \n",
" 2444.08 | \n",
" 2449.81 | \n",
" 714734000 | \n",
"
\n",
" \n",
" 2018-05-09 | \n",
" KRX:KOSPI | \n",
" 2450.71 | \n",
" 2451.86 | \n",
" 2428.79 | \n",
" 2443.98 | \n",
" 593365000 | \n",
"
\n",
" \n",
" 2018-05-10 | \n",
" KRX:KOSPI | \n",
" 2458.67 | \n",
" 2464.72 | \n",
" 2448.01 | \n",
" 2464.16 | \n",
" 490004000 | \n",
"
\n",
" \n",
" 2018-05-11 | \n",
" KRX:KOSPI | \n",
" 2469.30 | \n",
" 2483.85 | \n",
" 2468.41 | \n",
" 2477.71 | \n",
" 599900000 | \n",
"
\n",
" \n",
" 2018-05-14 | \n",
" KRX:KOSPI | \n",
" 2482.97 | \n",
" 2486.17 | \n",
" 2471.91 | \n",
" 2476.11 | \n",
" 650707000 | \n",
"
\n",
" \n",
" 2018-05-15 | \n",
" KRX:KOSPI | \n",
" 2476.87 | \n",
" 2480.22 | \n",
" 2456.20 | \n",
" 2458.54 | \n",
" 712619000 | \n",
"
\n",
" \n",
" 2018-05-16 | \n",
" KRX:KOSPI | \n",
" 2446.64 | \n",
" 2465.55 | \n",
" 2444.67 | \n",
" 2459.82 | \n",
" 691813000 | \n",
"
\n",
" \n",
" 2018-05-17 | \n",
" KRX:KOSPI | \n",
" 2468.72 | \n",
" 2472.82 | \n",
" 2448.43 | \n",
" 2448.45 | \n",
" 596771000 | \n",
"
\n",
" \n",
" 2018-05-18 | \n",
" KRX:KOSPI | \n",
" 2459.73 | \n",
" 2461.95 | \n",
" 2452.34 | \n",
" 2460.65 | \n",
" 431376000 | \n",
"
\n",
" \n",
" 2018-05-21 | \n",
" KRX:KOSPI | \n",
" 2464.07 | \n",
" 2472.30 | \n",
" 2447.69 | \n",
" 2465.57 | \n",
" 588088000 | \n",
"
\n",
" \n",
" 2018-05-23 | \n",
" KRX:KOSPI | \n",
" 2462.98 | \n",
" 2476.86 | \n",
" 2460.07 | \n",
" 2471.91 | \n",
" 752675000 | \n",
"
\n",
" \n",
" 2018-05-24 | \n",
" KRX:KOSPI | \n",
" 2477.48 | \n",
" 2481.31 | \n",
" 2457.84 | \n",
" 2466.01 | \n",
" 638125000 | \n",
"
\n",
" \n",
" 2018-05-25 | \n",
" KRX:KOSPI | \n",
" 2452.80 | \n",
" 2466.57 | \n",
" 2444.77 | \n",
" 2460.80 | \n",
" 653592000 | \n",
"
\n",
" \n",
" 2018-05-28 | \n",
" KRX:KOSPI | \n",
" 2465.00 | \n",
" 2482.40 | \n",
" 2463.14 | \n",
" 2478.96 | \n",
" 708362000 | \n",
"
\n",
" \n",
" 2018-05-29 | \n",
" KRX:KOSPI | \n",
" 2476.70 | \n",
" 2479.68 | \n",
" 2457.18 | \n",
" 2457.25 | \n",
" 571836000 | \n",
"
\n",
" \n",
" 2018-05-30 | \n",
" KRX:KOSPI | \n",
" 2446.81 | \n",
" 2449.88 | \n",
" 2399.58 | \n",
" 2409.03 | \n",
" 575922000 | \n",
"
\n",
" \n",
" 2018-05-31 | \n",
" KRX:KOSPI | \n",
" 2428.83 | \n",
" 2430.15 | \n",
" 2415.50 | \n",
" 2423.01 | \n",
" 816930000 | \n",
"
\n",
" \n",
" 2018-06-01 | \n",
" KRX:KOSPI | \n",
" 2419.63 | \n",
" 2445.31 | \n",
" 2418.11 | \n",
" 2438.96 | \n",
" 603023000 | \n",
"
\n",
" \n",
" 2018-06-04 | \n",
" KRX:KOSPI | \n",
" 2444.62 | \n",
" 2452.67 | \n",
" 2441.25 | \n",
" 2447.76 | \n",
" 438929000 | \n",
"
\n",
" \n",
" 2018-06-05 | \n",
" KRX:KOSPI | \n",
" 2450.39 | \n",
" 2455.78 | \n",
" 2432.81 | \n",
" 2453.76 | \n",
" 501363000 | \n",
"
\n",
" \n",
" 2018-06-07 | \n",
" KRX:KOSPI | \n",
" 2468.26 | \n",
" 2478.67 | \n",
" 2466.01 | \n",
" 2470.58 | \n",
" 474146000 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" code open high low close volume\n",
"date \n",
"2018-04-24 KRX:KOSPI 2478.47 2479.32 2454.44 2464.14 524280000\n",
"2018-04-25 KRX:KOSPI 2444.19 2453.54 2436.51 2448.81 466095000\n",
"2018-04-26 KRX:KOSPI 2460.62 2484.09 2456.20 2475.64 520917000\n",
"2018-04-27 KRX:KOSPI 2497.75 2508.13 2484.19 2492.40 464957000\n",
"2018-04-30 KRX:KOSPI 2502.29 2515.38 2500.22 2515.38 746291000\n",
"2018-05-03 KRX:KOSPI 2506.94 2507.91 2487.25 2487.25 614102000\n",
"2018-05-04 KRX:KOSPI 2486.47 2487.77 2461.38 2461.38 612024000\n",
"2018-05-08 KRX:KOSPI 2468.45 2479.75 2444.08 2449.81 714734000\n",
"2018-05-09 KRX:KOSPI 2450.71 2451.86 2428.79 2443.98 593365000\n",
"2018-05-10 KRX:KOSPI 2458.67 2464.72 2448.01 2464.16 490004000\n",
"2018-05-11 KRX:KOSPI 2469.30 2483.85 2468.41 2477.71 599900000\n",
"2018-05-14 KRX:KOSPI 2482.97 2486.17 2471.91 2476.11 650707000\n",
"2018-05-15 KRX:KOSPI 2476.87 2480.22 2456.20 2458.54 712619000\n",
"2018-05-16 KRX:KOSPI 2446.64 2465.55 2444.67 2459.82 691813000\n",
"2018-05-17 KRX:KOSPI 2468.72 2472.82 2448.43 2448.45 596771000\n",
"2018-05-18 KRX:KOSPI 2459.73 2461.95 2452.34 2460.65 431376000\n",
"2018-05-21 KRX:KOSPI 2464.07 2472.30 2447.69 2465.57 588088000\n",
"2018-05-23 KRX:KOSPI 2462.98 2476.86 2460.07 2471.91 752675000\n",
"2018-05-24 KRX:KOSPI 2477.48 2481.31 2457.84 2466.01 638125000\n",
"2018-05-25 KRX:KOSPI 2452.80 2466.57 2444.77 2460.80 653592000\n",
"2018-05-28 KRX:KOSPI 2465.00 2482.40 2463.14 2478.96 708362000\n",
"2018-05-29 KRX:KOSPI 2476.70 2479.68 2457.18 2457.25 571836000\n",
"2018-05-30 KRX:KOSPI 2446.81 2449.88 2399.58 2409.03 575922000\n",
"2018-05-31 KRX:KOSPI 2428.83 2430.15 2415.50 2423.01 816930000\n",
"2018-06-01 KRX:KOSPI 2419.63 2445.31 2418.11 2438.96 603023000\n",
"2018-06-04 KRX:KOSPI 2444.62 2452.67 2441.25 2447.76 438929000\n",
"2018-06-05 KRX:KOSPI 2450.39 2455.78 2432.81 2453.76 501363000\n",
"2018-06-07 KRX:KOSPI 2468.26 2478.67 2466.01 2470.58 474146000"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"get_data('KRX:KOSPI')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"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.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}