How to calculate the trend for stock prices

I am trying to calculate and draw trend lines for stock prices. I did some searching and thought all day, there is no really good idea on how to do this.

I have a daily price history and you want to find the intersection between the trend line and the price.

Could you give some ideas or recommendations?

Thank you very much.

Trendline example

+5
source share
2 answers
import pandas as pd import quandl as qdl from scipy.stats import linregress # get AAPL 10 years data data = qdl.get("WIKI/AAPL", start_date="2007-01-01", end_date="2017-05-01") data0 = data.copy() data0['date_id'] = ((data0.index.date - data0.index.date.min())).astype('timedelta64[D]') data0['date_id'] = data0['date_id'].dt.days + 1 # high trend line data1 = data0.copy() while len(data1)>3: reg = linregress( x=data1['date_id'], y=data1['Adj. High'], ) data1 = data1.loc[data1['Adj. High'] > reg[0] * data1['date_id'] + reg[1]] reg = linregress( x=data1['date_id'], y=data1['Adj. High'], ) data0['high_trend'] = reg[0] * data0['date_id'] + reg[1] # low trend line data1 = data0.copy() while len(data1)>3: reg = linregress( x=data1['date_id'], y=data1['Adj. Low'], ) data1 = data1.loc[data1['Adj. Low'] < reg[0] * data1['date_id'] + reg[1]] reg = linregress( x=data1['date_id'], y=data1['Adj. Low'], ) data0['low_trend'] = reg[0] * data0['date_id'] + reg[1] # plot data0['Adj. Close'].plot() data0['high_trend'].plot() data0['low_trend'].plot() 

enter image description here

+1
source

Some ideas and recommendations:

Based on your statement (cit. :)
I did a few searches and thought all day , there is really no good idea on how to do this.
I can make sure that there is no universally good idea how to solve this, but it should not make you nervous. Generations of CTA have spent their whole lives doing this with their individual horizons, with the best efforts they could put into mastering this, so that at least we can find out that they left us as a way to next.

A trend is an OPINION rather than a somewhat calculative line

1) DETERMINE Trend:
As an initial surprise, keep in mind that the trend is more likely a function that depends on exotics (external), which is more associated with opinion than with the history of TimeSeries data (observed).

In other words, as soon as a person realizes that trend information is simply missing from the TimeSeries dataset, things will start to become much clearer.

2) if you think that you are strong enough in your Trend identification methods, but you can EXTEND such a trend as the line of faith in the FUTURE (hypothesis)

3) MARKET and only The Market VALIDATES (or ignores) such an β€œaccepted” belief.

4) GENERAL CONFIDENCE OF RE-CONFIRM such a line of faith as a trend indicator recognized by the majority (measured by market risk, it is subject to fairness and not popular voting, the fewer crowds or critics of self-defense CTAs)


Does it ever work?

The USDCAD example example above ( reduction in a new window for a full-blown independent presentation) reflects all this, plus adds several FUNDAMENTAL EVENT examples that were introduced β€œthrough” the technically designed (with quantitative confirmation) main attractors, demonstrating part of the real life of the river flow called FX- by trading.

+1
source

All Articles