volvisdata 1.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- volvisdata/__init__.py +1 -0
- volvisdata/graph_data.py +515 -0
- volvisdata/market_data.py +501 -0
- volvisdata/market_data_prep.py +857 -0
- volvisdata/utils.py +119 -0
- volvisdata/vol_methods.py +916 -0
- volvisdata/volatility.py +547 -0
- volvisdata/volatility_params.py +139 -0
- volvisdata-1.0.1.dist-info/LICENSE +21 -0
- volvisdata-1.0.1.dist-info/METADATA +36 -0
- volvisdata-1.0.1.dist-info/RECORD +13 -0
- volvisdata-1.0.1.dist-info/WHEEL +5 -0
- volvisdata-1.0.1.dist-info/top_level.txt +1 -0
volvisdata/utils.py
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Utility functions for refreshing parameters and getting implied volatility
|
|
3
|
+
from prices
|
|
4
|
+
|
|
5
|
+
"""
|
|
6
|
+
import copy
|
|
7
|
+
import datetime as dt
|
|
8
|
+
from pandas.tseries.offsets import BDay
|
|
9
|
+
from volvisdata.volatility_params import vol_params_dict
|
|
10
|
+
from volvisdata.market_data_prep import DataPrep
|
|
11
|
+
# pylint: disable=invalid-name
|
|
12
|
+
|
|
13
|
+
class Utils():
|
|
14
|
+
"""
|
|
15
|
+
Utility functions for refreshing parameters
|
|
16
|
+
|
|
17
|
+
"""
|
|
18
|
+
@classmethod
|
|
19
|
+
def init_params(cls, inputs: dict) -> dict:
|
|
20
|
+
"""
|
|
21
|
+
Initialise parameter dictionary
|
|
22
|
+
Parameters
|
|
23
|
+
----------
|
|
24
|
+
inputs : Dict
|
|
25
|
+
Dictionary of parameters supplied to the function.
|
|
26
|
+
Returns
|
|
27
|
+
-------
|
|
28
|
+
params : Dict
|
|
29
|
+
Dictionary of parameters.
|
|
30
|
+
"""
|
|
31
|
+
# Copy the default parameters
|
|
32
|
+
params = copy.deepcopy(vol_params_dict)
|
|
33
|
+
|
|
34
|
+
# For all the supplied arguments
|
|
35
|
+
for key, value in inputs.items():
|
|
36
|
+
|
|
37
|
+
# Replace the default parameter with that provided
|
|
38
|
+
params[key] = value
|
|
39
|
+
|
|
40
|
+
if 'r' not in inputs.keys():
|
|
41
|
+
cls.set_interest_rate(params=params)
|
|
42
|
+
else:
|
|
43
|
+
cls.set_interest_rate(params=params, r=params['r'])
|
|
44
|
+
|
|
45
|
+
if 'q' not in inputs.keys():
|
|
46
|
+
cls.set_dividend_yield(params=params)
|
|
47
|
+
|
|
48
|
+
params = cls.set_start_date(params=params)
|
|
49
|
+
|
|
50
|
+
return params
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@staticmethod
|
|
54
|
+
def set_start_date(params: dict) -> dict:
|
|
55
|
+
"""
|
|
56
|
+
Set start date to previous working day if not provided
|
|
57
|
+
|
|
58
|
+
Parameters
|
|
59
|
+
----------
|
|
60
|
+
params : Dict
|
|
61
|
+
Dictionary of key parameters.
|
|
62
|
+
|
|
63
|
+
Returns
|
|
64
|
+
-------
|
|
65
|
+
params : Dict
|
|
66
|
+
Dictionary of key parameters.
|
|
67
|
+
|
|
68
|
+
"""
|
|
69
|
+
if params['start_date'] is None:
|
|
70
|
+
start_date_as_dt = (dt.datetime.today() - BDay(1)).date()
|
|
71
|
+
params['start_date'] = str(start_date_as_dt)
|
|
72
|
+
|
|
73
|
+
return params
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
@staticmethod
|
|
77
|
+
def set_interest_rate(
|
|
78
|
+
params: dict,
|
|
79
|
+
r: float | None = None) -> dict:
|
|
80
|
+
"""
|
|
81
|
+
Returns the yield curve interpolation function
|
|
82
|
+
|
|
83
|
+
Parameters
|
|
84
|
+
----------
|
|
85
|
+
params : Dict
|
|
86
|
+
Dictionary of key parameters.
|
|
87
|
+
r : Float, Optional
|
|
88
|
+
Interest Rate.
|
|
89
|
+
|
|
90
|
+
Returns
|
|
91
|
+
-------
|
|
92
|
+
params : Dict
|
|
93
|
+
Dictionary of key parameters.
|
|
94
|
+
|
|
95
|
+
"""
|
|
96
|
+
params['yield_curve'] = DataPrep.generate_yield_curve(r=r)
|
|
97
|
+
|
|
98
|
+
return params
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
@staticmethod
|
|
102
|
+
def set_dividend_yield(params: dict) -> dict:
|
|
103
|
+
"""
|
|
104
|
+
Returns the dividend yield
|
|
105
|
+
|
|
106
|
+
Parameters
|
|
107
|
+
----------
|
|
108
|
+
params : Dict
|
|
109
|
+
Dictionary of key parameters.
|
|
110
|
+
|
|
111
|
+
Returns
|
|
112
|
+
-------
|
|
113
|
+
params : Dict
|
|
114
|
+
Dictionary of key parameters.
|
|
115
|
+
|
|
116
|
+
"""
|
|
117
|
+
params['q'] = DataPrep.dividend_yield(params['ticker'])
|
|
118
|
+
|
|
119
|
+
return params
|