Warmup and convergence #688
Replies: 4 comments 5 replies
-
I have done the work of evaluating all the indicators in the library and providing guidance in the documentation about how much is needed to provide moderate and high levels of precision, it's usually written in the following format, and will be unique for each indicator.
If you want to test these on your own, here's example code: IEnumerable<Quote> quotes = [provide at least 1000 quote periods];
int[] quotesQuantities =
new int[] { 5, 14, 28, 40, 50, 75, 100, 120, 150, 200, 250, 350, 500, 600, 700, 800, 900, 1000 };
foreach (int qty in quotesQuantities)
{
IEnumerable<Quote> evalQuotes = quotes.TakeLast(qty);
IEnumerable<AdxResult> results = evalQuotes.GetAdx(14);
AdxResult last = results.LastOrDefault();
Console.WriteLine(
"ADX(14) on {0:d} with {1,4} historical quotes: {2:N8}",
last.Date, evalQuotes.Count(), last.Adx);
} We have done this evaluation on all relevant indicators. You can also see and run the convergence test code in our repo. |
Beta Was this translation helpful? Give feedback.
-
If you wanted to exclude these warmup periods from your results, here's how we recommend doing it: // fetch historical quotes from your feed (your method)
IEnumerable<Quote> quotes = GetHistoryFromFeed("SPY");
// calculate 14-period ADX
int n = 14;
IEnumerable<AdxResult> results = quotes
.GetAdx(lookbackPeriods: n)
.RemoveWarmupPeriods(2*n+100); We use Without the removal of warmup periods, you will get a result set that is identical in size as the original quotes provided. When removing the warmup periods, it will be See .RemoveWarmupPeriods() docs in the Guide for more info. |
Beta Was this translation helpful? Give feedback.
This comment has been hidden.
This comment has been hidden.
-
May I know then how charting Tools like Trading View would calculate. And specially for such stocks which dont have a huge history data available. Example, Now trading view calculates the supertrend and i dont know what smoothening it applies. But whatever formulae it may have hidden behind for smoothening, the data available is limited for both trading view and [Stock.Indicators] library I am using the code below
My result is off from what i see on Trading view. Attaching both raw weekly feed data of the same symbol and the export of the supertrend computation Raw: Library computed result : Couldnt export data from Trading view as Essential plan doesn't support it. Please check it once there if needed Thanks |
Beta Was this translation helpful? Give feedback.
-
Important
Warmup and convergence periods occur in most indicators in our library. Using the minimum amount of quote history as possible is NOT a good way to optimize your system.
If you were to put in the minimum amount of quote history data that you think is needed, it may not be enough to achieve desired precision -- this is not a bug or error in the formula, it's just part of the way the stochastic math works sometimes.
There are two reasons that initial indicator values may be missing or less accurate:
null
in our library.more on convergence
This chart demonstrates. The center dark line is the precise indicator value, and the top and bottom dark lines reflect how an initial guess value for the indicator might begin and then become accurate.
Example: ADX(14)
You think, I should provide 14 (N) periods of historical quotes to "optimize" for ADX(14), right?
So you try that and you get nothing in return, it's only a
null
result. You're in the incalculable zone.You then read the formula and can see that it starts to calculate values at the 2×N mark and you get 58.53; great! but there is a hidden problem that you may not know ... this value is wildly inaccurate! You're in the convergence zone.
If you then incrementally add more historical quotes to see this pattern you will see that precision to 2 decimal needs 150 historical quotes, and you'd need even more if you wanted even better precision.
This is why we recommend for ADX that you use 2×N+100 periods of historical quotes before your intended usage period. Please keep this in mind as this library does not provide warnings or Exceptions when do not provide enough quotes to achieve moderate accuracy.
Beta Was this translation helpful? Give feedback.
All reactions