Home   >   User Resources   >   Online Help   >   apaBonds.Simulate.Factors
 

 

Function index Version 3.0.0

apaBonds.Simulate.Factors(nScenarios, HorizonYears, FactorVols, FactorCorrels, StressProbability, StressVolMultiplier, StressMeanShifts, StressFactorCorrels, nIssuers, IssuerVol, Seed)

Excel=apaBonds.Simulate.Factors(nScenarios, HorizonYears, FactorVols, FactorCorrels, StressProbability, StressVolMultiplier, StressMeanShifts, StressFactorCorrels, nIssuers, IssuerVol, Seed)

Result

Simulates scenarios of the common risk factors that drive bond total returns over a horizon: a parallel change of interest rates, a change of the slope of the yield curve, a market-wide change of credit spreads, a stress regime flag and, optionally, one spread shock per issuer. The result is a nScenarios x (4 + nIssuers) matrix. Its columns are, in this order: level change L, slope change K, market spread change M, stress flag F (1 = stress scenario, 0 = normal scenario) and the issuer spread shocks u(1) to u(nIssuers). The factor scenarios are the input of apaBonds.TotalReturns.FromFactors, which turns them into bond total returns; apaBonds.Simulate.TotalReturns does both steps in one call. The function is non-volatile: with the same inputs and seed it always returns the same scenarios.

Syntax

nScenarios: number of scenarios (rows of the result)

HorizonYears: horizon in years, e.g. 1/12 for monthly returns; all volatilities are scaled by the square root of HorizonYears

FactorVols: 3 annualized volatilities in decimals (0.01 = 100 basis points) of the level, slope and market spread factor, as a row or column

FactorCorrels: optional 3 x 3 correlation matrix of level, slope and market spread changes in normal scenarios; default: identity matrix (uncorrelated factors)

StressProbability: optional probability in [0, 1] that a scenario is a stress scenario; default: 0 (no stress regime)

StressVolMultiplier: optional factor by which all factor and issuer volatilities are multiplied in stress scenarios; default: 1

StressMeanShifts: optional 3 mean shifts of level, slope and market spread in stress scenarios, as decimal changes over the horizon (not annualized, not scaled), e.g. -0.0015, 0.0005, 0.0015; default: 0, 0, 0

StressFactorCorrels: optional 3 x 3 correlation matrix of the three factors in stress scenarios; default: FactorCorrels

nIssuers: optional number of issuer spread shock columns appended to the result; must be at least the number of distinct issuers used in apaBonds.TotalReturns.FromFactors; default: 0 (no issuer shocks)

IssuerVol: optional annualized volatility in decimals of the issuer spread shocks; default: 0

Seed: optional integer seed of the random number generator; default: 1

Algorithm

The function simulates a small factor model of the yield curve and of credit spreads. The idea is that the returns of a bond portfolio over a short horizon are driven by a few common movements: rates go up or down for all maturities (level), long rates move differently from short rates (slope), and credit spreads widen or tighten for all issuers together (market spread). On top of these come issuer-specific spread movements. The function only simulates these factors; apaBonds.TotalReturns.FromFactors then translates them into the returns of each individual bond via its duration, convexity and credit sensitivity.

Scenarios are independent and equally likely. For each scenario s, the function first decides whether the scenario is a stress scenario. With U(s) a uniform random number in (0, 1) and p the StressProbability:

