@@ -20,7 +20,7 @@ test_that("tradeCycle US Domestic",{
2020
2121test_that(" barrierSpreadOption Boundary Conditions" , {
2222 # Test setup
23- epsilon <- 1e-05
23+ epsilon <- 1e-10
2424 F1 <- - 12.00
2525 F2 <- - 5.00
2626 T2M <- epsilon
@@ -32,8 +32,8 @@ test_that("barrierSpreadOption Boundary Conditions", {
3232 results <- tidyr :: expand_grid( # Using expand_grid instead of expand.grid for tibble output
3333 f1 = seq(- 15 , - 8 , by = 0.1 ),
3434 F2 = F2 ,
35- monitoring = c(" continuous" , " discrete " , " terminal" ),
36- type = c(" call" )
35+ monitoring = c(" continuous" , " terminal" ),
36+ type = c(" call" , " put " )
3737 ) %> %
3838 dplyr :: mutate(
3939 spread = F2 - f1 ,
@@ -71,21 +71,26 @@ test_that("barrierSpreadOption Boundary Conditions", {
7171 expect_true(all_match ,
7272 label = " All prices should match intrinsic values at expiry" )
7373
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 )
7576 expect_true(
76- all(results $ price [ results $ spread > = results $ B ] == 0 ),
77+ all(dplyr :: near( zz $ price , zz $ intrisic , tol = epsilon ) ),
7778 label = " Prices should be zero above barrier for up-and-out options"
7879 )
7980
81+ # Down and out options should have zero prices above barrier
82+ zz = results %> % dplyr :: filter(barrier_type == " do" , spread < = B )
8083 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 "
8386 )
8487
88+ # All prices must be non-negative
8589 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 "
8892 )
93+
8994})
9095
9196
0 commit comments