Skip to content

Instantly share code, notes, and snippets.

@slopp
Created June 16, 2016 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slopp/a8de035026a017b24f1e5b17ae3df794 to your computer and use it in GitHub Desktop.
Save slopp/a8de035026a017b24f1e5b17ae3df794 to your computer and use it in GitHub Desktop.
---
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: AAPL
---
## `r params$symbol`
```{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(close>open,'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))
```
---
output:
html_document:
toc: true
toc_float: true
code_folding: hide
params:
symbol: TSLA
---
# `r params$symbol`
## Summary{.tabset}
```{r, echo=FALSE, 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]`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment