vignettes/cfm_vignette.R

## ----setup, include=FALSE------------------------------------------------
knitr::opts_chunk$set(echo = TRUE)
library(magrittr)

## ------------------------------------------------------------------------
library(cfm)

all_symbols <- cfm::get_stocks()
length(all_symbols)

## ------------------------------------------------------------------------
dplyr::data_frame(Firm = all_symbols) %>%
    head(n = 13) %>%
    knitr::kable()

## ------------------------------------------------------------------------
all_indexes <- cfm::get_indexes()
all_indexes %>%
    nrow()

## ------------------------------------------------------------------------
all_indexes %>%
    head(n = 15) %>%
    knitr::kable()

## ------------------------------------------------------------------------
iam <- cfm::stock_data('ITISSALAT AL-MAGHRIB', '01/01/2015', '11/09/2017')
iam %>%
    dplyr::as_data_frame() %>%
    dplyr::select(Session, `Reference price`, `Last price`, `Number of shares traded`) %>%
    tail(n = 20) %>%
    knitr::kable()

## ------------------------------------------------------------------------
masi <- cfm::index_data('MASI', '01/01/2015', '11/09/2017')
masi %>%
    dplyr::as_data_frame() %>%
    tail(n = 20) %>%
    knitr::kable()

## ---- fig.width=7.5, fig.height=5----------------------------------------
masi %>%
    dplyr::inner_join(iam, by = 'Session') %>%
    dplyr::select(Session, `Last price`, Value) %>%
    dplyr::mutate(`Last price` = scales::rescale(`Last price`, to = c(0, 1))) %>%
    dplyr::mutate(Value = scales::rescale(Value, to = c(0, 1))) %>%
    ggplot2::ggplot(ggplot2::aes(x = Session)) +
    ggplot2::geom_line(ggplot2::aes(y = `Last price`, colour = 'IAM')) +
    ggplot2::geom_line(ggplot2::aes(y = Value, colour = 'MASI')) +
    ggplot2::ylab('Scaled Prices') +
    ggplot2::theme_minimal() +
    ggplot2::theme(legend.title = ggplot2::element_blank(), 
                   panel.grid.major = ggplot2::element_blank(),
                   panel.grid.minor = ggplot2::element_blank()) +
    ggplot2::ggtitle('ITISSALAT AL-MAGHRIB Price vs MASI Value', 
                     subtitle = 'From 01/01/2015 to 11/09/2017')
blnash508/cfm documentation built on May 30, 2019, 4:31 p.m.