New Shiny App on My Shiny Server

A new shiny application is under construction! See: https://czxa.top/shiny/stock/

This articles is my notes for learning two three articles which introduce some technical analysis methods in Stata.

Bollinger bands were developed by John bollinger in the 1980s and consist of an upper and lower band, defining an envelope of usual trading. A stock price moving outside this envelope triggers an investment decision. The upper band is calculated as K standard deviations above the stock’s moving average. The lower band is calculated as K standard deviations below the moving average. bollinger bands mimic the idea that random variables tend to stay within plus or minus two standard deviations from their mean. To this insight, Bollinger bands add that the financial data might be not stationary, so the means and standard deviations are updated continually.

The usual trading system using Bollinger bands is to sell when the price reached it upper band, because a reversion to the mean is expected. A contrarian Bollinger trading system reverses this logic: buy when the price crosses its upper band.

1 | `/* two deviations */` |

1 | `/* four deviations */` |

The MACD (“Mack-D”) is a momentum indicator commonly used by technical analysis. The MACD is equal to the difference between 2 EMAs of different lengths: (1) a long-term EMA of usually 26 days and (2) a short-term EMA of usually 12 days. The MACD is defined as the short-term EMA minus the long-term EMA. A third component is the so-called signal lines, which is usually a nine-day EMA of the MACD.

The convention is to plot the signal line over the MACD. A “bullish” indicator is when the signal line crosses above the MACD. A “bearish” indicator is when the signal line crosses below the MACD.

The MACD histogram is equal to the MACD less the signal line. As such, it oscillates above and below zero. A bullish signal is when the histogram becomes positive. A bearish signal is when the histogram becomes negative. The histogram is used as an indicator of momentum. When the histogram is positive ans increasing, the stock price is said to have increasing positive momentum. A negative and decreasing histogram implies steeper downside momentum.

It is often viewd as signaling the end of a current trend when the actual stock price diverges significantly from the MACD. Finally, the MACD rises steeply when the short-term EMA (usually 12 days) is rising faster than the long-term EMA (usually 26 days). That is, price have moved dramatically upward recently. Analysts sometimes infer that the current price has moved away from its equilibrium value, and they expect a downward correction.

1 | `clear all` |

1 | `clear all` |

1 | `clear all` |

$$RSI = 100 - \frac{100}{1 + RS}$$

where:

$$RS = \frac{average of upward returns over x days}{average of downward returns over x days}$$

1 | `clear all` |

1 | `* net install gr0076.pkg, from("http://www.stata-journal.com/software/sj19-1")` |

1 | `/* Draw Basic Candle Chart and Transaction Volume */` |

1 | `/* Add Bollinger bands, MACD, and RSI */` |

1 | `/* Chart Options */` |

1 | `/* Financial statements */` |

1 | `/* Earnings per share */` |

1 | `/* Econometric Analysis */` |

Day-of-the-week effect is one of most common return anomalies tested in the literature. It stems from the hypothesis that if securities compensate investors for risk for any holding period then a weekend return should be higher than a daily return. Thus, based on this hypothesis, it would be expected that returns for Fridays to Mondays should be higher than any other mid-week daily return. However, if investors expect higher returns for the weekend they would trade such expectation to take advantage of it. This would eliminate the higher weekend returns. Based on the efficient market hypothesis, such profitable pattern trading should not exist. In fact, if it exists, it would be akin to investors not taking advantage of a profitable trading strategy. Thus, existence of day-of-the-week is considered to be an anomaly: why would investors leave money on the table?

Dicle and Levendis (2014) argue that investors and academic study indexes as well as popular stocks. This leads to less popular stocks to be left not studied. They find no evidence of day-of-the-week effect for indexes. However, based on evaluation of 51 markets in 33 countries, approximately 8% of 37631 stocks present day-of-the-week effect.

The day-of-the-week effect test is quite simple. It basically evaluates returns for each day of the week to be statistically different from each other. For this purposes, a binary variable is assigned to each week day. However, in order to avoid binary variable trap (a.k.a. dummy trap) in the regression, one of the weekdays is left out(usually Wednesday). This allows each week day’s return to compared to the returns on Wednesdays.

1 | `cntrade2 1` |

It seems no day-of-the-week effect exists. Also it would be best to estimate this model using GARCH(1, 1) model instead of OLS to control for risk.

1 | `tsset date` |

Still no day-of-the-week effect was founded.

Dicle, M. F., & Levendis, J. D. (2017). Technical Financial Analysis Tools for Stata. The Stata Journal: Promoting Communications on Statistics and Stata, 17(3), 736–747. doi:10.1177/1536867x1701700312

Dicle, Mehmet F., Stata for Finance Students (October 28, 2018). Available at SSRN: https://ssrn.com/abstract=2318687 or http://dx.doi.org/10.2139/ssrn.2318687

Dicle, M. F. (2019). Candle charts for financial technical analysis. The Stata Journal: Promoting Communications on Statistics and Stata, 19(1), 200–209. doi:10.1177/1536867x19830918

#
Stata

Update your browser to view this website correctly. Update my browser now