Package PortRisk. R topics documented: November 1, Type Package Title Portfolio Risk Analysis Version Date

Similar documents
Package BatchGetSymbols

Package BatchGetSymbols

Package eesim. June 3, 2017

Dakota Wixom Quantitative Analyst QuantCourse.com

Package tailloss. August 29, 2016

Package GCPM. December 30, 2016

Package MSMwRA. August 7, 2018

Package optimstrat. September 10, 2018

Market Risk VaR: Model- Building Approach. Chapter 15

Diversification. Finance 100

Package beanz. June 13, 2018

Package quantileda. R topics documented: February 2, 2016

Package uqr. April 18, 2017

Package Strategy. R topics documented: August 24, Type Package

Package ELMSO. September 3, 2018

Package gmediation. R topics documented: June 27, Type Package

Package cumstats. R topics documented: January 16, 2017

Package LNIRT. R topics documented: November 14, 2018

Economics 424/Applied Mathematics 540. Final Exam Solutions

Package ensemblemos. March 22, 2018

Package finiteruinprob

P VaR0.01 (X) > 2 VaR 0.01 (X). (10 p) Problem 4

Modeling Portfolios that Contain Risky Assets Risk and Return I: Introduction

Package ratesci. April 21, 2017

Package smam. October 1, 2016

The mean-risk portfolio optimization model

Package LendingClub. June 5, 2018

Modeling Portfolios that Contain Risky Assets Risk and Reward II: Markowitz Portfolios

Package rtip. R topics documented: April 12, Type Package

Package RcmdrPlugin.RiskDemo

Lecture IV Portfolio management: Efficient portfolios. Introduction to Finance Mathematics Fall Financial mathematics

Package semsfa. April 21, 2018

The Optimization Process: An example of portfolio optimization

Package QRank. January 12, 2017

Extend the ideas of Kan and Zhou paper on Optimal Portfolio Construction under parameter uncertainty

The University of Chicago, Booth School of Business Business 41202, Spring Quarter 2011, Mr. Ruey S. Tsay. Solutions to Final Exam.

Package ald. February 1, 2018

Tests for Intraclass Correlation

THE CHINESE UNIVERSITY OF HONG KONG Department of Mathematics MMAT5250 Financial Mathematics Homework 2 Due Date: March 24, 2018

PAST. Portfolio Attribution and Simulation Toolkit. Vijay Vaidyanathan AAII Silicon Valley, 11March 2008

The University of Chicago, Booth School of Business Business 41202, Spring Quarter 2017, Mr. Ruey S. Tsay. Solutions to Final Exam

The University of Chicago, Booth School of Business Business 41202, Spring Quarter 2010, Mr. Ruey S. Tsay Solutions to Final Exam

Package FADA. May 20, 2016

Portfolio Risk Management and Linear Factor Models

Package dng. November 22, 2017

Quantitative Risk Management

Midterm Exam. b. What are the continuously compounded returns for the two stocks?

mfx: Marginal Effects, Odds Ratios and Incidence Rate Ratios for GLMs

Chapter 8. Markowitz Portfolio Theory. 8.1 Expected Returns and Covariance

Portfolio theory and risk management Homework set 2

Washington University Fall Economics 487. Project Proposal due Monday 10/22 Final Project due Monday 12/3

Asymptotic methods in risk management. Advances in Financial Mathematics

STA218 Analysis of Variance

Much of what appears here comes from ideas presented in the book:

Session 8: The Markowitz problem p. 1

SOLUTIONS 913,

Package PortfolioOptim

Financial volatility, currency diversication and banking stability

Final Exam Suggested Solutions

Information Share, or, measuring the importance of different markets

UNIVERSITY OF OSLO. Please make sure that your copy of the problem set is complete before you attempt to answer anything.

Lecture 1: Empirical Properties of Returns

Package ProjectManagement

Advanced Financial Economics Homework 2 Due on April 14th before class

Package scenario. February 17, 2016

Principles of Finance Risk and Return. Instructor: Xiaomeng Lu

