4
4
import pdesolvers .pdes .black_scholes as bse
5
5
import pdesolvers .solvers .black_scholes_solvers as solver
6
6
import pdesolvers .utils .utility as utility
7
+ import pdesolvers .enums .option_type as enum
8
+
9
+ class TestBlackScholesEquation :
10
+
11
+ def test_check_invalid_option_type_input (self ):
12
+ with pytest .raises (TypeError , match = "Option type must be of type OptionType enum" ):
13
+ self .equation = bse .BlackScholesEquation ('woo' , 300 , 1 , 0.2 , 0.05 , 100 , 100 , 2000 )
7
14
8
15
class TestBlackScholesSolvers :
9
16
10
17
def setup_method (self ):
11
- self .equation = bse .BlackScholesEquation ('call' , 300 , 1 , 0.2 , 0.05 , 100 , 100 , 2000 )
18
+ self .equation = bse .BlackScholesEquation (enum . OptionType . EUROPEAN_CALL , 300 , 1 , 0.2 , 0.05 , 100 , 100 , 2000 )
12
19
13
20
# explicit method tests
14
21
@@ -26,7 +33,7 @@ def test_check_terminal_condition_for_call_explicit(self):
26
33
assert np .array_equal (result [:, - 1 ], expected_payoff )
27
34
28
35
def test_check_terminal_condition_for_put_explicit (self ):
29
- self .equation .option_type = 'put'
36
+ self .equation .option_type = enum . OptionType . EUROPEAN_PUT
30
37
result = solver .BlackScholesExplicitSolver (self .equation ).solve ().get_result ()
31
38
32
39
test_asset_grid = self .equation .generate_grid (self .equation .S_max , self .equation .s_nodes )
@@ -36,7 +43,7 @@ def test_check_terminal_condition_for_put_explicit(self):
36
43
assert np .array_equal (result [:,- 1 ], expected_payoff )
37
44
38
45
def test_check_valid_option_type (self ):
39
- self .equation .option_type = 'woo'
46
+ self .equation .option_type = "INVALID"
40
47
41
48
with pytest .raises (ValueError , match = "Invalid option type - please choose between call/put" ):
42
49
solver .BlackScholesExplicitSolver (self .equation ).solve ().get_result ()
@@ -57,7 +64,7 @@ def test_check_terminal_condition_for_call_cn(self):
57
64
assert np .array_equal (result [:, - 1 ], expected_payoff )
58
65
59
66
def test_check_terminal_condition_for_put_cn (self ):
60
- self .equation .option_type = 'put'
67
+ self .equation .option_type = enum . OptionType . EUROPEAN_PUT
61
68
result = solver .BlackScholesCNSolver (self .equation ).solve ().get_result ()
62
69
63
70
test_asset_grid = self .equation .generate_grid (self .equation .S_max , self .equation .s_nodes )
0 commit comments