1
1
use approx:: assert_abs_diff_eq;
2
2
use quantrs:: options:: {
3
- AmericanOption , AsianOption , BinaryOption , BinomialTreeModel , Black76Model , BlackScholesModel ,
4
- EuropeanOption , Greeks , Instrument , LookbackOption , MonteCarloModel , Option , OptionGreeks ,
5
- OptionPricing , OptionType , RainbowOption ,
3
+ AmericanOption , AsianOption , BermudanOption , BinaryOption , BinomialTreeModel , Black76Model ,
4
+ BlackScholesModel , EuropeanOption , Greeks , Instrument , LookbackOption , MonteCarloModel , Option ,
5
+ OptionGreeks , OptionPricing , OptionType , RainbowOption ,
6
6
} ;
7
7
8
8
struct MockModel { }
@@ -26,6 +26,7 @@ fn assert_implements_option_trait<T: Option>(option: &T) {
26
26
option. clone ( ) . set_time_to_maturity ( 1.0 ) ;
27
27
option. strike ( ) ;
28
28
option. time_to_maturity ( ) ;
29
+ option. expiration_dates ( ) ;
29
30
option. option_type ( ) ;
30
31
option. style ( ) ;
31
32
option. flip ( ) ;
@@ -786,6 +787,32 @@ mod binomial_tree_tests {
786
787
}
787
788
}
788
789
790
+ mod bermudan_option_tests {
791
+ use super :: * ;
792
+
793
+ #[ test]
794
+ fn test_itm ( ) {
795
+ let instrument = Instrument :: new ( ) . with_spot ( 52.0 ) ;
796
+ let expiration_dates = vec ! [ 0.0 , 1.0 , 2.0 ] ;
797
+ let option = BermudanOption :: new ( instrument, 50.0 , expiration_dates, OptionType :: Call ) ;
798
+ let model = BinomialTreeModel :: new ( 0.05 , 0.182321557 , 2 ) ;
799
+
800
+ assert_abs_diff_eq ! ( model. price( & option) , 8.8258 , epsilon = 0.0001 ) ;
801
+ assert_abs_diff_eq ! ( model. price( & option. flip( ) ) , 2.5722 , epsilon = 0.0001 ) ;
802
+ }
803
+
804
+ #[ test]
805
+ fn test_otm ( ) {
806
+ let instrument = Instrument :: new ( ) . with_spot ( 50.0 ) ;
807
+ let expiration_dates = vec ! [ 0.0 , 1.0 , 2.0 ] ;
808
+ let option = BermudanOption :: new ( instrument, 60.0 , expiration_dates, OptionType :: Call ) ;
809
+ let model = BinomialTreeModel :: new ( 0.05 , 0.182321557 , 2 ) ;
810
+
811
+ assert_abs_diff_eq ! ( model. price( & option) , 10.0000 , epsilon = 0.0001 ) ;
812
+ assert_abs_diff_eq ! ( model. price( & option. flip( ) ) , 10.0000 , epsilon = 0.0001 ) ;
813
+ }
814
+ }
815
+
789
816
mod rainbow_option_tests {
790
817
use super :: * ;
791
818
@@ -1908,6 +1935,20 @@ mod option_trait_tests {
1908
1935
OptionType :: Put ,
1909
1936
) ;
1910
1937
assert_implements_option_trait ( & opt) ;
1938
+ let opt = BermudanOption :: new (
1939
+ Instrument :: new ( ) . with_spot ( 100.0 ) ,
1940
+ 100.0 ,
1941
+ vec ! [ 1.0 ] ,
1942
+ OptionType :: Call ,
1943
+ ) ;
1944
+ assert_implements_option_trait ( & opt) ;
1945
+ let opt = BermudanOption :: new (
1946
+ Instrument :: new ( ) . with_spot ( 100.0 ) ,
1947
+ 100.0 ,
1948
+ vec ! [ 1.0 ] ,
1949
+ OptionType :: Put ,
1950
+ ) ;
1951
+ assert_implements_option_trait ( & opt) ;
1911
1952
let opt = AsianOption :: fixed (
1912
1953
Instrument :: new ( ) . with_spot ( 100.0 ) ,
1913
1954
100.0 ,
0 commit comments