\u76ee\u5f55<\/p> \n
- \n
- \u65f6\u95f4\u5e8f\u5217\u5206\u6790\u5de5\u5177\u7bb1\u2014\u2014tidyquant<\/a>\n
- \n
tidyquant<\/code> \u7684\u7528\u9014<\/a><\/li> \n
- \u52a0\u8f7d\u5305<\/a><\/li> \n
tq_get<\/code>\uff1a\u83b7\u5f97\u6570\u636e<\/a>\n
- \n
- \u4ece Yahoo! Finance \u83b7\u5f97\u80a1\u7968\u6570\u636e<\/a><\/li> \n
- \u4ece FRED \u83b7\u5f97\u7ecf\u6d4e\u6570\u636e<\/a><\/li> \n <\/ul><\/li> \n
- \u4f7f\u7528
tq_transmute<\/code> \u548c
tq_mutate<\/code> \u8f6c\u6362\u6570\u636e<\/a>\n
- \n
tq_transmute<\/code><\/a><\/li> \n
tq_mutate<\/code><\/a><\/li> \n <\/ul><\/li> \n
- \u53ef\u7528\u51fd\u6570<\/a><\/li> \n <\/ul><\/li> \n <\/ul> \n <\/div> \n <\/div> \n
\u65f6\u95f4\u5e8f\u5217\u5206\u6790\u5de5\u5177\u7bb1\u2014\u2014tidyquant<\/h1> \n
\n
\u672c\u6587\u7ffb\u8bd1\u81ea\u300aDemo Week: class(Monday) <- tidyquant\u300b<\/p> \n
\u539f\u6587\u94fe\u63a5\uff1ahttp:\/\/www.business-science.io\/code-tools\/2017\/10\/23\/demo_week_tidyquant.html<\/a><\/p> \n <\/blockquote> \n
<\/p> \n
tidyquant<\/code> \u7684\u7528\u9014<\/h2> \n
\u4f7f\u7528
tidyquant<\/code> \u7684\u516d\u5927\u7406\u7531\uff1a<\/p> \n
- \n
- \u76f4\u63a5\u4ece Yahoo! Finance\u3001FRED Database\u3001Quandl \u7b49\u6570\u636e\u6e90\u83b7\u5f97\u7f51\u7edc\u6570\u636e<\/strong><\/li> \n
- \u7b80\u5316 xts\u3001zoo\u3001quantmod\u3001TTR \u548c PerformanceAnalytics \u4e2d\u91d1\u878d\u53ca\u65f6\u95f4\u5e8f\u5217\u51fd\u6570\u7684\u8c03\u7528<\/strong><\/li> \n
- \u53ef\u89c6\u5316<\/strong>: \u6f02\u4eae\u7684\u4e3b\u9898\u4ee5\u53ca\u9488\u5bf9\u91d1\u878d\u7684 geom\uff08\u4f8b\u5982
geom_ma<\/code>\uff09<\/li> \n
- \u6784\u5efa\u6295\u8d44\u7ec4\u5408<\/strong><\/li> \n
- \u8d22\u52a1\u5206\u6790\u4ee5\u53ca\u6295\u8d44\u7ec4\u5408\u5f52\u56e0\u65b9\u6cd5<\/strong><\/li> \n
- \u4e3a\u91d1\u878d\u4e0e\u65f6\u95f4\u5e8f\u5217\u5206\u6790\u63d0\u4f9b\u575a\u5b9e\u7684\u57fa\u7840<\/strong>\uff1a
tidyquant<\/code> \u4f1a\u81ea\u52a8\u52a0\u8f7d
tidyverse<\/code> \u548c\u5404\u79cd\u91d1\u878d\u3001\u65f6\u95f4\u5e8f\u5217\u5206\u6790\u5305\uff0c\u8fd9\u4f7f\u5f97\u5b83\u6210\u4e3a\u4efb\u4f55\u91d1\u878d\u6216\u65f6\u95f4\u5e8f\u5217\u5206\u6790\u7684\u7406\u60f3\u8d77\u70b9\u3002<\/li> \n <\/ol> \n
\u8be5\u6559\u7a0b\u5c06\u4f1a\u4ecb\u7ecd\u524d\u4e24\u4e2a\u4e3b\u9898\u3002\u5176\u4ed6\u4e3b\u9898\u8bf7\u67e5\u770b tidyquant \u7684\u6587\u6863<\/a>\u3002<\/p> \n
\u52a0\u8f7d\u5305<\/h2> \n
\u8bf7\u5148\u5b89\u88c5
tidyquant<\/code>\uff1a<\/p> \n
# Install libraries\ninstall.packages("tidyquant")<\/code><\/pre> \n
\u52a0\u8f7d
tidyquant<\/code>\u3002<\/p> \n
# Load libraries\nlibrary(tidyquant) # Loads tidyverse, financial pkgs, used to get and manipulate data<\/code><\/pre> \n
tq_get<\/code>\uff1a\u83b7\u5f97\u6570\u636e<\/h2> \n
\u4f7f\u7528
tq_get()<\/code> \u83b7\u5f97\u7f51\u7edc\u6570\u636e\u3002
tidyquant<\/code> \u63d0\u4f9b\u4e86\u5927\u91cf API \u7528\u4e8e\u8fde\u63a5\u5305\u62ec Yahoo! Finance\u3001FRED Economic Database\u3001Quandl \u7b49\u7b49\u5728\u5185\u7684\u6570\u636e\u6e90\u3002<\/p> \n
\u4ece Yahoo! Finance \u83b7\u5f97\u80a1\u7968\u6570\u636e<\/h3> \n
\u5c06\u4e00\u5217\u80a1\u7968\u4ee3\u7801\u4f20\u5165
tq_get()<\/code>\uff0c\u540c\u65f6\u8bbe\u7f6e
get = "stock.prices"<\/code>\u3002\u53ef\u4ee5\u6dfb\u52a0
from<\/code> \u548c
to<\/code> \u53c2\u6570\u8bbe\u7f6e\u6570\u636e\u7684\u8d77\u59cb\u548c\u7ed3\u675f\u65e5\u671f\u3002<\/p> \n
# Get Stock Prices from Yahoo! Finance\n\n# Create a vector of stock symbols\nFANG_symbols <- c("FB", "AMZN", "NFLX", "GOOG")\n\n# Pass symbols to tq_get to get daily prices\nFANG_data_d <- FANG_symbols %>%\n tq_get(\n get = "stock.prices",\n from = "2014-01-01", to = "2016-12-31")\n\n# Show the result\nFANG_data_d<\/code><\/pre> \n
## # A tibble: 3,024 x 8\n## symbol date open high low close volume adjusted\n## <chr> <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>\n## 1 FB 2014-01-02 54.83 55.22 54.19 54.71 43195500 54.71\n## 2 FB 2014-01-03 55.02 55.65 54.53 54.56 38246200 54.56\n## 3 FB 2014-01-06 54.42 57.26 54.05 57.20 68852600 57.20\n## 4 FB 2014-01-07 57.70 58.55 57.22 57.92 77207400 57.92\n## 5 FB 2014-01-08 57.60 58.41 57.23 58.23 56682400 58.23\n## 6 FB 2014-01-09 58.65 58.96 56.65 57.22 92253300 57.22\n## 7 FB 2014-01-10 57.13 58.30 57.06 57.94 42449500 57.94\n## 8 FB 2014-01-13 57.91 58.25 55.38 55.91 63010900 55.91\n## 9 FB 2014-01-14 56.46 57.78 56.10 57.74 37503600 57.74\n## 10 FB 2014-01-15 57.98 58.57 57.27 57.60 33663400 57.60\n## # ... with 3,014 more rows<\/code><\/pre> \n
\u53ef\u4ee5\u4f7f\u7528
ggplot2<\/code> \u753b\u51fa\u4e0a\u8ff0\u7ed3\u679c\u3002\u4f7f\u7528
tidyquant<\/code> \u63d0\u4f9b\u7684\u4e3b\u9898\uff08\u8c03\u7528
theme_tq()<\/code> \u548c
scale_color_tq()<\/code>\uff09\u5b9e\u73b0\u91d1\u878d\u3001\u5546\u52a1\u98ce\u683c\u7684\u53ef\u89c6\u5316\u6548\u679c\u3002<\/p> \n
# Plot data\nFANG_data_d %>%\n ggplot(aes(x = date, y = adjusted, color = symbol)) + \n geom_line() +\n facet_wrap(~ symbol, ncol = 2, scales = "free_y") +\n theme_tq() +\n scale_color_tq() +\n labs(title = "Visualize Financial Data")<\/code><\/pre> \n
<\/p> \n
\u4ece FRED \u83b7\u5f97\u7ecf\u6d4e\u6570\u636e<\/h3> \n
\u4e0b\u9762\u7684\u4f8b\u5b50\u6765\u81ea\u623f\u5730\u7f8e\u526f\u9996\u5e2d\u7ecf\u6d4e\u5b66\u5bb6 Leonard Kieffer<\/strong> \u8fd1\u671f\u7684\u6587\u7ae0\u2014\u2014\u300aA (TIDYQUANT)UM OF SOLACE\u300b<\/a>\u3002\u6211\u4eec\u5c06\u4f7f\u7528
tq_get()<\/code> \u5e76\u8bbe\u7f6e\u53c2\u6570
get = "economic.data"<\/code> \u6765\u4ece FRED \u7ecf\u6d4e\u6570\u636e\u5e93\u83b7\u53d6\u6570\u636e\u3002<\/p> \n
\u5c06\u4e00\u5217 FRED \u4ee3\u7801\u4f20\u9012\u5230
tq_get()<\/code>\u3002<\/p> \n
# Economic Data from the FRED\n\n# Create a vector of FRED symbols\nFRED_symbols <- c('ETOTALUSQ176N', # All housing units\n 'EVACANTUSQ176N', # Vacant\n 'EYRVACUSQ176N', # Year-round vacant\n 'ERENTUSQ176N') # Vacant for rent\n\n# Pass symbols to tq_get to get economic data\nFRED_data_m <- FRED_symbols %>%\n tq_get(get="economic.data", from = "2001-04-01")\n\n# Show results\nFRED_data_m<\/code><\/pre> \n
## # A tibble: 260 x 3\n## symbol date price\n## <chr> <date> <int>\n## 1 ETOTALUSQ176N 2001-04-01 117786\n## 2 ETOTALUSQ176N 2001-07-01 118216\n## 3 ETOTALUSQ176N 2001-10-01 118635\n##","orderid":"0","title":"\u65f6\u95f4\u5e8f\u5217\u5206\u6790\u5de5\u5177\u7bb1\u2014\u2014tidyquant(\u4e00)","smalltitle":"","mid":"0","fname":"R\u8bed\u8a00","special_id":"0","bak_id":"0","info":"0","hits":"360","pages":"4","comments":"0","posttime":"2019-09-03 02:41:25","list":"1567449685","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"https:\/\/www.cppentry.com\/upload_files\/","ispic":"0","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"\u65f6\u95f4\u5e8f\u5217<\/A> \u5206\u6790<\/A> \u5de5\u5177\u7bb1<\/A> tidyquant<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"120.229.33.54","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"\u65f6\u95f4\u5e8f\u5217\u5206\u6790\u5de5\u5177\u7bb1\u2014\u2014tidyquant","lastview":"1711453248","digg_num":"0","digg_time":"0","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}
- \u7b80\u5316 xts\u3001zoo\u3001quantmod\u3001TTR \u548c PerformanceAnalytics \u4e2d\u91d1\u878d\u53ca\u65f6\u95f4\u5e8f\u5217\u51fd\u6570\u7684\u8c03\u7528<\/strong><\/li> \n
- \u4ece FRED \u83b7\u5f97\u7ecf\u6d4e\u6570\u636e<\/a><\/li> \n <\/ul><\/li> \n
- \u52a0\u8f7d\u5305<\/a><\/li> \n