knitr::opts_chunk$set(echo = TRUE)

pseR

Pull and analyse PSE data. Currently limited only to Investagrams as source which is limited to past year data only.

Installation

Install devtools to easily install pseR.

install.packages("devtools")
devtools::install_github("nfrimando/pseR")

Examples

Extract historical PSE data with pse_get()

suppressPackageStartupMessages({library(pseR); library(dplyr)}) 
stock.dt <- pse_get(c("JFC", "MBT", "FGEN","BPI", "URC",
                            "ALI", "MER", "ABS", "GLO"))
stock.dt %>% head()

Analytics using tidyquant

The package tidyquant has convenient functions that allows easy implementation for visualisation and analysis. (It also has functions to pull data for PSE from various sources. The easy-to-access sources though are usually not updated. E.g. Yahoo! Finance).

suppressPackageStartupMessages({library(tidyquant); library(ggplot2)})
stock.dt %>%
  ggplot(aes(x = as.Date(date), y = close)) +
  geom_barchart(aes(open = open, high = high, low = low, close = close)) +
  labs(title = "PSE Stocks Daily Past 1 Year", y = "Closing Price", x = "") + 
  facet_wrap(~code, scales = "free") + 
  scale_x_date(date_breaks = "3 months", date_labels = "%b %d") + 
  theme_tq()

Correlation Visualisation with ggcorrplot

suppressPackageStartupMessages({library(tidyr); library(ggcorrplot)})
stock.dt %>%
  group_by(code) %>% 
  arrange(desc(date)) %>% 
  # filter(row_number() <= 150) %>% 
  ungroup() %>% 
  select(code, date, perc_change) %>% 
  spread(key = code, value = perc_change) %>% 
  select(-date) %>% 
  cor() %>% 
  ggcorrplot(
    hc.order = TRUE, 
    type = "lower",
    outline.col = "white",
    ggtheme = ggplot2::theme_gray,
    colors = c("#6D9EC1", "white", "#E46726"),
    insig = "blank",
    lab = TRUE,
    lab_size = 6
  )


nfrimando/pseR documentation built on Jan. 10, 2022, 4:27 p.m.