This is notes from the Udemy Course
Algorithmic Trading & Quantitative Analysis Using Python
You can scroll left and right using the left-right arrows on your keyboard.
In [1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
In [2]:
df = pd.read_csv('AAPL.csv')
In [3]:
df.head()
Out[3]:
In [4]:
# Get percentage change of closing price from the day before
df['Percent Change'] = df['Close'].pct_change()
In [5]:
df.head()
Out[5]:
In [6]:
# Get rolling mean of closing price for the past 20 days
df['MA'] = df['Close'].rolling(window=20).mean()
In [7]:
df.head(30)
Out[7]:
In [8]:
df.dropna()
Out[8]:
Plot closing price and MA for last 200 days
In [9]:
ax = df.iloc[-200:, :].plot(kind="line", x='Date', y='Close', figsize=(19, 20))
df.iloc[-200:, :].plot(kind="line", x='Date', y='MA', ax=ax)
ax.set_title('Closing and MA for last 200 days')
Out[9]:
Leave a Reply