Coverage for src/dummypy/payoffs.py: 100%

6 statements  

« prev     ^ index     » next       coverage.py v7.14.3, created at 2026-06-29 05:53 +0000

1"""Payoff functions for vanilla European option contracts.""" 

2 

3import numpy as np 

4import numpy.typing as npt 

5 

6 

7def call_payoff(spot: npt.ArrayLike, strike: float) -> npt.NDArray[np.float64]: 

8 """Return the expiry payoff of a European call option. 

9 

10 Args: 

11 spot: Underlying spot price(s) at expiry. Scalars and array-likes 

12 are both accepted. 

13 strike: Strike price of the option. 

14 

15 Returns: 

16 Element-wise payoff ``max(spot - strike, 0)`` as a float array. 

17 """ 

18 return np.maximum(np.asarray(spot, dtype=np.float64) - strike, 0.0) 

19 

20 

21def put_payoff(spot: npt.ArrayLike, strike: float) -> npt.NDArray[np.float64]: 

22 """Return the expiry payoff of a European put option. 

23 

24 Args: 

25 spot: Underlying spot price(s) at expiry. Scalars and array-likes 

26 are both accepted. 

27 strike: Strike price of the option. 

28 

29 Returns: 

30 Element-wise payoff ``max(strike - spot, 0)`` as a float array. 

31 """ 

32 return np.maximum(strike - np.asarray(spot, dtype=np.float64), 0.0)