Skip to content

Commit 346b72f

Browse files
add warning re:par yield composition (#181)
1 parent 767357f commit 346b72f

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

docs/src/models.md

+27-4
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ julia> rate(r)
7070
7171
```
7272

73-
#### Arithmetic
74-
75-
Adding, subtracting, multiplying, dividing, and comparing rates is supported.
76-
7773
### Available Models - Yields
7874

7975
- [`FinanceModels.Yield.Constant`](@ref)
@@ -82,6 +78,10 @@ Adding, subtracting, multiplying, dividing, and comparing rates is supported.
8278
- [`FinanceModels.Yield.NelsonSiegel`](@ref)
8379
- [`FinanceModels.Yield.NelsonSiegelSvensson`](@ref)
8480

81+
#### Arithmetic
82+
83+
Adding, subtracting, multiplying, dividing, and comparing rates is supported.
84+
8585
Yield models can also be composed. Here is an example of fitting rates and spread separately and then adding the two models together:
8686

8787
```julia-repl
@@ -106,6 +106,29 @@ julia> discount(0.04,3)
106106
0.8889963586709148
107107
```
108108

109+
!!! warning "Caution with Spreads"
110+
111+
It is fairly common to see spreads and rates provided separately where both are quoted in par convention. For example, US Treasury par rates with the associated par risk spreads. Because par rates are dependent on the amount and path of rates preceeding the given tenor, **it is not valid to construct a "spread curve" with par rates and then use it in composition with a "rate curve"**.
112+
113+
That is, while the zero rates and spreads in the preceeding example allow for additive or subtractive composition, it is not the case for par rates and spreads. Note the different discount factors produced:
114+
115+
```julia
116+
q_rate = ParYield([0.01,0.02,0.03]);
117+
q_spread = ParYield([0.01,0.01,0.01]);
118+
q_yield = ParYield([0.02,0.03,0.04]);
119+
120+
m_rate = fit(Spline.Linear(),q_rate,Fit.Bootstrap());
121+
m_spread = fit(Spline.Linear(),q_spread,Fit.Bootstrap());
122+
m_yield = fit(Spline.Linear(),q_yield,Fit.Bootstrap());
123+
124+
# The curves are different!
125+
discount(m_spread + m_rate,3)
126+
# 0.8889963586709149
127+
128+
discount(m_yield,3)
129+
# 0.8864366955434709
130+
```
131+
109132
### Creating New Yield Models
110133

111134
See the [FinanceModels.jl Guide](@ref) for an example of creating a model from scratch. Some additional aspects to note:

test/CompositeYield.jl

+12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@
1717

1818
@test discount(yield, 1.0) 1 / (1 + riskfree[2] + spread[2])^1
1919
@test discount(yield, 1.5) 1 / (1 + riskfree[3] + spread[3])^1.5
20+
21+
rates = ZCBYield([0.01, 0.02, 0.03])
22+
spreads = ZCBYield([0.02, 0.03, 0.04])
23+
yields = ZCBYield([0.03, 0.05, 0.07])
24+
25+
r = fit(Spline.Linear(), rates, Fit.Bootstrap())
26+
s = fit(Spline.Linear(), spreads, Fit.Bootstrap())
27+
y = fit(Spline.Linear(), yields, Fit.Bootstrap())
28+
29+
@test discount(r + s, 1) discount(y, 1)
30+
@test discount(r + s, 2) discount(y, 2)
31+
@test discount(r + s, 3) discount(y, 3)
2032
end
2133

2234
@testset "multiplicaiton and division" begin

0 commit comments

Comments
 (0)