Robust Trendline Fitting
Install and import
npm install fintech-algorithmsimport { fitRobustTrendline } from "fintech-algorithms/geometric-chart-patterns/pivots-and-levels/robust-trendline-fitting";Signature
fitRobustTrendline(pivots, kind, toleranceBps, minInliers, maxPoints)Worked example
executed Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.
Input
[
{
"kind": "low",
"event_index": 0,
"confirmation_index": 3,
"price": 99.48431564193378
},
{
"kind": "low",
"event_index": 10,
"confirmation_index": 13,
"price": 109.94717245212351
},
{
"kind": "low",
"event_index": 20,
"confirmation_index": 23,
"price": 121.51041751873485
}
]Showing 3 of 4 elements.
"low"7531240Call
fitRobustTrendline(pivots, kind, toleranceBps, minInliers, maxPoints)Returns
object with 10 fields: kind, slope_log_per_bar, intercept_log, projected_index, projected_price, inlier_count, outlier_count, median_absolute_residual_bps, …
{
"kind": "low",
"slope_log_per_bar": 0.010000000000000009,
"intercept_log": 4.6,
"projected_index": 40,
"projected_price": 148.4131591025766,
"inlier_count": 3,
"outlier_count": 1,
"median_absolute_residual_bps": 0,
"inlier_event_indexes": [0, 10, 20],
"source_pivot_count": 4
}Other exports
This module also exports
detectCausalPivots. Every module additionally exports run as an alias of its
primary function, and a meta object carrying its catalog id, domain, family,
shape and article URL.
Diagrams
How it works
This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.
References
- Random Sample Consensus: A Paradigm for Model Fitting — Martin A. Fischler and Robert C. Bolles
- sklearn.linear_model.RANSACRegressor — scikit-learn project
- Linear Least Squares Regression — NIST/SEMATECH
- Pine Script Concepts: Repainting — TradingView