Koffi-Fredysessie / BRVM

Ce package R fournit une interface conviviale pour accéder aux données de la BRVM, qui est une bourse régionale desservant plusieurs pays d'Afrique de l'Ouest. Avec ce package, les utilisateurs peuvent facilement récupérer des données historiques sur les prix des actions, les volumes de transactions et d'autres indicateurs financiers.
https://rpubs.com/Fredysessie/Readme_BRVM_Stock
Other
7 stars 1 forks source link

R Shiny proposal of our project #22

Closed Fredysessie closed 2 years ago

Fredysessie commented 2 years ago

Hi to every body. Belowing code will work only if the BRVM_get is same to the one of https://github.com/AODiakite/BRVM/blob/patch-3/R/get-bvrm-ticker-data.R

Please @spsanderson and @AODiakite that means we will need to add some news function as "company_sector". I"m working on it. The first page "About society" need more option. I just add some boxes to have an idea. Later we will arrange them well. the 2nd and others pages are just proposition also. It remains their plots, reactivity and others. Try to explore the r shiny version and give your best suggestions. Thanks and best regard.

library(shiny)
library(shinydashboard)
library(plotly)
library(ggplot2)
library(shinyWidgets)
library(shinythemes)
library(datasets)
library(timeSeries)
library(xts)
library(plotly)
library(quantmod)
library(gsheet)
library(httr)
library(stringr)
library(dplyr)
library(tidyr)
library(rvest)
library(formattable)
library(data.table)
library(kableExtra)
library(rlang)
library(lubridate)
library(purrr)
library(DT)
library(highcharter)
library(tidyverse)
library(tseries)
library(timeSeries)
library(forecast)
library(highr)
library(bslib)
library(thematic)

shinyOptions(bslib = TRUE)
bs_global_theme()
bs_theme_base_colors(bg = "#002B36", fg = "#EEE8D5")
bs_theme_accent_colors(primary = "#2AA198")
thematic::thematic_shiny()

