@@ -20,7 +20,7 @@ test_that("tradeCycle US Domestic",{
20
20
21
21
test_that(" barrierSpreadOption Boundary Conditions" , {
22
22
# Test setup
23
- epsilon <- 1e-05
23
+ epsilon <- 1e-10
24
24
F1 <- - 12.00
25
25
F2 <- - 5.00
26
26
T2M <- epsilon
@@ -32,8 +32,8 @@ test_that("barrierSpreadOption Boundary Conditions", {
32
32
results <- tidyr :: expand_grid( # Using expand_grid instead of expand.grid for tibble output
33
33
f1 = seq(- 15 , - 8 , by = 0.1 ),
34
34
F2 = F2 ,
35
- monitoring = c(" continuous" , " discrete " , " terminal" ),
36
- type = c(" call" )
35
+ monitoring = c(" continuous" , " terminal" ),
36
+ type = c(" call" , " put " )
37
37
) %> %
38
38
dplyr :: mutate(
39
39
spread = F2 - f1 ,
@@ -71,21 +71,26 @@ test_that("barrierSpreadOption Boundary Conditions", {
71
71
expect_true(all_match ,
72
72
label = " All prices should match intrinsic values at expiry" )
73
73
74
- # Additional specific tests
74
+ # Up and out options should have zero prices above barrier
75
+ zz = results %> % dplyr :: filter(barrier_type == " uo" , spread > = B )
75
76
expect_true(
76
- all(results $ price [ results $ spread > = results $ B ] == 0 ),
77
+ all(dplyr :: near( zz $ price , zz $ intrisic , tol = epsilon ) ),
77
78
label = " Prices should be zero above barrier for up-and-out options"
78
79
)
79
80
81
+ # Down and out options should have zero prices above barrier
82
+ zz = results %> % dplyr :: filter(barrier_type == " do" , spread < = B )
80
83
expect_true(
81
- all(results $ price > = 0 ),
82
- label = " All prices should be non-negative "
84
+ all(dplyr :: near( zz $ price , zz $ intrisic , tol = epsilon ) ),
85
+ label = " Prices should be zero below barrier for dowm-and-out options "
83
86
)
84
87
88
+ # All prices must be non-negative
85
89
expect_true(
86
- all(results $ price [ results $ spread < = results $ X ] = = 0 ),
87
- label = " Prices should be zero below strike for call options "
90
+ all(results $ price > = 0 ),
91
+ label = " All prices should be non-negative "
88
92
)
93
+
89
94
})
90
95
91
96
0 commit comments