library(DT)
library(formattable)
library(ggthemes)
library(quantmod)
library(dplyr)
library(plotly)
library(xts)
prices <- round(getSymbols("TSLA", auto.assign = FALSE, src = "yahoo"), 2)
close <- Cl(xts::last(prices))
open <- Op(xts::last(prices))
recent <- xts::last(prices, n = 90)
prices_df <- prices %>%
as_tibble() %>%
mutate(
Date = index(prices),
Direction = ifelse(TSLA.Close >= TSLA.Open, 'Increasing', 'Decreasing')
)Stock Report
Report for TSLA
The stock closed down at 425.85 dollars per share yesterday.
Price History
The chart below is made with the quantmod and plotly R packages. An API returns all of the price history based on the stock tick symbol “TSLA.”.
fig1 <- plot_ly(prices_df) %>%
add_trace(
type = "candlestick", x = ~Date, name = "TSLA",
open = ~TSLA.Open, close = ~TSLA.Close,
high = ~TSLA.High, low = ~TSLA.Low,
increasing = list(line = list(color = '#17BECF')),
decreasing = list(line = list(color = '#7F7F7F'))
) %>%
layout(yaxis = list(title = "Price"))
fig2 <- plot_ly(prices_df) %>%
add_bars(
x = ~Date, y = ~TSLA.Volume, name = "TSLA Volume",
color = ~Direction, colors = c('#17BECF', '#7F7F7F')
) %>%
layout(yaxis = list(title = "Volume"), xaxis = list(title = ""))
subplot(
fig1, fig2, heights = c(0.7, 0.2), nrows = 2,
shareX = TRUE, titleY = TRUE
) %>%
layout(
hovermode = "x", margin = list(t = 80),
title = paste("Tesla from", min(prices_df$Date), "to", max(prices_df$Date)),
xaxis = list(
rangeselector = list(
x = 0, y = 1, xanchor = 'left', yanchor = "top",
visible = TRUE, font = list(size = 9),
buttons = list(
list(count = 1, label = 'RESET', step = 'all'),
list(count = 1, label = '1 YR', step = 'year', stepmode = 'backward'),
list(count = 3, label = '3 MO', step = 'month', stepmode = 'backward'),
list(count = 1, label = '1 MO', step = 'month', stepmode = 'backward')
)
)
),
legend = list(
x = 1, y = 1, xanchor = 'right',
orientation = 'h', font = list(size = 10)
)
)Raw Data
The table below displays the daily price data for the stock. A concise, interactive table is created with the DT package.
recent %>%
as_tibble() %>%
mutate(TSLA.Volume = TSLA.Volume / 1000000) %>%
datatable() %>%
formatCurrency(c("TSLA.Open", "TSLA.High", "TSLA.Low", "TSLA.Close"), digits = 2) %>%
formatRound("TSLA.Volume", digits = 0)Legacy Information
This report also produces a CSV file containing recent price data, which may be used in other analysis.
This report also produces an email that is sent to key stakeholders with summary information.