One month after the corona shock that sent off investors from all over the world, there are gradually increasing voices that the first wave has bottomed out. By the way, what scares investors is the "night" when they are sleeping. Even if trading on the Tokyo Stock Exchange is closed, Nikkei average futures are actively traded on the Osaka Stock Exchange (so-called OSE) night session and the Chicago Mercantile Exchange during London time and New York time. It is not uncommon for the stock price to plummet at night without knowing it ... when you wake up in the morning ** "Ohagyaa!" **. I was wondering here, but for "medium- to long-term investors" who carry over positions at night, the current market may be a bottoming out and a great bargaining point, but day traders who do not carry over positions at night. The world in which you can see may be completely different. This time, I will download the hourly data of the Nikkei Stock Average using the ** MT5 ** python API, which is a favorite of day traders around the world, and analyze the relationship between the nighttime opening return and the daytime return of the Nikkei Stock Average. I did.
As mentioned at the beginning, the time spans seen by medium- to long-term investors and day traders are completely different, so the image of the “rise” of the Nikkei Stock Average on March 27, 2020 is also very different. In particular, it is not uncommon for day traders to see the day as "GU (gap up) & close-up", even though it was a "rise" for medium- to long-term investors. There is no.
From the closing price of 18,832.21 yen on the previous day to 19,389.43 yen on the day of the day ** A large increase of nearly 600 yen! ** **
From the opening price of 19,021.97 yen on the day, the end of the front session was 18,901.46 yen, a drop of nearly ▲ 100 yen, and then the back market started from 19,045.80 yen, and at 15:00 when the day trader closed the position, it increased by about +100 yen to 19,176.30 yen. ** It was an almost flat day for day traders. ** **
Did you know what you want to analyze from the above example? Then, immediately download the hourly data (= 24 hours x 252 business days / year x 3 years) for the past 3 years from the broker via MT5, and ** close return (= close the day before → close to the day) ** and * * Let's examine the relationship between daytime returns (= close to the day → close on the day) **.
# set time index to raw bar data
def time_set(rate):
rate_time = rate.dropna(how='all', axis='index').reset_index()
rate_time['time'] = pd.to_datetime(rate_time['time'], unit='s')
rate_time = rate_time.set_index('time')
return rate_time
# specify symbol to research
symbol = 'JP225Cash'
# get bar data from MT5
mt5.initialize()
_rate = pd.DataFrame(mt5.copy_rates_from_pos(symbol, mt5.TIMEFRAME_H1, 0, 24 * 252 * 3)).set_index('time')
mt5.shutdown()
rate = time_set(_rate)
# XM: GMT+3, JP: GMT+9, diff = 6
rate.index = [x + relativedelta(hours=6) for x in rate.index]
rate_open = rate[rate.index.hour == 9]['open']
rate_close = rate[rate.index.hour == 15]['close']
rate_close.index = [x - relativedelta(hours=6) for x in rate_close.index]
rate_TK = pd.concat([rate_open, rate_close], axis='columns')
rate_TK.columns = ['open', 'close']
rate_TK['close to open'] = (rate_TK['open'] / rate_TK['close'].shift(1) - 1) * 100
rate_TK['open to close'] = (rate_TK['close'] / rate_TK['open'] - 1) * 100
rate_TK['close to close'] = (rate_TK['close'] / rate_TK['close'].shift(1) - 1) * 100
rate_TK = rate_TK.dropna()
sns.jointplot('close to open', 'open to close', rate_TK)
plt.show()
The horizontal axis is the closer return, and the vertical axis is the closing return. First of all, you can roughly see three trends.
By the way, after analyzing so far, it seems that the audience will hear such a voice. ** "Isn't there a big difference in the meaning of a crash (surge) in the medium term between the uptrend and the downtrend?" ** ** "Isn't the upside surge in the downtrend (the situation right now) a heavy upside due to profitable sales?" ** That may be true. Now, let's do the same analysis for the two cases where the 3-month average return is positive (uptrend) and negative (downtrend).
# calc 3M average return
rate_TK['3M Mean'] = rate_TK['close to close'].rolling(63).mean()
# split 2 cases: up trend / down trend
rate_TK_3MUP = rate_TK[rate_TK['3M Mean'] >= 0]
rate_TK_3MDN = rate_TK[rate_TK['3M Mean'] < 0]
# plot
sns.jointplot('close to open', 'open to close', rate_TK_3MUP)
plt.show()
sns.jointplot('close to open', 'open to close', rate_TK_3MDN)
plt.show()
The scenery has changed a lot! I mean, there is no clear tendency. In other words, it is difficult to predict daytime returns by looking at the close returns. ** There are rumors that the stock price is falling in Tokyo time (= Nikkei average) and rising in NY time (= Dow), etc. If you analyze it, you will find that it is not so easy. ** ** And, in fact, in the "Tokyo time ⇔ NY time anomaly" strategy, at least in the uptrend market, it seems difficult to make a profit by trading only on the intraday of Tokyo time without carrying over the position at night.
The results seen over the entire period are shown here. After all, ** Isn't the day trader who earns a lot of money going hunting without missing the fierce repulsion at the fire place in the downtrend? ** **
Let's consider two investment patterns here.
# Global v.s. Abenomics
Buy_and_Hold = ((1 + rate_TK['close to close'] / 100).cumprod() - 1) * 100
Tokyo_time = ((1 + rate_TK['open to close'] / 100).cumprod() - 1) * 100
# plot
Buy_and_Hold.plot(legend='B&H')
Tokyo_time.plot(legend='TK time B&H')
(Tokyo_time - Buy_and_Hold).plot(kind='area', stacked=False)
plt.title('cumulative return')
plt.show()
Here is a plot of the cumulative return of each strategy calculated with the above code. The blue close to close is the cumulative return of the global economic buying strategy, the orange open to close is the cumulative return of the Abenomics buying strategy, and the green area is the difference between the two strategic returns (Abenomics return-world economic return). If you look at it this way, you'll see why the Abenomics buying-and-hold strategy isn't something you've thrown away, or ** isn't it much better to buy it only during the day than to carry it over at night? Isn't it good to avoid risk? ** ** Also, for the past three years, most of the rise in the Nikkei Stock Average has been brought about at night, but in the last year the difference has gradually narrowed. ** In the corona shock, the Abenomics buying strategy is finally the global economy. You can see that the buying strategy has been greatly outperformed **! Mr. Abe, I'll do it (?).
Recommended Posts