YURI Term Structure Engine

236
Dividing a near volatility index by a further dated one gives you one number that shows which of the two is priced higher today. On its own, that ratio tells you very little, because it usually gives the same answer and the exceptions rarely last. This engine keeps a ledger of what the ratio does not carry: every completed run of each state across the loaded history, how many days it lasted, and where the run you are looking at sits in that list.

HOW TO USE IT

Put it on a daily chart of a symbol that trades on US exchange days, such as a stock index or a large index fund. The chart's own price is not read; both volatility series are requested by the script, and the chart only supplies the calendar they are laid onto.

Read the status line first. There are two warmups and it names whichever is still short: by default, the ledger wants 20 completed runs of the current state, and the two percentiles want 1260 data days, which is five years.

Then read the table from the top down. Structure gives the ratio of the near index to the far one and the state cut from it: inverted at or above 1.00, steep at or below 0.90, flat between. This run says which state is open and what day of it this is. Against past runs is the reading the script exists for: that day count as a percentile of every finished run of the same state on this chart, with the number of runs behind it. Those past runs provides their median and their longest, so a run on its fifth day can be held against a median of four days and a longest of 110 without doing arithmetic off the chart.

In the pane, the thick purple line is that percentile. It climbs while a run lasts and drops when the state changes, so a sawtooth is the expected shape.

Near level and its percentile sit beside the structure for one reason: a high volatility index under a steep curve and a high one under an inverted curve are different situations. The shading between the two thin lines shows which of the two ranks is ahead.

To read a different pair, point Near series and Far series at two volatility indexes on the same market with different horizons.

WHY THE RATIO ALONE IS NOT ENOUGH

Measured on the default pair over 5076 daily bars from 2006-07-17 to 2026-09-18, with the state edges at 1.00 and 0.90, the ratio sat at or above 1.00 on 555 of them. Those days form 152 runs, of which 151 reach the ledger and hold 553 days between them; the one left out is the run that was already open when the history began, and it is dropped because the chart cannot see when it started. The median ledgered run lasted one day. Seventy two percent lasted two days or fewer. The longest lasted 63.

So "the ratio is above 1.00" and "the ratio has been above 1.00 for six days" are facts about very different events, and only the second needs a record kept. A line drawn at 1.00 separates the states, but it does not separate the one day run from the sixty three day one, and by the count above the one day run is the common case and the sixty three day run the exception.

Where the edge sits does not explain this. Moving it to 1.02 gives 93 runs, a median of one day and 69 percent lasting two days or fewer. At 1.05, 57 runs, a median of two days and 65 percent.

How a run is ended does explain part of it, and that part matters more, so it was measured too. A run ends here the moment the ratio crosses back over the edge, with nothing smoothing the crossing. Let a run survive one day on the wrong side of the edge and the same history gives 114 inverted runs with a median of two days and 54 percent lasting two days or fewer. At two days of slack, 97 runs, a median of three and 45 percent. At three days, 85 runs, a median of four and 41 percent. The steep side moves the same way: 273 runs at a median of 4 days with no slack, then 177 at 6, 134 at 8 and 115 at 12. Those counts include the run the ledger drops, which is why the first row reads one higher per state than the ledger sizes quoted above.

So the headline figures describe the market and the rule for cutting runs together, and the cutting rule accounts for more of them. The engine is left without smoothing, because any smoothing is a second choice made on your behalf; this paragraph reports its effect instead.

WHAT THE ENGINE KEEPS

Three states, cut by two edges you set. Inverted at or above the upper edge, steep at or below the lower one, flat between them. All three are ledgered, because a long quiet stretch is as much an event as a short loud one. A script that counted only the loud ones would be a stress detector presented as a neutral readout.

Every time the state changes, the run that just ended is pushed onto that state's own list with its length in days. The current run's age is then read as a percentile of that list, and the size of the list is printed beside the percentile, because a percentile means little without its sample size.

One list per state rather than one shared list, so the cap that limits the list's size applies per state. A shared list capped at one size would leave too few entries for the rarest state, the inverted one, which is usually the one people want to read.

Over the default window the three lists come out at 272 steep runs with a median of 4 days and a longest of 110, 417 flat runs with a median of 2 and a longest of 60, and 151 inverted runs with a median of 1 and a longest of 63.

THE OTHER TWO COORDINATES

Structure is where the ratio sits in its own trailing history, ranked as a percentile over the ranking window. Level is where the near series' own close sits in the same window, ranked the same way.

They are two separate measurements. Over 3816 ranked bars of the default pair they come out at a Spearman correlation of plus 0.67, which is a strong relationship and is a long way from identity. The distance between them is drawn as a shaded band, and it is wide: a median of minus 2 points, quartiles at minus 17 and plus 11, and a full range from minus 67 to plus 81. On 31 percent of ranked bars the two sit more than 25 points apart and on 5 percent more than 50.

