How to Estimate Period of Trend in Stock Market Trading Part-1

You got to know about the trend by applying the Exponential Moving Average combination but scared of taking a trade yet. The reason is very simple you don’t know how long the trend would last. This is a very critical point when we answer the question that how to trade the stock market profitably.

You got the share, you caught up the trend and still frozen. Let us build a mathematical model around it and then we apply on some real stock price data on the National Stock Exchange. We will use www.in.finance.yahoo.com for historical data of shares. We have to follow through the following steps — -

(A) Mathematical Modeling of Trend Period

(B) Model Building, Training and Testing

© Back Testing and Evaluating Model

(D) Key Learnings

(E) Conclusion

Let us begin by fitting the idea into a mathematical model.

(A) Mathematical Modeling of Trend Period

A data series of stock prices consists of primarily three phases — a) Uptrend, b) Downtrend and c) Sideways. The Uptrend phase is when the stock price shows a rise for consecutive periods, the Downtrend phase is when the stock price shows downslope for consecutive periods and the Sideways phase shows neither upward nor downward trend and price moves with stable range.

Intuitively, Uptrend and Downtrend phases are two types of trend and the Sideways phase is reflects no trend. Now, assigning trend or no trend to a stock price movement depends upon what is the lookup period. Lookup period means how long is the time period, say 5-day, 10-day, 15-day or 30-day. A stock price may have a trend in 5 day period but may have downtrend or sideways phase in 15-day or 30-day periods. We have to fix the lookup period beforehand.

Let’s take 10-day as lookup period. Now, we need to define when it is in trend (Uptrend or Downtrend) or No Trend. Figure 1 presents how each type looks like in share price movements.

Figure 1

In the graphs of Figure 1, the 10-Day Period is taken as the evaluation period and we are comparing the price movements between T Period and T-1 Period. Both T and T-1 Period contain 10 Days Share Prices. The following differences can be taken between sideways and any trend (uptrend or downtrend) in share price movements.

Table 1

There can be more scenarios based on combinations of three types of share price movements like Downtrend in T-1 Period and Uptrend in T Period, Downtrend in T-1 Period and Sideways in T Period, Uptrend in T-1 Period and Downtrend in T Period & finally, Uptrend in T-1 Period and Sideways in T Period. So, we can have seven scenarios of Uptrend, Downtrend and Sideways share price movements.

In this part of the article, we will focus only on the first three combinations shown in the picture. Now, we convert the information contained in the table into statistical hypotheses.

Hypotheses Set 1

Null: Means of share prices in T-1 and T Period are equal.

Alt: Means of share prices in T-1 and T Period are not equal.

We will apply a -test on share price data of T-1 Period and T Period. If we fail to reject the null hypothesis, then, we can infer that share prices are sideways in T-1 and T Periods and there is no trend in T Period.

Similarly, we can frame other hypotheses sets.

Hypotheses Set 2

Null: Medians of share prices in T-1 and T Period are equal.

Alt: Medians of share prices in T-1 and T Period are not equal.

Hypotheses Set 3

Null: Standard Deviations of share prices in T-1 and T Period are equal.

Alt: Standard Deviations of share prices in T-1 and T Period are not equal.

Hypotheses Set 4

Null: Medians of share prices in T-1 and T Period are equal.

Alt: Medians of share prices in T-1 and T Period are not equal.

Now, we select three shares listed on the National Stock Exchange. To download share prices, we will use Yahoo Finance API. We will resp of the model-building part in the next section.

A Machine Learning Enthusiast, Passionate About Using Machine Learning for Building Startups