knitr::opts_chunk$set(echo = TRUE)
library(magrittr)

Presentation

CFM (Casablanca Financial Market) is a R package that has been designed to simplify financial programming workflow with Casablanca stock exchange data.

Currently, it implements 5 mains functions:

Demo

The number of firms currently listed in Casablanca stock exchange:
library(cfm)

all_symbols <- cfm::get_stocks()
length(all_symbols)
A sample of listed firms:
dplyr::data_frame(Firm = all_symbols) %>%
    head(n = 13) %>%
    knitr::kable()
The number of available indexes:
all_indexes <- cfm::get_indexes()
all_indexes %>%
    nrow()
A sample of available indexes:
all_indexes %>%
    head(n = 15) %>%
    knitr::kable()
ITISSALAT AL-MAGHRIB Historical Data:
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 Historical Data:
masi <- cfm::index_data('MASI', '01/01/2015', '11/09/2017')
masi %>%
    dplyr::as_data_frame() %>%
    tail(n = 20) %>%
    knitr::kable()
Plotting MASI vs ITISSALAT AL-MAGHRIB
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.