Package SimCorMultRes

Modeling Portfolios that Contain Risky Assets Risk and Reward I: Introduction

Package RTDAmeritrade

Package stable. February 6, 2017

1 Bayesian Bias Correction Model

STA258 Analysis of Variance

Package SMFI5. February 19, 2015

Asset Allocation and Risk Assessment with Gross Exposure Constraints

Tests for Two Means in a Cluster-Randomized Design

Note on Using Excel to Compute Optimal Risky Portfolios. Candie Chang, Hong Kong University of Science and Technology

Homework #4 Suggested Solutions

Solutions to questions in Chapter 8 except those in PS4. The minimum-variance portfolio is found by applying the formula:

The Fundamental Review of the Trading Book: from VaR to ES

MATH 4512 Fundamentals of Mathematical Finance

Answer FOUR questions out of the following FIVE. Each question carries 25 Marks.

Package cbinom. June 10, 2018

Package rpms. May 5, 2018

Package XNomial. December 24, 2015

Package jrvfinance. R topics documented: August 29, 2016

Package GenOrd. September 12, 2015

Risk Measurement in Credit Portfolio Models

PORTFOLIO OPTIMIZATION AND SHARPE RATIO BASED ON COPULA APPROACH

Structural Models in Credit Valuation: The KMV experience. Oldrich Alfons Vasicek NYU Stern, November 2012

"Vibrato" Monte Carlo evaluation of Greeks

Optimal weights for the MSCI North America index. Optimal weights for the MSCI Europe index

ON SOME ASPECTS OF PORTFOLIO MANAGEMENT. Mengrong Kang A THESIS

Techniques for Calculating the Efficient Frontier

Econ 424/CFRM 462 Portfolio Risk Budgeting

Sample Midterm Questions Foundations of Financial Markets Prof. Lasse H. Pedersen

Portfolios that Contain Risky Assets Portfolio Models 1. Risk and Reward

Risk Reward Optimisation for Long-Run Investors: an Empirical Analysis

Portfolio Optimization with Alternative Risk Measures

The University of Chicago, Booth School of Business Business 41202, Spring Quarter 2012, Mr. Ruey S. Tsay. Solutions to Final Exam

Washington University Fall Economics 487

Transcription:

Type Package Title Portfolio Risk Analysis Version 1.1.0 Date 2015-10-31 Package PortRisk November 1, 2015 Risk Attribution of a portfolio with Volatility Risk Analysis. License GPL-2 GPL-3 Depends R (>= 3.0.0) Imports zoo, MCMCpack, tseries, copula, MASS NeedsCompilation no Author Sourish Das [aut, cre], Tamal Kanti Panja [aut] Maintainer Sourish Das <sourish.das@gmail.com> Repository CRAN Date/Publication 2015-11-01 18:17:27 R topics documented: PortRisk-package...................................... 2 access............................................ 2 portvol, mctr, cctr...................................... 3 portvol.bayes, mctr.bayes, cctr.bayes........................... 6 risk.attrib.copula...................................... 8 risk.attribution........................................ 9 SnP500List......................................... 11 SnP500Returns....................................... 12 volatility........................................... 13 Index 14 1

2 access PortRisk-package Portfolio Risk Analysis Details Risk Attribution of a portfolio with Volatility Risk Analysis. Package: PortRisk Type: Package Version: 1.1.0 Date: 2015-10-31 License: GPL-2 GPL-3 Depends: R (>= 3.0.0) Imports: zoo, tseries, MCMCpack, copula, MASS This package includes functions to compute the volatility risk attributes such as Volatility, Portfolio Volatility, MCTR, CCTR etc. Author(s) Sourish Das [aut, cre], Tamal Kanti Panja [aut]. Maintainer: Sourish Das <sourish.das@gmail.com> access Access Daily Stock Returns by Dates Access data from a zoo type daily returns table and returns as a zoo object. Basically, it returns a table of daily returns of a given list of company ticker names for a time period given as the input. access(tickers, start, end, data) Arguments tickers start end data A character vector of ticker names of companies in the portfolio. Start date in the format "yyyy-mm-dd". End date in the format "yyyy-mm-dd". A zoo object whose rownames are dates and colnames are ticker names of the companies. Values of the table corresponds to the daily returns of the stocks of corresponding ticker names.

