VaR.data: Compute the VaR for different percentiles

View source: R/var_data.R

VaR.dataR Documentation

Compute the VaR for different percentiles

Description

Compute the VaR for different perncentiles and plot it in tables of various format: one in console, one as a data frame, and one as an image.

Usage

VaR.data(ticker, from, to, p = c(0.99, 0.95), W = 1)

Arguments

ticker

A single character variable storing the ticker of the stock to be downloaded. Note that since data are downloaded from Yahoo finance, the ticker should be the same as the ones reported on Yahoo finance. See examples. This variable can also be a data.frame with either two columns (one with dates in format %Y%d% and one with daily return of the portfolio), or one column with the daily returns of the portfolio and as rownames the dates. See examples

from

A single character variable storing the starting date from which we want to download the data. The format should be "yyyy-mm-dd"

to

A single character variable storing the ending date up to the day in which we want to download the stock data. The format should be "yyyy-mm-dd"

p

Numeric vector containing the desired percentile. Could also be a single numeric variable. Default to p = c(0.99,0.95)

W

Amount invested in the portfolio (or stock) stored in the variable "ticker". Default to W = 1

Examples

## Not run: 
#With ticker as a single character variable
VaR.data("MSFT" , from = "2017-01-01", to = "2020-01-01" , p = c(0.95,0.97,0.99))

#With a data frame of one single column of returns and dates as name of the rows as ticker
returns <- rnorm(n = 1827, mean = 0 , sd = 3)/100
dates <- seq(as.Date("2015-01-01"), as.Date("2020-01-01"), by = "days")
df <- data.frame(returns)
rownames(df) <- dates
VaR.data(df, from = "2017-01-01", to = "2020-01-01", p=0.99)

#With a data frame of two columns as ticker, one of dates and one of returns
returns <- rnorm(n = 1827, mean = 0 , sd = 3)/100
dates <- seq(as.Date("2015-01-01"), as.Date("2020-01-01"), by = "days")
df <- data.frame(dates, returns)
VaR.data(df, from, to )

## End(Not run)

gabrielebonvicini/aaa documentation built on May 21, 2022, 12:07 a.m.