# Forecasting - Drift Method

จำนวนเข้าชม 5201
Introduction

Nothing fancy in terms of code, take this post as an educational post where i provide information rather than an useful tool.

Time-Series Forecasting And The Drift Method

In time-series analysis one can use many many forecasting methods, some share similarities but they can all by classified in groups and sub-groups, the drift method is a forecasting method that unlike averages/naive methods does not have a constant (flat) forecast, instead the drift method can increase or decrease over time, this is why its a great method when it comes to forecasting linear trends.

Basically a drift forecast is like a linear extrapolation, first you take the first and last point of your data and draw a line between those points, extend this line into the future and you have a forecast, thats pretty much it.

One of the advantage of this method is first its simplicity, everyone could do it by hand without any mathematical calculations, then its ability to be non-conservative, conservative methods involve methods that fit the data very well such as linear/non-linear regression that best fit a curve to the data using the method of least-squares, those methods take into consideration all the data points, however the drift method only care about the first and last point.

Understanding Bias And Variance

In order to follow with the ability of methods to be non-conservative i want to introduce the concept of bias and variance, which are essentials in time-series analysis and machine learning.

First lets talk about training a model, when forecasting a time-series we can divide our data set in two, the first part being the training set and the second one the testing set. In the training set we fit a model to the training data, for example :

We use 200 data points, we split this set in two sets, the first one is for training which is in blue, and the other one for testing which is in green.

Basically the Bias is related to how well a forecasting model fit the training set, while the variance is related to how well the model fit the testing set. In our case we can see that the drift line does not fit the training set very well, it is then said to have high bias. If we check the testing set :

We can see that it does not fit the testing set very well, so the model is said to have high variance. It can be better to talk of bias and variance when using regression, but i think you get it. This is an important concept in machine learning, you'll often see the term "overfitting" which relate to a model fitting the training set really well, those models have a low to no bias, however when it comes to testing they don't fit well at all, they have high variance.

Conclusion On The Drift Method

The drift method is good at forecasting linear trends, and thats all...you see, when forecasting financial data you need models that are able to capture the complexity of the price structure as well as being robust to noise and outliers, the drift method isn't able to capture such complexity, its not a super smart method, same goes for linear regression . This is why more peoples are switching to more advanced models such a neural networks that can sometimes capture such complexity and return decent results.

So this method might not be the best but if you like lines then here you go.

สคริปต์โอเพนซอร์ซ

จากใจ TradingView ผู้เขียนสคริปต์นี้ได้เผยแพร่เป็นโอเพนซอร์ส เพื่อให้ผู้ค้าสามารถเข้าใจและตรวจสอบได้ ยินดีด้วย! คุณสามารถใช้มันได้ฟรี แต่การใช้โค๊ดนี้ซ้ำเพื่อการเผยเเพร่ อยู่ภายใต้ กฎของเรา คุณสามารถตั้งเป็นรายการโปรดเพื่อใช้กับชาร์ตได้

ต้องการที่จะใช้สคริปต์นี้บนชาร์ตใช่ไหม?
Patreon: https://www.patreon.com/alexgrover

You can also check out some of the indicators I made for luxalgo : https://www.tradingview.com/u/LuxAlgo/#published-scripts

## ความคิดเห็น

Hahahaha, I'm sure, one day you will post an indicator that will just be:

"...
//@version=4
..."

;-)
ตอบกลับ
Duyck
@Duyck, You can't post an indicator without a plot object.
ตอบกลับ
alexgrover
@alexgrover, haha, true, well this one is actually about as close to that as you can get! :)
ตอบกลับ
Duyck
@Duyck, Other projects will include more code, as i said in the introduction the post was rather made to introduce the concept of bias and variance.
ตอบกลับ
Alex appreciated for your great work so far. I was learned a lot of knowledge from your posting especially the article on your post at fighshare.com.
Keep it up of your great work; and also appreciated your generosity for shared all your work in public; thank you Alex =D
ตอบกลับ
Is there a way to measure the angle between a horizontal line and your line? Can be used for higher highs, lower lows...etc and the angle thing can be a good way to take the correct decision for entries. Cheers!
ตอบกลับ
edward_Z
@edward_Z, The line here does not have numerical values, therefore i don't think it is possible, how unfortunate.
ตอบกลับ
alexgrover
@alexgrover, I'll try a thing, to draw a horizontal line for current price (track price) and write a condition for when the forecast line is < or > than the current price. It will not measure the angle but I think can be filtered with a dynamic % distance between these 2 lines. I'll give it a try, and if there are good results I will publish it and tag you. Keep the good work, you are the man!
ตอบกลับ
Thanks Alex for the knowledge!!!! Appreciate it!!! Looking forward to its use.
ตอบกลับ
sudhir.mehta