portvol, mctr, cctr 3 Value Returns a zoo series as a table of daily returns corresponding to the company ticker names in tickers for the given time period. Basically, it picks up a block from a large table of daily returns of the stocks corresponding to the dates. See Also zoo # list all the ticker names in a character vector tckk <- colnames(snp500returns) # access the data corresponding to the first 3 ticker names # for the time period January 1, 2013 - January 10, 2013 access(tickers = tckk[1:3], start = "2013-01-01", end = "2013-01-10", portvol, mctr, cctr Portfolio Volatility and Contribution to Total Volatility Risk (MCTR & CCTR) portvol computes portfolio volatility of a given portfolio for specific weight and time period. mctr & cctr computes the Marginal Contribution to Total Risk (MCTR) & Conditional Contribution to Total Risk (CCTR) for the given portfolio. portvol(tickers, weights = rep(1,length(tickers)), start, end, data) mctr(tickers, weights = rep(1,length(tickers)), start, end, data) cctr(tickers, weights = rep(1,length(tickers)), start, end, data)

4 portvol, mctr, cctr Arguments tickers weights start end data A character vector of ticker names of companies in the portfolio. A numeric vector of weights assigned to the stocks corresponding to the ticker names in tickers. The sum of the weights need not to be 1 or 100 (in percentage). By default, equal weights to all the stocks are assigned (i.e., by rep(1, length(tickers))). Start date in the format "yyyy-mm-dd". End date in the format "yyyy-mm-dd". A zoo object whose rownames are dates and colnames are ticker names of the companies. Values of the table corresponds to the daily returns of the stocks of corresponding ticker names. Details As any portfolio can be considered as bag of p-many risky assets, it is important to figureout how these assets contributes to total volatility risk of the portfolio. We consider an investment period and suppose r j denote return to source j for the same period, where j = 1, 2,..., p. The portfolio return over the period is p R p = w j r j j=1 where w j is the portfolio exposure to the asset j, i.e., portfolio weight, such that w j 0 and p j=1 w j = 1. Portfolio manager determines the size of w j at the beginning of the investment period. Portfolio volatility is defined as σ = w T Σw where w = (w 1, w 2,..., w p ) and Σ being the variance-covariance matrix of the assets in the portfolio. The weights (w j ) are the main switches of portfolio s total volatility. Therefore, it is important for a manager to quantify, the sensitivity of the portfolio s volatility with respect to small change in w. This can be achieved by differentiating the portfolio volatility with respect to w, σ w = 1 σ Σw = ρ where ρ = (ρ 1, ρ 2,..., ρ p ) is know as Marginal Contribution to Total Risk (MCTR). Note that MCTR of asset i is ρ i = 1 p σ ij w j. σ j=1 The CCTR (aka. Conditional Contribution to Total Risk) is the amount that an asset add to total portfolio volatility. In other words, ξ i = w i ρ i is the CCTR of asset i, i.e., σ = p w i ρ i. Therefore portfolio volatility can be viewed as weighted average of MCTR. i=1

portvol, mctr, cctr 5 Value portvol mctr cctr A numeric value. Volatility of a given portfolio in percentage. A named numeric vector of Marginal Contribution to Total Risk (MCTR) in percentage with names being the ticker names. A named numeric vector of Conditional Contribution to Total Risk (CCTR) in percentage with names being the ticker names. See Also zoo # consider the portfolio containing the first 4 stocks pf <- colnames(snp500returns)[1:4] st <- "2013-01-01" # start date en <- "2013-01-31" # end date # suppose the amount of investments in the above stocks are # $1,000, $2,000, $3,000 & $1,000 respectively wt <- c(1000,2000,3000,1000) # weights # portfolio volatility for the portfolio pf with equal (default) weights pv1 <- portvol(pf, start = st, end = en, # portfolio volatility for the portfolio pf with weights as wt pv2 <- portvol(pf, weights = wt, start = st, end = en, # similarly, # mctr for the portfolio pf with weights as wt mc <- mctr(pf, weights = wt, start = st, end = en, # cctr for the portfolio pf with weights as wt cc <- cctr(pf, weights = wt, start = st, end = en, sum(cc) == pv2 # note that, sum of the cctr values is the portfolio volatility

