Display candlesticks for FX (forex) data in Python

Overview

Forex data on this site Display candlesticks.

environment

For the time being, move the sample that displays stock price data

Regarding the display, this post is described in more detail. The sample of Site here is displayed as it is.

fig.py


import plotly.graph_objects as go

import pandas as pd
from datetime import datetime

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')

fig = go.Figure(data=[go.Candlestick(x=df['Date'],
                open=df['AAPL.Open'],
                high=df['AAPL.High'],
                low=df['AAPL.Low'],
                close=df['AAPL.Close'])])

fig.show()

It was displayed as follows. newplot.png

Display FX data

Display HISTDATA_COM_ASCII_EURJPY_M1_201911.zip of this site I would like to try. To do this, first convert the contents of the zip file to pd.DataFrame.

import pandas as pd
from zipfile import ZipFile
ascii_minute_names = ["datetime_str", "Open", "High", "Low", "Close", "Volume"]
ascii_minute_datetime_format = "%Y%m%d %H%M%S"

with ZipFile("HISTDATA_COM_ASCII_EURJPY_M1201911.zip", 'r') as z:
    with z.open("DAT_ASCII_EURJPY_M1_201911.csv") as f:
        df = pd.read_csv(f, names=ascii_minute_names, sep=";")
        df["datetime"] = pd.to_datetime(df.datetime_str, format=ascii_minute_datetime_format)
        df = df.set_index("datetime")
        del df["datetime_str"]

print(df.head())

"""
output:
                        Open     High      Low    Close  Volume
datetime                                                       
2019-11-01 00:00:00  120.599  120.601  120.595  120.598       0
2019-11-01 00:01:00  120.597  120.598  120.592  120.595       0
2019-11-01 00:02:00  120.597  120.603  120.597  120.601       0
2019-11-01 00:03:00  120.600  120.600  120.592  120.598       0
2019-11-01 00:04:00  120.597  120.603  120.593  120.597       0
"""

Display! * It takes time to execute because the data is large.

import plotly.graph_objects as go

import pandas as pd
from datetime import datetime

fig = go.Figure(data=[
    go.Candlestick(
        x=df.index,
        open=df.Open,
        high=df.High,
        low=df.Low,
        close=df.Close
    )
])

fig.show()

It was displayed as follows.

newplot (1).png

that's all!

Recommended Posts

Display candlesticks for FX (forex) data in Python
Display UTM-30LX data in Python
Receive and display HTML form data in Python
Create your own Big Data in Python for validation
Handle Ambient data in Python
Python for Data Analysis Chapter 4
Search for strings in Python
Techniques for sorting in Python
Python for Data Analysis Chapter 2
Backtesting FX Systre in Python (1)
About "for _ in range ():" in python
Python for Data Analysis Chapter 3
[Understand in the shortest time] Python basics for data analysis
Get Leap Motion data in Python.
Check for memory leaks in Python
Check for external commands in python
Read Protocol Buffers data in Python3
Get data from Quandl in Python
FX Systre Parameter Optimization in Python
Handle NetCDF format data in Python
Python course for data science_useful techniques
Waveform display of audio in Python
Display characters like AA in python
Hashing data in R and Python
Preprocessing template for data analysis (Python)
Data formatting for Python / color plots
Run unittests in Python (for beginners)
Install Networkx in Python 3.7 environment for use in malware data science books
Display LaTeX notation formulas in Python, matplotlib
Get additional data in LDAP with python
Data input / output in Python (CSV, JSON)
Ant book in python: Sec. 2-4, data structures
Notes on nfc.ContactlessFrontend () for nfcpy in python
Try working with binary data in Python
Display a list of alphabets in Python 3
Tips for dealing with binaries in Python
Display Python 3 in the browser with MAMP
Summary of various for statements in Python
Type annotations for Python2 in stub files!
Get Google Fit API data in Python
Template for writing batch scripts in python
Convert FX 1-minute data to 5-minute data with Python
Python: Preprocessing in machine learning: Data acquisition
How to display multiplication table in python
Get Youtube data in Python using Youtube Data API
Memo of pixel position operation for image data in Python (numpy, cv2)
Detailed Python techniques required for data shaping (1)
Process multiple lists with for in Python
MongoDB for the first time in Python
Easily graph data in shell and Python
Get a token for conoha in python
Sample for handling eml files in Python
AtCoder cheat sheet in python (for myself)
I searched for prime numbers in python
How to use "deque" for Python data
Notes for using python (pydev) in eclipse
Display pyopengl in a browser (python + eel)
Python: Preprocessing in machine learning: Data conversion
Tips for making small tools in python
Use pathlib in Maya (Python 2.7) for upcoming Python 3.7
Detailed Python techniques required for data shaping (2)