A high level with an unremarkable structure, and a remarkable structure at an unremarkable level, are both ordinary on this pair. Late August 2020 is the widest case in one direction, the level ranked 81 points above the structure. February 2013 is the widest in the other, the structure ranked 67 points above the level.

WHY THE THREE GO TOGETHER

Each was measured to carry something the other two do not, on the same pair and window.

A run's age against the ratio printed on the same bar: Spearman minus 0.55 inside steep runs, plus 0.54 inside inverted ones, plus 0.12 inside flat ones. Against the near series' level rather than the ratio: minus 0.27, plus 0.57, plus 0.09. The largest of those in absolute terms is 0.57. The age is related to the ratio, as it should be, but it does not restate it.

Structure rank against level rank: plus 0.67, quoted above.

That is three coordinates whose pairwise absolute correlations all sit under 0.8 on this data, which is the bar set before any of them was drawn. One candidate did not clear it, and it is reported here. The extreme a run reaches, its highest ratio on the inverted side and its lowest on the steep side, tracks the run's own length at plus 0.72 across the 151 inverted runs and minus 0.89 across the 272 steep ones. The steep figure is past the line. So the extreme is printed in the table as a raw number for context and it is neither ranked against past runs nor drawn in the pane.

READING IT

The pane carries three series on a nought to one hundred scale. The thick purple line is the current run's age as a percentile of past runs of the same state. It climbs through a run and drops when the state changes, so a sawtooth is the expected shape. The two thin lines are the structure rank in orange and the level rank in grey, with the distance between them shaded: blue when the level is ranked above the structure, orange when the structure is ranked above the level. An exact tie is left uncoloured.

The pane is tinted by state: red for inverted, grey for flat, teal for steep.

The table carries the ratio with its state and its structure percentile, the near series' close with its level percentile, which run is open and what day of it this is, that day as a percentile of past runs with the number of those runs, the median and longest of them, the extreme this run has reached, which two series are being read, and a status line.

The data window carries the ratio, both closes, the run's extreme, the run's age in days, the number of completed runs behind it, the distance between the two ranks, and a count of bars the engine held a value over.

TIMING

Everything the engine holds is a function of daily closing values. The bar that is forming moves as it forms and settles when it closes. A bar that has closed is not rewritten afterwards, which was checked by recomputing the whole series on charts truncated at three different points, one of them six hundred bars back so that the ledger's own history was cut too, and finding the last bar of each identical to the corresponding bar of the full run to the last digit.

Both series are pulled with lookahead off. The ledger advances only on a bar where the requested series changes day, so a run gains a day when that bar first forms and not once per tick inside it.

CHARTS AND CALENDARS

It needs a standard chart, and this refusal is tested before every other one. A script that reads two other symbols is especially exposed here: the request that fetches them serves those symbols under the chart's own type, so on a Heikin Ashi, Renko, Kagi, Line Break, Point and Figure or Range chart neither close is the close the exchange printed. Both are constructed values, the ratio between them is a ratio of two constructed values, and the run lengths in the ledger would record how long that ratio stayed on one side of an edge it was on only in the drawing. Nothing else in the engine would object, since the timeframe is right, the two edges are in order, the pair resolves and the two bar times agree, so the status line would report a reading. That is why it is named first.

It needs a chart of one day a bar. A weekly chart, an intraday chart, a tick chart and a two, three or five day chart are refused by name. The multi-day case is named separately because such a chart is a daily chart as far as most tests are concerned.

On any refused chart every plotted series is empty, the pane tint and the shading are gone, every value cell reads as a dash, the row labels stay, and the status line is the only thing that reports a reading. The three reference lines at 0, 50 and 100 stay as well, because they take constants and carry no reading.

A chart can also carry more bars than the series has. On a symbol that trades seven days a week, a request for a daily CBOE series hands back the same Friday value on Saturday and Sunday, and a run counted in chart bars would come out half again as long as the run that happened. The engine counts days of the requested series rather than chart bars, which was checked by running the same history on a chart with a bar every calendar day: 5076 data days over 7369 chart bars, and a ledger identical to the one the matched chart produced, entry for entry. The status line announces the mismatch, since the percentile ranks are still measured over chart bars and a repeated value is a repeated value.

With two external series, the usual failure is not a missing value, though that is the obvious guess. When the requested series has no bar for the chart's bar, the platform hands back its previous value rather than nothing. So a close is rarely absent once a symbol resolves, and what goes wrong instead is silent: the near series prints today, the far one is still yesterday's, and the division computes normally but compares two different days.

