My last post Arbitrage on cross-section returns in Brazilian stock market presents an example about how can we profit from this. The intention of this article is to show another curious pattern that was born here in the brazilian future stock index that is derived from this interaction between those markets.
For those who doesn’t know what i’m taking about, i do strongly suggest that read the previous posts for a deep understanding.
Before explaining the curious pattern, let me explain the conditions that the future market and the stock markets have here in Brazil which led me to suppose why of such a pattern do exists. And when i said suppose is because i’m not 100% sure that the following explanation is the right one. It’s only the most plausible for me.
When we thinking in enter in the brazilian stock market, basically, we have 3 options:
As explained before, these assets are traded by different peoples, looking at different reports, with different opinions (That’s the main reason why trend-following in the stock market it’s not so profitable as in commodities: there must be a consensus in the market about the direction that the the whole stock market is taking).
The stock market and the future market opens and closes at different times: Stocks and ETFs opens at 10:00 AM and closes at 05:00 PM and the futures market opens at 09:00 AM and closes at 18:00 PM, as you can see in the picture down here:
Well, as they are the same thing, stocks, Index ETF and Future Stock Index have to trade at a same level. If they don’t, anyone can profit from a simple arbitrage stategy. But, the future stock index spend 2 hours more trading than the other. That mean that only the players that do trade at him will incorporate the newsflow to the price. If a very relevant company announces it results, the future stock will be the first proxy of how the market reacted to this. The key point here is: Do the Stocks traders agree with the overall change that future stocks had overnight?
That fact allow us to create at least three hypothetical scenarios:
As the previous articles, to test those hypothesis, i’ll be using only the IND serie that can be found on the official FTP provided by the BM&F. I created a continuos series, adding the roll returns (same method used by Bloomberg). The data here vary from 22/12/2014 to 31/05/2016. All the data was stored in a local MongoDB server, acessed via Python by a excellent API called Arctic.
To test which of those scenarios is was what prevailed in the dataset, i’ll try to fit the following linear model in the data i have:
Where Y will be today’s return of the stock index between 10:00 AM and 10:30 AM and X will be the return from yesterday’s close ’till today’s stock market open. That means we are trying to find some form of predictive power in the overnight’s change on the firsts minutes when both markets are open.
We begin collecting the data from our server and storing into a Pandas DataFrame called ind.
If we plot the index serie, we’ll see that it is perfect:
After that, we can create both X and Y DataFrames. By this, we begin slicing our data in the desired times:
With that done, we can create our X and Y vectors. I used the absolute returns insted of percentual changes.
We can then make a scatter plot:
A first glance tells us that there is a certain relationship between the data. We can mesure this using the linregress function from scipy library.
What results:
LinregressResult(slope=-0.12893318214562502, intercept=-3.7789479936766783, rvalue=-0.25846893596511661, pvalue=9.1634252170004753e-07, stderr=0.025794645132302303)
What this output is telling us is that the calculated value for slope in our model is negative and equals to -0.1289 and it is statistically different from zero (as we can see interpreting that pretty low pvalue).
A negative slope means that there is a negative relation between the return of yesterday’s close and todays open (X) and the return of today’s 10:30 AM with today’s open. So, we can conclude that the hypothesis 3 is the correct and can create a trading system that sells/buy the index if they go up/down at the open at the stock market and rebuys/resells 10:30 AM.
But, is 10:30 AM the best hour to close our trade? Is there any kind of filter we can put in the strategy? There is some better form to operate this? This patterns cover the coasts? Obviously, all that questions need to be answered before trading this system, but, we got another alpha here. I intend to exploid more this results in the next articles.
]]>
The trading idea that will be presented here is quite simple and was first proposed by Andrew W. Lo and A. Craig MacKinlay, in their paper When Are Contrarian Profits Due to Stock Market Overreacction (1990). The same pattern was also documented in the paper Contrarian Strategies and Cross-Autocorrelations in Stock Returns (1998) in the French Stock market.
The base point of this trading strategy is that stocks do overreact. To test this, it’s natural to test for the presence of autocorrelation in the stocks returns. For those who doesn’t know, correlation is a number that measure the presence os statiscical relationship between two time series. Let X and Y two random variables, the correlation between them is:
Where are the sample standard deviation of the series and and are the sample means. The concept of autocorrelation derives from the fact that we are trying to find some kind of correlation in X and in its own past values, not with another random variable.
So, the obvious starting point for testing stocks overreaction is evaluating the presence of autocorrelation between today’s return and past n returns.
In this article, i’m going to test this hypothesis for the Brazilian stocks. The data used here was directly from the BM&F Bovespa FTP. This database contains more than 2 years of tick-by-tick data, but, for this study, was adjusted to the daily frequency. Th data span vary from 25/11/2014 and 20/01/2017.
The data was corrected from dividends, splits, inplits and subscription rights accordingly to Bloomberg’s database.
As mentioned before, the first basic idea for testing for overreaction in stocks is looking if there is any kind of autocorrelation in the time series of returns for individual stocks. The language i’ll be using for this is Python.
Let’s first retrieve the data first. I’ve put all my data in a MongoDB server. The acess to it is done via an excellent library called Arctic. For those how don’t know Arctic project, you can check it here.
Now, equities is a Pandas DataFrame cointaining the first 97 most liquid stocks in brazilian equity market. We can do this also using Yahoo/Google Finance databases; you’ll find the same results.
Right now, ret_eq will be our return serie. It’s a 535 x 97 DataFrame (535 days for 97 stocks). The autocorrelation is simple done using acf function, contained in the statsmodels.tsa.stattools library.
In this test, we’ll gonna be using a 80% confidence interval. It’s not a huge confidence, but the main purpose here is always to find Alpha and not to prove our models has a super high statistical security. When it comes to stock market, few things have that and normally mostly of the Alpha do exist in situations where the confidence interval is lower than the usual 95%.
When we mean our individual results and plot it, what we get is not so exciting:
This graph is simple the means of the autocorrelation values between the return series and itself lagged in n days. As you can see, there isn’t any lag that gave us some statistical confidence, even in 80%. So, can we conclude then that stocks do not overreact? NO.
As mentioned in my previous post, stocks have a lot of cross-correlation. Why don’t we try mesure the overreaction using this concept? The idea now will be mesure if there is some kind of overreaction when some stock outperforms (or underperforms) the mean return of the market (instead of just see if it went up or down like before).
To do this, i used the same metodology as Lo and Craig. Instead of using the Index to track market perfomance, they simple used a equally-weighted returns of all stocks.
Quite simple.
Now, using the same calculation than before, our results changes a little:
Now we can see that there is some kind of negative autocorrelation in the relative return series and itself lagged by 1 day. That means that mostly of the days when a stock outperform the market, the next day it tends to underperform.
If we do simple sell the outperformers in the market close and buy the underperformers, using the same capital allocation to everyone, we get this result curve:
Easy, huh?
Obviously, that’s not so simple. Any kind of cost was added to this backtest. When dealing with stocks that’s critical, so that’s why i won’t measure any kind of perfomance of this trading strategy yet because that’s still on the rough stone. There’s a lot to mold. We can test other more intelligent types of position sizing, filters, stops… We can the same ideia for higher and lower frequencies. And that’s what I intend to do, but on next articles.
The idea here is to show that’s still Alpha around there, even with pretty old ideas.
]]>
As we know, future index contracts are financial agreements where the object of trading is the Ibovespa index’s score at a predetermined future date. Thus, the quotation of the future index derives (or should be derived) from the IBOV price serie. However, as you know, the players in the future index markets and stocks are not the same:
Are those uncorrelated and simultaneously buying and selling pressures that open the space for the Cash & Carry operations can be done.
Cash & Carry is an arbitrage strategy between spot and futures markets, where the trader buys / sells one of the assets and do the reverse operation on the other, seeking to exploit temporary inefficiency between these markets.
There is, therefore, a mathematical relationship based on economic precepts that governs the future index price (as well as any other asset traded in the futures market, being a commodity, currency, etc.). The future index, in this case, is a function of the IBOV price, the weighted rent rate of the assets that make up the theoretical portfolio of the index and the interest rate practiced in the economy, carried over to the contract’s maturity.
However, as we can see in the chart below, however much the two assets seem to go together, there are times when there are inefficiencies:
Notice, however, the roughness in the chart below. If the relationship between them is below average, it would be possible to make profits by buying the future index and selling the shares, waiting for the ratio to be corrected to dismantle the transaction (the opposite is true if the ratio is above normal).
As a zero-risk operation, there is a lot of competition in this market, and those investors with access to very low costs (generally, investors who participate in the BMF & Bovespa incentive program for high-frequency traders), as well as those with high execution speed (Investors operating via co-location) will have advantages over other players when capturing these distortions.
No. Much as in essence, future index derives from Ibov, in practice what happens sometimes is the opposite. A foreign investor wishing to trade relevant resources in the Bovespa index will have two ways of doing this:
Thus, buying or selling the future index becomes much easier than trading stocks. It is no wonder that the futures market (IND and WIN) trades twice as much as every stocks together.
In this way, when we say that there is a foreign flow moving the stock market, we are talking about a buyer / seller flow entering (in most cases) the future index and being felt by the stocks by the arbitrators operations.
Obviously this is just one of the possible moves. If the futures market is low in liquidity, reverse trading can also happen.
We conclude then that if these movements caused by other markets occur all the time, the basic concept of technical analysis (in the intraday spectrum) would lose its meaning. Price does not predict price! In other words, the idea that past prices would contain indications of future movements is not valid since most of the stock movement would result from movements of the future index brought to the stock market through the action of the arbitrageurs.
See some examples of intraday movements. Below is the graph of the future index (INDJ16) of 06/04/2016.
Now see how 6 of the most importants Brazilian’s stocks did traded that day (PETR4, VALE5, BBDC4, KROT3, LAME4, ABEV3).
Pretty simmilar, huh?
Did not understand? Did not like it? Do not you remember? Please contact us, your feedback is always welcome.
]]>
But how could we not be impressed by the idea that it would be possible to master a technique that would indicate the points of entry and exit of operations in the financial market? And what, in addition, would it be possible to program algorithms that operate autonomously, looking for investment opportunities the whole time, without being subject to discretionary analysis or emotions?
The idea behind this series of articles will be to present a set of arguments that makes me to believe that the use of technical analysis to operate stocks in the intraday time frame does not make sense. Note that I will try to refute its applicability only for day-trade operations.
In lower frequency strategies, technical analysis may have good applicability. Trend Following models are the prime examples of this. Its input signals can be derived from the crossing between simple moving averages, Channel Breakouts, the analysis of the Hurst exponent of the time series studied, among others. It is important to emphasize that for such strategies, the input signal is NOT the most important parameter. The position sizing models used as well as the correct dimensioning of the stop-losses are by far much more important for the long-term survival of the stategy. I will not delve further into this topic because we intend to write a series of articles specifically on trend-following, besides presenting a complete model that we use applied to actions, with backtests and tests of sensitivity of the parameters.
But then why technical analysis as input signal in intraday frequency does not make sense?
To answer this question, I will divide the explanation into two topics:
What characteristics would the market need to have to make price-based strategies profitable?
Who are the players that are active in the intraday stock market and what variables are relevant to their decision-making?
There are hundreds of technical indicators. Each indicator is calculated as a function of price and some other variables (in general, some lag). If we consider that each combination of indicator and parameter brings us some different information (from the point of view of technical analysis), the combination between them is capable of generating infinite new indicators. We can characterize these indicators in three categories: momentum, trend and volatility indicators.
Moment Indicators: Williams, Stochastic, IFR, SAR, Hilo Activator, etc.
Trend Indicators: MACD, Moving Averages, ADX, etc
Volatility Indicators: Average True Range (ATR), Bollinger Bands, Price Channels, etc.
Some of these indicators can be very useful in some aspects of automated systems. ATR, for example, is widely used to scale stops in low frequency systems. The point is that when we refer to input signals in operations, all indicators have one thing in common: they are derived from past quotes.
In this way, systems that use such indicators are essentially operating the idea that price predicts price. Such a concept would be true if the major market players, for the most part, used past prices as an important variable in their decision-making. And when I talk about the main agents, I mean the players who can move the price. Thus, it is necessary to analyze who these investors would be, and what variables are relevant to each one of them.
The stock market (just like any other) is made up of thousands of different investors. Everyone believes they are doing the right trade at a fair price. And they might be. Both buyer and seller. What obviously differs them are their decision-making logics, as well as the time horizon sought by the operation. Simply put, we can classify agents into:
As we know, prices move through imbalances between supply and demand. Investors intent on buying / selling assets, but not in a hurry, record their intentions in the bid book, increasing the availability of assets in bid / ask, hoping that tougher investors will pay the spread and take them to market. If in a certain time window more investors propose to take more to the market at ask, for example, the price goes up. If they hit the bid more, the price drops.
For technical (or even quantitative) strategies to achieve alpha, it is necessary to find some pattern in the market that precedes a buyer / seller flow of most other market agents (or some large investor) in order for them to move the price.
If we are operating some Bollinger-Bands mean reverting strategy or some trend-following strategy based on ADX, we need other more relevant players to do the same after we get into the transaction. If this does not happen (and I seriously believe that it does not happen, given the number of concurrent and uncorrected investors in action), the movement that will follow such technical indications will be due only to the vectorial sum between the forces acting on the offer book at that moment.
And, as mentioned before, there is a group of investors that is present during all the course of the trading session: the arbitrators. However, I will dedicate the whole 2 part of this article trying to explain the performance of these players, as well as their influence on stock prices.
Questions, suggestions or rewies? Make contact. I’ll always be open to good discussion.
]]>