@@ -129,6 +129,30 @@ def test_BsmNormNdMc(self):
129
129
p2 = np .array ([39.42304794 , 33.60383167 , 28.32667559 , 23.60383167 , 19.42304794 ])
130
130
np .testing .assert_almost_equal (p , p2 )
131
131
132
+ def test_BsmBasket1Bm (self ):
133
+ ### Check the BsmBasket1Bm price should be same as that of the Bsm price if sigma components are same.
134
+ for k in range (100 ):
135
+ n = np .random .randint (1 , 8 )
136
+ spot = np .random .uniform (80 , 120 , size = n )
137
+ strike = np .random .uniform (80 , 120 , size = 10 )
138
+ sigma = np .random .uniform (0.01 , 1 )* np .ones (n )
139
+ texp = np .random .uniform (0.1 , 10 )
140
+ intr = np .random .uniform (0 , 0.1 )
141
+ divr = np .random .uniform (0 , 0.1 )
142
+ weight = np .random .rand (n )
143
+ weight /= np .sum (weight )
144
+
145
+ cp = np .where (np .random .rand (10 ) > 0.5 , 1 , - 1 )
146
+ is_fwd = (np .random .rand () > 0.5 )
147
+
148
+ m = pf .BsmBasket1Bm (sigma , weight = weight , intr = intr , divr = divr , is_fwd = is_fwd )
149
+ p = m .price (strike , spot , texp , cp )
150
+
151
+ m2 = pf .Bsm (sigma [0 ], intr = intr , divr = divr , is_fwd = is_fwd )
152
+ p2 = m2 .price (strike , np .sum (spot * weight ), texp , cp )
153
+ np .testing .assert_almost_equal (p , p2 )
154
+
155
+
132
156
133
157
if __name__ == '__main__' :
134
158
print (f'Pyfeng loaded from { pf .__path__ } ' )
0 commit comments