triangular function

Triangular distribution

Triangular distribution

Computes the pdf, cdf, value at risk and expected shortfall for the triangular distribution given by [REMOVE_ME] \begin{array}{ll}&\displaystylef (x) = \left\{\begin{array}{ll}\displaystyle0, & \mbox{if $x < a$,}\\\\\displaystyle\frac {2 (x - a)}{(b - a) (c - a)}, & \mbox{if $a \leq x \leq c$,}\\\\\displaystyle\frac {2 (b - x)}{(b - a) (b - c)}, & \mbox{if $c < x \leq b$,}\\\\\displaystyle0, & \mbox{if $b < x$,}\end{array} \right.\\&\displaystyleF (x) = \left\{\begin{array}{ll}\displaystyle0, & \mbox{if $x < a$,}\\\\\displaystyle\frac {(x - a)^2}{(b - a) (c - a)}, & \mbox{if $a \leq x \leq c$,}\\\\\displaystyle1 - \frac {(b - x)^2}{(b - a) (b - c)}, & \mbox{if $c < x \leq b$,}\\\\\displaystyle1, & \mbox{if $b < x$,}\end{array} \right.\\&\displaystyle{\rm VaR}_p (X) = \left\{\begin{array}{ll}\displaystylea + \sqrt{p (b - a) (c - a)}, & \mbox{if $0 < p < \frac {c - a}{b - a}$,}\\\\\displaystyleb - \sqrt{(1 - p) (b - a) (b - c)}, & \mbox{if $\frac {c - a}{b - a} \leq p < 1$,}\end{array} \right.\\&\displaystyle{\rm ES}_p (X) =\left\{\begin{array}{ll}\displaystylea + \frac {2}{3} \sqrt{p (b - a) (c - a)}, & \mbox{if $0 < p < \frac {c - a}{b - a}$,}\\\\\displaystyleb + \frac {a - c}{p} + \frac {2 (2 c - a - b)}{3 p} +2 \sqrt{(b - a) (b - c)} \frac {(1 - p)^{3/2}}{3 p}, &\mbox{if $\frac {c - a}{b - a} \leq p < 1$}\end{array} \right.\end{array} [REMOVE_ME_2]

for axba \leq x \leq b, 0<p<10 < p < 1, <a<-\infty < a < \infty, the first location parameter, <a<c<-\infty < a < c < \infty, the second location parameter, and <c<b<-\infty < c < b < \infty, the third location parameter.

Description

Computes the pdf, cdf, value at risk and expected shortfall for the triangular distribution given by

\begin{array}{ll}&\displaystylef (x) = \left\{\begin{array}{ll}\displaystyle0, & \mbox{if $x < a$,}\\\\\displaystyle\frac {2 (x - a)}{(b - a) (c - a)}, & \mbox{if $a \leq x \leq c$,}\\\\\displaystyle\frac {2 (b - x)}{(b - a) (b - c)}, & \mbox{if $c < x \leq b$,}\\\\\displaystyle0, & \mbox{if $b < x$,}\end{array} \right.\\&\displaystyleF (x) = \left\{\begin{array}{ll}\displaystyle0, & \mbox{if $x < a$,}\\\\\displaystyle\frac {(x - a)^2}{(b - a) (c - a)}, & \mbox{if $a \leq x \leq c$,}\\\\\displaystyle1 - \frac {(b - x)^2}{(b - a) (b - c)}, & \mbox{if $c < x \leq b$,}\\\\\displaystyle1, & \mbox{if $b < x$,}\end{array} \right.\\&\displaystyle{\rm VaR}_p (X) = \left\{\begin{array}{ll}\displaystylea + \sqrt{p (b - a) (c - a)}, & \mbox{if $0 < p < \frac {c - a}{b - a}$,}\\\\\displaystyleb - \sqrt{(1 - p) (b - a) (b - c)}, & \mbox{if $\frac {c - a}{b - a} \leq p < 1$,}\end{array} \right.\\&\displaystyle{\rm ES}_p (X) =\left\{\begin{array}{ll}\displaystylea + \frac {2}{3} \sqrt{p (b - a) (c - a)}, & \mbox{if $0 < p < \frac {c - a}{b - a}$,}\\\\\displaystyleb + \frac {a - c}{p} + \frac {2 (2 c - a - b)}{3 p} +2 \sqrt{(b - a) (b - c)} \frac {(1 - p)^{3/2}}{3 p}, &\mbox{if $\frac {c - a}{b - a} \leq p < 1$}\end{array} \right.\end{array}

for axba \leq x \leq b, 0<p<10 < p < 1, <a<-\infty < a < \infty, the first location parameter, <a<c<-\infty < a < c < \infty, the second location parameter, and <c<b<-\infty < c < b < \infty, the third location parameter.

dtriangular(x, a=0, b=2, c=1, log=FALSE) ptriangular(x, a=0, b=2, c=1, log.p=FALSE, lower.tail=TRUE) vartriangular(p, a=0, b=2, c=1, log.p=FALSE, lower.tail=TRUE) estriangular(p, a=0, b=2, c=1)

Arguments

  • x: scaler or vector of values at which the pdf or cdf needs to be computed
  • p: scaler or vector of values at which the value at risk or expected shortfall needs to be computed
  • a: the value of the first location parameter, can take any real value, the default is zero
  • c: the value of the second location parameter, can take any real value but must be greater than a, the default is 1
  • b: the value of the third location parameter, can take any real value but must be greater than c, the default is 2
  • log: if TRUE then log(pdf) are returned
  • log.p: if TRUE then log(cdf) are returned and quantiles are computed for exp(p)
  • lower.tail: if FALSE then 1-cdf are returned and quantiles are computed for 1-p

Returns

An object of the same length as x, giving the pdf or cdf values computed at x or an object of the same length as p, giving the values at risk or expected shortfall computed at p.

References

Stephen Chan, Saralees Nadarajah & Emmanuel Afuecheta (2016). An R Package for Value at Risk and Expected Shortfall, Communications in Statistics - Simulation and Computation, 45:9, 3416-3434, tools:::Rd_expr_doi("10.1080/03610918.2014.944658")

Author(s)

Saralees Nadarajah

Examples

x=runif(10,min=0,max=1) dtriangular(x) ptriangular(x) vartriangular(x) estriangular(x)
  • Maintainer: Leo Belzile
  • License: GPL (>= 2)
  • Last published: 2023-04-22

Useful links