Estimating Portfolio Risk and Return from Historical Data in R
Summary
The document gives a brief orientation to calculating portfolio risk and return in R from historical holdings data. It points to computational finance materials and portfolio analytics resources, and names common tasks: measuring the standard deviation of a return series, calculating returns from price or equity series, and applying rolling analyses. It also mentions tools for annualized returns and drawdown analysis.
The responses focus on software functions, packages, and external learning materials rather than explaining the underlying portfolio calculations in detail. They do not provide a complete workflow for joining data from a SQL database, combining individual asset returns into portfolio returns, or choosing an appropriate covariance and annualization convention. The snippets are illustrative references, so users would need to supply their own data handling, portfolio weights, and methodological choices.
Key ideas
- A portfolio return series can be summarized by its standard deviation as a basic risk measure.
- Return calculations can be derived from an equity or price series using simple or logarithmic conventions.
- Rolling functions support analysis over moving windows.
- Annualized return and drawdown functions provide additional historical performance measures.
- The document points to R packages and examples but leaves the portfolio construction workflow unspecified.
Tags
Full text
# Determining portfolio risk return in R given historical data for individual holdings? # 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? ## Answer by user1234440 (score 5, accepted) https://quant.stackexchange.com/a/4869 There are a lot of code in Eric Zivots recent class in computational finance. - http://spark-public.s3.amazonaws.com/compfinance/R%20code/portfolio.r - http://spark-public.s3.amazonaws.com/compfinance/R%20code/testport.r - 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 ``` ## Answer by Matt Wolf (score 7) https://quant.stackexchange.com/a/4868 - Step 1: Get your data from SQL into R -> http://www.r-bloggers.com/?s=SQL - Step 2: Run your analysis/optimizations like -> http://www.r-bloggers.com/portfolio-optimization-in-r-part-1/ 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
Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.