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

Exemple of plot for more than one data #17

Closed Fredysessie closed 2 years ago

Fredysessie commented 2 years ago
##For two dataframe
library(plotly)
library(quantmod)
library(tidyverse)
library(tseries)
library(timeSeries)
glob.ret<-BRVM_get(.symbol = c("ONTBF", "BICC"), .from = '2009-05-24', .to = '2022-01-01')

##Instead of assigning the return to a global.return data
##We must think about how to assign directely in the function the name of every company to his ticker in symbol vector
#referig to GetSymbols of quantmod package
#The function must start by something like
# getSymbols {{{
#"getSymbols" <-
#function(Symbols=NULL,
#         env=parent.frame(),  ### 0.4-0
         #env=NULL,          ### 0.5-0
#        reload.Symbols=FALSE,
#        verbose=FALSE,
#         warnings=TRUE,
#        src="yahoo",
#         symbol.lookup=TRUE,
#        auto.assign=getOption('getSymbols.auto.assign',TRUE),
#        ...)

#I Can't find the best way  but i'm thinking about it
"https://github.com/cran/quantmod/blob/master/R/getSymbols.R"
#You can take a look, may be you will have an idea idea

for (elem in unique(glob.ret$ticker)) {
    assign(elem, as_tibble(subset(glob.ret, ticker==elem)))

##I updated the BRVM_get function so this is added
#ONTBF<-ONTBF%>%
#  group_by(date_col)%>%
#  summarise(open=ceiling(mean(open)),
#           high= ceiling(mean(high)),
#            low= ceiling(mean(low)),
#            close= ceiling(mean(close)),
#            colume= ceiling(mean(volume)))

#BICC<-BICC%>%
#  group_by(date_col)%>%
#  summarise(open=ceiling(mean(open)),
#           high= ceiling(mean(high)),
#            low= ceiling(mean(low)),
#            close= ceiling(mean(close)),
#            colume= ceiling(mean(volume)))
BICC<-as.xts(BICC, order.by=BICC$date_col)
ONTBF<-as.xts(ONTBF, order.by=ONTBF$date_col)

ds2<-na.omit(as.data.frame(merge(ONTBF$close, BICC$close, all = T)))
ds2$Date<-rownames(ds2)  ##Add Date

###Loop to turn character to numeric data
for (el in 2:ncol(ds2)){
  ds2[,el]<-as.numeric(ds2[,el])
}

fig2 <- plot_ly(ds2, x = ~Date)
fig2 <- fig2 %>% add_lines(y = ~close, name = "ONTBF")
fig2 <- fig2 %>% add_lines(y = ~close.1, name = "BICC")
fig2 <- fig2 %>% layout(
  title = "Stock Prices",
  xaxis = list(
    rangeselector = list(
      buttons = list(
        list(
          count = 3,
          label = "3 mo",
          step = "month",
          stepmode = "backward"),
        list(
          count = 6,
          label = "6 mo",
          step = "month",
          stepmode = "backward"),
        list(
          count = 1,
          label = "1 yr",
          step = "year",
          stepmode = "backward"),
        list(
          count = 5,
          label = "5 yr",
          step = "year",
          stepmode = "backward"),
        list(
          count = 10,
          label = "10 yr",
          step = "year",
          stepmode = "backward"),
        #        list(
        #          count = 1,
        #          label = "YTD",
        #          step = "year",
        #          stepmode = "todate"),
        list(step = "all"))),

    rangeslider = list(type = "date")),

  yaxis = list(title = "Closing Price"))

fig2
spsanderson commented 2 years ago

I'll take a look tomorrow

spsanderson commented 2 years ago

If the data is coming back as a tibble then we can make the ticker column a factor and make sure the data is in long format and then use ggplot(aes(group = ticker)) to plot the data with a single geom, we can make a parameter of .interactive to return a plotly plot. Or unless you are looking specifically for quantmod plots then we should look at some working examples of those and how the data needs to be formatted to work with them.

Fredysessie commented 2 years ago

image Hi every one. Does some one has idea about how we can hide the warning message that are printing out? Thanks in advance

spsanderson commented 2 years ago

I don’t know have to look into it

Sent from my iPhone www.spsanderson.com

On Mar 4, 2022, at 6:45 PM, Koffi Frederic Sessie @.***> wrote:



Hi every one. how can he hide the warning message that are printing out.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.

Fredysessie commented 2 years ago
library(plotly)
library(quantmod)
library(tidyverse)
library(tseries)
library(dplyr)
library(timeSeries)
library(forecast)

BICC<- BRVM_get(.symbol = "BICC")
BICC1<-BICC

###Le code si bosse bien Travailler le code après
BICC<-as.xts(BICC[,-c(1:2)],
                order.by=BICC$date_col
                #,order.by=index(BICC1.a)
                #, updated=Sys.time()
)

##This plot is nice i think
##It helps users to export the result
fig<- hchart(BICC)%>%
  hc_exporting(
    enabled = TRUE, # always enabled
    filename = paste0("BICC chart")
  )
fig

image

Fredysessie commented 2 years ago

I don’t know have to look into it Sent from my iPhone www.spsanderson.com On Mar 4, 2022, at 6:45 PM, Koffi Frederic Sessie @.***> wrote:  Hi every one. how can he hide the warning message that are printing out. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.

Please @spsanderson can we later add in our functions some posssibilities about packages :

# For example declare packages wich will be use in the function
packages <- c("dplyr","ggplot2","rlang", "tseries")

# Loop through each package
for (package in packages) {    
    # Install package
    if (!package in installed.packages()) {        
        # Install it
        install.packages(
            package,
            dependencies = TRUE
        )        
    }    
    # Load package
       if (!package in .packages()) {        
        # Load it
        library(
            package,
            character.only = TRUE
        )  
    }
}
spsanderson commented 2 years ago

I don't see why this would be necessary since any library we use needs to be declared in the description file and the import section will force its install for users. I could do an on attach that makes sure the libraries are loaded inthe session when someone does library(BRVM)

Fredysessie commented 2 years ago

Ok i understand. Ok so it is not necessary

Fredysessie commented 2 years ago

i'll delete the previous message. Thanks.

Fredysessie commented 2 years ago

If the data is coming back as a tibble then we can make the ticker column a factor and make sure the data is in long format and then use ggplot(aes(group = ticker)) to plot the data with a single geom, we can make a parameter of .interactive to return a plotly plot. Or unless you are looking specifically for quantmod plots then we should look at some working examples of those and how the data needs to be formatted to work with them.