# Determining portfolio risk return in R given historical data for individual holdings?

Currently we compute portfolio risk and return via our own C# program. Historical data is stored in a SQL database. We want to compute the risk and return parameters - given a portfolio (i.e. not computing the efficient frontier). It's the R syntax that we're not familiar with (Vs the theory of computing the risk-return).

So, how would one go about computing portfolio risk-return in R?

There are a lot of code in Eric Zivots recent class in computational finance.

Also, you can google some slides in his class where he provides a lot of examples:

http://spark-public.s3.amazonaws.com/compfinance/Lecture%20Notes/PortfolioTheoryMatrixPowerpoint.pdf

Sample Code:

Standard Deviation of Return series:

sd(x)  #where x = portfolio return series


Rolling Analysis

rollapplyr(x,days,function) #rolling analysis given function


Calculate Return

require(PerformanceAnalytics)    #heaps of functions for portfolio analytics
require(TTR)     #package with indicator functions
ROC(x,days)      #given equity series, get log return
ROC(x,days,type="discrete") #given equity series, get discrete return series
findDrawdowns(R) #find drawdown for time series
Return.annualized(R,n)   #R = return series, N = number of periods in year

• Those are all for determining the efficient frontier (and then the min or max variance within it). I'm looking for the risk-return for a portfolio; given a portfolio (I.e. portfolio weights are fixed, assets are known as is the historical data behind the assets) Dec 29, 2012 at 4:36
• I am assuming you are defining risk in traditional metrics. Given weights and historical data, wouldn't a simple weighted return of each asset give the return series of the portfolio? From there wouldn't you just go about calculating the standard deviation and annualized return of the portfolio return series? In R, you just use "sd(return.series)" to get risk. and return just use PerformanceAnalytics functions to get return Dec 29, 2012 at 14:56
• Yup, it is simple in theory and I was expecting it to be simple in code too. I was actually expecting 3-4 lines of R code as the answer :) ... It's not the theory, it's the R syntax we're unfamiliar with (as well as integrating it with our C# based systems). But those more complex issue are questions for another day. Thanks and happy new year! Dec 29, 2012 at 22:33

It cannot get that much easier. You would have found those yourself faster on google than the time it took to post your question here. Plus there are a dozen duplicate questions you could have gotten similar information

• Thanks. Google did give several results but the overall options were quite ... diverse? So I thought I'd ask fellow folks here. Dec 29, 2012 at 0:50
• Actually, none of your answers answer the question. I'm looking for risk-return GIVEN a portfolio - not plotting an efficient frontier. The system won't let me undo my vote up Dec 29, 2012 at 4:27
• @Sid , then you did not carefully go through the links. Each single link I provided calculates, as the most basic building blocks, portfolio risk and portfolio returns. Dec 29, 2012 at 6:11