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:
library(quantmod)
## Loading required package: xts
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
## Loading required package: TTR
## Version 0.4-0 included new data defaults. See ?getSymbols.
library(plyr)
library(xts)
library(zoo)
library(dygraphs)
library(data.table)
##
## Attaching package: 'data.table'
## The following objects are masked from 'package:xts':
##
## first, last
what_metrics <- yahooQF(c("Price/Sales",
"P/E Ratio",
"Price/EPS Estimate Next Year",
"PEG Ratio",
"Dividend Yield",
"Return On Assets",
"Return On Equity",
"Market Capitalization"))
tickers <- c("FB", "TWTR", "AAPL")
metrics <- getQuote(paste(tickers, sep="", collapse=";"), what=what_metrics)
metrics <- data.frame(Symbol=tickers, metrics[,2:length(metrics)])
colnames(metrics) <- c("Symbol", "Revenue Multiple", "Earnings Multiple","Earnings Multiple (Forward)", "Price-to-Earnings-Growth", "Div Yield", "Market Cap")
data.table(metrics)
## Symbol Revenue Multiple Earnings Multiple Earnings Multiple (Forward)
## 1: FB 14.88 37.36 25.76
## 2: TWTR 4.82 N/A 44.08
## 3: AAPL 3.72 17.92 14.64
## Price-to-Earnings-Growth Div Yield Market Cap
## 1: 1.20 N/A 484.74B
## 2: 3.17 N/A 11.63B
## 3: 1.58 1.57 815.38B
start <- as.Date("2017-01-01")
end <- as.Date("2017-07-01")
getSymbols("AAPL", src = "yahoo", from = start, to = end)
plot(AAPL[, "AAPL.Close"], main = "AAPL")
start <- as.Date("2017-01-01")
end <- as.Date("2017-07-01")
getSymbols("TWTR", src = "yahoo", from = start, to = end)
plot(TWTR[, "TWTR.Close"], main = "TWTR")
tart <- as.Date("2017-01-01")
end <- as.Date("2017-07-01")
getSymbols("FB", src = "yahoo", from = start, to = end)
plot(FB[, "FB.Close"], main = "FB")