[PYTHON] [Introduction to Systre] Exchange rates and stocks: Behavior during a crash ♬

Is it the same? ??

With the announcement of quitting, both exchange rates and stocks fell all at once.

At that time, I don't know the reason, but I would like to summarize that the time series data of exchange rates and stocks show the same behavior. And, in terms of data science, I would like to think about what kind of analysis should be done in such cases.

What i did

・ Exchange rate crash data ・ Stock market crash data ・ One analysis ・ Another analysis ・ About the factors of similarity

・ Exchange rate crash data

It started at about the same time the news was reported August 28, 14:06 Signs; 14: 06: 05.637 Start: 14: 07: 17.348 End: 14: 07: 45.083 The graph below is a graph of exchange rate changes after this decline. All the graphs have almost the same curve, which is intriguing for data scientists.

・ Stock market crash data

When I examined the stock market crash curve, I found that it also drew a curve very similar to the exchange rate, as shown below. Since the trading of this data ends at 15:00, it is cut off in the middle compared to the exchange rate. ntt.png 6.png nihonkouku.png mitsubishiufj.png nissan.png

・ One analysis

Exchange rates and stock prices seem to have different rates of decline, but they seem to have characteristics such as whether the movement after the decline is rising, falling, or having a vibration component.

Data analysis policy ① Analysis of time series data was done in the following article before ・ [Introduction to element decomposition] Arrange time series analysis methods with R and python ♬ That is, it decomposes into trend, seasonal, and noize. (2) I think that the same behavior means that the trend and seasonal (if any) other than noize are the same. ③ You can see a big flow of trend, whether it is up or down. ④ And seasonal will show regular fluctuations like periodic vibrations. ⑤ Furthermore, it seems that the following method can be used as a test of whether the variable elements of the time series are periodic. ・ [Introduction to R language] Time-series analysis of changes in the number of deaths ♬

** I would like to carry out this analysis as soon as the data is available **

・ Another analysis

It is to make a Gif animation as follows and compare the direct behavior. Even if you arrange them side by side, you can see different features that are difficult to see. The code is below.

from PIL import Image

st_list=['1','2','3','4','5','6','7','8','9']
images = []
s = len(st_list)+1
for i in st_list:
    im = Image.open('./datascientist/fx/{}.png'.format(i)) 
    im =im.resize(size=(774, 417), resample=Image.NEAREST)
    images.append(im)
images[0].save('./datascientist/fxstock.gif', save_all=True, append_images=images[1:s], duration=100*5, loop=0)

The result is as follows. I dare to hide the brand. fxstock-.gif Although the stocks have been turned down, we can see that the characteristics of exchange rates and stock prices are very different. That is, (1) The exchange rate has fallen very sharply (within 1 minute), but the stock price has fallen in about 3 minutes. (2) The behavior after the decline is very similar. Repulsion (red bar graph) occurs 5 minutes after the start of the decline (3) In particular, the change in MACD will be the same behavior including the time axis that the MACD changes from negative to positive at the same time (around 11 minutes after the start of the decline), then becomes negative again, and then changes positive again. It seems that it has become.

・ About the factors of similarity

This is just a delusion, so you might not want to write it, but the following are possible. (1) A major company (investor who can move huge money) buys and sells with a similar program (it seems that the way of thinking and the code are similar) (2) Since Mr. Abe's announcement was an important matter report of the highest-ranking important person, it is considered to be a so-called'emergency', and it seems that "emergency yen buying" and "emergency profitability" are thoroughly implemented. (3) And it was a sudden announcement within the trading hours, and I could not afford to think about other strategies other than the means of (2).

And, as you can't tell from the above data, especially the stock price ④ It means "continuation of emergency" How long it will last, each behavior has already changed for each brand, and there is currently no data-friendly material to predict what will happen in the future. Actually, you may be able to see it if you follow each data carefully. .. ..

Summary

・ In the case of historical exchange rates and stock price fluctuations, I tried to arrange the behavior of exchange rates and stock prices when they crashed. ・ It can be said that the behavior between exchanges is the same regardless of the brand on the time axis of about 1 hour. ・ The behavior between stock prices showed similar behavior. ・ The behavior of foreign exchange and stock prices at the time of decline was slightly different, but the behavior after the decline was very similar including the time axis.

・ For details on the behavior at the time of decline, I would like to carry out after obtaining the data. ・ Emergency exchange rates and stock price fluctuations are thought to be similar to the behavior this time, so I will investigate.

Recommended Posts

[Introduction to Systre] Exchange rates and stocks: Behavior during a crash ♬
[Introduction to Tensorflow] Understand Tensorflow properly and try to make a model
A quick introduction to pytest-mock
A super introduction to Linux
[Introduction to Systre] Fibonacci Retracement ♬
[Introduction to Python3 Day 1] Programming and Python
A light introduction to object detection
[Introduction to Python] What is the difference between a list and a tuple?
Get exchange rates on Heroku regularly and upload logs to Amazon S3