A distribution from its characteristic function
invert_chf.RdA law's bucket masses on a grid, by inverting its characteristic
function: aggregate's AggregateCHF (chfagg). The characteristic
function is sampled on the FFT's frequency grid, times
sinc(t * step / 2), and inverted once, so bucket k holds the
probability within half a step of x_min + k * step. With step left
out, the window is sized from the law's tails (Chernoff bounds) to leave
1 - bucket_sizing_p of the mass outside, half on each side, and the
step is rounded up to 1, 2, 4, 5 or 8 times a power of ten (a power of
two below 1); when the dropped frequencies are above 1e-6 the step moves
down that ladder while that helps. A Tweedie's mass at 0 is inverted
apart, so it does not ring.
Usage
invert_chf(
law,
log2 = 16,
step = NULL,
x_min = NULL,
bucket_sizing_p = 0.99999,
tilt = TRUE
)
chf_distribution(ptr)Arguments
- law
A
normal_distribution(),gamma_distribution(),exponential_distribution(),inverse_gaussian_distribution(),tweedie(), anaffine_distribution()of one of them, astable_distribution(),normal_inverse_gaussian_distribution(),variance_gamma_distribution(),tempered_stable_distribution(),tweedie_power_distribution(), or your own characteristic function: an R function of a numeric vector of frequenciestreturningE exp(i t X)at each, as a complex vector. Your own function needsstepandx_min.- log2
The grid has
2^log2buckets, 1 to 28.- step
The bucket; sized from the tails when
NULL.- x_min
The grid's first point, with
step; placed from the tails whenNULL. A givenx_minfixes the grid, so it is inverted untilted:tilt = TRUEfalls back to no tilt (a heavy tail wraps onto the window, and the report's tilt is 0), and a numbertiltis an error.- bucket_sizing_p
The mass the window covers when it is sized from the tails.
- tilt
TRUE: a law with one power tail (astable_distribution()withbeta1 or -1) at the automatic tilt, a stable law with two split into its halves and each tilted, every other law untilted; no tilt whenx_minis given.FALSE: never tilt (a heavy tail wraps onto the window). A numbertau >= 0: exactlytaue-folds of damping across the window, for a stable law only, and an error withx_mingiven or on a window (astepthat puts it on the body) whose light side below it the tilt would magnify past round-off.- ptr
Internal.
Value
A chf_distribution, which inherits from distribution, with
properties xs, masses, step, x_min and report (a list:
log2, step_given, truncation_error (|phi(pi / step)| of the
continuous part), is_truncated (above 1e-6), outside_below and
outside_above (the Chernoff bounds on the mass outside the window,
which wraps in, or under a tilt the tail mass beyond the window),
tilt_left and tilt_right (the e-folds of damping on each side),
edge_error (the modelled worst relative error at the heavy end of a
law with one power tail, NaN otherwise), total_mass, law_mean
and law_variance). VaR() and TVaR() read its masses as
inverted, as aggregate's AggregateCHF.q and .tvar: the TVaR over
the buckets of positive mass, not renormalized.
Details
A stable law with one power tail is inverted along the line
Im s = theta, where the integrand decays like exp(-theta x) f(x):
what wraps is the damped tail, and the mass beyond the window is left
out and reported in report$outside_above (or, for a left tail, added
to the first bucket and reported in report$outside_below). The
automatic tilt balances the damped wrap against the round-off the tilt
amplifies, and caps the step.
The masses are as inverted, not renormalized. Supports mean(),
variance(), cdf() (the masses at grid points at or below q),
quantile() and VaR() (the first grid point whose cumulative mass
reaches p); chf_to_grid() gives a grid_distribution from 0.
Examples
d <- invert_chf(gamma_distribution(4, 25), log2 = 12)
c(d@step, d@x_min, mean(d))
#> [1] 0.25 0.00 100.00
c(VaR(d, 0.99), TVaR(d, 0.99))
#> [1] 251.2500 284.1069
d@report$truncation_error
#> [1] 1.026577e-10
own <- invert_chf(function(t) (1 - 25i * t)^-4, log2 = 12, step = 0.25, x_min = 0)
max(abs(own@masses - d@masses))
#> [1] 8.673617e-19