knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE, 
                      error = FALSE)
library(InvestR)
library(ggplot2)
library(kableExtra)
data("ExampleReport")
fund_bench <- combine_xts(fund, bench)
fund_market <- combine_xts(fund, bench, etf_ret)
plot_col <- c('firebrick', 'dodgerblue', 'goldenrod', 'seagreen3')

\newpage

Performance Summary

viz_perf(fund_bench, plot_col = plot_col)

\newpage

Performance Summary

Periodic Returns

Returns as of r zoo::index(fund_bench)[nrow(fund_bench)] (periods greater than one year are annualized)

cal_ret <- tbl_cal_perf(fund_bench)
kbl <- kable(cal_ret$fmt[, 1:10], align = rep('r', 10))
kbl_in <- kable_styling(kbl, latex_options = 'striped')
row_spec(kbl_in, 0, align = 'c', background = '#104E8B', color = 'white', bold = TRUE)

\vspace{15pt}

Calendar Returns

Fund Ticker r colnames(fund)[1]

mon_ret <- tbl_month_ret(fund, dig = 2)
kbl <- kable(mon_ret$fmt, align = rep('r', 14))
kbl_in <- kable_styling(kbl)
kbl_in <- column_spec(kbl_in, 14, bold = TRUE)
row_spec(kbl_in, 0, align = 'c', background = '#104E8B', color = 'white', bold = TRUE)

\newpage

Key Performance Metrics

From r zoo::index(fund_bench)[1] to r zoo::index(fund_bench)[nrow(fund_bench)]

res <- tbl_perf_stat(fund, bench, rf)
kbl <- kable(res$fmt)
kbl_in <- kable_styling(kbl, latex_options = 'striped')
row_spec(kbl_in, 0, align = 'c', background = '#104E8B', color = 'white', bold = TRUE)

\vspace{15pt}

viz_capm(fund_bench) +
  scale_color_manual(values = plot_col) +
  theme(legend.position = 'bottom')

Drawdowns and Value at Risk

viz_drawdown(fund_bench, 'months') +
  scale_color_manual(values = plot_col) +
  theme(legend.position = 'bottom')
viz_drawdown(fund, 'months') +
  scale_color_manual(values = plot_col) +
  theme(legend.position = 'bottom')

\newpage

r colnames(fund)[1] 10 Worst Drawdowns

res <- tbl_drawdowns(fund)
rownames(res$fmt) <- NULL
kbl <- kable(res$fmt)
kbl_in <- kable_styling(kbl, latex_options = 'striped')
row_spec(kbl_in, 0, align = 'c', background = '#104E8B', color = 'white', bold = TRUE)

Historical Value at Risk (Annualized)

res <- tbl_risk_quantile(fund_bench)
kbl <- kable(res$fmt)
kbl_in <- kable_styling(kbl, latex_options = 'striped')
row_spec(kbl_in, 0, align = 'c', background = '#104E8B', color = 'white', bold = TRUE)

r colnames(fund)[1] Monthly Historical Value at Risk Plot

x <- change_freq(fund, 'months')
viz_pdf_risk(x)

Style

Rolling Weekly Style Analysis

res <- viz_style_drift(fund, style_ind, comp_plot = TRUE)
res$style_plot

r colnames(fund)[1] Compared to Rolling Style Portfolio

res$comp_plot

Style Weights

fact <- style_ind
colnames(fact) <- c('Large Growth', 'Small Growth', 'Large Value', 'Small Value')
viz_style(fund, fact) + xlab('')

\newpage

Sector Style

ETF Returns to Proxy Sectors - Rolling 36 Months

viz_roll_style(fund, sector, 'month', 36) +
  scale_fill_manual(values = c('dodgerblue', 'goldenrod', 'brown', 'seagreen', 
                                'darkgreen', 'purple2', 'darkorange', 'darkgrey',
                                'navy', 'violet', 'turquoise2'))

Single Period Estimation from r zoo::index(sector)[1] to r zoo::index(sector)[nrow(sector)]

viz_style(fund, sector)

Correlation

viz_corr(fund_market, 2)

\newpage

viz_dendro(fund_market)

PCA

Max pairwise correlation estimate and varimax rotation

res <- viz_pca(fund_market)
res$loadings
res$var_expl

\newpage

Factor Analysis

Fama-French 3 Factor Plus Momentum (Weekly)

kbl_mv_reg(fund_bench, ff, rf, 'weeks', net_rf_x = FALSE)


alejandro-sotolongo/InvestR documentation built on Jan. 9, 2021, 2:20 p.m.