Title: | Risk Management and Optimization for Portfolio Investment |
---|---|
Description: | Provides functions for risk management and portfolio investment of securities with practical tools for data processing and plotting. Moreover, it contains functions which perform the COS Method, an option pricing method based on the Fourier-cosine series (Fang, F. (2008) <doi:10.1137/080718061>). |
Authors: | Wei Ling [aut, cre], Yang Liu [aut] |
Maintainer: | Wei Ling <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.1 |
Built: | 2024-11-22 04:22:04 UTC |
Source: | https://github.com/cran/RMOPI |
Restore the distribution with the COS method under different parameters settings for error analysis.
CosPdfMulti(x, Chf, N, a, b)
CosPdfMulti(x, Chf, N, a, b)
x |
vector of observations |
Chf |
the characteristic function |
N |
the number of cos term for summation |
a |
the lower limit of the truncation interval |
b |
the upper limit of the truncation interval |
A matrix that contains restored p.d.f. with different parameters
N <- 2**(1:6) x <- seq(-5, 5, by = 10 / (32 - 1)) a <- -10.0 b <- 10.0 CosPdfMulti(x, StNormChf, N, a, b)
N <- 2**(1:6) x <- seq(-5, 5, by = 10 / (32 - 1)) a <- -10.0 b <- 10.0 CosPdfMulti(x, StNormChf, N, a, b)
Restore the distribution with the characteristic function through the COS method, an option pricing method based on the Fourier-cosine series.
CosPdfRecovery(x, Chf, N, a, b)
CosPdfRecovery(x, Chf, N, a, b)
x |
vector of observations |
Chf |
the characteristic function |
N |
the number of cos term for summation |
a |
the lower limit of the truncation interval |
b |
the upper limit of the truncation interval |
The approximated probability density of x
Fang F. and Oosterlee C.W. 2008. "A Novel Pricing Method for European Options Based on Fourier-Cosine Series Expansions", Siam Journal on Scientific Computing. 31(2): 826-848. doi: 10.1137/080718061.
N <- 32 x <- seq(-5, 5, by = 10 / (32 - 1)) a <- -6.0 b <- 6.0 CosPdfRecovery(x, StNormChf, N, a, b)
N <- 32 x <- seq(-5, 5, by = 10 / (32 - 1)) a <- -6.0 b <- 6.0 CosPdfRecovery(x, StNormChf, N, a, b)
Approximate the standard European call option price with the COS method, an option pricing method based on the Fourier-cosine series.
CosValueOption(ValueOption, GBMChf, r, tau, N, a, b, method = "integrate")
CosValueOption(ValueOption, GBMChf, r, tau, N, a, b, method = "integrate")
ValueOption |
the value function of the option |
GBMChf |
the characteristic function for GBM |
r |
the |
tau |
the |
N |
the number of cos term for summation |
a |
the lower limit of the truncation interval |
b |
the upper limit of the truncation interval |
method |
how to calculate the integral, one of "integrate" and "jiahe" |
The approximated euro call option price
Fang F. and Oosterlee C.W. 2008. "A Novel Pricing Method for European Options Based on Fourier-Cosine Series Expansions", Siam Journal on Scientific Computing. 31(2): 826-848. doi: 10.1137/080718061.
r <- 0.1 sigmaS0 <- 0.2 tau <- 10 S0 <- 1 K <- 1 mu <- log(S0) + (r - 0.5 * sigmaS0^2) * tau sigma <- sigmaS0 * sqrt(tau) a <- -10 b <- 10 N <- 64 GBMChf <- function(u){NormChf(u,mu,sigma)} ValueOption <- function(x){EuroCallOption(x,K)} CosValueOption(ValueOption, GBMChf,r,tau, N, a, b)
r <- 0.1 sigmaS0 <- 0.2 tau <- 10 S0 <- 1 K <- 1 mu <- log(S0) + (r - 0.5 * sigmaS0^2) * tau sigma <- sigmaS0 * sqrt(tau) a <- -10 b <- 10 N <- 64 GBMChf <- function(u){NormChf(u,mu,sigma)} ValueOption <- function(x){EuroCallOption(x,K)} CosValueOption(ValueOption, GBMChf,r,tau, N, a, b)
Calculate useful statistics for an multivariate data.
Describe(data, digits = 2)
Describe(data, digits = 2)
data |
vector of observations |
digits |
integer deciding the number of decimal places |
A tibble of statistics, including min, max, mean, sd, Q25, Q50, Q75, kurt, Skew, n, na
swan <- rGarch(len = 180) Describe(tibble(a1 = swan, a2 = swan + 1), 2)
swan <- rGarch(len = 180) Describe(tibble(a1 = swan, a2 = swan + 1), 2)
Calculate useful statistics for an univariate data.
DescribeVector(data, digits = 2)
DescribeVector(data, digits = 2)
data |
vector of observations |
digits |
integer deciding the number of decimal places |
A tibble of statistics, including min, max, mean, sd, Q25, Q50, Q75, kurt, Skew, n, na
swan <- rGarch(len = 180) DescribeVector(swan)
swan <- rGarch(len = 180) DescribeVector(swan)
With global variable K, the strike price, calculate the value of European call option.
EuroCallOption(x, K)
EuroCallOption(x, K)
x |
the stock price |
K |
the strike price |
The value of European call option
EuroCallOption(x = 2,K = 1)
EuroCallOption(x = 2,K = 1)
Calculate the F_k coefficients for the COS method, an option pricing method based on the Fourier-cosine series.
F_k(Chf, N, a, b)
F_k(Chf, N, a, b)
Chf |
the characteristic function |
N |
the number of cos term for summation |
a |
the lower limit of the truncation interval |
b |
the upper limit of the truncation interval |
A vector of F_k coefficients
Fang F. and Oosterlee C.W. 2008. "A Novel Pricing Method for European Options Based on Fourier-Cosine Series Expansions", Siam Journal on Scientific Computing. 31(2): 826-848. doi: 10.1137/080718061.
N <- 32 a <- -6.0 b <- 6.0 F_k(StNormChf, N, a, b)
N <- 32 a <- -6.0 b <- 6.0 F_k(StNormChf, N, a, b)
Backtest for the buy and hold with a fixed weights strategy.
FixBacktest(rets, weights)
FixBacktest(rets, weights)
rets |
historic multivariate returns |
weights |
holding weights of stock |
A backtest return series
names <- c("swan", "bear", "tiger") date <- as.Date("2015-01-01") + days(0:179) mu <- c(0.2, 0.08, 0.1) sigma <- matrix(c(1, 0.25, -0.3, 0.25, 0.25, 0, -0.3, 0, 0.36), 3, 3) allret <- rMvReturnSim(names, date, mu, sigma) tsret <- as.timeSeries(allret) FixBacktest(tsret, rep(1 / 3, 3))
names <- c("swan", "bear", "tiger") date <- as.Date("2015-01-01") + days(0:179) mu <- c(0.2, 0.08, 0.1) sigma <- matrix(c(1, 0.25, -0.3, 0.25, 0.25, 0, -0.3, 0, 0.36), 3, 3) allret <- rMvReturnSim(names, date, mu, sigma) tsret <- as.timeSeries(allret) FixBacktest(tsret, rep(1 / 3, 3))
Plot the Acf figure with observations of a single variable beautifully.
ggacf(data, lag = 10)
ggacf(data, lag = 10)
data |
vector of observations |
lag |
the maximum lag to calculate the acf |
A ggplot figure of the acf
swan <- rGarch(len = 180) ggacf(swan^2, 20)
swan <- rGarch(len = 180) ggacf(swan^2, 20)
Plot the box figure beautifully with ggplot.
ggboxplot(data, mapping)
ggboxplot(data, mapping)
data |
a tibble |
mapping |
the mapping parameter of ggplot |
A box figure by ggplot
names <- c("swan", "bear", "tiger") date <- as.Date("2015-01-01") + days(0:179) mu <- c(0.2, 0.08, 0.1) sigma <- matrix(c(1, 0.25, -0.3, 0.25, 0.25, 0, -0.3, 0, 0.36), 3, 3) allret <- rMvReturnSim(names, date, mu, sigma) totret <- StackRet(allret, date) ggboxplot(totret, aes(x = stock, y = ret))
names <- c("swan", "bear", "tiger") date <- as.Date("2015-01-01") + days(0:179) mu <- c(0.2, 0.08, 0.1) sigma <- matrix(c(1, 0.25, -0.3, 0.25, 0.25, 0, -0.3, 0, 0.36), 3, 3) allret <- rMvReturnSim(names, date, mu, sigma) totret <- StackRet(allret, date) ggboxplot(totret, aes(x = stock, y = ret))
Plot the histgram figure beautifully with ggplot.
gghistplot(data, mapping, bins = 10)
gghistplot(data, mapping, bins = 10)
data |
a tibble |
mapping |
the mapping parameter |
bins |
the number of bins |
A histogram figure by ggplot
date <- as.Date("2015-01-01") + days(0:180) thero <- returns(rGbm("thero", date))[-1] tthero <- tibble(x = date[-1], y = thero) gghistplot(tthero, aes(x = thero, y = stat(density)), bins = 20)
date <- as.Date("2015-01-01") + days(0:180) thero <- returns(rGbm("thero", date))[-1] tthero <- tibble(x = date[-1], y = thero) gghistplot(tthero, aes(x = thero, y = stat(density)), bins = 20)
Plot the time series data beautifully with ggplot.
gglineplot(data, mapping, date_labels = "%Y/%m/%d", date_breaks = "2 weeks")
gglineplot(data, mapping, date_labels = "%Y/%m/%d", date_breaks = "2 weeks")
data |
a tibble |
mapping |
the mapping parameter |
date_labels |
the x label |
date_breaks |
the period of the x label |
A ggplot figure of the time series
date <- as.Date("2015-01-01") + days(0:180) thero <- returns(rGbm("thero", date))[-1] tthero <- tibble(x = date[-1], y = thero) gglineplot(tthero, aes(x, y), "%Y/%m", "1 months")
date <- as.Date("2015-01-01") + days(0:180) thero <- returns(rGbm("thero", date))[-1] tthero <- tibble(x = date[-1], y = thero) gglineplot(tthero, aes(x, y), "%Y/%m", "1 months")
Plot the Pacf figure with observations of a single variable beautifully.
ggpacf(data, lag = 10)
ggpacf(data, lag = 10)
data |
vector of observations |
lag |
the maximum lag to calculate the pacf |
A ggplot figure of the pacf
swan <- rGarch(len = 180) ggpacf(swan^2, 20)
swan <- rGarch(len = 180) ggpacf(swan^2, 20)
Construct four types portfolio with specificition and constraints.
InvestmentPortfolio(data, method, spec, constraints = "LongOnly")
InvestmentPortfolio(data, method, spec, constraints = "LongOnly")
data |
multivariate returns, must be "timeSeries" type |
method |
porofolio type, one of "fea", "minrisk", "globalminrisk" and "sharp" |
spec |
specificition of portfolio |
constraints |
constraints of trade |
A portfolio
Markowitz H. 1952. "Portfolio Selection", The Journal of Finance, 7(1), 77–91. doi: 10.2307/2975974.
library(fPortfolio) names <- c("swan", "bear", "tiger") date <- as.Date("2015-01-01") + days(0:179) mu <- c(0.2, 0.08, 0.1) sigma <- matrix(c(1, 0.25, -0.3, 0.25, 0.25, 0, -0.3, 0, 0.36), 3, 3) allret <- rMvReturnSim(names, date, mu, sigma) tsret <- as.timeSeries(allret) feaSpec <- portfolioSpec() setWeights(feaSpec) <- rep(1 / 3, times = 3) InvestmentPortfolio(tsret, "fea", feaSpec)
library(fPortfolio) names <- c("swan", "bear", "tiger") date <- as.Date("2015-01-01") + days(0:179) mu <- c(0.2, 0.08, 0.1) sigma <- matrix(c(1, 0.25, -0.3, 0.25, 0.25, 0, -0.3, 0, 0.36), 3, 3) allret <- rMvReturnSim(names, date, mu, sigma) tsret <- as.timeSeries(allret) feaSpec <- portfolioSpec() setWeights(feaSpec) <- rep(1 / 3, times = 3) InvestmentPortfolio(tsret, "fea", feaSpec)
Calculate the max absolute error of the cos method for different parameters given a vector of x.
LogErrorCosPdf(x, f, Chf, a, b, N)
LogErrorCosPdf(x, f, Chf, a, b, N)
x |
vector of observations |
f |
the true p.d.f. |
Chf |
the characteristic function |
a |
the lower limit of the truncation interval |
b |
the upper limit of the truncation interval |
N |
the number of cos term for summation |
A matrix that contains the log max error for different parameters
N <- c(1:200) L <- c(10, 20, 60, 100, 1000) a <- -L / 2 b <- L / 2 x <- seq(-5, 5, by = 10 / (32 - 1)) LogErrorCosPdf(x, dnorm, NormChf, a, b, N)
N <- c(1:200) L <- c(10, 20, 60, 100, 1000) a <- -L / 2 b <- L / 2 x <- seq(-5, 5, by = 10 / (32 - 1)) LogErrorCosPdf(x, dnorm, NormChf, a, b, N)
The Characteristic Function of Normal Distribution
NormChf(u, mu = 0, sigma = 1)
NormChf(u, mu = 0, sigma = 1)
u |
observation |
mu |
the |
sigma |
the |
The value of Characteristic Function
NormChf(1)
NormChf(1)
Plot the p.d.f functions for the univariate distribution with data processed by StackRet.
PdfMultiPlot(data, x, y, Variable)
PdfMultiPlot(data, x, y, Variable)
data |
a tibble contains x, y and Variable and the last one is the group variable |
x |
x |
y |
y |
Variable |
the group label |
A ggplot figure of the probability density functions
N <- 2**(1:6) x <- seq(-5, 5, by = 10 / (32 - 1)) a <- -10.0 b <- 10.0 f_x1 <- CosPdfMulti(x, StNormChf, N, a, b) colnames(f_x1) <- paste("N = 2 ^ ", c(1:6), sep = "") mt1 <- StackRet(f_x1, x) colnames(mt1) <- c("x", "y", "Variable") PdfMultiPlot(mt1, x, y, Variable)
N <- 2**(1:6) x <- seq(-5, 5, by = 10 / (32 - 1)) a <- -10.0 b <- 10.0 f_x1 <- CosPdfMulti(x, StNormChf, N, a, b) colnames(f_x1) <- paste("N = 2 ^ ", c(1:6), sep = "") mt1 <- StackRet(f_x1, x) colnames(mt1) <- c("x", "y", "Variable") PdfMultiPlot(mt1, x, y, Variable)
Plot the p.d.f function for the univariate distribution with x and y.
PdfSinglePlot(data, x, y)
PdfSinglePlot(data, x, y)
data |
a tiible contains x and y |
x |
x |
y |
y |
A ggplot figure of the probability density function
N <- 32 x <- seq(-5, 5, by = 10 / (32 - 1)) a <- -6.0 b <- 6.0 f_x <- CosPdfRecovery(x, StNormChf, N, a, b) tnorm <- tibble(x = x, y = f_x) PdfSinglePlot(tnorm, x, y)
N <- 32 x <- seq(-5, 5, by = 10 / (32 - 1)) a <- -6.0 b <- 6.0 f_x <- CosPdfRecovery(x, StNormChf, N, a, b) tnorm <- tibble(x = x, y = f_x) PdfSinglePlot(tnorm, x, y)
Simulate a Garch series given its data generate process with mean part.
rGarch( u = 0, a0 = rnorm(1, 0, 1), sigma20 = rnorm(1, 0, 1)^2, alpha = c(0.5, 0.5), beta = 0.25, len = 10 )
rGarch( u = 0, a0 = rnorm(1, 0, 1), sigma20 = rnorm(1, 0, 1)^2, alpha = c(0.5, 0.5), beta = 0.25, len = 10 )
u |
the mean series |
a0 |
vector of the start part |
sigma20 |
vector of the initial variance |
alpha |
the |
beta |
the |
len |
the length, include defined |
A simulated garch series
Bollerslev T. 1986. "Generalized autoregressive conditional heteroskedasticity", Journal of Econometrics, 31(3): 307-327. doi: 10.1016/0304-4076(86)90063-1.
rGarch()
rGarch()
Simulate a Garch series given its data generate process without mean part.
rGarcha( a0 = rnorm(1, 0, 1), sigma20 = rnorm(1, 0, 1)^2, alpha = c(0.5, 0.5), beta = 0.25, len = 10 )
rGarcha( a0 = rnorm(1, 0, 1), sigma20 = rnorm(1, 0, 1)^2, alpha = c(0.5, 0.5), beta = 0.25, len = 10 )
a0 |
vector of the start part |
sigma20 |
vector of the initial variance |
alpha |
the |
beta |
the |
len |
the length, include defined |
A simulated garch series
Bollerslev T. 1986. "Generalized autoregressive conditional heteroskedasticity", Journal of Econometrics, 31(3): 307-327. doi: 10.1016/0304-4076(86)90063-1.
rGarcha()
rGarcha()
Simulate an multivariate series following Geometric Brownian Motion (GBM)
rGbm(name, time, start = 100, mu = 0.01, sigma = 0.02)
rGbm(name, time, start = 100, mu = 0.01, sigma = 0.02)
name |
vector of series names |
time |
vector of time, must be a "Date" type variable |
start |
vector of start positions |
mu |
vector of |
sigma |
vector of |
a simulated multivariate GBM series
date <- as.Date("2015-01-01") + days(0:29) rGbm(c("bear", "tiger", "swan"), date)
date <- as.Date("2015-01-01") + days(0:29) rGbm(c("bear", "tiger", "swan"), date)
Simulate multivariate prices for interconnected stocks with each price series following Geometric Brownian Motion (GBM).
rGbms( name, len, start = c(1000, 1000), mu = rep(1e-04, 2), sigma = matrix(c(2e-04, 1e-04, 1e-04, 2e-04), 2, 2), digits = 2 )
rGbms( name, len, start = c(1000, 1000), mu = rep(1e-04, 2), sigma = matrix(c(2e-04, 1e-04, 1e-04, 2e-04), 2, 2), digits = 2 )
name |
vector of series names |
len |
the length |
start |
vector of start positions |
mu |
vector of |
sigma |
vector of |
digits |
integer deciding the number of decimal places |
A simulated multivariate GBM series with each series interconnected
rGbms(c("bear", "tiger"), len = 36)
rGbms(c("bear", "tiger"), len = 36)
Simulate an univariate series following Geometric Brownian Motion (GBM).
rGbmSingle(len, start = 100, mu = 0.01, sigma = 0.02)
rGbmSingle(len, start = 100, mu = 0.01, sigma = 0.02)
len |
the length |
start |
the start position |
mu |
the |
sigma |
the |
a simulated univariate GBM series
rGbmSingle(100)
rGbmSingle(100)
Calculate cumulative return, annualized return, max drawdown, annualized sharp ratio, calmar ratio, sortino ratio, alpha, beta and information ratio with returns.
RiskIndicators(ret, rb, rf = 0)
RiskIndicators(ret, rb, rf = 0)
ret |
vector of return |
rb |
return of market portfolio |
rf |
risk free rate |
A matrix of return and risk indicators
date <- as.Date("2015-01-01") + days(0:249) ret <- as.xts(rnorm(250), date) rb <- as.xts(rep(0, 250), date) RiskIndicators(ret, rb = rb, rf = 0)
date <- as.Date("2015-01-01") + days(0:249) ret <- as.xts(rnorm(250), date) rb <- as.xts(rep(0, 250), date) RiskIndicators(ret, rb = rb, rf = 0)
Simulate stocks prices following multivariate normal distribution.
rMvReturnSim( names, date, mu = rep(0, 2), sigma = matrix(c(1, 0.5, 0.5, 1), 2, 2) )
rMvReturnSim( names, date, mu = rep(0, 2), sigma = matrix(c(1, 0.5, 0.5, 1), 2, 2) )
names |
vector of names |
date |
vector of time, must be "Date" type |
mu |
vector of |
sigma |
vector of |
Multivariate stock prices
names <- c("swan", "bear") date <- as.Date("2015-01-01") + days(0:29) rMvReturnSim(names, date)
names <- c("swan", "bear") date <- as.Date("2015-01-01") + days(0:29) rMvReturnSim(names, date)
Simulate stock trade data with assumption that the stock price following Geometric Brownian Motion (GBM).
rTrade(time, start = 100, mu = 1e-04, sigma = 2e-04)
rTrade(time, start = 100, mu = 1e-04, sigma = 2e-04)
time |
time vector of time, must be a "Date" type variable |
start |
the start position |
mu |
the |
sigma |
the |
Stock trade data with Open, High, Low and Close
date <- as.Date("2015-01-01") + days(0:29) rTrade(date)
date <- as.Date("2015-01-01") + days(0:29) rTrade(date)
Simulate multivariate stock trade data with assumption that each stock price following Geometric Brownian Motion (GBM). And these prices are interconnected.
rTrades( name, time, start = c(1000, 1000), mu = rep(1e-04, 2), sigma = matrix(c(2e-04, 1e-04, 1e-04, 2e-04), 2, 2), digits = 2 )
rTrades( name, time, start = c(1000, 1000), mu = rep(1e-04, 2), sigma = matrix(c(2e-04, 1e-04, 1e-04, 2e-04), 2, 2), digits = 2 )
name |
vector of names |
time |
time vector of time, must be "Date" type |
start |
vector of start positions |
mu |
vector of |
sigma |
vector of |
digits |
integer deciding the number of deciamal places |
A list of stock trade data with Open, High, Low and Close
date <- as.Date("2015-01-01") + days(0:29) rTrades(c("swan", "bear"), date)
date <- as.Date("2015-01-01") + days(0:29) rTrades(c("swan", "bear"), date)
Calculate sharp ratio of stock with running window.
Sharp(x, rf = 0, n = 10)
Sharp(x, rf = 0, n = 10)
x |
vector of price |
rf |
risk free rate |
n |
the length of running window |
The sharp ratio series with length the same as x
date <- as.Date("2015-01-01") + days(0:29) trade <- rTrade(date) x <- trade$Close Sharp(x)
date <- as.Date("2015-01-01") + days(0:29) trade <- rTrade(date) x <- trade$Close Sharp(x)
LogErrorCosPdf
for plotRearrange the data from LogErrorCosPdf
for plot
StackForPlot(error, a, b, N)
StackForPlot(error, a, b, N)
error |
return of |
a |
the lower limit of the truncation interval |
b |
the upper limit of the truncation interval |
N |
the number of cos term for summation |
Suitable tibble data for plot by group in ggplot
N <- c(1:200) L <- c(10, 20, 60, 100, 1000) a <- -L / 2 b <- L / 2 x <- seq(-5, 5, by = 10 / (32 - 1)) el <- LogErrorCosPdf(x, dnorm, NormChf, a, b, N) StackForPlot(el, a, b, N)
N <- c(1:200) L <- c(10, 20, 60, 100, 1000) a <- -L / 2 b <- L / 2 x <- seq(-5, 5, by = 10 / (32 - 1)) el <- LogErrorCosPdf(x, dnorm, NormChf, a, b, N) StackForPlot(el, a, b, N)
Change the arrangement of multivariate data to generate suitable data for ggplot.
StackRet(rets, date)
StackRet(rets, date)
rets |
multivariate data, arranged by column |
date |
vector of common information for variables |
Suitable tibble data for plot by group in ggplot
names <- c("swan", "bear", "tiger") date <- as.Date("2015-01-01") + days(0:179) mu <- c(0.2, 0.08, 0.1) sigma <- matrix(c(1, 0.25, -0.3, 0.25, 0.25, 0, -0.3, 0, 0.36), 3, 3) allret <- rMvReturnSim(names, date, mu, sigma) StackRet(allret, date)
names <- c("swan", "bear", "tiger") date <- as.Date("2015-01-01") + days(0:179) mu <- c(0.2, 0.08, 0.1) sigma <- matrix(c(1, 0.25, -0.3, 0.25, 0.25, 0, -0.3, 0, 0.36), 3, 3) allret <- rMvReturnSim(names, date, mu, sigma) StackRet(allret, date)
The Characteristic Function of Standard Normal Distribution
StNormChf(u)
StNormChf(u)
u |
observation |
The value of Characteristic Function
StNormChf(1)
StNormChf(1)
Calculate the V_k Series for Option Pricing with the COS Method, an option pricing method based on the Fourier-cosine series.
V_k(ValueOption, N, a, b, method = "integrate")
V_k(ValueOption, N, a, b, method = "integrate")
ValueOption |
the value function of the option |
N |
the number of cos term for summation |
a |
the lower limit of the truncation interval |
b |
the upper limit of the truncation interval |
method |
how to calculate the integral, one of "integrate" and "jiahe" |
The V_k series
Fang F. and Oosterlee C.W. 2008. "A Novel Pricing Method for European Options Based on Fourier-Cosine Series Expansions", Siam Journal on Scientific Computing. 31(2): 826-848. doi: 10.1137/080718061.
r <- 0.1 sigmaS0 <- 0.2 tau <- 10 S0 <- 1 K <- 1 mu <- log(S0) + (r - 0.5 * sigmaS0^2) * tau sigma <- sigmaS0 * sqrt(tau) a <- -10 b <- 10 N <- 64 ValueOption <- function(x){EuroCallOption(x,K)} V_k(ValueOption, N, a, b)
r <- 0.1 sigmaS0 <- 0.2 tau <- 10 S0 <- 1 K <- 1 mu <- log(S0) + (r - 0.5 * sigmaS0^2) * tau sigma <- sigmaS0 * sqrt(tau) a <- -10 b <- 10 N <- 64 ValueOption <- function(x){EuroCallOption(x,K)} V_k(ValueOption, N, a, b)
Calculate VaR with three method and implement unconditional and conditional coverage test.
VaRSimTest(data, method, alpha, fun, ...)
VaRSimTest(data, method, alpha, fun, ...)
data |
vector of returns |
method |
the VaR method, one of "param", "hist" and "mc" |
alpha |
the VaR confidence level |
fun |
function calculating VaR, limited by |
... |
the extra parameters of |
A list of VaR and coverage test outcome
Christoffersen P. F. 1998. "Evaluating Interval Forecasts", International Economic Review, 841-862. doi: 10.2307/2527341.
Kupiec PH. 1995. "Techniques for Verifying the Accuracy of Risk Measurement Models", The Journal of Derivatives, 3(2), 73-84. doi: 10.3905/jod.1995.407942.
swan <- rGarch(len = 30) date <- as.Date("2015-01-01") + days(0:(length(swan) - 1)) tswan <- tibble(garch = swan, date = date) tsswan <- as.xts(swan, date) alpha = 0.05 num = 100000 mu = mean(tsswan) sd = sd(tsswan) VaRSimTest(tsswan, "mc", alpha , rnorm, 100000, mu, sd)
swan <- rGarch(len = 30) date <- as.Date("2015-01-01") + days(0:(length(swan) - 1)) tswan <- tibble(garch = swan, date = date) tsswan <- as.xts(swan, date) alpha = 0.05 num = 100000 mu = mean(tsswan) sd = sd(tsswan) VaRSimTest(tsswan, "mc", alpha , rnorm, 100000, mu, sd)