|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# |
| 3 | +# @Date : 2021/11/15 |
| 4 | +# @Author : sukai |
| 5 | + |
| 6 | +GREEKS = ['delta', 'gamma', 'theta', 'vega', 'rho'] |
| 7 | + |
| 8 | + |
| 9 | +class OptionFilter: |
| 10 | + def __init__(self, implied_volatility_min=None, implied_volatility_max=None, open_interest_min=None, |
| 11 | + open_interest_max=None, delta_min=None, delta_max=None, gamma_min=None, gamma_max=None, |
| 12 | + theta_min=None, theta_max=None, vega_min=None, vega_max=None, rho_min=None, rho_max=None, |
| 13 | + in_the_money=None): |
| 14 | + """ |
| 15 | + option filter |
| 16 | + :param implied_volatility_min: |
| 17 | + :param implied_volatility_max: |
| 18 | + :param open_interest_min: |
| 19 | + :param open_interest_max: |
| 20 | + :param delta_min: |
| 21 | + :param delta_max: |
| 22 | + :param gamma_min: |
| 23 | + :param gamma_max: |
| 24 | + :param theta_min: |
| 25 | + :param theta_max: |
| 26 | + :param vega_min: |
| 27 | + :param vega_max: |
| 28 | + :param rho_min: |
| 29 | + :param rho_max: |
| 30 | + :param in_the_money: |
| 31 | + """ |
| 32 | + self.implied_volatility_min = implied_volatility_min |
| 33 | + self.implied_volatility_max = implied_volatility_max |
| 34 | + self.open_interest_min = open_interest_min |
| 35 | + self.open_interest_max = open_interest_max |
| 36 | + self.delta_min = delta_min |
| 37 | + self.delta_max = delta_max |
| 38 | + self.gamma_min = gamma_min |
| 39 | + self.gamma_max = gamma_max |
| 40 | + self.theta_min = theta_min |
| 41 | + self.theta_max = theta_max |
| 42 | + self.vega_min = vega_min |
| 43 | + self.vega_max = vega_max |
| 44 | + self.rho_min = rho_min |
| 45 | + self.rho_max = rho_max |
| 46 | + self.in_the_money = in_the_money |
| 47 | + |
| 48 | + def to_dict(self): |
| 49 | + return {'greeks': self._get_greeks(), |
| 50 | + 'implied_volatility': self._min_max('implied_volatility'), |
| 51 | + 'open_interest': self._min_max('open_interest'), |
| 52 | + 'in_the_money': self.in_the_money} |
| 53 | + |
| 54 | + def _get_greeks(self): |
| 55 | + return {greek: self._min_max(greek) for greek in GREEKS} |
| 56 | + |
| 57 | + def _min_max(self, k): |
| 58 | + return {'min': getattr(self, k + '_min'), 'max': getattr(self, k + '_max')} |
0 commit comments