Risk
VaR/ES diagnostics, GARCH/EGARCH estimates, extreme-value models, backtesting, walk-forward validation and risk reports.
See the usage guide for task-oriented examples. Signatures below are generated from the public headers at the same commit as the rest of this site.
-
struct egarch_parameters
Parameters of an EGARCH(1,1) model.
-
struct egarch_result
Result of an EGARCH(1,1) fit.
Public Members
-
egarch_parameters params
Fitted parameters.
-
std::vector<double> conditional_variances
Variance path in return units squared, one value per cleaned observation.
-
std::vector<double> residuals
Standardized residuals aligned with
conditional_variances.
-
double log_likelihood
Gaussian log-likelihood, excluding the first observation.
-
bool converged
Whether the optimizer and parameter, variance and stationarity checks passed.
-
egarch_parameters params
-
struct extreme_risk_result
Combined value-at-risk and expected-shortfall estimate from an EVT model.
Public Members
-
double var
Value-at-risk estimate, signed by the tail.
-
double cvar
Conditional tail expectation, signed by the tail.
-
double tail_index
Fitted GPD or GEV shape parameter.
-
double threshold
GPD magnitude threshold; NaN for GEV fits.
-
std::size_t n_exceedances
GPD exceedance count; zero for GEV fits.
-
double alpha
Tail probability used for the estimates.
-
std::optional<double> location
GEV location; empty for GPD fits.
-
std::optional<double> scale
GEV scale; empty for GPD fits.
-
std::optional<std::size_t> n_blocks
GEV block count; empty for GPD.
-
double var
-
struct garch11_parameters
Parameters of a GARCH(1,1) model.
-
struct garch11_result
Result of a GARCH(1,1) fit.
Public Members
-
garch11_parameters params
Fitted parameters.
-
std::vector<double> conditional_variances
Variance path in return units squared, one value per cleaned observation.
-
std::vector<double> residuals
Standardized residuals aligned with
conditional_variances.
-
double log_likelihood
Gaussian log-likelihood, excluding the first observation.
-
bool converged
Whether the optimizer and parameter, variance and stationarity checks passed.
-
garch11_parameters params
-
struct garch_conditional_estimate
GARCH-family VaR or ES estimate and the variance path used.
Public Members
-
double value
Signed risk estimate; negative for losses at lower-tail probabilities.
-
std::vector<double> conditional_variances
Variance forecast path in return units squared from
forecast_volatility, one value per horizon step.
-
bool converged
Convergence flag of the fit that produced the path.
-
double value
-
struct garch_forecast_result
Forecast and fit diagnostics returned by
forecast_volatility.
-
struct gev_parameters
Fitted generalized extreme-value distribution of block extremes.
-
struct gjr_garch_parameters
Parameters of a GJR-GARCH(1,1) model.
-
struct gjr_garch_result
Result of a GJR-GARCH(1,1) fit.
Public Members
-
gjr_garch_parameters params
Fitted parameters.
-
std::vector<double> conditional_variances
Variance path in return units squared, one value per cleaned observation.
-
std::vector<double> residuals
Standardized residuals aligned with
conditional_variances.
-
double log_likelihood
Gaussian log-likelihood, excluding the first observation.
-
bool converged
Whether the optimizer and parameter, variance and stationarity checks passed.
-
gjr_garch_parameters params
-
struct gpd_parameters
Fitted generalized Pareto distribution for threshold exceedances.
-
struct hill_estimate
Hill tail-index estimate and the exceedances used.
-
struct refit_parameters
Parameters recorded for one walk-forward refit.
-
struct risk_backtest_result
Result of a VaR or ES backtest, including coverage statistics and a deterministic input digest.
Public Members
-
risk_backtest_method method
Risk measure backtested.
-
double confidence_level
Confidence level used for the forecast.
-
std::size_t observations
Number of paired non-NaN observations.
-
std::size_t exceptions
VaR: realized below forecast; ES: realized below the tail threshold.
-
double expected_exceptions
observations * (1 - confidence_level).
-
double exception_rate
exceptions / observations; 0 when empty.
-
double kupiec_lr
Kupiec unconditional-coverage statistic; 0 for ES.
-
double kupiec_pvalue
Chi-square (df 1) p-value; 1 for ES.
-
double christoffersen_lr
Independence statistic; 0 for ES.
-
double christoffersen_pvalue
Chi-square (df 1) p-value; 1 for ES.
-
std::string inputs_digest
Lowercase SHA-256 over aligned timestamps and values; native form, not the Python CSV digest.
-
std::map<std::string, double> diagnostics
VaR adds
significanceandsmall_sample; ES addsrealized_es,forecast_es,z_score,n_bootstrapandseed.
-
risk_backtest_status status
Backtest classification.
-
risk_backtest_method method
-
struct risk_estimate
Point risk estimate plus provenance and diagnostics.
Public Members
-
risk_forecast_method method = risk_forecast_method::historical
Estimation method.
-
double confidence_level = 0.95
Confidence level used for the estimate.
-
std::size_t horizon = 1U
Configured forecast horizon.
-
std::string sign_convention = {losses_negative_sign_convention}
Sign convention label;
losses_negative.
-
double estimate = 0.0
Point estimate; negative for losses under
losses_negative.
-
bool has_forecast_timestamp = false
Whether
forecast_timestampwas populated.
-
std::string inputs_digest
Lowercase SHA-256 hex digest of the cleaned timestamps and values.
-
bool has_forecast = false
Whether a forward forecast path is populated; current point estimates leave it false.
-
std::vector<double> forecast_values
Optional forecast values; empty for point estimates.
-
std::map<std::string, double> diagnostics
Method-specific numeric diagnostics; keys depend on
method.
-
std::string kernel
Backend kernel: empty for historical,
evt_var/evt_cvarfor EVT, andconditional_var/conditional_esfor GARCH.
-
std::string note
Note populated when a GARCH fit does not converge; empty otherwise.
-
risk_estimate_status status = risk_estimate_status::ok
Estimate status.
-
risk_forecast_method method = risk_forecast_method::historical
-
struct risk_forecast_config
Settings for a point VaR or expected-shortfall estimate.
Public Members
-
risk_forecast_method method = risk_forecast_method::historical
Estimation method.
-
double confidence_level = 0.95
Confidence level in (0, 1); the tail probability is 1 - confidence_level.
-
std::size_t horizon = 1U
Forecast horizon in observations; used by the GARCH method and must be at least 1.
-
garch_model garch_kernel = garch_model::garch
GARCH family used when
methodisgarch.
-
std::optional<double> threshold
GPD threshold in absolute magnitude units; empty selects the automatic threshold and GEV ignores it.
-
std::optional<std::size_t> block_size
GEV block size in observations; empty selects the automatic block size and GPD ignores it.
-
risk_forecast_method method = risk_forecast_method::historical
-
struct risk_forecast_event
One out-of-sample forecast event in a validation report.
-
struct risk_model_spec
Versioned model specification shared by walk-forward VaR and validation reports.
Public Members
-
risk_forecast_target forecast_target = risk_forecast_target::var
Forecast target; walk-forward VaR supports
varonly.
-
double confidence_level = 0.99
Confidence level; must be finite in (0, 1).
-
std::size_t horizon = 1U
Forecast horizon in observations; must be at least 1.
-
std::string distribution = "normal"
Distribution label;
historicalornormal.
-
std::string sign_convention = "losses_negative"
Sign convention label; only
losses_negativeis accepted.
-
std::size_t window = 252U
Estimation window length in observations; at least 2.
-
std::size_t refit_cadence = 1U
Number of forecast steps between refits; at least 1.
-
std::string model_version = "1.0"
Model version label; only
1.0is accepted.
-
risk_forecast_target forecast_target = risk_forecast_target::var
-
struct risk_refit_event
Parameters recorded for one refit in a validation report.
-
struct risk_report_diagnostics
Diagnostic fields describing how a validation report was produced.
Public Members
-
std::string method
Distribution label from the specification.
-
std::string quantile_method
weibullfor historical andnormal_ppffor normal.
-
std::size_t window = 0U
Estimation window length.
-
std::size_t refit_cadence = 0U
Forecast steps per refit.
-
std::size_t forecast_count = 0U
Number of forecast events.
-
std::string backtest_status
Backtest status name (
pass,fail,inconclusive, orexperimental).
-
std::string reason
Reason for a non-ok status; empty for ok reports.
-
std::size_t n_observations = 0U
Input observation count; populated for insufficient-data reports.
-
std::string method
-
struct risk_validation_report
Versioned validation report projected from a walk-forward VaR result.
Public Functions
-
risk_validation_report_dict to_dict() const
Returns a detached native dict representation of the report fields.
- Throws:
fincore_error – If forecast events, refits, or a present backtest contain non-finite values.
- Returns:
Dictionary with one field per native report field.
-
std::string to_json() const
Serializes the report to deterministic JSON text.
Keys are emitted in sorted order with two-space indentation, Python-compatible float text, and a trailing newline. Non-finite numbers and invalid UTF-8 are rejected.
- Throws:
input_error – If the specification is invalid, a numeric field is not finite, or a text field is not valid UTF-8.
- Returns:
JSON text ending with a newline.
-
std::filesystem::path write_json(const std::filesystem::path &path) const
Writes the deterministic JSON artifact to
pathand returns it.Parent directories are not created, matching the source contract.
- Parameters:
path – Destination path; the file is created or truncated.
- Throws:
fincore_error – If report fields violate the serialization contract or the file cannot be opened or written.
- Returns:
The same path after a successful write.
Public Members
-
walk_forward_status status = walk_forward_status::unsupported
Run status.
-
std::string inputs_digest
Lowercase SHA-256 hex digest from the result.
-
risk_model_spec specification
Specification echoed from the result.
-
std::vector<risk_forecast_event> forecast_events
Forecast events; empty for non-ok reports.
-
std::vector<risk_refit_event> refits
Refit parameters; empty for non-ok reports.
-
risk_report_diagnostics diagnostics
Report diagnostics.
-
bool has_backtest = false
Whether
backtestholds a backtest.
-
risk_backtest_result backtest = {}
Backtest payload; meaningful only when
has_backtestis true.
-
std::string traffic_light_zone
Basel zone; empty without a backtest.
-
std::optional<std::string> timestamp_index_name
Optional index label supplied to the builder.
-
std::optional<std::string> timestamp_timezone
Optional index timezone label; the native builder leaves it empty.
-
std::string disclosure = {basel_reference_disclosure}
Basel reference disclosure text.
-
int schema_version = risk_validation_report_schema_version
Report schema version.
-
risk_validation_report_dict to_dict() const
-
struct risk_validation_report_dict
Native detached dictionary projection of
risk_validation_report.This is the C++ equivalent of the source’s JSON-compatible
to_dictmapping: every native report field is represented exactly once. Python object identity and mapping subclassing are not claimed.Public Members
-
int schema_version = risk_validation_report_schema_version
Report schema version.
-
std::string status
Status name:
ok,insufficient_data, orunsupported.
-
std::string inputs_digest
Lowercase SHA-256 hex digest from the walk-forward result.
-
std::optional<std::string> timestamp_index_name
Optional index label.
-
std::optional<std::string> timestamp_timezone
Optional index timezone label; not populated by the native builder.
-
risk_model_spec specification
Specification echoed from the result.
-
std::vector<risk_forecast_event> forecast_events
Forecast events; empty for non-ok reports.
-
std::vector<risk_refit_event> refits
Refit parameters; empty for non-ok reports.
-
risk_report_diagnostics diagnostics
Report diagnostics.
-
std::optional<risk_backtest_result> backtest
Backtest payload; empty when the report has no backtest.
-
std::string traffic_light_zone
Basel zone; empty without a backtest.
-
std::string disclosure
Basel reference disclosure text.
-
int schema_version = risk_validation_report_schema_version
-
struct walk_forward_var_result
Result of a walk-forward VaR run.
Public Members
-
risk_model_spec spec
Specification used to produce the result.
-
std::vector<double> forecast
VaR forecast path aligned with
index; empty unlessstatusisok.
-
std::vector<double> realized
Realized returns aligned with
index; empty unlessstatusisok.
-
std::vector<timestamp> refit_timestamps
Timestamps of all refits; the first equals
index.front()whenok.
-
std::vector<refit_parameters> fits
Parameters recorded for each refit, one per
refit_timestampsentry.
-
std::string inputs_digest
Lowercase SHA-256 hex digest of the input values and the confidence level, window, refit cadence, distribution and model version.
-
walk_forward_status status
Run status.
-
std::string unsupported_reason
Reason for an
unsupportedorinsufficient_dataresult; empty forok.
-
std::size_t n_observations = 0U
Number of input observations.
-
risk_backtest_result backtest
Out-of-sample VaR backtest; meaningful only when
has_backtestis true.
-
bool has_backtest
Whether
backtestwas populated.
-
risk_model_spec spec
-
enum class fincore::evt_model
Extreme-value model used for a tail estimate.
Values:
-
enumerator gpd
Peaks-over-threshold generalized Pareto model.
-
enumerator gev
Block-maxima generalized extreme-value model.
-
enumerator gpd
-
enum class fincore::evt_tail
Tail of the return distribution used by an EVT model.
Values:
-
enumerator lower
Lower tail (losses).
-
enumerator upper
Upper tail (gains).
-
enumerator lower
-
enum class fincore::garch_model
GARCH-family model selected by the convenience functions.
Values:
-
enumerator garch
GARCH(1,1) with a zero mean.
-
enumerator egarch
EGARCH(1,1).
-
enumerator gjr_garch
GJR-GARCH(1,1) with an asymmetric shock term.
-
enumerator garch
-
enum class fincore::gpd_estimation_method
Estimation method for a generalized Pareto fit.
Values:
-
enumerator mle
Maximum-likelihood fit of the GPD.
-
enumerator pwm
Probability-weighted-moment fit using L-moments.
-
enumerator mle
-
enum class fincore::risk_backtest_method
Risk measure exercised by a backtest.
Values:
-
enumerator var
Value-at-risk exception backtest.
-
enumerator es
Expected-shortfall backtest.
-
enumerator var
-
enum class fincore::risk_backtest_status
Classification of a VaR or ES backtest.
Values:
-
enumerator pass
Coverage tests do not reject the model and the sample is adequate.
-
enumerator fail
A coverage test rejects the model and the sample is adequate.
-
enumerator inconclusive
Fewer than three paired observations or fewer than five expected exceptions; the sample is too small to test.
-
enumerator experimental
Experimental backtest; used by the ES bootstrap path.
-
enumerator pass
-
enum class fincore::risk_distribution
Distribution labels for walk-forward VaR.
Values:
-
enumerator historical
Empirical distribution using the Weibull quantile.
-
enumerator normal
Normal distribution using the mean and sample deviation.
-
enumerator historical
-
enum class fincore::risk_estimate_status
Completion status of a risk estimate.
Values:
-
enumerator ok
At least two non-NaN observations were available and any GARCH fit converged.
-
enumerator insufficient_data
Fewer than two non-NaN observations were available.
-
enumerator failed
The GARCH fit did not converge or failed its stationarity checks.
-
enumerator ok
-
enum class fincore::risk_forecast_method
Risk-estimation method used by
forecast_varandforecast_es.Values:
-
enumerator historical
Historical quantile and tail-mean estimate.
-
enumerator evt
Extreme-value estimate using the configured EVT kernel.
-
enumerator garch
GARCH-family conditional estimate.
-
enumerator historical
-
enum class fincore::risk_forecast_target
Target risk measure produced by a forecast.
Values:
-
enumerator var
Value at risk.
-
enumerator es
Expected shortfall.
-
enumerator pair
Pair target label for cross-component metadata.
-
enumerator var
-
enum class fincore::risk_tail
Tail of the return distribution used by a risk model.
Values:
-
enumerator lower
Lower (loss) tail.
-
enumerator upper
Upper (gain) tail.
-
enumerator lower
-
enum class fincore::walk_forward_status
Completion status of a walk-forward VaR run.
Values:
-
enumerator ok
Forecast path and backtest were produced.
-
enumerator insufficient_data
Fewer observations than one full window plus one.
-
enumerator unsupported
The specification combination is not supported.
-
enumerator ok
-
risk_backtest_result fincore::backtest_es(const dataframe &forecast, const dataframe &realized, double confidence_level = 0.975, std::size_t n_bootstrap = 1000U, std::uint64_t seed = 20260817U, std::string_view forecast_column = "forecast", std::string_view realized_column = "realized")
Runs an experimental bootstrap expected-shortfall backtest.
The realized tail contains realized values strictly below the linear
1 - confidence_levelquantile; realized ES is the tail mean and forecast ES the aligned forecast mean. A seeded bootstrap of the tail supplies the standard deviation of resampled tail means used in the reported z-score. The status is alwaysexperimental, and the Kupiec and Christoffersen fields are neutral (0 and 1).- Parameters:
forecast – Frame containing ES forecasts.
realized – Frame containing realized returns.
confidence_level – Confidence level in (0, 1).
n_bootstrap – Number of bootstrap resamples of the realized tail.
seed – Seed for the native
std::mt19937_64bootstrap.forecast_column – Forecast column name.
realized_column – Realized column name.
- Throws:
input_error – If
confidence_levelis not in (0, 1); a column is missing, not a double column, or contains an embedded NUL; or the frames share no timestamps.- Returns:
ES backtest diagnostics, digest and
experimentalstatus.
-
risk_backtest_result fincore::backtest_var(const dataframe &forecast, const dataframe &realized, double confidence_level = 0.99, double significance = 0.05, std::string_view forecast_column = "forecast", std::string_view realized_column = "realized")
Runs a VaR exception backtest on aligned forecast and realized series.
Both frames are aligned on their common timestamps, and pairs with a NaN forecast or realized value are dropped. An exception is a realized value strictly below the forecast. The result is
inconclusivewhen there are fewer than three paired observations or fewer than five expected exceptions; otherwise it isfailwhen either coverage p-value is belowsignificanceandpassotherwise.- Parameters:
forecast – Frame containing VaR forecasts.
realized – Frame containing realized returns.
confidence_level – Confidence level in (0, 1).
significance – P-value threshold for rejecting coverage or independence.
forecast_column – Forecast column name.
realized_column – Realized column name.
- Throws:
input_error – If
confidence_levelis not in (0, 1); a column is missing, not a double column, or contains an embedded NUL; or the frames share no timestamps.- Returns:
Backtest statistics, diagnostics, digest and status.
-
std::string fincore::basel_traffic_light(std::size_t exceptions, std::size_t observations, double confidence_level = 0.99)
Classifies an exception count into a Basel traffic-light zone.
Zones are determined from binomial quantiles at 95% (green/yellow boundary) and 99.99% (yellow/red boundary) for the expected exception probability. Returns
greenwhenobservationsis zero.- Parameters:
exceptions – Observed exception count.
observations – Number of observations.
confidence_level – Model confidence level in (0, 1).
- Throws:
input_error – If
observationsis non-zero andconfidence_levelis not finite in (0, 1).- Returns:
green,yellow, orred.
-
risk_validation_report fincore::build_risk_validation_report(const walk_forward_var_result &result, std::optional<std::string> timestamp_index_name = std::nullopt)
Builds a validation report from a walk-forward VaR result.
The result is revalidated before projection: the forecast, realized and index lengths must agree, refit timestamps must follow the specification cadence, fit parameters must reproduce their forecast segments, the digest must be lowercase SHA-256 hex, and the backtest must match a recomputation over the path. The report owns copies of all projected fields.
- Parameters:
result – Walk-forward result to project.
timestamp_index_name – Optional index label copied into the report.
- Throws:
input_error – If the result violates the validation contract.
- Returns:
Validation report with specification echo, events, refits, diagnostics, optional backtest and traffic-light zone.
-
double fincore::christoffersen_lr(std::span<const int> exceptions)
Returns the Christoffersen independence likelihood-ratio statistic.
Flags are treated as binary; non-zero entries count as exceptions. Returns zero when fewer than two flags are supplied.
- Parameters:
exceptions – Exception flags in chronological order.
- Returns:
Independence likelihood-ratio statistic.
-
garch_conditional_estimate fincore::conditional_es(const dataframe &returns, garch_model model, double alpha = 0.05, std::size_t horizon = 1U, std::string_view column = returns_column)
Computes a conditional normal expected shortfall from a GARCH-family variance forecast.
The fit is performed by
forecast_volatility; the value is-sqrt(sum(forecast variances)) * pdf(z(alpha)) / alphaover the requested horizon.- Parameters:
returns – Frame containing decimal simple returns.
model – GARCH family to fit.
alpha – Tail probability in (0, 1); values outside yield NaN.
horizon – Number of variance steps; must be at least 1.
column – Column holding the return series.
- Throws:
input_error – If
horizonis zero or the selected fit rejects its input.- Returns:
Signed expected-shortfall estimate, the variance forecast path and the fit convergence flag.
-
garch_conditional_estimate fincore::conditional_var(const dataframe &returns, garch_model model, double alpha = 0.05, std::size_t horizon = 1U, std::string_view column = returns_column)
Computes a conditional normal VaR from a GARCH-family variance forecast.
The fit is performed by
forecast_volatility; the value isz(alpha) * sqrt(sum(forecast variances))over the requested horizon.- Parameters:
returns – Frame containing decimal simple returns.
model – GARCH family to fit.
alpha – Tail probability in (0, 1); values outside yield NaN.
horizon – Number of variance steps; must be at least 1.
column – Column holding the return series.
- Throws:
input_error – If
horizonis zero or the selected fit rejects its input.- Returns:
Signed VaR estimate, the variance forecast path and the fit convergence flag.
-
double fincore::es_calibration_score(double forecast_es, std::span<const double> realized, double confidence_level)
Returns the relative realized-versus-forecast expected-shortfall score.
Realized ES is the mean of realized values at or below the linear
1 - confidence_levelquantile, and is zero when that tail is empty. The score is(realized_es - forecast_es) / abs(forecast_es).- Parameters:
forecast_es – Forecast expected shortfall.
realized – Realized return observations.
confidence_level – Confidence level used to select the realized tail.
- Returns:
Relative calibration score, or NaN when
abs(forecast_es)is below 1e-15.
-
double fincore::evt_cvar(const dataframe &data, double alpha = 0.05, evt_model model = evt_model::gpd, evt_tail tail = evt_tail::lower, std::optional<double> threshold = std::nullopt, std::optional<std::size_t> block_size = std::nullopt, std::string_view column = returns_column)
Estimates the conditional tail expectation with an extreme-value model.
Uses the same fitting and threshold policy as
evt_var, then reports the mean of the tail beyond VaR (CVaR/ES). The estimate is signed bytailand lies further into the selected tail than the corresponding VaR.- Parameters:
data – Frame containing the return series.
alpha – Tail probability in (0, 1).
model – EVT model.
tail – Tail to estimate.
threshold – Positive GPD magnitude threshold; empty selects the automatic threshold.
block_size – GEV block size in observations; empty selects the automatic block size.
column – Column holding decimal simple returns.
- Throws:
input_error – If
alphais not finite in (0, 1), a GPD threshold leaves an exceedance probability belowalpha, a fit is not finite,xiis at least 1 (infinite CVaR), or the column is missing or contains an embedded NUL.- Returns:
Signed CVaR estimate.
-
double fincore::evt_var(const dataframe &data, double alpha = 0.05, evt_model model = evt_model::gpd, evt_tail tail = evt_tail::lower, std::optional<double> threshold = std::nullopt, std::optional<std::size_t> block_size = std::nullopt, std::string_view column = returns_column)
Estimates the value at risk with an extreme-value model.
alphais the tail probability, not the confidence level: for example0.05targets the 95% tail. The GPD path fits a peaks-over-threshold model; whenthresholdis empty, a threshold is chosen to leave enough strict exceedances to coveralpha, starting from the 90th percentile of the selected tail. The GEV path uses block maxima and ignoresthreshold. The result is signed bytail, so lower-tail estimates are negative.- Parameters:
data – Frame containing the return series.
alpha – Tail probability in (0, 1).
model – EVT model.
tail – Tail to estimate.
threshold – Positive GPD magnitude threshold; empty selects the automatic threshold.
block_size – GEV block size in observations; empty selects the automatic block size.
column – Column holding decimal simple returns.
- Throws:
input_error – If
alphais not finite in (0, 1), a GPD threshold leaves an exceedance probability belowalpha, a fit or VaR is not finite, or the column is missing or contains an embedded NUL.- Returns:
Signed VaR estimate.
-
double fincore::expected_exception_count(std::size_t observations, double confidence_level)
Returns the expected number of VaR exceptions.
The expected count is
observations * (1 - confidence_level).- Parameters:
observations – Number of observations.
confidence_level – Model confidence level.
- Returns:
Expected exception count.
-
extreme_risk_result fincore::extreme_risk(const dataframe &returns, double alpha = 0.05, evt_tail tail = evt_tail::lower, evt_model model = evt_model::gpd, std::optional<double> threshold = std::nullopt, std::optional<std::size_t> block_size = std::nullopt, std::string_view column = returns_column)
Estimates VaR, CVaR and fitted tail parameters with an extreme-value model.
Runs the same fit and threshold policy as
evt_varandevt_cvarand returns both estimates. For GPD,thresholdandn_exceedancesdescribe the fit and the location, scale and block fields are empty. For GEV, the location, scale and block fields are set, whilethresholdis NaN andn_exceedancesis zero.- Parameters:
returns – Frame containing the return series.
alpha – Tail probability in (0, 1).
tail – Tail to estimate.
model – EVT model.
threshold – Positive GPD magnitude threshold; ignored for GEV.
block_size – GEV block size in observations; empty selects the automatic block size.
column – Column holding decimal simple returns.
- Throws:
input_error – If
alphais not finite in (0, 1), a fit is not finite,xiis at least 1 (infinite CVaR), or the column is missing or contains an embedded NUL.- Returns:
Signed VaR and CVaR with fitted tail parameters.
-
egarch_result fincore::fit_egarch(const dataframe &returns, std::string_view column = returns_column)
Fits an EGARCH(1,1) model by Gaussian maximum likelihood.
NaN observations are dropped; at least ten non-NaN observations with finite values and positive variance are required. The fit uses multi-start Nelder-Mead optimization.
- Parameters:
returns – Frame containing decimal simple returns.
column – Column holding the return series.
- Throws:
input_error – If fewer than ten non-NaN observations remain, a non-finite value remains, the series has zero variance, or the column is missing or contains an embedded NUL.
- Returns:
Fitted parameters, conditional variances, residuals, likelihood and convergence flag.
-
garch11_result fincore::fit_garch11(const dataframe &returns, bool constant_mean = false, std::string_view column = returns_column)
Fits a GARCH(1,1) model by Gaussian maximum likelihood.
NaN observations are dropped; at least eleven non-NaN observations with finite values and positive variance are required. A zero mean is imposed unless
constant_meanis true.- Parameters:
returns – Frame containing decimal simple returns.
constant_mean – Estimate a constant mean instead of fixing it at zero.
column – Column holding the return series.
- Throws:
input_error – If fewer than eleven non-NaN observations remain, a non-finite value remains, the series has zero variance, or the column is missing or contains an embedded NUL.
- Returns:
Fitted parameters, conditional variances, residuals, likelihood and convergence flag. A failed convergence is reported through
converged, not by throwing.
-
gjr_garch_result fincore::fit_gjr_garch(const dataframe &returns, std::string_view column = returns_column)
Fits a GJR-GARCH(1,1) model by Gaussian maximum likelihood.
NaN observations are dropped; at least ten non-NaN observations with finite values and positive variance are required. The fit uses multi-start Nelder-Mead optimization.
- Parameters:
returns – Frame containing decimal simple returns.
column – Column holding the return series.
- Throws:
input_error – If fewer than ten non-NaN observations remain, a non-finite value remains, the series has zero variance, or the column is missing or contains an embedded NUL.
- Returns:
Fitted parameters, conditional variances, residuals, likelihood and convergence flag.
-
std::vector<double> fincore::forecast_egarch(const egarch_result &result, std::size_t horizon = 1U)
Forecasts the conditional variance path of an EGARCH(1,1) fit.
The first step uses the last log-variance and standardized residual; later steps use a constant drift and the fitted
betapersistence. A result without conditional variances yields a path of NaNs.- Parameters:
result – Fitted EGARCH(1,1) result.
horizon – Number of variance steps; must be at least 1.
- Throws:
input_error – If
horizonis zero.- Returns:
Variance forecasts in return units squared, one per step.
-
risk_estimate fincore::forecast_es(const dataframe &returns, const risk_forecast_config &config = {}, std::string_view column = returns_column)
Estimates the expected shortfall of a return series.
NaN observations are dropped before estimation, and the index must be strictly ascending and duplicate-free. Historical and EVT methods return a single point estimate and do not use
config.horizon; the GARCH method composes the conditional variance forecast over the configured horizon.- Parameters:
returns – Return series with ascending, duplicate-free timestamps.
config – Estimation method, confidence level and method settings.
column – Column holding decimal simple returns.
- Throws:
input_error – If the configuration is invalid; the column is missing, not a double column, or contains an embedded NUL; the index is duplicated or unsorted; no non-NaN observation remains; or the selected EVT or GARCH kernel rejects the data.
- Returns:
Point expected-shortfall estimate, diagnostics, digest and status. The estimate is negative for losses under the
losses_negativeconvention.
-
std::vector<double> fincore::forecast_garch11(const garch11_result &result, std::size_t horizon = 1U)
Forecasts the conditional variance path of a GARCH(1,1) fit.
The first step uses the last conditional variance and residual; later steps use the fitted persistence
alpha + beta. A result without conditional variances yields a path of NaNs.- Parameters:
result – Fitted GARCH(1,1) result.
horizon – Number of variance steps; must be at least 1.
- Throws:
input_error – If
horizonis zero.- Returns:
Variance forecasts in return units squared, one per step.
-
std::vector<double> fincore::forecast_gjr_garch(const gjr_garch_result &result, std::size_t horizon = 1U)
Forecasts the conditional variance path of a GJR-GARCH(1,1) fit.
The first step uses the last conditional variance and signed residual; later steps use the fitted persistence
alpha + 0.5 * gamma + beta. A result without conditional variances yields a path of NaNs.- Parameters:
result – Fitted GJR-GARCH(1,1) result.
horizon – Number of variance steps; must be at least 1.
- Throws:
input_error – If
horizonis zero.- Returns:
Variance forecasts in return units squared, one per step.
-
risk_estimate fincore::forecast_var(const dataframe &returns, const risk_forecast_config &config = {}, std::string_view column = returns_column)
Estimates the value at risk of a return series.
NaN observations are dropped before estimation, and the index must be strictly ascending and duplicate-free. Historical and EVT methods return a single point estimate and do not use
config.horizon; the GARCH method composes the conditional variance forecast over the configured horizon.- Parameters:
returns – Return series with ascending, duplicate-free timestamps.
config – Estimation method, confidence level and method settings.
column – Column holding decimal simple returns.
- Throws:
input_error – If the configuration is invalid; the column is missing, not a double column, or contains an embedded NUL; the index is duplicated or unsorted; no non-NaN observation remains; or the selected EVT or GARCH kernel rejects the data.
- Returns:
Point VaR estimate, diagnostics, digest and status. The estimate is negative for losses under the
losses_negativeconvention.
-
garch_forecast_result fincore::forecast_volatility(const dataframe &returns, garch_model model, std::size_t horizon = 1U, std::string_view column = returns_column)
Fits a GARCH-family model and forecasts its variance path.
- Parameters:
returns – Frame containing decimal simple returns.
model – GARCH family to fit.
horizon – Number of variance steps; must be at least 1.
column – Column holding the return series.
- Throws:
input_error – If
horizonis zero or the selected fit rejects its input.- Returns:
Variance forecasts with the fitted likelihood and convergence flag.
-
double fincore::garch11_log_likelihood(std::span<const double> eps, double omega, double alpha, double beta)
Returns the Gaussian GARCH(1,1) log-likelihood for fixed parameters.
The first conditional variance is the population variance of
epsand the likelihood sums over the remaining observations, so the first observation is a one-step burn-in.- Parameters:
eps – Zero-mean return shocks.
omega – Variance intercept.
alpha – ARCH coefficient.
beta – GARCH coefficient.
- Returns:
Log-likelihood; NaN when fewer than two shocks are supplied, or negative infinity when a conditional variance is not positive and finite.
-
gev_parameters fincore::gev_fit(const dataframe &data, std::optional<std::size_t> block_size = std::nullopt, evt_tail tail = evt_tail::lower, std::string_view column = returns_column)
Fits a generalized extreme-value distribution to block extremes.
NaN values are dropped; each complete block contributes its maximum for
upperor the negated minimum forlower, so the fitted location and scale are in tail-magnitude units. The default block size is the integer square root of the remaining observation count.- Parameters:
data – Frame containing the return series.
block_size – Positive number of consecutive observations per block; empty selects
floor(sqrt(n)).tail – Tail whose block extremes are fitted.
column – Column holding decimal simple returns.
- Throws:
input_error – If no observation remains,
block_sizeis zero or leaves no complete block, the block extremes have no positive finite variation, the fit does not reach a finite likelihood, a fitted parameter is non-finite or the scale is not positive, or the column is missing or contains an embedded NUL.- Returns:
Fitted shape, location, scale and block count.
-
gpd_parameters fincore::gpd_fit(const dataframe &data, std::optional<double> threshold = std::nullopt, gpd_estimation_method method = gpd_estimation_method::mle, evt_tail tail = evt_tail::lower, std::string_view column = returns_column)
Fits a generalized Pareto distribution to tail exceedances.
Magnitudes are reflected losses for
lowerand gains forupper; the default threshold is the 90th linear percentile of those magnitudes. At least ten strict exceedances are required. The maximum-likelihood path reproduces the pinned source objective and bounds, which can drivexito its upper bound. The PWM path uses L-moment formulas.- Parameters:
data – Frame containing the return series.
threshold – Positive magnitude threshold; empty selects the 90th percentile of the tail magnitudes.
method – Estimation method.
tail – Tail to fit.
column – Column holding decimal simple returns.
- Throws:
input_error – If the selected tail has no observations, the threshold is not finite and positive, fewer than ten exceedances remain, a PWM moment is invalid, or the column is missing or contains an embedded NUL.
- Returns:
Fitted shape, scale, threshold and exceedance count.
-
hill_estimate fincore::hill_estimator(const dataframe &data, std::optional<double> threshold = std::nullopt, evt_tail tail = evt_tail::upper, std::string_view column = returns_column)
Estimates the Hill tail index from the selected tail magnitudes.
Magnitudes are reflected losses for
lowerand gains forupper; the default threshold is the 90th linear percentile of those magnitudes. Only strict exceedances are used, and at least ten are required.- Parameters:
data – Frame containing the return series.
threshold – Positive magnitude threshold; empty selects the 90th percentile of the tail magnitudes.
tail – Tail to estimate.
column – Column holding decimal simple returns.
- Throws:
input_error – If the threshold is not finite and positive, fewer than ten exceedances remain, or the column is missing or contains an embedded NUL.
- Returns:
Hill tail index and the strict exceedances used.
-
double fincore::kupiec_lr(std::size_t observations, std::size_t exceptions, double confidence_level)
Returns the Kupiec proportion-of-failures likelihood-ratio statistic.
The expected exception probability is
1 - confidence_level. The statistic is clamped at zero and is zero whenobservationsis zero.- Parameters:
observations – Number of backtest observations.
exceptions – Number of observed exceptions.
confidence_level – Model confidence level; the expected exception probability is 1 - confidence_level.
- Returns:
Non-negative likelihood-ratio statistic.
-
std::string_view fincore::risk_backtest_status_name(risk_backtest_status status)
Returns the lowercase name of a backtest status.
- Parameters:
status – Backtest status.
- Returns:
pass,fail,inconclusive, orexperimental.
-
std::string_view fincore::risk_forecast_target_name(risk_forecast_target target)
Returns the lowercase name of a forecast target.
- Parameters:
target – Forecast target.
- Returns:
var,es, orpair.
-
std::string_view fincore::risk_tail_name(risk_tail tail)
Returns the lowercase name of a distribution tail.
- Parameters:
tail – Distribution tail.
- Returns:
lowerorupper.
-
void fincore::validate_risk_model_spec(const risk_model_spec &spec)
Validates a model specification against the supported contract.
- Parameters:
spec – Specification to validate.
- Throws:
input_error – If
confidence_levelis not finite in (0, 1),horizonis below 1,distributionis nothistoricalornormal,sign_conventionis notlosses_negative,windowis below 2,refit_cadenceis below 1, ormodel_versionis not1.0.
-
std::string_view fincore::walk_forward_status_name(walk_forward_status status)
Returns the lowercase name of a walk-forward status.
- Parameters:
status – Walk-forward status.
- Returns:
ok,insufficient_data, orunsupported.
-
walk_forward_var_result fincore::walk_forward_var(const dataframe &returns, const risk_model_spec &spec, std::string_view column = returns_column)
Runs a rolling-window walk-forward VaR backtest.
The first forecast is produced for the observation after the initial
spec.window; refits occur at that point and everyspec.refit_cadencesteps, each using exactly the preceding window. Normal forecasts use the mean plus the sample deviation times the normal quantile, falling back to the mean on zero deviation; historical forecasts use the type-6 (Weibull) quantile. The resulting path is backtested at a 0.05 significance level. A path requiresforecast_target='var',tail='lower',sign_convention='losses_negative'andhorizon=1; a horizon above 1, another target, tail or sign convention, or a historical rank(window + 1) * (1 - confidence_level)outside[1, window]up to floating-point tolerance returnsunsupportedwith a reason.- Parameters:
returns – Return series with strictly increasing, duplicate-free timestamps and finite values.
spec – Model specification.
column – Column holding decimal simple returns.
- Throws:
input_error – If the specification is invalid, the index is not strictly increasing, a value is not finite, or the column is missing or contains an embedded NUL.
- Returns:
Forecast path, refit parameters, backtest and status. Unsupported and insufficient-data results carry an empty path and a reason.
-
constexpr std::string_view fincore::losses_negative_sign_convention = "losses_negative"
Sign-convention label stating that losses are negative returns.
-
constexpr int fincore::risk_validation_report_schema_version = 1
Schema version emitted by risk validation reports.