Take the 2-minute tour ×
Quantitative Finance Stack Exchange is a question and answer site for finance professionals and academics. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

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

  1. http://spark-public.s3.amazonaws.com/compfinance/R%20code/portfolio.r
  2. http://spark-public.s3.amazonaws.com/compfinance/R%20code/testport.r
  3. http://spark-public.s3.amazonaws.com/compfinance/R%20code/rollingPortfolios.r

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
share|improve this answer
    
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
1  
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
add comment

or http://blog.streeteye.com/blog/2012/01/portfolio-optimization-and-efficient-frontiers-in-r/

or via RMetrics: http://www.statistik.wiso.uni-erlangen.de/lehre/bachelor/datenanalyse/Refcard3.pdf

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

share|improve this answer
    
Thanks. Google did give several results but the overall options were quite ... diverse? So I thought I'd ask fellow folks here. –  DeepSpace101 Dec 29 '12 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 –  DeepSpace101 Dec 29 '12 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. –  Matt Wolf Dec 29 '12 at 6:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.