@@ -61,3 +61,57 @@ import Accessors: @optic
61
61
@test isapprox (ad_val, fd_val; rtol= 1e-5 )
62
62
end
63
63
end
64
+
65
+ using Test
66
+ using Hedgehog2
67
+ using Dates
68
+ using Accessors
69
+ import Accessors: @optic
70
+
71
+ @testset " Greeks Agreement Test" begin
72
+ strike = 1.0
73
+ expiry = Date (2020 , 1 , 2 )
74
+ reference_date = Date (2020 , 1 , 1 )
75
+ rate = 0.03
76
+ spot = 1.0
77
+ sigma = 1.0
78
+
79
+ underlying = Hedgehog2. Forward ()
80
+ payoff = VanillaOption (strike, expiry, European (), Put (), underlying)
81
+ market_inputs = BlackScholesInputs (reference_date, rate, spot, sigma)
82
+ pricing_prob = PricingProblem (payoff, market_inputs)
83
+ bs_method = BlackScholesAnalytic ()
84
+
85
+ vol_lens = @optic _. market. sigma
86
+ spot_lens = @optic _. market. spot
87
+
88
+ # Vega
89
+ gprob = GreekProblem (pricing_prob, vol_lens)
90
+ vega_ad = solve (gprob, ForwardAD (), bs_method). greek
91
+ vega_fd = solve (gprob, FiniteDifference (1e-4 ), bs_method). greek
92
+ vega_an = solve (gprob, AnalyticGreek (), bs_method). greek
93
+ @test isapprox (vega_ad, vega_fd; rtol= 1e-5 )
94
+ @test isapprox (vega_ad, vega_an; rtol= 1e-5 )
95
+
96
+ # Gamma
97
+ gammaprob = SecondOrderGreekProblem (pricing_prob, spot_lens, spot_lens)
98
+ gamma_ad = solve (gammaprob, ForwardAD (), bs_method). greek
99
+ gamma_fd = solve (gammaprob, FiniteDifference (1e-4 ), bs_method). greek
100
+ gamma_an = solve (gammaprob, AnalyticGreek (), bs_method). greek
101
+ @test isapprox (gamma_ad, gamma_fd; rtol= 1e-5 )
102
+ @test isapprox (gamma_ad, gamma_an; rtol= 1e-5 )
103
+
104
+ # Volga
105
+ volgaprob = SecondOrderGreekProblem (pricing_prob, vol_lens, vol_lens)
106
+ volga_ad = solve (volgaprob, ForwardAD (), bs_method). greek
107
+ volga_fd = solve (volgaprob, FiniteDifference (1e-4 ), bs_method). greek
108
+ volga_an = solve (volgaprob, AnalyticGreek (), bs_method). greek
109
+ @test isapprox (volga_ad, volga_fd; rtol= 1e-3 )
110
+ @test isapprox (volga_ad, volga_an; rtol= 1e-5 )
111
+
112
+ # Theta (no analytic yet)
113
+ thetaprob = GreekProblem (pricing_prob, @optic _. payoff. expiry)
114
+ theta_ad = solve (thetaprob, ForwardAD (), bs_method). greek
115
+ theta_fd = solve (thetaprob, FiniteDifference (1 ), bs_method). greek
116
+ @test isapprox (theta_ad, theta_fd; rtol= 1e-5 )
117
+ end
0 commit comments