knitr::opts_chunk$set(echo = TRUE)
Pull and analyse PSE data. Currently limited only to Investagrams as source which is limited to past year data only.
Install devtools to easily install pseR
.
install.packages("devtools") devtools::install_github("nfrimando/pseR")
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()
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()
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 )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.