-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathriskmanagement_test.go
40 lines (34 loc) · 1011 Bytes
/
riskmanagement_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package fixedincome_test
import (
"math"
"testing"
"time"
"github.com/konimarti/fixedincome"
"github.com/konimarti/fixedincome/pkg/instrument/bond"
"github.com/konimarti/fixedincome/pkg/maturity"
"github.com/konimarti/fixedincome/pkg/term"
)
func TestInterestSensitivity(t *testing.T) {
// define zero bond
bond := bond.Straight{
Schedule: maturity.Schedule{
Settlement: time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC),
Maturity: time.Date(2031, 1, 1, 0, 0, 0, 0, time.UTC),
Frequency: 1,
Basis: "30E360",
},
Coupon: 0.0,
Redemption: 100.0,
}
// define flat yield curve
ts := term.Flat{2.0, 0.0}
// calculate sensitivity
pvbp := fixedincome.PVBP(&bond, &ts)
// fmt.Println("duration=", bond.Duration(&ts))
// fmt.Println("convexity=", bond.Convexity(&ts))
ts2 := ts
pvbpRef := bond.PresentValue(ts2.SetSpread(1.0)) - bond.PresentValue(&ts)
if math.Abs(pvbp-pvbpRef) > 0.0001 {
t.Errorf("pvbp calculation failed; got: %v, expected: %v", pvbp, pvbpRef)
}
}