diff options
Diffstat (limited to 'python/analytics')
| -rw-r--r-- | python/analytics/option.py | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/python/analytics/option.py b/python/analytics/option.py index 8c84b61e..fbd88d4d 100644 --- a/python/analytics/option.py +++ b/python/analytics/option.py @@ -44,18 +44,32 @@ def memoize(f): return v return cached_f -def ATMstrike(index, exercise_date): - exercise_date_settle = (pd.Timestamp(exercise_date) + 3* BDay()).date() - fp = index.forward_pv(exercise_date) / index.notional - closure = lambda S: g(index, S, exercise_date) - fp - eta = 1.1 - a = index.spread - b = index.spread * eta - while True: - if closure(b) > 0: - break - b *= eta - return brentq(closure, a, b) +def ATMstrike(index, exercise_date, price=False): + """computes the at-the-money strike. + + Parameters + ---------- + index : + Index object + exercise_date : datetime.date + expiration date. + price : bool, defaults to False + If price is true return a strike price, returns a spread otherwise. + """ + fi = ForwardIndex(index, exercise_date, price) + fp = fi.forward_pv + if price: + return 100 * (1 - fp) + else: + closure = lambda S: g(index, S, exercise_date) - fp + eta = 1.1 + a = index.spread + b = index.spread * eta + while True: + if closure(b) > 0: + break + b *= eta + return brentq(closure, a, b) class Swaption(ForwardIndex): """Swaption class""" |
