0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

超初心者がPythonでHistData.comから取得した1分足データを5分足データに変換してみた

Last updated at Posted at 2021-07-20

1分足だとグラフ化の際にデータ数が多すぎてみづらかったので5分足にする。

参考

以下で作成したコードを利用しています。

コード

import pandas as pd
import datetime
import mplfinance as mpf

# CSVから読み込み
df = pd.read_csv('./temp_historical_data/USDJPY.csv', nrows=1000)
df.columns = ['Date', 'Open', 'High', 'Low', 'Close', 'Volume']
df['Date'] = pd.to_datetime(df['Date'])
df.set_index('Date', inplace=True)

# 5分足変換
df5 = pd.DataFrame()
rule = '5T'
df5['Open'] = df['Open'].resample(rule).first()
df5['Close'] = df['Close'].resample(rule).last()
df5['High'] = df['High'].resample(rule).max()
df5['Low'] = df['Low'].resample(rule).min()

mpf.plot(df5, type='candle', datetime_format='%Y/%m/%d %H:%M', xrotation=90, style='yahoo', savefig=dict(fname='./figures/draw_sma.png',dpi=100))

簡単な説明

Dateはいじらなくて大丈夫っぽい?ただし、元データ(ここではdf)にDatetime型のindexを設定しておかないとだめなようだった。

0
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?