library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.3 v purrr 0.3.4
## v tibble 3.1.2 v dplyr 1.0.6
## v tidyr 1.1.3 v stringr 1.4.0
## v readr 1.4.0 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(tidyquant)
## Loading required package: lubridate
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
## 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
##
## Attaching package: 'xts'
## The following objects are masked from 'package:dplyr':
##
## first, last
##
## Attaching package: 'PerformanceAnalytics'
## The following object is masked from 'package:graphics':
##
## legend
## Loading required package: quantmod
## Loading required package: TTR
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
## == Need to Learn tidyquant? ====================================================
## Business Science offers a 1-hour course - Learning Lab #9: Performance Analysis & Portfolio Optimization with tidyquant!
## </> Learn more at: https://university.business-science.io/p/learning-labs-pro </>
library(timetk)
library(tibbletime)
##
## Attaching package: 'tibbletime'
## The following object is masked from 'package:stats':
##
## filter
5 aset porto folio yang akan diproses + SPY (S&P500 fund) weighted 25% + EFA (a non-US equities fund) weighted 25% + IJS (a small-cap value fund) weighted 20% + EEM (an emerging-mkts fund) weighted 20% + AGG (a bond fund) weighted 10%
symbols <- c("SPY","EFA", "IJS", "EEM","AGG")
prices <- getSymbols(symbols,
src = 'yahoo',
from = "2012-12-31",
to = "2017-12-31",
auto.assign = TRUE,
warnings = FALSE) %>%
map(~Ad(get(.))) %>%
reduce(merge) %>%
`colnames<-`(symbols)
## 'getSymbols' currently uses auto.assign=TRUE by default, but will
## use auto.assign=FALSE in 0.5-0. You will still be able to use
## 'loadSymbols' to automatically load data. getOption("getSymbols.env")
## and getOption("getSymbols.auto.assign") will still be checked for
## alternate defaults.
##
## This message is shown once per session and may be disabled by setting
## options("getSymbols.warning4.0"=FALSE). See ?getSymbols for details.
head(prices)
## SPY EFA IJS EEM AGG
## 2012-12-31 121.4001 45.08271 35.80101 37.33540 90.69235
## 2013-01-02 124.5116 45.78044 36.78332 38.06781 90.58621
## 2013-01-03 124.2303 45.33643 36.73464 37.79841 90.35763
## 2013-01-04 124.7758 45.56637 37.02226 37.87418 90.45559
## 2013-01-07 124.4349 45.36815 36.80544 37.58796 90.40664
## 2013-01-08 124.0769 45.11443 36.66384 37.25122 90.48826
prices_monthly <- to.monthly(prices, indexAt = "last", OHLC = FALSE)
head(prices_monthly)
## SPY EFA IJS EEM AGG
## 2012-12-31 121.4001 45.08271 35.80101 37.33540 90.69235
## 2013-01-31 127.6146 46.76360 37.71694 37.22597 90.12898
## 2013-02-28 129.2428 46.16101 38.33198 36.37571 90.66153
## 2013-03-28 134.1503 46.76360 39.90665 36.00530 90.75088
## 2013-04-30 136.7276 49.11050 39.95547 36.44307 91.62987
## 2013-05-31 139.9557 47.62783 41.66833 34.68363 89.79626
Daftar pustaka
http://www.reproduciblefinance.com/2017/09/25/asset-prices-to-log-returns/