For this project, we will be using a python package called FastQuant which will allow users to access pricing data on any listed Philippine companies stock up to the latest trading day.
Simple moving average (SMA) crossover strategy will be used to analyze the pricing and identify the tigger for tradings. This means that it is a "buy" signal if the closing price crosses the SMA from below and it is a "sell" signal if the closing price crosses the SMA from above.
Simple moving average (SMA) calculates the average of a selected range of prices, usually closing prices, by the number of periods in that range. - Investopedia
To learn more about the package, you may refer here: https://towardsdatascience.com/access-philippine-stock-data-with-only-2-lines-of-python-309780382b8d
import pandas as pd
from fastquant import get_pse_data
df = get_pse_data("SM", "2019-01-01", "2020-07-28")
print(df.head())
print(df.tail())
# Import pyplot from the matplotlib module
from matplotlib import pyplot as plt
# Plot the daily closing prices
df.close.plot(figsize=(10, 6))
plt.title("Daily Closing Prices of SM Investment Corp.\nfrom 2019-01-01 to 2020-07-28", fontsize=20)
# Derive the 30 day SMA of SM 's closing prices
ma30 = df.close.rolling(30).mean()
# Combine the closing prices with the 30 day SMA
close_ma30 = pd.concat([df.close, ma30], axis=1).dropna()
close_ma30.columns = ['Closing Price', 'Simple Moving Average (30 day)']
# Plot the closing prices with the 30 day SMA
close_ma30.plot(figsize=(10, 6))
plt.title("Daily Closing Prices vs 30 day SMA of SM Investment Corp.\nfrom 2019-01-01 to 2020-07-28", fontsize=20)