Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
One Pager Performance Report with R, knitr, and XeLaTeX.

One Pager Performance Report with knitr, R, and a Different Font

Although I suffer from complete ignorance of typography, with a little help from a post from Hyndsight and post from mages' blog, I wanted to try a different font on the one-pager performance report that we created in Onepager Now with knitR. I do not think Open Sans Light is the best choice for this report, but since it is the most popular font on Google I figured I could not be criticized too heavily by those more knowledgeable than me in typography.

options(tikzDefaultEngine = "xetex")


knit2pdf("onepager_text_graphics-knitr.rnw", compiler = "xelatex")
%get Open Sans Light from Google Webfonts
\setmainfont{Open Sans Light}
opts_chunk$set(concordance=TRUE, dev="tikz")
\section{\Huge Performance Summary with knitR and R}
{\large Here is a little experiment with R, knitr, and XeLaTeX to produce a performance report. I have done some samples in the past, but I wanted to iterate through a couple more, especially to evaluate other options for what has been started in the PApages package. Of course, this text could be easily replaced with some commentary from a manager about opportunities, thoughts, or current allocation. A dashboard set of charts also might be very helpful here.}
#do requires and set up environment for reporting
#get xts in df form so that we can melt with the reshape package
#will use just manager 1, sp500, and 10y treasury
managers <- managers[,c(1,8,9)]
#add 0 at beginning so cumulative returns start at 1
#also cumulative will match up datewise with returns
managers <- as.xts(rbind(rep(0,NCOL(managers)),coredata(managers)),[1],"%Y-%m-01"))-1,index(managers)))
managers.df <-,coredata(managers)),stringsAsFactors=FALSE)
#melt data which puts in a form that lattice and ggplot enjoy
managers.melt <- melt(managers.df,id.vars=1)
colnames(managers.melt) <- c("date","account","return")
managers.melt[,1] <- as.Date(managers.melt[,1])
#get cumulative returns starting at 1
managers.cumul <- as.xts(
#add end of first month to accommodate the 1 that we add
managers.cumul.df <-,
managers.cumul.melt <- melt(managers.cumul.df,id.vars=1)
colnames(managers.cumul.melt) <- c("date","account","return")
managers.cumul.melt[,1] <- as.Date(managers.cumul.melt[,1])
#get rolling returns for 1y, 3y, 5y, since inception
trailing <- table.TrailingPeriods(managers, periods=c(12,36,60,NROW(managers)),FUNCS=c("mean"),funcs.names=c("return"))
trailing.df <-"1y","3y","5y","SinceIncep"),
trailing.melt <- melt(trailing.df,id.vars=1:2)
colnames(trailing.melt) <- c("period","measure","account","return")
#function to get numbers in percent format
#will use \\ to play well with tikz
percent <- function(x, digits = 2, format = "f", ...)
paste(formatC(100 * x, format = format, digits = digits, ...), "%", sep = "")
\small Cumulative returns offer one of the best methods to evaluate the ability of a manager to achieve long term returns. Ultimately, the cumulative return is often one of the primary objectives of our clients.
trailingtable <- apply(trailing,MARGIN=2,FUN=percent)
rownames(trailingtable) <- c("1y","3y","5y",paste("Since Inception ",format(index(managers)[1],"%b %Y")))
print(xtable(trailingtable), floating=FALSE, scalebox=0.7)
\small However, cumulative returns must also be evaluated with reference to the risks incurred to generate those returns. Below are multiple risk measures. We are most concerned with limiting drawdowns shown in the bottom left chart.
risktable <- table.DownsideRisk(managers)
print(xtable(risktable), floating=FALSE, scalebox=0.6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.