1
- # ' Market timing models
2
- # '
3
- # ' Allows to estimate Treynor-Mazuy or Merton-Henriksson market timing model.
4
- # ' The Treynor-Mazuy model is essentially a quadratic extension of the basic
5
- # ' CAPM. It is estimated using a multiple regression. The second term in the
6
- # ' regression is the value of excess return squared. If the gamma coefficient
7
- # ' in the regression is positive, then the estimated equation describes a
8
- # ' convex upward-sloping regression "line". The quadratic regression is:
9
- # ' \deqn{R_{p}-R_{f}=\alpha+\beta (R_{b} - R_{f})+\gamma (R_{b}-R_{f})^2+
10
- # ' \varepsilon_{p}}{Rp - Rf = alpha + beta(Rb -Rf) + gamma(Rb - Rf)^2 +
11
- # ' epsilonp}
12
- # ' \eqn{\gamma}{gamma} is a measure of the curvature of the regression line.
13
- # ' If \eqn{\gamma}{gamma} is positive, this would indicate that the manager's
14
- # ' investment strategy demonstrates market timing ability.
15
- # '
16
- # ' The basic idea of the Merton-Henriksson test is to perform a multiple
17
- # ' regression in which the dependent variable (portfolio excess return and a
18
- # ' second variable that mimics the payoff to an option). This second variable
19
- # ' is zero when the market excess return is at or below zero and is 1 when it
20
- # ' is above zero:
21
- # ' \deqn{R_{p}-R_{f}=\alpha+\beta (R_{b}-R_{f})+\gamma D+\varepsilon_{p}}{Rp -
22
- # ' Rf = alpha + beta * (Rb - Rf) + gamma * D + epsilonp}
23
- # ' where all variables are familiar from the CAPM model, except for the
24
- # ' up-market return \eqn{D=max(0,R_{b}-R_{f})}{D = max(0, Rb - Rf)} and market
25
- # ' timing abilities \eqn{\gamma}{gamma}
26
- # ' @param Ra an xts, vector, matrix, data frame, timeSeries or zoo object of
27
- # ' the asset returns
28
- # ' @param Rb an xts, vector, matrix, data frame, timeSeries or zoo object of
29
- # ' the benchmark asset return
30
- # ' @param Rf risk free rate, in same period as your returns
31
- # ' @param method used to select between Treynor-Mazuy and Henriksson-Merton
32
- # ' models. May be any of: \itemize{ \item TM - Treynor-Mazuy model,
33
- # ' \item HM - Henriksson-Merton model} By default Treynor-Mazuy is selected
34
- # ' @param \dots any other passthrough parameters
35
- # ' @author Andrii Babii, Peter Carl
36
- # ' @seealso \code{\link{CAPM.beta}}
37
- # ' @references J. Christopherson, D. Carino, W. Ferson. \emph{Portfolio
38
- # ' Performance Measurement and Benchmarking}. 2009. McGraw-Hill, p. 127-133.
39
- # ' \cr J. L. Treynor and K. Mazuy, "Can Mutual Funds Outguess the Market?"
40
- # ' \emph{Harvard Business Review}, vol44, 1966, pp. 131-136
41
- # ' \cr Roy D. Henriksson and Robert C. Merton, "On Market Timing and Investment
42
- # ' Performance. II. Statistical Procedures for Evaluating Forecast Skills,"
43
- # ' \emph{Journal of Business}, vol.54, October 1981, pp.513-533 \cr
44
- # ' @examples
45
- # '
46
- # ' data(managers)
47
- # ' MarketTiming(managers[,1,drop=FALSE ], managers[,8,drop=FALSE ], Rf=.035/12, method = "HM")
48
- # ' MarketTiming(managers[80:120,1:6], managers[80:120,7,drop=FALSE ], managers[80:120,10,drop=FALSE ])
49
- # ' MarketTiming(managers[80:120,1:6], managers[80:120,8:7], managers[80:120,10,drop=FALSE ], method = "TM")
50
- # '
51
- # ' @export
52
- MarketTiming <- function (Ra , Rb , Rf = 0 , method = c(" TM" , " HM" ))
53
- { # @author Andrii Babii, Peter Carl
54
-
55
- # FUNCTION
56
-
57
- Ra = checkData(Ra )
58
- Rb = checkData(Rb )
59
- if (! is.null(dim(Rf )))
60
- Rf = checkData(Rf )
61
- Ra.ncols = NCOL(Ra )
62
- Rb.ncols = NCOL(Rb )
63
- pairs = expand.grid(1 : Ra.ncols , 1 )
64
- method = method [1 ]
65
- xRa = Return.excess(Ra , Rf )
66
- xRb = Return.excess(Rb , Rf )
67
-
68
- mt <- function (xRa , xRb )
69
- {
70
- switch (method ,
71
- " HM" = { S = xRb > 0 },
72
- " TM" = { S = xRb }
73
- )
74
- R = merge(xRa , xRb , xRb * S )
75
- R.df = as.data.frame(R )
76
- model = lm(R.df [, 1 ] ~ 1 + . , data = R.df [, - 1 ])
77
- return (coef(model ))
78
- }
79
-
80
- result = apply(pairs , 1 , FUN = function (n , xRa , xRb )
81
- mt(xRa [, n [1 ]], xRb [, 1 ]), xRa = xRa , xRb = xRb )
82
- result = t(result )
83
-
84
- if (ncol(Rb ) > 1 ){
85
- for (i in 2 : ncol(xRb )){
86
- res = apply(pairs , 1 , FUN = function (n , xRa , xRb )
87
- mt(xRa [, n [1 ]], xRb [, i ]), xRa = xRa , xRb = xRb )
88
- res = t(res )
89
- result = rbind(result , res )
90
- }
91
- }
92
-
93
- rownames(result ) = paste(rep(colnames(Ra ), ncol(Rb )), " to" , rep(colnames(Rb ), each = ncol(Ra )))
94
- colnames(result ) = c(" Alpha" , " Beta" , " Gamma" )
95
- return (result )
1
+ # ' Market timing models
2
+ # '
3
+ # ' Allows to estimate Treynor-Mazuy or Merton-Henriksson market timing model.
4
+ # ' The Treynor-Mazuy model is essentially a quadratic extension of the basic
5
+ # ' CAPM. It is estimated using a multiple regression. The second term in the
6
+ # ' regression is the value of excess return squared. If the gamma coefficient
7
+ # ' in the regression is positive, then the estimated equation describes a
8
+ # ' convex upward-sloping regression "line". The quadratic regression is:
9
+ # ' \deqn{R_{p}-R_{f}=\alpha+\beta (R_{b} - R_{f})+\gamma (R_{b}-R_{f})^2+
10
+ # ' \varepsilon_{p}}{Rp - Rf = alpha + beta(Rb -Rf) + gamma(Rb - Rf)^2 +
11
+ # ' epsilonp}
12
+ # ' \eqn{\gamma}{gamma} is a measure of the curvature of the regression line.
13
+ # ' If \eqn{\gamma}{gamma} is positive, this would indicate that the manager's
14
+ # ' investment strategy demonstrates market timing ability.
15
+ # '
16
+ # ' The basic idea of the Merton-Henriksson test is to perform a multiple
17
+ # ' regression in which the dependent variable (portfolio excess return and a
18
+ # ' second variable that mimics the payoff to an option). This second variable
19
+ # ' is zero when the market excess return is at or below zero and is 1 when it
20
+ # ' is above zero:
21
+ # ' \deqn{R_{p}-R_{f}=\alpha+\beta (R_{b}-R_{f})+\gamma D+\varepsilon_{p}}{Rp -
22
+ # ' Rf = alpha + beta * (Rb - Rf) + gamma * D + epsilonp}
23
+ # ' where all variables are familiar from the CAPM model, except for the
24
+ # ' up-market return \eqn{D=max(0,R_{b}-R_{f})}{D = max(0, Rb - Rf)} and market
25
+ # ' timing abilities \eqn{\gamma}{gamma}
26
+ # ' @param Ra an xts, vector, matrix, data frame, timeSeries or zoo object of
27
+ # ' the asset returns
28
+ # ' @param Rb an xts, vector, matrix, data frame, timeSeries or zoo object of
29
+ # ' the benchmark asset return
30
+ # ' @param Rf risk free rate, in same period as your returns
31
+ # ' @param method used to select between Treynor-Mazuy and Henriksson-Merton
32
+ # ' models. May be any of: \itemize{ \item TM - Treynor-Mazuy model,
33
+ # ' \item HM - Henriksson-Merton model} By default Treynor-Mazuy is selected
34
+ # ' @param \dots any other passthrough parameters
35
+ # ' @author Andrii Babii, Peter Carl
36
+ # ' @seealso \code{\link{CAPM.beta}}
37
+ # ' @references J. Christopherson, D. Carino, W. Ferson. \emph{Portfolio
38
+ # ' Performance Measurement and Benchmarking}. 2009. McGraw-Hill, p. 127-133.
39
+ # ' \cr J. L. Treynor and K. Mazuy, "Can Mutual Funds Outguess the Market?"
40
+ # ' \emph{Harvard Business Review}, vol44, 1966, pp. 131-136
41
+ # ' \cr Roy D. Henriksson and Robert C. Merton, "On Market Timing and Investment
42
+ # ' Performance. II. Statistical Procedures for Evaluating Forecast Skills,"
43
+ # ' \emph{Journal of Business}, vol.54, October 1981, pp.513-533 \cr
44
+ # ' @examples
45
+ # '
46
+ # ' data(managers)
47
+ # ' MarketTiming(managers[,1], managers[,8], Rf=.035/12, method = "HM")
48
+ # ' MarketTiming(managers[80:120,1:6], managers[80:120,7], managers[80:120,10])
49
+ # ' MarketTiming(managers[80:120,1:6], managers[80:120,8:7], managers[80:120,10], method = "TM")
50
+ # '
51
+ # ' @export
52
+ MarketTiming <- function (Ra , Rb , Rf = 0 , method = c(" TM" , " HM" ))
53
+ { # @author Andrii Babii, Peter Carl
54
+
55
+ # FUNCTION
56
+
57
+ Ra = checkData(Ra )
58
+ Rb = checkData(Rb )
59
+ if (! is.null(dim(Rf )))
60
+ Rf = checkData(Rf )
61
+ Ra.ncols = NCOL(Ra )
62
+ Rb.ncols = NCOL(Rb )
63
+ pairs = expand.grid(1 : Ra.ncols , 1 )
64
+ method = method [1 ]
65
+ xRa = Return.excess(Ra , Rf )
66
+ xRb = Return.excess(Rb , Rf )
67
+
68
+ mt <- function (xRa , xRb )
69
+ {
70
+ switch (method ,
71
+ " HM" = { S = xRb > 0 },
72
+ " TM" = { S = xRb }
73
+ )
74
+ R = merge(xRa , xRb , xRb * S )
75
+ R.df = as.data.frame(R )
76
+ model = lm(R.df [, 1 ] ~ 1 + . , data = R.df [, - 1 ])
77
+ return (coef(model ))
78
+ }
79
+
80
+ result = apply(pairs , 1 , FUN = function (n , xRa , xRb )
81
+ mt(xRa [, n [1 ]], xRb [, 1 ]), xRa = xRa , xRb = xRb )
82
+ result = t(result )
83
+
84
+ if (ncol(Rb ) > 1 ){
85
+ for (i in 2 : ncol(xRb )){
86
+ res = apply(pairs , 1 , FUN = function (n , xRa , xRb )
87
+ mt(xRa [, n [1 ]], xRb [, i ]), xRa = xRa , xRb = xRb )
88
+ res = t(res )
89
+ result = rbind(result , res )
90
+ }
91
+ }
92
+
93
+ rownames(result ) = paste(rep(colnames(Ra ), ncol(Rb )), " to" , rep(colnames(Rb ), each = ncol(Ra )))
94
+ colnames(result ) = c(" Alpha" , " Beta" , " Gamma" )
95
+ return (result )
96
96
}
0 commit comments