TradingView
taylor_o
2021년 8월 10일 오전 3시 41분

pricing_table 

KC HRW Wheat FuturesCBOT

설명

This script helps you evaluate the fair value of an option. It poses the question "if I bought or sold an option under these circumstances in the past, would it have expired in the money, or worthless? What would be its expected value, at expiration, if I opened a position at N standard deviations, given the volatility forecast, with M days to expiration at the close of every previous trading day?"

The default (and only) "hv" volatility forecast is based on the assumption that today's volatility will hold for the next M days.

To use this script, only one step is mandatory. You must first select days to expiration. The script will not do anything until this value is changed from the default (-1). These should be CALENDAR days. The script will convert to these to business days for forecasting and valuation, as trading in most contracts occurs over ~250 business days per year.

Adjust any other variables as desired:

model: the volatility forecasting model
window: the number of periods for a lagged model (e.g. hv)
filter: a filter to remove forecasts from the sample
filter type: "none" (do not use the filter), "less than" (keep forecasts when filter < volatility), "greater than" (keep forecasts when filter > volatility)
filter value: a whole number percentage. see example below
discount rate: to discount the expected value to present value
precision: number of decimals in output
trim outliers: omit upper N % of (generally itm) contracts

The theoretical values are based on history. For example, suppose days to expiration is 30. On every bar, the 30 days ago N deviation forecast value is compared to the present price. If the price is above the forecast value, the contract has expired in the money; otherwise, it has expired worthless. The theoretical value is the average of every such sample. The itm probabilities are calculated the same way.

The default (and only) volatility model is a 20 period EWMA derived historical (realized) volatility. Feel free to extend the script by adding your own.

The filter parameters can be used to remove some forecasts from the sample.

Example A:

filter: <any>
filter type: none
filter value: <any>

Default: the filter is not used; all forecasts are included in the the sample.

Example B:

filter: model
filter type: less than
filter value: 50

If the model is "hv", this will remove all forecasts when the historical volatility is greater than fifty.

Example C:

filter: rank
filter type: greater than
filter value: 75

If the model volatility is in the top 25% of the previous year's range, the forecast will be included in the sample apart from "model" there are some common volatility indexes to choose from, such as Nasdaq (VXN), crude oil (OVX), emerging markets (VXFXI), S&P (VIX) etc.

Refer to the middle-right table to see the current forecast value, its rank among the last 252 days, and the number of business days until
expiration.

NOTE: This script is meant for the daily chart only.

릴리즈 노트

added the straddle (0 stdev)

릴리즈 노트

puts (bottom right) and calls (top right) are now displayed simultaneously.

릴리즈 노트

added an input for trimming the top n% of outliers. this can be handy for some contracts like crude oil puts that have had very extreme moves.

릴리즈 노트

fixed the outlier trimming. now both itm and theo vals should reflect trimming the top N% of calls or puts from the sample.

릴리즈 노트

fixed math in puts

릴리즈 노트

made tables visually symmetrical

릴리즈 노트

- added itm total column
- added current volatility (model and value) to a table in the center right
- added a filter

The first two are essential for the new filter feature. The filter removes data points from the sample. For example, if set to "less than" and "0.4" (as in the sample chart), the sample will exclude all forecasts made when volatility exceeded 40%. In this natural gas example, the historical volatility model is over 40% a good deal of the time, so the sample is reduced from about ~7,500 to ~1,500, making the theoretical values are quite different.

릴리즈 노트

- fixed historical vol annualization

릴리즈 노트

Added a number of revisions to the filter feature. See the comment diff for a full explanation.

릴리즈 노트

forgot to add "rank" to the list of options... corrected

릴리즈 노트

fixed another bug with percentrank

릴리즈 노트

the forecast lines now reach to the proper expiration day

릴리즈 노트

- annualized with 252 periods per year by default
- some other defaults changed

릴리즈 노트

- Fixed a fairly serious error: using the present to filter out trades. Now the filter will eliminate trades when volatility was greater than (or less than) the forecast value at time the trade was made--not at the present.

Previously, the results reflected a situation in the trader would go back in time and cancel their trade when volatility rose. This is an example of look-ahead bias.

릴리즈 노트

Changed the default filter value to something more reasonable for many popular assets (20 is near the VIX median). Filter settings of

- Filter: model
- Filter type: greater than
- Filter value: 20

Means: only count trades taken when the model's current value was greater than 20. If the model is VIX, this might be a common value for equity option short volatility traders.

릴리즈 노트

The valuation and forecasting now use business days to expiration, rather than calendar days to expiration, for more accurate results. Note that you should still enter CALENDAR days into the "dte" input. The script converts them to business days for you. Holidays are not accounted for, unfortunately.

릴리즈 노트

- replaced some erroneous references to calendar dte with business dte.
- removed tnx (which was 10 year yield, not a volatility index... unfortunately, the real 10 year note volatility index, TYVIX, is not updated anymore)

릴리즈 노트

- removed TNX from input options

(also, forgot to mention that I changed "window" default to 20, as it is used with HV. HV20 is similar to IV30, as there are about 20 trading days in a calendar month).

릴리즈 노트

- number of standard deviations to display can now be set using the "range" parameters
- parameters grouped together
코멘트
parkyinoz
Nice, would be great if you could disable some values , e.g. so we can just see 1 & 2 standard deviations
taylor_o
@parkyinoz thanks for the suggestion. i have updated the script--check out the "range" parameters.
parkyinoz
@voided, that's awesome, thanks for doing that
lucfig
Hi, thanks for the gread script.
Any chance of making a similar one that, instead of a table, plots lines for the strikes dinamically, like boolinger bands. So we can test past strategies.
Best regards.
더보기