R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

About project: this is project of downloading stock prices and analysis the price values. first of all i download the three stock data and analyze it and plot the best visualization of stock prices that are easy for understandable.

library(pacman)
## Warning: package 'pacman' was built under R version 4.1.1
pacman::p_load(data.table, fixest, BatchGetSymbols, finreportr, ggplot2, lubridate)
## Set parameters
first.date <- Sys.Date() - 2500
last.date <- Sys.Date()
freq.data <- "monthly"
tickers <- c("TSLA", "NIO", "PRPL")

## Get Stock Prices
## we get the stock prices by using the BatchGetSymbols and it downloads the stock prices of stock data that is in ticker.

stocks <- BatchGetSymbols(tickers = tickers, 
                         first.date = first.date,
                         last.date = last.date, 
                         freq.data = freq.data,
                         do.cache = FALSE,
                         thresh.bad.data = 0)
## 
## Running BatchGetSymbols for:
##    tickers =TSLA, NIO, PRPL
##    Downloading data for benchmark ticker
## ^GSPC | yahoo (1|1)
## TSLA | yahoo (1|3) - Got 100% of valid prices | OK!
## NIO | yahoo (2|3) - Got 44% of valid prices | Feliz que nem lambari de sanga!
## PRPL | yahoo (3|3) - Got 86% of valid prices | Nice!
## Verify Returns
stocks_DT <- stocks$df.tickers %>% setDT() %>%          # Convert to data.table
  .[order(ticker, ref.date)]                           # Order by ticker and date
 

## Graph Returns and Prices and it give the best visulization of data that is easy to understandable for the reader that view plot and check out the recquired results.
returns_plot_all <- ggplot(stocks_DT, aes(x= ref.date, y = ret.adjusted.prices, colour = ticker)) +
  geom_line() + theme_bw() + labs(title = "", x = "Date", y= "Monthly Returns", subtitle = "") 

price_plot_all <- ggplot(stocks_DT, aes(x= ref.date, y = price.close, colour = ticker)) +
  geom_line() + theme_bw() + labs(title = "", x = "Date", y= "Closing Price", subtitle = "") 

returns_sep <- ggplot(stocks_DT[ticker %in% c("TSLA", "NIO", "PRPL")], aes(x = ref.date, y = ret.adjusted.prices)) + geom_line() + facet_wrap(~ticker, scales = "free_y") + theme_bw()
prices_sep <- ggplot(stocks_DT[ticker %in% c("TSLA", "NIO", "PRPL")], aes(x = ref.date, y = price.close)) + geom_line() + facet_wrap(~ticker, scales = "free_y") + theme_bw()

Including Plots

summary: for the visualization of data decision are very important i made decision to analyze the ref.date, closing price data, and monthly return that provide the best visualization of data. and in the graph we can check also all prices of stock and if we want to check the September prices we can check it also

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.