# 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) –  DeepSpace101 Dec 29 '12 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 –  user1234440 Dec 29 '12 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! –  DeepSpace101 Dec 29 '12 at 22:33
I am no expert in R, but I have done enough programming to be rather comfortable with the language. Contact me at trader.x30@gmail.com if you need some help, I am an undergraduate student willing to lend an helping hand :) (see above for some code) –  user1234440 Dec 30 '12 at 5:18