Last time tried to display the FX data of this site in Python. I used the data for 1 minute, but sometimes I wanted to convert it to any minute, so I will leave the implementation code.
Same as last time.
Graph display of HISTDATA_COM_ASCII_EURJPY_M1_201911.zip of this site To do. After downloading the data, execute the following.
import plotly.graph_objects as go
import pandas as pd
from datetime import datetime
df_one = df["2019-11-18": "2019-11-20"]
df_show = df_one
fig = go.Figure(data=[
    go.Candlestick(
        x=df_show.index,
        open=df_show.Open,
        high=df_show.High,
        low=df_show.Low,
        close=df_one.Close
    )
])
fig.show()
It will be displayed as follows.

You can convert it to 5 minutes using resample below. If you change the rate to 10T, 1H, etc., you can convert it to any foot.
df_five = pd.DataFrame()
rule = "5T"
df_five["Open"] = df_one["Open"].resample(rule).first()
df_five["Close"] = df_one["Close"].resample(rule).last()
df_five["High"] = df_one["High"].resample(rule).max()
df_five["Low"] = df_one["Low"].resample(rule).min()
Please do the following:
df_show = df_five
fig = go.Figure(data=[
    go.Candlestick(
        x=df_show.index,
        open=df_show.Open,
        high=df_show.High,
        low=df_show.Low,
        close=df_show.Close
    )
])
fig.show()
It will be displayed as follows.

I don't really understand the difference between 1 minute and 5 minutes, so let's compare the length and the beginning. 1 minute is ...
print(df_one.shape)
print(df_one.head())
'''
output: 
(4319, 5)
                        Open     High      Low    Close  Volume
datetime                                                       
2019-11-18 00:00:00  120.360  120.371  120.360  120.368       0
2019-11-18 00:01:00  120.368  120.372  120.360  120.360       0
2019-11-18 00:02:00  120.361  120.362  120.360  120.360       0
2019-11-18 00:03:00  120.360  120.376  120.360  120.376       0
2019-11-18 00:04:00  120.377  120.380  120.374  120.376       0
'''
5 minutes ...
print(df_five.shape)
print(df_five.head())
'''
output:
(864, 4)
                        Open    Close     High      Low
datetime                                               
2019-11-18 00:00:00  120.360  120.376  120.380  120.360
2019-11-18 00:05:00  120.376  120.382  120.387  120.369
2019-11-18 00:10:00  120.381  120.361  120.381  120.352
2019-11-18 00:15:00  120.361  120.354  120.365  120.341
2019-11-18 00:20:00  120.354  120.349  120.354  120.341
'''
It's about one-fifth the size, and the notch is also five minutes. Isn't it good?
that's all!
Recommended Posts