Last active
April 11, 2024 05:36
-
-
Save tak-akashi/142986ef7cc139ab25758129a634ec44 to your computer and use it in GitHub Desktop.
IMM通貨先物ポジション推移(ドル円)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import matplotlib.pyplot as plt | |
import matplotlib.dates as mdates | |
with open('annual.txt') as f: | |
data = f.readlines() | |
listy = [] | |
for i in range(len(data)): | |
if 'JAPANESE YEN - CHICAGO MERCANTILE EXCHANGE' in data[i]: | |
line_data = data[i].split(',') | |
dt = datetime.datetime.strptime(line_data[2],'%Y-%m-%d') | |
listy.append([dt,int(line_data[8])-int(line_data[9])]) | |
x = [] | |
y = [] | |
for i, j in listy: | |
x.append(i) | |
y.append(j) | |
plt.style.use('ggplot') | |
fig = plt.figure() | |
ax = fig.add_subplot(111) | |
ax.bar(x, y, width=4) | |
plt.title('IMM POSITION - JPY(NON-COMMERCIAL)', size=20) | |
plt.axhline(y=0, color='black') | |
# format your data to desired format. Here I chose YYYY-MM-DD but you can set it to whatever you want. | |
ax.xaxis.set_major_formatter(mdates.DateFormatter('%y-%m-%d')) | |
# rotate and align the tick labels so they look better | |
fig.autofmt_xdate() | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib3 | |
import requests | |
import zipfile, io, certifi | |
urllib3.disable_warnings() | |
url = 'https://www.cftc.gov/files/dea/history/deacot2018.zip' | |
res = requests.get(url) | |
z = zipfile.ZipFile(io.BytesIO(res.content)) | |
z.extractall() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
IMM通貨先物ポジション(ドル円)の推移を棒グラフで描画するスクリプトです。まず、CFTCのホームページからデータをスクレイピングして保存(import_cftc_file.py)。その後、データを取り出して描画する(imm_position.py)スクリプトです。