MCPcopy
hub / github.com/jasonstrimpel/volatility-trading / cones

Method cones

volatility/volest.py:143–248  ·  view source on GitHub ↗

Plots volatility cones Parameters ---------- windows : [int, int, ...] List of rolling windows for which to calculate the estimator cones quantiles : [lower, upper] List of lower and upper quantiles for which to plot the cones

(self, windows=[30, 60, 90, 120], quantiles=[0.25, 0.75])

Source from the content-addressed store, hash-verified

141 )
142
143 def cones(self, windows=[30, 60, 90, 120], quantiles=[0.25, 0.75]):
144 """Plots volatility cones
145
146 Parameters
147 ----------
148 windows : [int, int, ...]
149 List of rolling windows for which to calculate the estimator cones
150 quantiles : [lower, upper]
151 List of lower and upper quantiles for which to plot the cones
152 """
153
154 price_data = self._price_data
155
156 if len(windows) < 2:
157 raise ValueError(
158 'Two or more window periods required')
159 if len(quantiles) != 2:
160 raise ValueError(
161 'A two element list of quantiles is required, lower and upper')
162 if quantiles[0] + quantiles[1] != 1.0:
163 raise ValueError(
164 'The sum of the quantiles must equal 1.0')
165 if quantiles[0] > quantiles[1]:
166 raise ValueError(
167 'The lower quantiles (first element) must be less than the upper quantile (second element)')
168
169 max_ = []
170 min_ = []
171 top_q = []
172 median = []
173 bottom_q = []
174 realized = []
175 data = []
176
177 for window in windows:
178
179 estimator = self._get_estimator(
180 window=window,
181 price_data=price_data
182 )
183
184 max_.append(estimator.max())
185 top_q.append(estimator.quantile(quantiles[1]))
186 median.append(estimator.median())
187 bottom_q.append(estimator.quantile(quantiles[0]))
188 min_.append(estimator.min())
189 realized.append(estimator[-1])
190
191 data.append(estimator)
192
193 if self._estimator is "Skew" or self._estimator is "Kurtosis":
194 f = lambda x: "%i" % round(x, 0)
195 else:
196 f = lambda x: "%i%%" % round(x*100, 0)
197
198 # figure
199 fig = plt.figure(figsize=(8, 6))
200 fig.autofmt_xdate()

Callers 1

term_sheetMethod · 0.95

Calls 1

_get_estimatorMethod · 0.95

Tested by

no test coverage detected