TradingView
capissimo
23 אוג׳ 2019 07:13

Forecasting - Locally Weighted Regression 

Bitcoin / United States DollarCoinbase

תיאור

This is a continuation of the series on forecasting techniques.
Locally weighted linear regression is a non-parametric algorithm, that is, the model does not learn a fixed set of parameters as is done in ordinary linear regression. Rather parameters Θ (theta) are computed individually for each query point x. While computing Θ, a higher “preference” is given to the points in the training set lying in the vicinity of x than the points lying far away from x.
For a detailed discussion see geeksforgeeks.org/ml-locally-weighted-linear-regression/
and for the formula see fawda123.github.io/swmp_workshop_2016/training_modules/module2_wrtds/wrtds.pdf.

Here you can see a shortcut application of this technique to time series with results unexpectedly favorable for price data labelling.

Good at detecting pullbacks. Can be incorporated into a trading system as a signal generator. Alerting is included.
תגובות
capissimo
UPD: here's the mod that allows to work with securities other than BTC. Replace the lines 19 thru 35 with the following:

locally_weighted(x, p, b, mx) =>
PI = 3.14159265359
l = 0.0
for i=0 to p-1
l := b + b*i + b*2*x + b*sin(2*PI*i) + b*cos(2*PI*i)
scale(linreg(l, p, 0), mx)

//*** Inputs
price = input(close, "Price Data")
p = input(5, "Lookback Window")
span = input(8, "Rising/Falling span", minval=2)
crvs = input(false, "Show curves?")
lbls = input(true, "Show Labels?")
mmx = input(2, "Scaler Lookback", minval=1)

//*** Main
BETA = .5
lwr = locally_weighted(price, p, BETA, mmx)
capissimo
@capissimo, by the way, the best mmx value is 20
mercacoin
Excellent work, thanks for sharing, I made the changes that you suggest but it shows an error when adding them ,, line26: Could not find function or function reference scale.It does not recognize a function scale
capissimo
@mercacoin, see here tradingview.com/script/MO81UIFF-forecasting-locally-weighted-regression-rescaled/
or add these lines:
scaleMinimax(X, p, min, max) =>
hi = highest(X, p), lo = lowest(X, p)
(max - min) * (X - lo)/(hi - lo) + min

scale(X, p) => scaleMinimax(X, p, lowest(close, p), highest(close, p))
mercacoin
@capissimo, Perfect thank you very much, it works better, I'm going to try it:)
greyghost7
does this repaint?
capissimo
@greyghost7, it uses the current value of the price, not the previous.
capissimo
Tested with BTCUSD.
עוד