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
8 stars 1 forks source link

I think we're ready to publish the package #25

Closed Fredysessie closed 1 year ago

Fredysessie commented 2 years ago

Hi @spsanderson and @AODiakite hope that you are doing good. We can publish the package and continue with the r shiny after. Please befor doing it can you please add all the 2 news utils and 6 functions in the following comment to the main and their description? Waiting for your point of view. Thanks

Fredysessie commented 2 years ago

But we will add two more utils and 6 functions such as :

This list will be useful later to create some functions

.sectors =list(Agriculture = c("PALC","SCRC","SICC","SOGC","SPHC"),
               Distribution = c("ABJC","BNBC","CFAC","PRSC","SHEC","TTLC","TTLS"),
               Industry = c("CABC","FTSC","NEIC","NTLC","SEMC","SIVC","SLBC","SMBC","STBC","TTRC","UNLC","UNXC"),
               Finance = c("BOAB","BOABF","BOAC","BOAM","BOAN","BOAS","BICC","CBIBF","ECOC","ETIT","NSBC","ORGT","SAFC","SGBC","SIBC"),
               Transport = c("SDSC","SVOC"),
               "Public service" = c("CIEC","ONTBF","SDCC","SNTS"),
               Other = c("STAC"))

and

########

This list will be also useful later

  Countries<-list(BENIN =c("BOAB"), "BURKINA FASO" = c("BOABF", "CBIBF", "ONTBF"),
                  "IVORY COAST" = c("ABJC", "BICC", "BNBC","BOAC", "CABC", "CFAC", "CIEC", "ECOC", "FTSC", "NEIC",
                                    "NSBC","NTLC", "PALC", "PRSC", "SAFC", "SCRC", "SDCC", "SDSC", "SEMC","SGBC",
                                    "SHEC", "SIBC", "SICC", "SIVC", "SLBC", "SMBC", "SOGC","SPHC", "STAC", "STBC",
                                    "SVOC", "TTLC", "TTRC", "UNLC","UNXC"),
                  MALI = c("BOAM"), NIGER = c("BOAN"),
                  SENEGAL = c("BOAS", "SNTS", "TTLS"),
                  TOGO = c("ETIT", "ORGT"))

Create a permanent ticker descriptive dataframe

BRVM_ticker_desc<- function(){
  tryCatch(
    {
      Desc.BRVM.all <- rvest::read_html("https://www.brvm.org/en/cours-actions/0/status/200") %>%
        rvest::html_nodes('table') %>%
        rvest::html_table()
      Desc.BRVM.all <- Desc.BRVM.all[[4]]
      Desc.BRVM.all<-Desc.BRVM.all[1:2]
      colnames(Desc.BRVM.all)<-c(
        "Ticker",
        "Company name")

      #Create sector column
      Desc.BRVM.all$Sector<-NA
      for (elm in 1:length(Desc.BRVM.all$Ticker)){
        for (elm1 in 1 : length(.sectors)) {
          if (Desc.BRVM.all$Ticker[elm] %in% .sectors[[elm1]]) {     
            Desc.BRVM.all$Sector[elm]<-names(.sectors)[[elm1]]
          }
        }
      }

      #Create country column
      Desc.BRVM.all$Country<-NA
      for (elem in 1:length(Desc.BRVM.all$Ticker)){
        for (elem1 in 1 : length(Countries)) {
          if (Desc.BRVM.all$Ticker[elem] %in% Countries[[elem1]]) {     
            Desc.BRVM.all$Country[elem]<-names(Countries)[[elem1]]
          }
        }
      }
    },
    error = function(e) {
      print("Make sure you have an active internet connection")
    },
    warning = function(w) {
      print("Make sure you have an active internet connection")
    }
  )
  return(Desc.BRVM.all)
  #return(quotes_tbl)
}

########

To know the country of each company

company_country<- function(company){  
  company<-toupper(company)  
  for (elem in 1 :length(Countries)){
    if (company %in% Countries[[elem]]) {     
      return(names(Countries)[[elem]])
    }
  }
}

########

To know the sector of each company

function(company){
company<-toupper(company)  
 for (elem in 1 :length(.sectors)){
   # if (input$ticker %in% .sectors[[elem]]) {
   if (company %in% .sectors[[elem]]) {     
     return(names(.sectors)[[elem]])
   }
 }
}

################

To know the traded capitalisation value of each company

company_cap<- function(company){
  company<-toupper(company)
  tryCatch({
    brvm_cap_all <- rvest::read_html("https://www.brvm.org/en/capitalisations/0/status/200") %>%
      rvest::html_nodes('table') %>%
      rvest::html_table()
    brvm_cap_all <- brvm_cap_all[[4]]
    brvm_cap_all$`Global capitalization (%)`<-gsub(",", ".",brvm_cap_all$`Global capitalization (%)`)
    for (elm in 1:nrow(brvm_cap_all)){
      if (brvm_cap_all[elm,1]==company){
        the_cap<-paste0(brvm_cap_all[elm,6], "")
      }
    }

    return(the_cap)

  },
  error = function(e) {
    print("Make sure you have an active internet connection")
  },
  warning = function(w) {
    print("Make sure you have an active internet connection")
  })
}

###########

To know the traded volume value of each company

function(company){
  company<-toupper(company)
  tryCatch({
    brvm_trade_all <- rvest::read_html("https://www.brvm.org/en/volumes/0/status/200") %>%
      rvest::html_nodes('table') %>%
      rvest::html_table()
    brvm_trade_all <- brvm_trade_all[[4]]
    for (elm in 1:nrow(brvm_trade_all)){
      if (brvm_trade_all[elm,1]==company){
        trade_value<-paste0(brvm_trade_all[elm,4], "")
      }
    }

    return(trade_value)

  },
  error = function(e) {
    print("Make sure you have an active internet connection")
  },
  warning = function(w) {
    print("Make sure you have an active internet connection")
  })
}

##############

Function which help to know the rank of each company

company_nbrank<-function(.company){
  .company<-toupper(.company)
  tryCatch({
    companies_rk<-BRVM_company_rank()
    for (elm in 1:nrow(companies_rk)){
      if (companies_rk[elm,1]==.company){
        the_rank<- companies_rk[elm,8]
      }
    }
    if (the_rank!= 11& substr(the_rank, nchar(the_rank),nchar(the_rank)) == 1){
      the_rank<- paste0(the_rank, " st")
    }    
    else if (the_rank!= 12 & substr(the_rank, nchar(the_rank),nchar(the_rank)) == 2){
      the_rank<- paste0(the_rank, " nd")
    }
    else if (the_rank!= 13 & substr(the_rank, nchar(the_rank),nchar(the_rank)) == 3){
      the_rank<- paste0(the_rank, " rd")
    } else { 
      the_rank<- paste0(the_rank, " th")
    }
    the_rank<-paste0(.company," is the ", the_rank)        
    return(the_rank)
  },
  error = function(e) {
    print("Make sure you have an active internet connection")
  },
  warning = function(w) {
    print("Make sure you have an active internet connection")
  })
}
Fredysessie commented 2 years ago

Belowing pictures are the r shiny version.

image image image image image image image image image

Best regards

spsanderson commented 2 years ago

wow nice

AODiakite commented 2 years ago

Hi Koffi I really appreciate shiny app. You're doing well. Congrats ! Now lets submit the package !