The engine reads both series' own bar times for that reason only, reduces each to a calendar day, and reads nothing at all on a bar where the two disagree. On such a bar the ratio is blank, the state is blank, the run neither advances nor resets, the ranking source holds its last value rather than going empty, and the status line names the two symbols. The count of bars held that way is in the data window. On the default pair it is expected to read zero: both series are indices on one exchange calendar, so they have the same trading days and the test has nothing to catch. The test matters on a day one of them is late or a symbol is swapped for something that keeps a different calendar.

The test has a cost. A pair whose two sessions fall on opposite sides of a day boundary would be refused on every bar rather than read wrongly on every bar. That is deliberate: a refusal on every bar is easy to see, and a wrong reading is not.

WARMUP

There are two gates that open at different times, and the status line names whichever is still shut.

The percentiles want a full ranking window of data days behind them. At the default of 1260 the first ranked bar on the default pair is bar 1260, with 1261 data days behind it, and nothing is ranked before that.

The ledger wants its minimum number of completed runs of the state that is currently open. That gate opens far earlier, at bar 196 on the same chart, so on a short history the run reading arrives long before the percentiles do. It is also per state, which means it can shut again: a run of a rarer state can be cold long after a commoner one has warmed. Between bar 196 and bar 1260 that gate opens and shuts 41 times, and the status line follows it each time.

On the data this was built from, over the full window, the status reads ok on 3816 of 5076 bars, which is exactly the set where both halves are reading; the rest is warmup. A different data source will not give the same count, since it turns on which days each series has.

SETTINGS

Near series and far series. The defaults are a thirty day and a three month volatility index on the same underlying. Any two series can be put in, and the ratio is simply the first divided by the second, but the reading only means something if the two are the same measurement at two horizons.

The two edges. The upper one defaults to 1.00, which is parity, the point where the near series is priced at the far one; that is arithmetic rather than a chosen number. The lower one defaults to 0.90, a round distance below it, and it is the one edge here that is a judgement. It is exposed with a wide range and nothing in this script argues that it is the right number. The engine refuses to read if the lower edge is set at or above the upper one.

Ranking window. How much history the two percentile ranks are measured against, in days of the series. Longer spans more regimes and describes the current one less, and it also sets how much loaded history is needed before either rank appears.

Runs the ledger holds per state. Oldest first out once a list is full. At the default of 500 the list does not fill on the default pair's loaded history in any of the three states, so the cap does not engage there; it exists for a much longer history or a much finer pair of edges.

Completed runs before the ledger reads. Below this the age percentile is withheld and the status line says how far short the list is.

WHAT IT WILL NOT DO

It generates no entries and no exits. There is no position here, no size, no stop and no target.

It ships no alerts, on purpose. The natural alert on a file like this would be the state changing, and a state change delivered as a notification reads as an instruction whatever the text on it says.

It makes no forecast. A percentile of a run length describes the run. It says how this run compares with past runs of the same state on this chart, and it says nothing about what follows one, because this script measures nothing about what follows one.

It carries no entry or exit logic of any kind, and nothing conditions one reading on another. Adding a condition to a readout makes it look as if it answered a question it never asked.

It reports no hit rate, no performance and no backtest. Every number above is a measurement of this script's own output series or of its own arithmetic, and each is reproduced by the harness on every run.

The age percentile compares a run that has not finished with runs that have, so what it prints is a lower bound on what that run will read when it ends. It can only rise as the run goes on. Measured over the read bars of the default pair, the printed value sits below the run's own final value by 13.2 points on average on the steep side, 12.3 on the flat and 7.7 on the inverted; the medians are 7.5, 7.5 and 2.8. So a run reading in the middle of the list today is not a run that will end there.

Neither percentile is a probability. The age percentile is a frequency over the completed runs the chart loaded, and that sample is small. On the default pair it is 272 steep runs, 417 flat and 151 inverted, so a percentile near 50 carries a standard error of about 3.0 points on the steep list, 2.4 on the flat and 4.1 on the inverted; near 90 it is about 1.8, 1.5 and 2.4. Runs do not overlap each other, so those figures are not softened the way an overlapping window count would be, but runs do cluster in time, with a handful of years supplying a disproportionate share of the long ones. Treat the binomial figure as a floor rather than as the whole error.

The first run on any chart is cut off at the left edge, because the chart cannot see when it started. It is dropped rather than ledgered. It is one run out of several hundred, and the only one whose start is out of view.

A ledger describes the history it was built from. Run it across a change in how the two series relate and it keeps reporting the old distribution until enough new runs have been pushed. Any historical frequency lags in this way.

Runs are split at the edge exactly as the ratio crosses it, with nothing smoothing the crossing. A run that dips one day past an edge and comes back is two runs here and not one, which is a large part of why the inverted median is one day. The size of that effect is measured and quoted near the top of this description, and the choice is left as it is because any alternative is a judgement made on your behalf.

Any decision based on this readout is the reader's to make.

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.