ui<-fluidPage(
  theme=shinytheme("cerulean"),# returns URL of a shiny theme
  themeSelector(), ## not required but can be used to select the theme

  navbarPage(
    title= "BRVM stock exchange",
    id="nav",
    tabPanel("Introduction", value = "Introduction", icon = icon("info-circle"),
             column(1),
             column(10, align = "center",

                        h1(align = "center",strong("BRVM STOCK EXCHANGE")),
                        h3(align ="justify" ,"The regional stock exchange BRVM is the regional stock market for all the eight 8 Member States in the West African Economic and Monetary Union (WAEMU), namely: Benin, Burkina Faso, Ivory Coast, Guinea-Bissau, Mali, Niger, Senegal and Togo. The BRVM is an economic and a political institution and technical success story all in one. It is the only stock market in the world shared by several countries, run totally in digital format and integrated in a perfect manner. "),

                        h3(align = "left", em("The BRVM was established step by step:")),
                        h3(align ="justify", strong("14 November 1973"), ": Signing of the Treaty to establish the West African Monetary Union (WAMU). The founding members were Benin, Burkina Faso, Ivory Coast, Mali, Niger, Senegal and Togo. These countries were joined in 1997 by Guinea-Bissau;" ),
                        h3(align ="justify", strong("17 December 1993"), ": the WAMU Council of Ministers decides to establish a Regional Financial Market and assigns the West African Central Bank (Banque Centrale des Etats de l’Afrique de l’Ouest - BCEAO) to lead the project;"),
                        h3(align ="justify", strong(" 18 December 1996"), ": the founding of the BRVM and DC/BR as limited companies. The venue of the event is Cotonou, Benin;"),
                        h3(align ="justify", strong("November 20, 1997") ,": the WAMU Council of Ministers sets up a market regulation body called the Regional Council for Public Savings and Financial Markets - Regional Council for Public Savings and Financial Markets (CREPMF);" ),
                        h3(align ="justify", strong("16 September 1998") ,": the BRVM and DC/BR begin operations;" ),
                        h3(align ="justify", strong("24 March 1999"), ": Decentralized Electronic Trading is put in motion;" ),
                        h3(align ="justify", strong("12 November 2001"), ": transition to trading on a daily basis;"),
                        h3(align ="justify", strong("2 July 2007"), ": shift from a Settlement/Delivery period of T+5 to T+3 (DC/BR);"),
                        h3(align ="justify", strong("16 September 2013"), ": shift to continuous trading (BRVM);"),
                        h3(align ="justify", strong("10 June 2014"), "a 'Stand-alone' index is created in the WAEMU financial market by Morgan Stanley Capital International (MSCI), a financial services company"),
                        h3(align ="justify", strong("14 June 2014"), ": BRVM is integrated into the MSCI and S & P Dow Jones indices."),
                        h3(align ="justify", strong(""), ""),

                        br(),
                        h1(strong("Single stock")),
                        h3(align ="justify","Users are able through this section to input the ticker of the company of their choice, select range of dates, analyze each quote individually, evaluate its performance, etc."),

                        br(),
                        h2(strong("Multiple stock")),
                        h3(align ="justify","Through this section users are able to input more than one company ticker of their choice, select range of dates, compare stocks by sector or by country, evaluate their performances, etc."),

                        br(),
                        h2(strong("Stock price forcast")),
                        h3(align ="justify","In this section, users are able to forcast daily historical trading data of each stock that has been listed BRVM by using different models such us ARIMA, Copula, Monte Carlos simulation; etc. "),

                        br(),
                        h2(strong("About autors")),
                        h3(align ="justify","Authors informations are displays in this section."),
                        br(),
                        h3(align ="justify","Please note: this project is a live project that is still under construction, improvement, and updates as of this time.")
               )

    ),
    tabPanel("Single stock", value = "single_stock", icon = icon("chart-area"),
             sidebarLayout(
               sidebarPanel(width = 3, align = "center",
                            # style= "background-color: #dec4de",
                 selectInput("ticker", strong("Ticker"), quotes$Symbole,selectize = TRUE
                             #, multiple = TRUE
                 ),
                 dateRangeInput("date", strong("Select data range"),
                                start = "2012-01-01", end = (Sys.Date()-1)
                 ),

                 #selectInput("dataset","Select the dataset", choices=c("mtcars dataset" = "m", "pressure dataset" = "p")),
                 #tags$br(),
                 sliderInput("n", "Select nb. of data rows", min = 2, max = 10, value=6),
                 tags$br(),
                 #actionButton("button", "ActionButton"),
                 #tags$br(),
                 #br(),
                 #radioButtons("c", "Radiobuttons", c("Yes", "No"))
               ),
               mainPanel(
                 tabsetPanel(
                   tabPanel("About society",icon = icon("address-card",class="fa-regular fa-address-card"),
                            fluidRow(align ="center",
                              tags$br(), tags$br(),tags$br(),tags$br(), tags$br(),tags$br(),
                              valueBoxOutput("avail_data")
                              ,
                              #valueBoxOutput("society_rank"),
                              #infoBoxOutput("society_rank"),

                              #infoBoxOutput("country"),
                              #infoBoxOutput("capitalization"),
                              #infoBoxOutput("traded_value"),
                              infoBox("Rank", paste0(1, "st"),icon = icon("mortar-board"), color = "aqua", fill = FALSE), # icon("diamond"),  icon("bell-o")
                              #infoBox("Sector", 8000,icon = icon("institution")),
                              infoBoxOutput("Sector"),
                              tags$br(), tags$br(),tags$br(),tags$br(), tags$br(),tags$br(),
                              tags$br(), tags$br(),tags$br(),tags$br(), tags$br(),tags$br(),
                              infoBox("Country", 8000,icon = icon("globe") ),
                              infoBox("Capitalization", 8000,icon = icon("money")),
                              infoBox("Traded value", 8000,icon = icon("exchange")),
                              tags$br(), tags$br(),tags$br(),tags$br(), tags$br(),tags$br(),
                              tags$br(), tags$br(),tags$br(),tags$br(), tags$br(),tags$br(),
                              box(width = 4,
                                title = "Ranking",  solidHeader = T,
                                id = "mybox",
                                collapsible = TRUE,
                                closable = TRUE, status = "primary",
                                plotOutput("plot3")
                              )
                            )),
                   tabPanel("Data structure", icon = icon("table"), class="fa fa-table", verbatimTextOutput("struc")),
                   tabPanel("Data summary", icon = icon("list-alt"), class="fa-duotone fa-sigma", verbatimTextOutput("summary1")),
                   tabPanel("Dataset",icon = icon("database"), DTOutput('tbl1')),
                   tabPanel("Histogram and boxplot",icon = icon(""), class="fa-regular fa-database",
                            plotlyOutput("boxplot", width = "auto", height = "400px")),
                   tabPanel("Plot",icon = icon("bar-chart-o"), br(),br(), br(),
                            highchartOutput("plot1",width = "auto", height = "400px")) ,  # highchartOutput(outputId ="plot2")),

                   #tabPanel("Dataset", tableOutput("table"), icon = icon("database", class="fa-regular fa-database")),
                   #tabPanel("Summary Stats", verbatimTextOutput("summary"))
                 )
               )
             )),
    tabPanel("Multiple stock", tabName = "mult_stock", icon = icon("th"),
             #menuSubItem("Indexes", tabName = "index", icon = icon("institution"))
             sidebarLayout(
               sidebarPanel(width = 3, align = "center",
                            # style= "background-color: #dec4de" ,
                            selectInput("ticker_mult", strong("Ticker(s)"), quotes$Symbole, selectize = TRUE
                                        , multiple = TRUE
                            ),
                            br(),
                            dateRangeInput("date_mult", strong("Select data range"),
                                           start = "2012-01-01", end = (Sys.Date()-1)),

                            #actionButton("button", "ActionButton")
                            ),

               mainPanel(
                 tabsetPanel(
                   tabPanel("Societies informations",icon = icon("address-card",class="fa-regular fa-address-card")),
                   tabPanel("Data structure", icon = icon("table"), class="fa fa-table", verbatimTextOutput("struc1")),
                   tabPanel("Data summary", icon = icon("list-alt"), class="fa-duotone fa-sigma", verbatimTextOutput("summary2")),
                   tabPanel("Histogram and boxplot",icon = icon(""), DTOutput('tbl2')),
                   tabPanel("Dataset",icon = icon("database"), class="fa-regular fa-database", tableOutput("table2")),
                   tabPanel("Comparison plot",icon = icon("bar-chart-o"), plotlyOutput("plot2")) ,  # highchartOutput(outputId ="plot2"))
                 )
               )
             )
             )
    ,
    tabPanel("Indexes", tabName = "index", icon = icon("institution")),
    tabPanel("Volumes/Values", tabName = "volumes_values", icon = icon("exchange")),
    tabPanel("Stock price forcast", tabName = "forcast", icon = icon("chart-line")),
    tabPanel("About authors", tabName = "about", icon = icon("users"))
  )
  )

