diff options
| author | Shivesh Mandalia <shivesh.mandalia@outlook.com> | 2020-03-21 17:30:06 +0000 |
|---|---|---|
| committer | Shivesh Mandalia <shivesh.mandalia@outlook.com> | 2020-03-21 17:30:06 +0000 |
| commit | c5df1cb77e6e40f701ecf002687d7b3932b28d8f (patch) | |
| tree | 03535770c6510eb22230049403daf6a41c5cc392 /utils/misc.py | |
| download | MCOptionPricing-c5df1cb77e6e40f701ecf002687d7b3932b28d8f.tar.gz MCOptionPricing-c5df1cb77e6e40f701ecf002687d7b3932b28d8f.zip | |
Initial Commit
Diffstat (limited to 'utils/misc.py')
| -rw-r--r-- | utils/misc.py | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/utils/misc.py b/utils/misc.py new file mode 100644 index 0000000..708d759 --- /dev/null +++ b/utils/misc.py @@ -0,0 +1,65 @@ +# author : S. Mandalia +# shivesh.mandalia@outlook.com +# +# date : March 19, 2020 + +""" +Miscellaneous utility methods. +""" + + +__all__ = ['is_num', 'is_pos'] + + +def is_num(val: (int, float)) -> bool: + """ + Check if the input value is a non-infinite number. + + Parameters + ---------- + val : Value to check. + + Returns + ---------- + is_num : Whether it is a non-infinite number. + + Examples + ---------- + >>> from utils.misc import is_num + >>> print(is_num(10)) + True + >>> print(is_num(None)) + False + + """ + if not isinstance(val, (int, float)): + return False + return True + + +def is_pos(val: (int, float)) -> bool: + """ + Check if the input value is a non-infinite positive number. + + Parameters + ---------- + val : Value to check. + + Returns + ---------- + is_pos : Whether it is a non-infinite positive number. + + Examples + ---------- + >>> from utils.misc import is_pos + >>> print(is_pos(10)) + True + >>> print(is_pos(-10)) + False + + """ + if not is_num(val): + return False + if not val >= 0: + return False + return True |
