PREDICTING SM INVESTMENT CORP. (PH) STOCK PRICES

SM-Investments.jpg

Introduction

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

In [1]:
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())
90it [00:47,  2.15it/s]
             open   high    low  close        value  volume
dt                                                         
2019-01-02  927.5  928.0  910.0  915.5  151101190.0     NaN
2019-01-03  915.0  958.0  914.5  958.0  652288055.0     NaN
2019-01-04  951.0  965.0  946.0  946.0  565094590.0     NaN
2019-01-07  960.0  981.0  940.0  940.0  315327245.0     NaN
2019-01-08  944.0  955.5  932.0  938.0  212342825.0     NaN
            open  high  low  close  value    volume
dt                                                 
2020-07-22   NaN   NaN  NaN  915.0    NaN  193670.0
2020-07-23   NaN   NaN  NaN  900.0    NaN  419490.0
2020-07-24   NaN   NaN  NaN  900.5    NaN  147410.0
2020-07-27   NaN   NaN  NaN  884.0    NaN  271930.0
2020-07-28   NaN   NaN  NaN  900.0    NaN  589260.0
In [2]:
# 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)
Out[2]:
Text(0.5, 1.0, 'Daily Closing Prices of SM Investment Corp.\nfrom 2019-01-01 to 2020-07-28')
In [3]:
# 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)
Out[3]:
Text(0.5, 1.0, 'Daily Closing Prices vs 30 day SMA of SM Investment Corp.\nfrom 2019-01-01 to 2020-07-28')