server<-function(input, output, session){
  cs <- new.env()

  dt<-eventReactive(c(input$ticker, input$date[1], input$date[2]), {
  mydata<-BRVM_get(input$ticker,
                   .from = as.Date(input$date[1]),
                   .to = as.Date(input$date[2]))
                    })

  dt1<-eventReactive(c(input$ticker, input$date[1], input$date[2]), {
    mydata1<-BRVM_get(input$ticker,
                     .from = as.Date(input$date[1]),
                     .to = as.Date(input$date[2]))
    mydata1<-as.xts(mydata1[,-c(1,7)],
                    order.by=mydata1$Date)

  })

  tick.sect<-eventReactive(c(input$ticker),{
    all.sector<-BRVM_sector("All")
    dt.sector<-filter(all.sector, ticker==input$ticker)$sector

  })

  output$boxplot <- renderPlotly({
    plot_ly(
      data = as.data.frame(dt()),
      y=~Close,
      type = "box",
      boxpoints = "all"
    )

  })

  output$struc<- renderPrint({
    str(dt())
  })

  output$tbl1 = renderDT({
    datatable(
      dt(), escape = FALSE, filter = 'top', rownames = FALSE, 
      extensions = list('ColReorder' = NULL, 'RowReorder' = NULL, 
                        'Buttons' = NULL, 'Responsive' = NULL), 
      options = list(dom = 'BRrltpi', scrollX = TRUE, #autoWidth = TRUE, 
                     lengthMenu = list(c(10, 50, 100, -1), c('10', '50', '100', 'All')), 
                     ColReorder = TRUE, rowReorder = TRUE, 
                     buttons = list('copy', 'print', 
                                    list(extend = 'collection', 
                                         buttons = c('csv', 'excel', 'pdf'), 
                                         text = 'Download'), I('colvis'))))
})

  output$summary1 <- renderPrint({

    summary(dt())
  })

  output$plot1<-renderHighchart({

    hchart(dt1())%>%
      hc_exporting(
        enabled = TRUE, # always enabled,

        filename = paste0(input$ticker," chart : from",input$date[1], "to", input$date[2])
      )

  })
  output$avail_data<-renderValueBox({
    valueBox(icon = icon("database", class="fa-regular fa-database"),"Available data", nrow(dt()),  color = "green")
  })

  output$Sector<-renderInfoBox({
    valueBox(icon = icon("institution", class="fa-regular fa-database"),"Belong to", paste0(tick.sect()," ", " sector"),  color = "green")
  })

}

shinyApp(ui=ui, server = server)
AODiakite commented 2 years ago

Hi Fredy, Can you post the app so I can see what it looks like ?

spsanderson commented 2 years ago

I suggest also using a framework like golem which might be helpful. I'll take a look as I still need to look over the charts code, I'm working on a consulting project tonight so I'll be online.

Fredysessie commented 2 years ago

Hi Fredy, Can you post the app so I can see what it looks like ?

Yes i'll. Give me some moment to achieve the first and second page and i'll post the app. Thanks @AODiakite

Fredysessie commented 2 years ago

I suggest also using a framework like golem which might be helpful. I'll take a look as I still need to look over the charts code, I'm working on a consulting project tonight so I'll be online.

Sounds good. I'll be oneline too till 1 ou 2 AM.