#introduction This project will use BBRI stock data sourced from Yahoo Finance to obtain historical stock price data to report stock metrics and performance. We use dataset from 21 october 2017 to 21 october 2022

#library

options("install.lock"=FALSE)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tidyr)
library(lubridate)
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
library(ggplot2)
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout

#load dataset

dfbri <- read.csv("data_input/BBRI.JK.csv")
head(dfbri)
##         Date        Open        High         Low       Close   Adj.Close
## 1 2017-10-23 3140.000000 3145.000000 3110.000000 3125.000000 2678.236572
## 2 2017-10-24 3140.000000 3140.000000 3090.000000 3095.000000 2652.525391
## 3 2017-10-25 3095.000000 3140.000000 3090.000000 3120.000000 2673.951416
## 4 2017-10-26 3140.000000 3150.000000 3120.000000 3125.000000 2678.236572
## 5 2017-10-27 3125.000000 3140.000000 3115.000000 3120.000000 2673.951416
## 6 2017-10-30 3130.000000 3140.000000 3105.000000 3110.000000 2665.381104
##      Volume
## 1  82390000
## 2  57974000
## 3  79974500
## 4 113016500
## 5 134568500
## 6 115711500
str(dfbri)
## 'data.frame':    1253 obs. of  7 variables:
##  $ Date     : chr  "2017-10-23" "2017-10-24" "2017-10-25" "2017-10-26" ...
##  $ Open     : chr  "3140.000000" "3140.000000" "3095.000000" "3140.000000" ...
##  $ High     : chr  "3145.000000" "3140.000000" "3140.000000" "3150.000000" ...
##  $ Low      : chr  "3110.000000" "3090.000000" "3090.000000" "3120.000000" ...
##  $ Close    : chr  "3125.000000" "3095.000000" "3120.000000" "3125.000000" ...
##  $ Adj.Close: chr  "2678.236572" "2652.525391" "2673.951416" "2678.236572" ...
##  $ Volume   : chr  "82390000" "57974000" "79974500" "113016500" ...
nrow(dfbri)
## [1] 1253

#cleansing data

dfbri <- dfbri %>%
  mutate(
    Date = ymd(Date),
    Open = as.numeric(Open),
    High = as.numeric(High),
    Low = as.numeric(Low),
    Close = as.numeric(Close),
    Adj.Close = as.numeric(Adj.Close),
    Volume = as.numeric(Volume)
    
  )
## Warning in mask$eval_all_mutate(quo): NAs introduced by coercion

## Warning in mask$eval_all_mutate(quo): NAs introduced by coercion

## Warning in mask$eval_all_mutate(quo): NAs introduced by coercion

## Warning in mask$eval_all_mutate(quo): NAs introduced by coercion

## Warning in mask$eval_all_mutate(quo): NAs introduced by coercion

## Warning in mask$eval_all_mutate(quo): NAs introduced by coercion
str(dfbri)
## 'data.frame':    1253 obs. of  7 variables:
##  $ Date     : Date, format: "2017-10-23" "2017-10-24" ...
##  $ Open     : num  3140 3140 3095 3140 3125 ...
##  $ High     : num  3145 3140 3140 3150 3140 ...
##  $ Low      : num  3110 3090 3090 3120 3115 ...
##  $ Close    : num  3125 3095 3120 3125 3120 ...
##  $ Adj.Close: num  2678 2653 2674 2678 2674 ...
##  $ Volume   : num  8.24e+07 5.80e+07 8.00e+07 1.13e+08 1.35e+08 ...

#exploratory data analysis

ggplot(dfbri, aes(x = Close)) +
  geom_histogram(bins = 30) +
  xlab("Closing Price of BBRI stock") + ylab("Frequency") +
  ggtitle("Histogram of BBRI stock closing price")
## Warning: Removed 1 rows containing non-finite values (stat_bin).

ggplot(dfbri, aes(x = Date, y = Close )) +
  geom_line() +
  xlab("Date") + ylab("Closing Price of BBRI stock") +
  ggtitle("BBRI stock price trend over time")+
  theme(plot.title = element_text(face = "bold")) +
  theme(plot.title = element_text(hjust = 0.5))

*insight

based on the plot that has been made, the trend of the BBRI stock price has fallen or fallen in 2020 but in this visualization we can’t see the details so we will make it using plotly

plot_ly(dfbri, x =~dfbri$Date) %>% 
  add_lines( y =~dfbri[,2], name = "BBRI") %>% 
  layout(
    title = "        BBRI",
    xaxis = list(
      rangeselector = list(
        buttons = list(
          list(
            count = 1,
            label = "1 month",
            step = "month",
            stepmode = "backward"
          ),
          list(
            count = 3, 
            label = "3 month",
            step = "month",
            stepmode = "backward"),
          list(
            count = 6,
            label = "6 month",
            step = "month",
            stepmode = "backward"),
          list(
            count = 12,
            label = "1 year",
            step = "month",
            stepmode = "backward"
          ),
          list(
            count = 60,
            label = "5 year",
            step = "month",
            stepmode = "backward"
          )
        )), title = "Date"),
    rangeslider = list(type = "date"),
    yaxis = list(title = "Price")
)
## Warning: 'layout' objects don't have these attributes: 'rangeslider'
## Valid attributes include:
## '_deprecated', 'activeshape', 'annotations', 'autosize', 'autotypenumbers', 'calendar', 'clickmode', 'coloraxis', 'colorscale', 'colorway', 'computed', 'datarevision', 'dragmode', 'editrevision', 'editType', 'font', 'geo', 'grid', 'height', 'hidesources', 'hoverdistance', 'hoverlabel', 'hovermode', 'images', 'legend', 'mapbox', 'margin', 'meta', 'metasrc', 'modebar', 'newshape', 'paper_bgcolor', 'plot_bgcolor', 'polar', 'scene', 'selectdirection', 'selectionrevision', 'separators', 'shapes', 'showlegend', 'sliders', 'spikedistance', 'template', 'ternary', 'title', 'transition', 'uirevision', 'uniformtext', 'updatemenus', 'width', 'xaxis', 'yaxis', 'barmode', 'bargap', 'mapType'
*insight

Based on this visualization plot, it looks detailed and interactive, in July 2020, the stock price fell and its development fluctuated