bb.plot: Plots the log of prices and highlight bear states

Description Usage Arguments Value Examples

View source: R/Functions.r

Description

This function plots the log of prices and highlights bear states

Usage

1
bb.plot(price, bull, dates, price.name=NULL, log.scale=TRUE)

Arguments

price

a numeric vector of price values

bull

a logical vector that contains the states of the market. This vector is returned by function run_dating_alg or run_filtering_alg.

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

Value

None

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
{
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
}

bbdetection documentation built on April 1, 2021, 5:06 p.m.