6 portvol.bayes, mctr.bayes, cctr.bayes portvol.bayes, mctr.bayes, cctr.bayes Portfolio Volatility and Contribution to Total Volatility Risk (MCTR & CCTR): Bayesian Approach portvol.bayes computes portfolio volatility of a given portfolio for specific weight and time period. mctr.bayes & cctr.bayes computes the Marginal Contribution to Total Risk (MCTR) & Conditional Contribution to Total Risk (CCTR) for the given portfolio. portvol.bayes(tickers, weights = rep(1,length(tickers)), start, end, data, sim.size = 1000) mctr.bayes(tickers, weights = rep(1,length(tickers)), start, end, data, sim.size = 1000) cctr.bayes(tickers, weights = rep(1,length(tickers)), start, end, data, sim.size = 1000) Arguments tickers weights start end data Details A character vector of ticker names of companies in the portfolio. A numeric vector of weights assigned to the stocks corresponding to the ticker names in tickers. The sum of the weights need not to be 1 or 100 (in percentage). By default, equal weights to all the stocks are assigned (i.e., by rep(1, length(tickers))). Start date in the format "yyyy-mm-dd". End date in the format "yyyy-mm-dd". A zoo object whose rownames are dates and colnames are ticker names of the companies. Values of the table corresponds to the daily returns of the stocks of corresponding ticker names. sim.size Simulation size, default 1000. As any portfolio can be considered as bag of p-many risky assets, it is important to figureout how these assets contributes to total volatility risk of the portfolio. We consider an investment period and suppose r j denote return to source j for the same period, where j = 1, 2,..., p. The portfolio return over the period is p R p = w j r j j=1

portvol.bayes, mctr.bayes, cctr.bayes 7 where w j is the portfolio exposure to the asset j, i.e., portfolio weight, such that w j 0 and p j=1 w j = 1. Portfolio manager determines the size of w j at the beginning of the investment period. Portfolio volatility is defined as σ = w T Σw where w = (w 1, w 2,..., w p ) and Σ being the variance-covariance matrix of the assets in the portfolio. S is the sample portfolio-covariance matrix. If S W ishart(n 1, Σ) and prior distribution on Σ is Then posterior distribution is Σ Inv W ishart(n 0, Ψ) Value For more detail, see portvol, mctr, cctr Σ S Inv W ishart(n 0 + n 1, Ψ + S) portvol mctr cctr A numeric value. Volatility of a given portfolio in percentage. A named numeric vector of Marginal Contribution to Total Risk (MCTR) in percentage with names being the ticker names. A named numeric vector of Conditional Contribution to Total Risk (CCTR) in percentage with names being the ticker names. See Also zoo # consider the portfolio containing the first 4 stocks pf <- colnames(snp500returns)[1:4] st <- "2013-01-01" # start date en <- "2013-01-31" # end date # suppose the amount of investments in the above stocks are # $1,000, $2,000, $3,000 & $1,000 respectively wt <- c(1000,2000,3000,1000) # weights # portfolio volatility for the portfolio pf with equal (default) weights pv1 <- portvol(pf, start = st, end = en, # portfolio volatility for the portfolio pf with weights as wt pv2 <- portvol(pf, weights = wt, start = st, end = en,

