Title: | Identification of Bull and Bear States of the Market |
---|---|
Description: | Implements two algorithms of detecting Bull and Bear markets in stock prices: the algorithm of Pagan and Sossounov (2002, <doi:10.1002/jae.664>) and the algorithm of Lunde and Timmermann (2004, <doi:10.1198/073500104000000136>). The package also contains functions for printing out the dating of the Bull and Bear states of the market, the descriptive statistics of the states, and functions for plotting the results. For the sake of convenience, the package includes the monthly and daily data on the prices (not adjusted for dividends) of the S&P 500 stock market index. |
Authors: | Valeriy Zakamulin |
Maintainer: | Valeriy Zakamulin <[email protected]> |
License: | GPL-3 |
Version: | 1.0 |
Built: | 2024-12-04 07:13:58 UTC |
Source: | CRAN |
This function prints out (in console window) the dating of bull-bear states. The outcome of this function is a table in LaTeX format.
bb.dating.states(price, bull, dates)
bb.dating.states(price, bull, dates)
price |
a numeric vector of price values |
bull |
a logical vector that contains the states of the market. This vector
is returned by function |
dates |
a vector of dates |
A data frame object that contains the dating of bull-bear states.
{ library(zoo) library(xtable) library(ggplot2) sp500 <- sp500m # choose the monthly data dates <- index(sp500) # retrieve dates dates <- as.yearmon(dates) # convert dates to "yearmon" format if monthly data price <- as.vector(coredata(sp500)) # retrieve prices setpar_dating_alg(4, 6, 4, 16, 20) # parameters for monthly data bull <- run_dating_alg(price) # detect the states bb.dating.states(price, bull, dates) }
{ library(zoo) library(xtable) library(ggplot2) sp500 <- sp500m # choose the monthly data dates <- index(sp500) # retrieve dates dates <- as.yearmon(dates) # convert dates to "yearmon" format if monthly data price <- as.vector(coredata(sp500)) # retrieve prices setpar_dating_alg(4, 6, 4, 16, 20) # parameters for monthly data bull <- run_dating_alg(price) # detect the states bb.dating.states(price, bull, dates) }
This function plots the log of prices and highlights bear states
bb.plot(price, bull, dates, price.name=NULL, log.scale=TRUE)
bb.plot(price, bull, dates, price.name=NULL, log.scale=TRUE)
price |
a numeric vector of price values |
bull |
a logical vector that contains the states of the market. This vector
is returned by function |
dates |
a vector of dates in Date format |
price.name |
the name of the time-series of prices that will appear on the y-axis of the plot |
log.scale |
a logical variable that specifies whether to use log scale along the y-axis |
None
{ library(zoo) library(xtable) library(ggplot2) price <- as.vector(coredata(sp500m)) # retrieve monthly prices dates <- index(sp500m) # retrieve dates from zoo-object setpar_dating_alg(4, 6, 5, 15, 20) # parameters for monthly data bull <- run_dating_alg(price) # detect bull-bear states bb.plot(price, bull, dates, "S&P 500") # plot the result }
{ library(zoo) library(xtable) library(ggplot2) price <- as.vector(coredata(sp500m)) # retrieve monthly prices dates <- index(sp500m) # retrieve dates from zoo-object setpar_dating_alg(4, 6, 5, 15, 20) # parameters for monthly data bull <- run_dating_alg(price) # detect bull-bear states bb.plot(price, bull, dates, "S&P 500") # plot the result }
This function prints out (in console window) the summary statistics of bull-bear states. The outcome of this function is a table in LaTeX format.
bb.summary.stat(price, bull)
bb.summary.stat(price, bull)
price |
a numeric vector of price values |
bull |
a logical vector that contains the states of the market. This vector
is returned by function |
A data frame that contains the descriptive statistics.
{ library(zoo) library(xtable) library(ggplot2) sp500 <- sp500m # choose the monthly data price <- as.vector(coredata(sp500)) # retrieve prices setpar_dating_alg(4, 6, 4, 16, 20) # parameters for monthly data bull <- run_dating_alg(price) # detect the states bb.summary.stat(price, bull) }
{ library(zoo) library(xtable) library(ggplot2) sp500 <- sp500m # choose the monthly data price <- as.vector(coredata(sp500)) # retrieve prices setpar_dating_alg(4, 6, 4, 16, 20) # parameters for monthly data bull <- run_dating_alg(price) # detect the states bb.summary.stat(price, bull) }
The daily closing prices of the DJIA index from January 1985
djiad
djiad
An object of class "zoo"
containing the daily closing prices of the DJIA index from January 1985
Other data sets:
djiam
,
sp500d
,
sp500m
The monthly closing prices of the DJIA index from January 1985
djiam
djiam
An object of class "zoo"
containing the monthly closing prices of the DJIA index from January 1985
Other data sets:
djiad
,
sp500d
,
sp500m
This function implements the dating algorithm of Bry and Boschan (1971) to identify Bull and Bear states
run_dating_alg(index)
run_dating_alg(index)
index |
vector containing the stock price index |
A logical vector that contains TRUE for Bull states and FALSE for Bear states
Be aware that the states in the beginning and in the end of "index"
are not properly defined.
The users are advised to always visually check the correctness of the result
(during Bull states the prices should generally increase, during the Bear states decrease).
Bry, G. and Boschan, C. (1971). Cyclical Analysis of Time Series: Selected Procedures and Computer Programs. NBER.
Pagan, A. R. and Sossounov, K. A. (2003). A Simple Framework for Analysing Bull and Bear Markets. Journal of Applied Econometrics, 18 (1), 23-46.
Gonzalez, L., Powell, J. G., Shi, J., and Wilson, A. (2005). Two Centuries of Bull and Bear Market Cycles. International Review of Economics and Finance, 14 (4), 469-486.
This function implements the filtering algorithm of Lunde and Timmermann (2004) to identify Bull and Bear states
run_filtering_alg(index)
run_filtering_alg(index)
index |
vector containing the stock price index |
A logical vector that contains TRUE for Bull states and FALSE for Bear states
Be aware that the states in the beginning and in the end of "index"
are not properly defined
Lunde, A. and Timmermann, A. (2004). Duration Dependence in Stock Prices: An Analysis of Bull and Bear Markets. Journal of Business and Economic Statistics, 22 (3), 253-273.
This function sets the paramters of the dating algorithm of Bry and Boschan (1971)
setpar_dating_alg(t_window, t_censor, t_phase, t_cycle, max_chng)
setpar_dating_alg(t_window, t_censor, t_phase, t_cycle, max_chng)
t_window |
the half-size of the rolling window to find minima and maxima |
t_censor |
the size of the left and right margin (for the cencoring operation) |
t_phase |
the minimum phase (bull or bear) length |
t_cycle |
the minimum full cycle length |
max_chng |
the change (in percentages) in the |
None
All parameters but "max_chng"
are given in a number of observations.
For example, if data are at the monthly frequency, "t_cycle=16"
defines that the minimum cycle length should be 16 months.
Bry, G. and Boschan, C. (1971). Cyclical Analysis of Time Series: Selected Procedures and Computer Programs. NBER.
Pagan, A. R. and Sossounov, K. A. (2003). A Simple Framework for Analysing Bull and Bear Markets. Journal of Applied Econometrics, 18 (1), 23-46.
Gonzalez, L., Powell, J. G., Shi, J., and Wilson, A. (2005). Two Centuries of Bull and Bear Market Cycles. International Review of Economics and Finance, 14 (4), 469-486.
This function sets the paramters of the filtering algorithm of Lunde and Timmermann (2004)
setpar_filtering_alg(tr_bull, tr_bear)
setpar_filtering_alg(tr_bull, tr_bear)
tr_bull |
threshold to idenitfy a Bull state (in percentages) |
tr_bear |
threshold to idenitfy a Bear state (in percentages) |
None
Lunde, A. and Timmermann, A. (2004). Duration Dependence in Stock Prices: An Analysis of Bull and Bear Markets. Journal of Business and Economic Statistics, 22 (3), 253-273.
The daily closing prices of the S&P 500 index
sp500d
sp500d
An object of class "zoo"
containing daily closing prices of the S&P 500 index starting from January 1950
Other data sets:
djiad
,
djiam
,
sp500m
Monthly closing prices of the S&P 500 index
sp500m
sp500m
An object of class "zoo"
containing monthly closing prices of the S&P 500 index starting from January 1950
Other data sets:
djiad
,
djiam
,
sp500d