In [1]:
import numpy as np
import pandas as pd

from pandas_datareader import data

import matplotlib
import matplotlib.pyplot as plt

%matplotlib inline

In [2]:
# 삼성전자
# http://finance.yahoo.com/quote/005930.KS?p=005930.KS

df = data.get_data_yahoo(
    "005930.KS",
    start="20160101",
    end="20161231",
)

In [3]:
df.head()


Out[3]:
Open High Low Close Volume Adj Close
Date
2016-01-01 1260000.0 1260000.0 1260000.0 1260000.0 0 1239852.43
2016-01-04 1260000.0 1260000.0 1205000.0 1205000.0 306900 1185731.88
2016-01-05 1202000.0 1218000.0 1186000.0 1208000.0 216000 1188683.91
2016-01-06 1208000.0 1208000.0 1168000.0 1175000.0 366700 1156211.59
2016-01-07 1166000.0 1183000.0 1151000.0 1163000.0 282300 1144403.47

In [4]:
ax = df["Adj Close"].plot(label=True)
ax.set_title("삼성전자 주가 변화 (2016)")


Out[4]:
<matplotlib.text.Text at 0x1108cd5f8>

In [5]:
# 이동평균선 ( 5일선, 20일선, 60일선 )

df["MA5"] = df["Adj Close"].rolling(window=5).mean()
df["MA20"] = df["Adj Close"].rolling(window=20).mean()
df["MA60"] = df["Adj Close"].rolling(window=60).mean()

ax = df[["MA5", "MA20", "MA60", "Adj Close"]].plot()
ax.set_xlim("20161201", "20161231")
ax.set_ylim(1500000, 1900000)
ax.set_title("삼성전자 차트 - 이동평균선")


Out[5]:
<matplotlib.text.Text at 0x110a122b0>