8 risk.attrib.copula # similarly, # mctr for the portfolio pf with weights as wt mc <- mctr(pf, weights = wt, start = st, end = en, # cctr for the portfolio pf with weights as wt cc <- cctr(pf, weights = wt, start = st, end = en, sum(cc) == pv2 # note that, sum of the cctr values is the portfolio volatility risk.attrib.copula Risk Attribution of a Portfolio with t-copula Combined representation of the risk attributes MCTR, CCTR, Portfolio Volatility, Portfolio Value at Risk (VaR) and individual Volatility of the stocks in a given portfolio for a Markowitz s Optimized weights using t-copula. risk.attrib.copula(tickers, data, start, end, sim.size=1000, df=10) Arguments tickers data start end A character vector of ticker names of companies in the portfolio. A zoo object whose rownames are dates and colnames are ticker names of the companies. Values of the table corresponds to the daily returns of the stocks of corresponding ticker names. Start date in the format "yyyy-mm-dd". End date in the format "yyyy-mm-dd". sim.size Simulation size. Default at 1000. df Degrees of freedom for t-copula. Default set at 10. Details It calculate portfolio Value at Risk after fitting t-copula with empirical distribution on marginals. It simulate returns from the fitted t-copula and uses Markowitz s Optimized weight.

risk.attribution 9 Value Returns a list of following objects: Volatility Data frame caontaining Markowitz s optimized weights, individual stock s volatility, MCTR, CCTR for the given tickers. Portfolio Volatility Portfolio Volatility Portfilio VaR Portfolio Value at Risk See Also volatility, portvol, mctr, cctr, zoo # load the data SnP500Returns # consider the portfolio containing the stocks of the companies # Apple, IBM, Intel, Microsoft pf <- c("aapl","ibm","intc","msft") # risk attribution for the portfolio pf # for the time period January 1, 2013 - January 10, 2013 st<-"2013-01-01" ed<-"2013-10-10" risk.attrib.copula(tickers = pf, data = SnP500Returns, start = st, end = ed, sim.size=1000, df=10) risk.attribution Risk Attribution of a Portfolio Combined representation of the risk attributes MCTR, CCTR, CCTR percentage, Portfolio Volatility and individual Volatility of the stocks in a given portfolio for a given weight and time period. risk.attribution(tickers, weights = rep(1,length(tickers)), start, end, data, CompanyList = NULL)

10 risk.attribution Arguments tickers weights start end data CompanyList A character vector of ticker names of companies in the portfolio. A numeric vector of weights assigned to the stocks corresponding to the ticker names in tickers. The sum of the weights need not to be 1 or 100 (in percentage). By default, equal weights to all the stocks are assigned (i.e., by rep(1, length(tickers))). Start date in the format "yyyy-mm-dd". End date in the format "yyyy-mm-dd". A zoo object whose rownames are dates and colnames are ticker names of the companies. Values of the table corresponds to the daily returns of the stocks of corresponding ticker names. A dataframe containing all the Company names corresponding to the ticker names as its rownames. The input for this argument is optional. Details For details of the risk attributes refer to the corresponding functions. See volatility for individual volatility of the stocks and portvol for portfolio volatility, MCTR & CCTR. Value CCTR percentage for a stock in the portfolio is defined as the percentage of the portfolio volatility contributed by that stock for the given weight. i.e., where σ is the portfolio volatility. CCT R(%) = CCT R σ 100 Returns a dataframe with rownames as the ticker names as given in the input tickers with the last row corresponding to the portfolio values. The result contains the following columns: Company Name Weight MCTR CCTR CCTR(%) Volatility Optional. Available only if the dataframe with the company names corresponding to the ticker names as rownames is supplied as input in risk.attribution for the argument CompanyList. Standardized value of the weights assigned to the stocks in the portfolio. Value of this column corresponding to portfolio is the sum of the weights (i.e. 1). Marginal Contribution to Total Risk (MCTR) in percentage. MCTR corresponding to the portfolio will be shown as NA, since it is meaningless. Conditional Contribution to Total Risk (CCTR) in percentage. CCTR corresponding to the portfolio is the sum of the CCTR values, which is the portfolio volatility. Percentage of the portfolio volatility contributed by the stock for the given weight. Clearly, CCTR percentage corresponding to the portfolio is 100. Individual volatility of the stocks in percentage. Note that, the value of this column corresponding to the portfolio is not the sum of this column. It is the portfolio volatility.

