tidyquant: Tidy Quantitative Financial Analysis

> library(tidyquant)
Loading required package: lubridate

Attaching package: 'lubridate'
The following object is masked from 'package:base':

    date
Loading required package: PerformanceAnalytics
Loading required package: xts
Loading required package: zoo

Attaching package: 'zoo'
The following objects are masked from 'package:base':

    as.Date, as.Date.numeric

Package PerformanceAnalytics (1.4.3541) loaded.
Copyright (c) 2004-2014 Peter Carl and Brian G. Peterson, GPL-2 | GPL-3
http://r-forge.r-project.org/projects/returnanalytics/

Attaching package: 'PerformanceAnalytics'
The following object is masked from 'package:graphics':

    legend
Loading required package: quantmod
Loading required package: TTR
Version 0.4-0 included new data defaults. See ?getSymbols.
Learn from a quantmod author: https://www.datacamp.com/courses/importing-and-managing-financial-data-in-r
Loading required package: tidyverse
+ ggplot2 2.2.1.9000        Date: 2017-05-06
+ tibble  1.3.0                R: 3.3.2
+ tidyr   0.6.1               OS: macOS Sierra 10.12.4
+ readr   1.1.0              GUI: RStudio 1.1.222
+ purrr   0.2.2           Locale: ja_JP.UTF-8
+ dplyr   0.5.0.9004          TZ: Asia/Tokyo
+ stringr 1.2.0           
+ forcats 0.2.0
Conflicts -----------------------------------------------------------------
* add(),           from magrittr, masks git2r::add()
* as.difftime(),   from lubridate, masks base::as.difftime()
* date(),          from lubridate, masks base::date()
* equals(),        from magrittr, masks testthat::equals()
* filter(),        from dplyr, masks stats::filter()
* first(),         from dplyr, masks xts::first()
* intersect(),     from lubridate, masks base::intersect()
* is_empty(),      from purrr, masks git2r::is_empty()
* is_less_than(),  from magrittr, masks testthat::is_less_than()
* is_null(),       from purrr, masks testthat::is_null()
* lag(),           from dplyr, masks stats::lag()
* last(),          from dplyr, masks xts::last()
* matches(),       from dplyr, masks testthat::matches()
* not(),           from magrittr, masks testthat::not()
* pull(),          from dplyr, masks git2r::pull()
* setdiff(),       from lubridate, masks base::setdiff()
* union(),         from lubridate, masks base::union()
* when(),          from purrr, masks git2r::when()

Attaching package: 'tidyquant'
The following object is masked from 'package:dplyr':

    as_tibble
The following object is masked from 'package:tibble':

    as_tibble
> data("FANG")

バージョン: 0.5.1


関数名 概略
FANG Stock prices for the "FANG" stocks.
as_tibble Coerce to tibble. Enable preserving row names when coercing matrix and time-series-like bjects with row names.
as_xts Coerce objects to xts, designed to work with tibble and data.frame objects
coord_x_date Zoom in on plot regions using date ranges or date-time ranges
deprecated Deprecated functions
geom_bbands Plot Bollinger Bands using Moving Averages
geom_chart Plot Financial Charts in ggplot2
geom_ma Plot moving averages
palette_tq tidyquant palettes for use with scales
scale_manual tidyquant colors and fills for ggplot2.
theme_tq tidyquant themes for ggplot2.
tidyquant tidyquant: Integrating quantitative financial analysis tools with the tidyverse
tq_get Get quantitative data in 'tibble' format
tq_index Get all stocks in a stock index or stock exchange in 'tibble' format
tq_mutate Mutates quantitative data
tq_performance Computes a wide variety of summary performance metrics from stock or portfolio returns
tq_portfolio Aggregates a group of returns by asset into portfolio returns

FANG

Facebook, Amazon, Netflix, Googleの2013年から2016年の株価データセット

> head(FANG)
# A tibble: 6 × 8
  symbol       date      open      high       low     close    volume
   <chr>     <date>     <dbl>     <dbl>     <dbl>     <dbl>     <dbl>
1     FB 2013-01-02 27.440001 28.180000 27.420000 28.000000  69846400
2     FB 2013-01-03 27.879999 28.469999 27.590000 27.770000  63140600
3     FB 2013-01-04 28.010000 28.930000 27.830000 28.760000  72715400
4     FB 2013-01-07 28.690001 29.790001 28.650000 29.420000  83781800
5     FB 2013-01-08 29.510000 29.600000 28.860001 29.059999  45871300
6     FB 2013-01-09 29.670000 30.600000 29.490000 30.590000 104787700
# ... with 1 more variables: adjusted <dbl>

as_xts

> tq_get("AAPL", get = "stock.prices") %>%
+     as_xts(date_col = date)

tq_get

Arguments

  • x
  • get
  • complete_cases
  • ...
> tq_get_options()
 [1] "stock.prices"       "stock.prices.japan" "financials"        
 [4] "key.stats"          "key.ratios"         "dividends"         
 [7] "splits"             "economic.data"      "exchange.rates"    
[10] "metal.prices"       "quandl"             "quandl.datatable"
> # tq_get_stock_index_options()
> tq_get()
Error in tq_get(): argument "x" is missing, with no default