Fs={1ifUs<p0otherwiseF_{s} = \left\{ \begin{matrix} 1 & \text{if}\quad U_{s} < p \\ 0 & \text{otherwise} \end{matrix} \right.\

Then three independent standard normal numbers ε(s) are drawn and correlated with the lower Cholesky factor Λ of the correlation matrix of the regime, i.e. FactorCorrels in normal scenarios and StressFactorCorrels in stress scenarios:

zs=ΛFsεs,ΛFsΛFs⊤=CorrFs,εs∼N(0,I3)z_{s} = \Lambda_{F_{s}}\,\varepsilon_{s},\quad\quad\Lambda_{F_{s}}\Lambda_{F_{s}}^{\top} = {Corr}_{F_{s}},\quad\quad\varepsilon_{s} \sim N(0,I_{3})

The three common factors X = (L, K, M) are the correlated normals scaled to the horizon, multiplied by m (the StressVolMultiplier) in stress scenarios and shifted by the stress mean shifts δ in stress scenarios:

Xs,j=σjhmFszs,j+Fsδj,j∈{L,K,M}X_{s,j} = \sigma_{j}\sqrt{h}\mspace{6mu} m^{F_{s}}\, z_{s,j} + F_{s}\,\delta_{j},\quad\quad j \in \{ L,K,M\}

With σ(j) the annualized FactorVols, h the HorizonYears and δ(j) the StressMeanShifts. The issuer spread shocks are independent normals with the issuer volatility σ(I), also scaled up by m in stress:

us,k=σIhmFsηs,k,ηs,k∼N(0,1),k=1,…,nIssuersu_{s,k} = \sigma_{I}\sqrt{h}\mspace{6mu} m^{F_{s}}\,\eta_{s,k},\quad\quad\eta_{s,k} \sim N(0,1),\quad\quad k = 1,\ldots,n_{Issuers}

Interpretation of the factors (all values are decimal yield changes over the horizon, e.g. 0.001 = +10 basis points):

Level L: parallel shift of the risk-free yield curve. A positive L means higher rates and therefore losses on all bonds, proportional to their duration.

Slope K: change of the steepness of the curve. In apaBonds.TotalReturns.FromFactors a bond with duration D experiences the rate change L + K x (D - D0) / D0, where D0 is the pivot duration. A positive K steepens the curve: bonds longer than the pivot see rates rise by more than L, shorter bonds by less. Bonds at the pivot are not affected by K.

Market spread M: common change of credit spreads. Each bond responds with the beta of its credit bucket (e.g. 0.3 for AAA, 1 for A, 3 for BB), so a market spread widening of 10 basis points widens BB spreads by 30 basis points in that example. This captures the empirical fact that spreads of lower-rated bonds move by a multiple of those of high-grade bonds.

Stress flag F: identifies the regime of the scenario. It is returned so that results can be analyzed by regime (e.g. average returns in stress scenarios) It is not used by apaBonds.TotalReturns.FromFactors, because the stress effects are already contained in L, K, M and u.

Issuer shocks u: spread movements specific to one issuer, shared by all bonds of that issuer. They generate concentration risk, which is why issuer limits matter in the optimization.

Why a stress regime: with StressProbability = 0 all factors are jointly normal, and portfolio returns are close to normal. Real bond returns have fat tails and a negative skew, driven by episodes in which volatility jumps, spreads widen sharply and correlations change. The stress regime makes the scenario distribution a mixture of two normal distributions: most scenarios come from the calm regime, a fraction p from a regime with higher volatility (StressVolMultiplier), a shifted mean (StressMeanShifts) and different correlations (StressFactorCorrels). A typical "flight to quality" stress has a negative level shift (government yields fall), a positive spread shift (credit spreads widen) and a more negative correlation between level and spread. As a result, high-grade, long-duration bonds can gain in stress while lower-rated bonds lose, which is exactly the diversification effect that a tail risk measure such as CVaR rewards.

Calibration: the volatilities are annualized and scaled by the square root of the horizon. An annualized level volatility of 0.015 (150 basis points) corresponds to a monthly standard deviation of 0.015 x √(1/12) ≈ 0.0043 (43 basis points). The stress mean shifts, by contrast, are changes over the horizon and are not scaled. Note that the stress mean shifts also shift the unconditional mean of the factors: with p = 10% and a spread shift of 0.0015 per month, the average spread change is 0.1 x 0.0015 = 0.00015 per month, which reduces the average return of a bond with spread duration 6 by about 0.1% per month. Keep the shifts moderate or compensate the carry accordingly if average returns should stay close to the yields.

Random numbers: the function uses its own random number generator (xoshiro256** seeded via SplitMix64 from Seed, normal numbers via Box-Muller), so results are reproducible, independent of other calculations and thread-safe. For every scenario the random numbers are drawn in a fixed order: one uniform number, three normal numbers for the factors and nIssuers normal numbers for the issuers. The draws therefore do not depend on the parameter values: if you change e.g. StressVolMultiplier, the same random numbers are used and only the effect of the parameter change is visible (common random numbers). Changing nScenarios keeps the first scenarios unchanged; changing nIssuers changes the sequence and therefore all scenarios.

Remarks

Example: =apaBonds.Simulate.Factors(600, 1/12, {0.015, 0.008, 0.006}, CorrNormal, 0.1, 2, {-0.0015, 0.0005, 0.0015}, CorrStress, 15, 0.004, 145) returns 600 monthly scenarios in a 600 x 19 range: level, slope, spread, stress flag and 15 issuer shocks. The example workbook ApaLibExample_BondTotalReturnSimulation.xlsx shows the complete process from factors to the mean-CVaR efficient frontier.

Correlation matrices must be symmetric, have ones on the diagonal and be positive definite. The output is a fixed-size array: enter the formula as an array formula over nScenarios rows and 4 + nIssuers columns.

Check of a simulation: in the normal scenarios (F = 0) the standard deviation of L divided by √h should be close to the level volatility, and the share of scenarios with F = 1 close to StressProbability; the deviations shrink with the number of scenarios.