Convert FX 1-minute data to 5-minute data with Python


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.

1-minute data display

Graph display of 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=[

It will be displayed as follows. newplot (2).png

Convert from 1 minute to 5 minutes

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()

5-minute data display

Please do the following:

df_show = df_five

fig = go.Figure(data=[

It will be displayed as follows. newplot (3).png

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 ...


(4319, 5)
                        Open     High      Low    Close  Volume
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 ...


(864, 4)
                        Open    Close     High      Low
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

Convert FX 1-minute data to 5-minute data with Python
Convert Excel data to JSON with python
Convert list to DataFrame with python
Convert memo at once with Python 2to3
Convert Hiragana to Romaji with Python (Beta)
Convert HEIC files to PNG files with Python
Convert Chinese numerals to Arabic numerals with Python
Sample to convert image to Wavelet with Python
Data analysis with python 2
Convert 202003 to 2020-03 with pandas
Data analysis with Python
Convert data with shape (number of data, 1) to (number of data,) with numpy.
Convert PDF to image (JPEG / PNG) with Python
Convert PDFs to images in bulk with Python
Convert svg file to png / ico with Python
Convert Windows epoch values to date with python
I tried to get CloudWatch data with Python
Write CSV data to AWS-S3 with AWS-Lambda + Python
Convert strings to character-by-character list format with python
Sample data created with python
Connect to BigQuery with Python
[python] Convert date to string
Convert numpy int64 to python int
Connect to Wikipedia with Python
Get Youtube data with python
Convert csv, tsv data to matrix with python --using MovieLens as an example
How to convert horizontally held data to vertically held data with pandas
Post to slack with Python 3
Convert the image in .zip to PDF with Python
How to convert JSON file to CSV file with Python Pandas
Convert Scratch project to Python
[Python] Convert Shift_JIS to UTF-8
Backtesting FX Systre with Python (2)
PyInstaller memorandum Convert Python [.py] to [.exe] with 2 lines
Switch python to 2.7 with alternatives
Write to csv with Python
I tried to analyze J League data with Python
Convert python 3.x code to python 2.x
Read json data with python
I want to be able to analyze data with Python (Part 3)
I tried to make various "dummy data" with Python faker
20200329_Introduction to Data Analysis with Python Second Edition Personal Summary
I want to be able to analyze data with Python (Part 4)
Convert images to sepia toning with PIL (Python Imaging Library)
I want to be able to analyze data with Python (Part 2)
Convert video to black and white with ffmpeg + python + opencv
Get additional data to LDAP with python (Writer and Reader)
[Introduction to Python] How to get data with the listdir function
Convert .ipynb to .html (with BatchFile)
[Python] How to FFT mp3 data
Python: How to use async with
Link to get started with python
Convert markdown to PDF in Python
[Python] Write to csv file with Python
Create folders from '01' to '12' with python
Nice to meet you with python
Try to operate Facebook with Python
Output to csv file with Python
How to deal with imbalanced data
How to deal with imbalanced data
[Python] Get economic data with DataReader