SnP500List 11 Note In the result or output (see example), both the values of the last row (Portfolio) corresponding to the columns CCTR and Volatility are same (Portfolio Volatility). It should also be noted that, Portfolio Volatility is the sum of CCTR values corresponding to all the stocks but not the sum of individual Volatility of the stocks. See Also volatility, portvol, mctr, cctr, zoo # load the data SnP500Returns # consider the portfolio containing the stocks of the companies # Apple, IBM, Intel, Microsoft pf <- c("aapl","ibm","intc","msft") # suppose the amount of investments in the above stocks are # $10,000, $40,000, $20,000 & $30,000 respectively wt <- c(10000,40000,20000,30000) # weights # risk attribution for the portfolio pf with weights wt # for the time period January 1, 2013 - January 31, 2013 risk.attribution(tickers = pf, weights = wt, start = "2013-01-01", end = "2013-01-31", # to attach the company names corresponding to the ticker names # load the dataset containing the company names data(snp500list) risk.attribution(tickers = pf, weights = wt, start = "2013-01-01", end = "2013-01-31", data = SnP500Returns, CompanyList = SnP500List) SnP500List List of S&P500 Stocks in 2013 List of company names corresponding to the ticker names of the stocks listed in S&P500 List in the year 2013. data(snp500list)

12 SnP500Returns Format A data frame with 500 observations on the following variable. Company Names of companies as character string corresponding to their ticker names as rowname. data(snp500list) head(snp500list) SnP500Returns Daily Returns of S&P500 Stocks in 2013 Daily log returns corresponding to the ticker names of the stocks of the companies listed in S&P500 List in the year 2013. Format The format is zoo series from 2013-01-02 to 2013-12-31. rownames are the dates in the format "yyyy-mm-dd" and colnames are the ticker names of the stocks. Source Yahoo Finance <http://finance.yahoo.com> See Also access to pick a block from this large zoo series.

volatility 13 volatility Individual Volatility of Stock(s) Volatility of one or more stock(s) for a given time period. volatility(tickers, start, end, data) Arguments tickers start end data List of ticker names of companies. A character vector. Start date in the format "yyyy-mm-dd". End date in the format "yyyy-mm-dd". A zoo object whose rownames are dates and colnames are ticker names of the companies. Values of the table corresponds to the daily returns of the stocks of corresponding ticker names. Details Volatility of a given stock for a time period is defined as the standard deviation of the returns of that stock in that time period. Value A named numeric vector of volatility in percentage with names being the ticker names of the stocks given as input in tickers. See Also zoo tckk <- colnames(snp500returns) # volatility of the stock of the company Apple # for the time period January 1, 2013 - January 31, 2013 volatility("aapl", start = "2013-01-01", end = "2013-01-31", # volatility of the first three stocks in SnP500Returns # for the time period January 1, 2013 - January 31, 2013 volatility(tickers = tckk[1:3], start = "2013-01-01", end = "2013-01-31",

Index Topic datasets SnP500List, 11 SnP500Returns, 12 access, 2, 12 cctr, 7, 9, 11 cctr (portvol, mctr, cctr), 3 cctr.bayes (portvol.bayes, mctr.bayes, cctr.bayes), 6 mctr, 7, 9, 11 mctr (portvol, mctr, cctr), 3 mctr.bayes (portvol.bayes, mctr.bayes, cctr.bayes), 6 PortRisk (PortRisk-package), 2 PortRisk-package, 2 portvol, 7, 9 11 portvol (portvol, mctr, cctr), 3 portvol, mctr, cctr, 3 portvol.bayes (portvol.bayes, mctr.bayes, cctr.bayes), 6 portvol.bayes, mctr.bayes, cctr.bayes, 6 risk.attrib.copula, 8 risk.attribution, 9 SnP500List, 11 SnP500Returns, 12 volatility, 9 11, 13 zoo, 3, 5, 7, 9, 11 13 14