Safe_TE | R Documentation |
Safely calculated TE. Problem with PerformanceAnalytics - if the dates aren't exactly aligned, the calculation is wrong. See ?Safe_TE for an example of date misallignment, its impact on TE and how the corrected version works. Will auto correct if there is one entry per month.
Safe_TE(Ra, Rb, scale = 12)
Ra |
Returns series (xts). If not xts, will make it xts. |
Rb |
BM series (xts). If not xts, will make it xts. |
# Problem with PerformanceAnalytics - if the dates aren't exactly aligned, the calculation is wrong.
# An example of this is:
library(tidyverse); library(fmxdat);library(lubridate);library(xts)
# Load capped swix as bm
alsi <- fmxdat::Jalshtr %>% mutate(YM = format(date, "%Y%B")) %>% group_by(YM) %>% filter(date == last(date)) %>% ungroup() %>% mutate(Returns = TRI / lag(TRI)-1) %>%filter(!is.na(Returns)) %>% filter(date > ymd(20100131))
funds <- fmxdat::asisa %>% filter(Funds %in% c("Fund_1", "Fund_10")) %>% mutate(YM = format(date, "%Y%B")) %>% filter(date > ymd(20100131))
Endate <- ymd(20210430)
# For the past three years, the dates align:
Ra <- alsi %>% filter(date <= Endate) %>% filter(date >= fmxdat::safe_month_min(last(date), N = 36)) %>% tbl2xts::tbl_xts(cols_to_xts = Returns)
Rb <- funds %>% filter(date <= Endate) %>% filter(date >= fmxdat::safe_month_min(last(date), N = 36)) %>% tbl2xts::tbl_xts(cols_to_xts = Returns, spread_by = Funds)
PerformanceAnalytics::TrackingError(Ra, Rb, scale = 12)
fmxdat::Safe_TE(Ra, Rb, scale = 12)
# But they have different dates for certain months (e.g. see: index(Ra)[!index(Ra) %in% index(Rb)])
Rb <- funds %>% tbl2xts::tbl_xts(cols_to_xts = Returns, spread_by = Funds) %>% filter(date <= Endate)
Ra <- alsi %>% tbl2xts::tbl_xts(cols_to_xts = Returns) %>% filter(date <= Endate)
PerformanceAnalytics::TrackingError(Ra, Rb, scale = 12)
fmxdat::Safe_TE(Ra, Rb, scale = 12)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.