Skip to content

Instantly share code, notes, and snippets.

@slopp
Created July 18, 2016 17:49
Show Gist options
  • Save slopp/bb6d3ff1a8a49eb2134807c153547ca8 to your computer and use it in GitHub Desktop.
Save slopp/bb6d3ff1a8a49eb2134807c153547ca8 to your computer and use it in GitHub Desktop.
---
output:
html_document:
toc: true
toc_float: true
code_folding: hide
params:
symbol: TSLA
---
# `r params$symbol`
## Summary{.tabset}
```{r, echo=TRUE, message=FALSE}
library(quantmod)
library(dygraphs)
prices <- round(getSymbols(params$symbol, auto.assign = FALSE), 2)
close <- Cl(last(prices))
open <- Op(last(prices))
```
The stock closed `r ifelse(close>open,'up','down')` at `r close` dollars per share yesterday.
### Price History
The chart below is made with the `quantmod` and `dygraphs` R packages.
***
```{r echo=FALSE}
dygraphs::dygraph(prices) %>% dyRangeSelector()
```
### Raw Data
The table below displays the daily price data for the stock. We made a concise, interactive table with the `DT` package, a new package for making searchable data tables.
***
```{r echo=TRUE}
DT::datatable(data.frame(prices[, 1:4], 2))
```
## Model{.tabset}
### Plot
This model is fit with the auto.arima function in the forecast package.
```{r, warning=FALSE, message=FALSE}
library(forecast)
m <- auto.arima(prices[,1])
plot(forecast(m,12))
```
### Forecasts
```{r, warning=FALSE, message=FALSE}
f <- forecast(m,12)
```
The forecast for tomorrow is `r as.numeric(f$mean)[1]`.
---
title: "My Document"
output: html_document
params:
minimum:
label: "Minimum:"
value: 100
input: slider
min: 0
max: 1000
region:
label: "Region:"
value: east
input: select
choices: [east, west, north, south]
data:
label: "Input dataset:"
value: results.csv
input: file
---
## My parameters
The minimum is: `r params$minimum` in region `r params$region` using the dataset ...
---
output: html_document
params:
symbol: AMZN
name: Amazon
---
## `r params$symbol` : `r params$name`
```{r, echo=FALSE, message=FALSE}
library(quantmod)
prices <- round(getSymbols(params$symbol, auto.assign = FALSE), 2)
close <- Cl(last(prices))
open <- Op(last(prices))
```
The stock closed `r ifelse(open>close,'up','down')` at `r close` dollars per share yesterday.
## Price History
The chart below is made with the `quantmod` R package, a widely used package for collecting and visualizing financial data in R. You can learn more about `quantmod` at the website
***
```{r echo=FALSE}
chartSeries(prices, theme = chartTheme("white", bg.col = "white"))
```
## Raw Data
The table below displays the daily price data for the stock. In the next section, we will learn how to make a concise, interactive table with the `DT` package, a new package for making searchable data tables. You can learn more about the `DT` package at the website
***
```{r echo=FALSE}
DT::datatable(data.frame(prices[, 1:4], 2))
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment