apaBonds.TotalReturns.FromFactors(Factors, HorizonYears, Yields, Durations, Convexities, CreditBuckets, BucketBetas, Issuers, SpreadDurations, IdioVols, PDs, LGDs, SlopePivotDuration, Seed)
=apaBonds.TotalReturns.FromFactors(Factors, HorizonYears, Yields, Durations, Convexities, CreditBuckets, BucketBetas, Issuers, SpreadDurations, IdioVols, PDs, LGDs, SlopePivotDuration, Seed)Result
Calculates the total returns of a set of bonds over the horizon for each factor scenario produced by apaBonds.Simulate.Factors. The result is a nScenarios x nBonds matrix of simple total returns in decimals (0.01 = +1%), one row per scenario and one column per bond, which can be used directly as scenario input of the mean-CVaR, mean-CDaR or other scenario-based optimization functions. Each return is the sum of carry, the price effect of the rate change, the price effect of the spread change and a convexity adjustment; optionally, idiosyncratic spread noise and issuer defaults are added.
Syntax
Factors: nScenarios x (4 + nIssuers) output of apaBonds.Simulate.Factors (level, slope, market spread, stress flag, issuer shocks); a matrix with only 4 columns means no issuer shocks
HorizonYears: horizon in years; must be the horizon used to simulate the factors
Yields: nBonds annual yields to maturity in decimals, as a row or column
Durations: nBonds modified durations, as a row or column
Convexities: nBonds convexities (as used in ΔP/P ≈ -D Δy + ½ C Δy²), or one value for all bonds
CreditBuckets: nBonds credit bucket labels (e.g. AAA, A, BB) which are looked up in BucketBetas; alternatively nBonds numeric spread betas if BucketBetas is omitted
BucketBetas: optional two-column table with the bucket label in the first and the beta to the market spread factor in the second column (a two-row table is accepted as well); labels are compared case-insensitively and without leading or trailing blanks; omit if CreditBuckets contains the betas
Issuers: optional nBonds issuer labels; bonds with the same label share the issuer spread shock and default together; issuers are numbered in the order of their first appearance, i.e. the first distinct issuer uses the first issuer column of Factors; default: every bond is its own issuer
SpreadDurations: optional nBonds spread durations, or one value for all bonds; default: Durations
IdioVols: optional nBonds annualized volatilities in decimals of bond-specific spread noise, or one value for all bonds; default: 0
PDs: optional nBonds annual default probabilities in [0, 1], or one value for all bonds; default: 0 (no defaults)
LGDs: optional nBonds losses given default in [0, 1], or one value for all bonds; default: 0.6
SlopePivotDuration: optional duration D0 at which the slope factor has no effect; default: average of Durations
Seed: optional integer seed for the idiosyncratic noise and the default draws; default: 2, which together with seed 1 for the factors reproduces apaBonds.Simulate.TotalReturns with its default seed
Algorithm
The function reprices every bond i in every scenario s with a second-order (duration and convexity) approximation of the bond price. Over a short horizon, the total return of a bond consists of the income it earns (carry) and the price change caused by the change of its yield. The yield of a corporate bond is the risk-free rate plus the credit spread, so its yield change is the sum of a rate change Δr and a spread change Δc.
Step 1, rate change: the risk-free rate change of bond i is the level change plus the slope change weighted by the distance of the bond duration D(i) from the pivot duration D0:
A bond with duration 2D0 sees the rate change L + K, a bond at the pivot sees L, a bond with a very short duration about L - K. Duration is used as a proxy for the maturity bucket of the bond on the curve.
Step 2, spread change: the credit spread change of bond i combines the market spread factor scaled by the beta β of its credit bucket, the shock of its issuer k(i) and bond-specific noise:
With β(b(i)) from BucketBetas, u(s, k(i)) from the issuer columns of Factors (0 if Factors has only 4 columns) and σ(e, i) the annualized IdioVols. The market component makes all credit bonds move together, the issuer component makes bonds of the same issuer move together, and the noise term captures everything specific to one bond (liquidity, technicals).
Step 3, total return: the return over the horizon is the carry, minus duration times the rate change, minus spread duration times the spread change, plus the convexity adjustment on the total yield change:
With y(i) the yield, h the horizon in years, D(i) the duration, SD(i) the spread duration and C(i) the convexity. The carry y x h is the return the bond earns if neither rates nor spreads change; it is the deterministic part of the return and the main source of differences in expected returns between bonds. The duration terms are the first-order price sensitivities: a bond with duration 6 loses about 6% if its yield rises by 1 percentage point. The convexity term is always positive and makes the price-yield relationship curved: large yield moves in either direction are slightly better for the bondholder than the linear approximation suggests, which matters in stress scenarios with large moves.
Step 4, defaults (only if PDs are not 0): each issuer k defaults in a scenario if a uniform random number V(s, k) drawn for that issuer falls below the default probability over the horizon, which is derived from the annual probability PD(i):
Because the uniform number belongs to the issuer, all bonds of an issuer default in the same scenario (with different PDs per bond, a bond with a higher PD defaults whenever a bond of the same issuer with a lower PD defaults). The return of a defaulted bond is -LGD, i.e. the investor recovers 1 - LGD of the bond value and earns no carry. Defaults are independent across issuers; they create rare, large losses and are therefore relevant for CVaR, but they require many scenarios to be represented reliably: with an annual PD of 1% and monthly scenarios, a single issuer defaults in only about one of 1200 scenarios.
Putting it together, the variance of a bond return in normal scenarios is driven by its exposures to the common factors. Ignoring convexity, for a bond at the pivot duration (D = D0, so the slope factor drops out) with correlation ρ between level and market spread:
This formula helps to calibrate the volatilities to observed return volatilities of bond indices by duration and rating, and it shows the main diversification lever: with a negative correlation between rates and spreads (spreads widen when rates fall), rate and spread risk partially offset each other, the more so the higher the spread beta of the bond.
Random numbers: the noise and default draws use a generator seeded with Seed (see apaBonds.Simulate.Factors). For each scenario, the function first draws one uniform number per issuer and then one normal number per bond, regardless of whether PDs and IdioVols are 0, so changing these parameters does not change the other random numbers.
Remarks
Example: with factors in Factors!B2:T601 and the bond data in columns of sheet Bonds, =apaBonds.TotalReturns.FromFactors(Factors!B2:T601, 1/12, Bonds!G2:G31, Bonds!E2:E31, Bonds!F2:F31, Bonds!C2:C31, Parameters!A22:B24, Bonds!B2:B31, Bonds!H2:H31, Bonds!I2:I31, Bonds!K2:K31, Bonds!L2:L31, , 146) returns 600 x 30 monthly total return scenarios (see ApaLibExample_BondTotalReturnSimulation.xlsx).
Separating factor simulation and repricing has three advantages: the factor scenarios can be inspected and analyzed (e.g. returns by regime via the stress flag), the same factors can be applied to different bond universes so that their scenarios are consistent, and factor scenarios from other sources (historical factor changes, hand-made stress scenarios, other simulation models) can be used. Any matrix with the same column layout is accepted, for example historical monthly changes of a government yield, a curve slope and a credit spread index, with the stress flag column set to 0.
Check: with all factors equal to 0 and no noise or defaults, every bond return equals its carry y x h.
Limitations: the duration-convexity approximation is accurate for short horizons and moderate yield changes. The model ignores roll-down along the curve, changes of duration over the horizon, embedded options (callable bonds), currency effects and the term structure of spreads. Defaulted bonds return -LGD without carry. Scenarios are equally likely.
