My First Jupyter Post

Written by Rafael Quintanilha

Installing the Dependencies

First we will download the yfinance module from pip. We'll use this library to download stock data.

!pip install yfinance
import yfinance as yf
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
Requirement already satisfied: yfinance in /home/rafael/anaconda3/lib/python3.7/site-packages (0.1.54) Requirement already satisfied: multitasking>=0.0.7 in /home/rafael/anaconda3/lib/python3.7/site-packages (from yfinance) (0.0.9) Requirement already satisfied: requests>=2.20 in /home/rafael/anaconda3/lib/python3.7/site-packages (from yfinance) (2.22.0) Requirement already satisfied: pandas>=0.24 in /home/rafael/anaconda3/lib/python3.7/site-packages (from yfinance) (0.25.1) Requirement already satisfied: numpy>=1.15 in /home/rafael/anaconda3/lib/python3.7/site-packages (from yfinance) (1.17.2) Requirement already satisfied: certifi>=2017.4.17 in /home/rafael/anaconda3/lib/python3.7/site-packages (from requests>=2.20->yfinance) (2019.9.11) Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /home/rafael/anaconda3/lib/python3.7/site-packages (from requests>=2.20->yfinance) (1.24.2) Requirement already satisfied: idna<2.9,>=2.5 in /home/rafael/anaconda3/lib/python3.7/site-packages (from requests>=2.20->yfinance) (2.8) Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /home/rafael/anaconda3/lib/python3.7/site-packages (from requests>=2.20->yfinance) (3.0.4) Requirement already satisfied: pytz>=2017.2 in /home/rafael/anaconda3/lib/python3.7/site-packages (from pandas>=0.24->yfinance) (2019.3) Requirement already satisfied: python-dateutil>=2.6.1 in /home/rafael/anaconda3/lib/python3.7/site-packages (from pandas>=0.24->yfinance) (2.8.0) Requirement already satisfied: six>=1.5 in /home/rafael/anaconda3/lib/python3.7/site-packages (from python-dateutil>=2.6.1->pandas>=0.24->yfinance) (1.12.0)
aapl = yf.download("AAPL", start="2020-01-01")
[*********************100%***********************] 1 of 1 completed

Let's take a look into our dataframe:

aapl
Open High Low Close Adj Close Volume
Date
1980-12-12 0.128348 0.128906 0.128348 0.128348 0.101261 469033600
1980-12-15 0.122210 0.122210 0.121652 0.121652 0.095978 175884800
1980-12-16 0.113281 0.113281 0.112723 0.112723 0.088934 105728000
1980-12-17 0.115513 0.116071 0.115513 0.115513 0.091135 86441600
1980-12-18 0.118862 0.119420 0.118862 0.118862 0.093777 73449600
... ... ... ... ... ... ...
2020-09-14 114.720001 115.930000 112.800003 115.360001 115.360001 140150100
2020-09-15 118.330002 118.830002 113.610001 115.540001 115.540001 184642000
2020-09-16 115.230003 116.000000 112.040001 112.129997 112.129997 154679000
2020-09-17 109.720001 112.199997 108.709999 110.339996 110.339996 178011000
2020-09-18 110.400002 110.879997 106.089996 106.839996 106.839996 286693600

10027 rows × 6 columns

Plotting Data

Charts are cool. Why not plot one then?

aapl["Adj Close"].plot()
<matplotlib.axes._subplots.AxesSubplot at 0x7f042f3ab310>

Back