Monday, September 30, 2019

Finally Bollinger Bands #1


Finally, the long wait is over. Since my last post (3 weeks ago), I’ve been doing some work on the Bollinger Band analysis I promised. It has taken way too long. There are 2 reasons for this. First, I’m still in the nursing home. There are far too many interruptions during the day to get any time to work on the project. At night I mostly sleep but have been able to squeeze in a few early morning hours to work on the simulation program. Second, the program turned out to be more complicated than I anticipated. That coupled with sporadic work periods led to a frustrating development cycle. But finally, I’m at the point where I’m beginning to generate results that I can study. Now on to Bollinger Bands.

Bollinger Bands is a technical analysis tool used to set buy and sell price points for a given stock on the financial markets. We are going to apply the formulas to bitcoin prices (BTC). The calculation has 2 components. The first is the simple moving average (SMA) over the period of time being considered. The second is the standard deviation of these prices over the period. We’ll start with the normal defaults (20 days and 2 standard deviations).

The simulation program looks at data for a specific day. It uses the closing BTC price for the previous 20 days. It computes the SMA and standard deviation for this data. It then sets an upper and lower price range. The upper price limit (sell signal) is the SMA plus 2 standard deviations. The lower limit (buy signal) is the SMA minus 2 standard deviations. The program then sets buy and sell limits. It looks at the high and low price for the day in question to determine if a trade would have occurred.  If no trade would have been made, then the limit orders are reset for the following day.

When the simulation is run for each day in 2018, trades would have been made on 99 days (67 buys and 32 sells). The 2019 data through the end of August found trades on 80 days (16 buys and 64 sells). While the number of trades is interesting, the real interest lies in the profitability (or loss) of these trades. There are lots of other interesting questions or options. We’ll start addressing these in my next post. Hopefully the posts will happen more frequently. Follow @billlanke on Twitter to know when these occur.

Friday, September 6, 2019

Filter by slope and trend


The next and final topic I want to look at is using 2 regression results to filter the correlation results in order to finally answer the questionDo recent prices predict future ones? “. The previous results were unsatisfactory in my mind. All along I’ve included 2 regression calculations in my code, linear and quadratic. My correlation analysis starts by looking at BTC prices over a past number of days, let’s use the previous 7 days. We then use linear regression to fit a straight line through these 7 data points. The slope of the resulting equation indicates a growing price (positive slope) or a declining price (negative slope). We then did quadratic regression on the same 7 data points. The result is an equation that is curved. The 2nd co-efficient indicates the curve is bending upward (positive number) or downward (negative number). I refer to this as “Trend”. I first discussed regression (with plots) on this blog back in July.

After fooling around with several parameters, I decided to put limits on several items. Ultimately, I selected a range from 7 days before and 7 days after a given day. I also created 2 indicators. The 1st represented the slope and the 2nd represented the trend. Each is a single letter, B-buy because the value is positive, N-neutral because value was not computed, or S-sell because value is negative. Following is a table of values from the analysis.

Indicator
Ave Corr 2018
Ave Corr 2019

Description
2018
2019
BB
0.390
0.382

Total days
365
201
BN
0.062
0.089

Both slope and trend non-negative
241
128
BS
0.165
0.147

Both positive (no Day1 -1, -2, or -3)
208
110
SB
-0.332
-0.316

Range -7 to 7 BB
132
78
SN
-0.213
-0.188

Range -7 to 7 SS
153
83
SS
-0.559
-0.564




Grand Total
-0.099
-0.077





There was a clear difference in the average correlations. The best positive correlation occurred when both indicators were “B-buy”. The most negative was when both signaled “S-sell”. Clearly the use of factors enhanced the results of the analysis. The right columns of numbers counted the number of days that had clear buy or sell signals. More good news, it appears as though there are enough days with good indicators to make active trading a worthwhile project.

Finally, I’ve answered the question “Do recent prices predict future ones? “. The answer is yes. I’ll continue with the project and include these factors in my studies. Next up, the use of Bollinger Bands to predict BTC prices. I’ll tweet, @billlanke, when I post on the blog.