
外為どっとコム用の時間帯別勝率ツール
外為どっとコムからダウンロードできる取引履歴をまとめてブチ込むと、
時間帯別の勝率を出せるツールを作りました。
東京時間午前・午後、欧州時間、NY時間とざっくり分けています。
※元々そういう機能あるぞ?って場合はごめんなさいw
準備と使い方
外為どっとコムのアプリケーションから約定履歴をダウンロードしてください。
ツール(後述)を起動すると、ファイル選択ダイアログが開きます。
先ほどダウンロードした履歴を選択して(複数選択可能)、開くを押します。
すると、結果がコンソールウィンドウに表示されます。
時間帯・取引回数・勝率・利益など。
このツールを使うにはPythonのインストールと、pandasの追加が必要です。Pythonは、無料でダウンロードできるので検索してインストールしてください。
pandasは、pythonをインストールした後にウインドウズマークをクリックしてcmdとキーを打ち、「pip install pandas」これをコピペしてください。
これで準備完了です。
以下にPythonコードを記載します。
知らないと、なんだコレ面倒くせえってなると思いますけど、
エディタにコピペして.pyと拡張子をつけて保存するだけです。
プログラムから開く→Pythonで使用してください。
import tkinter as tk
from tkinter import filedialog
import pandas as pd
# Function to select multiple files
def select_files():
root = tk.Tk()
root.withdraw() # Hide the main window
file_paths = filedialog.askopenfilenames() # Show the file selection dialog
return file_paths
# Function to categorize the hours into time slots
def categorize_hour(hour):
if 7 <= hour < 12:
return '07-12'
elif 12 <= hour < 16:
return '12-16'
elif 16 <= hour < 21:
return '16-21'
elif 21 <= hour or hour < 5: # 5時までを含むように変更
return '21-5'
else:
return 'other'
# Use the select_files function
file_paths = select_files()
dataframes = [] # List to store DataFrames
for file_path in file_paths:
# Load the CSV file with SHIFT-JIS encoding
df = pd.read_csv(file_path, encoding='SHIFT-JIS', skiprows=2)
# Remove the rows where '約定区分' is '新規'
df = df[df['約定区分'] != '新規']
# Convert the '決済約定日時' column to datetime
df['決済約定日時'] = pd.to_datetime(df['決済約定日時'], format='%y/%m/%d %H:%M:%S')
# Create a new column '勝ち負け' to show whether the trade is win(1) or loss(0)
df['勝ち負け'] = (df['スポット損益'] > 0).astype(int)
# Extract the hour from '決済約定日時'
df['hour'] = df['決済約定日時'].dt.hour
# Apply the function to the 'hour' column and create a new column '時間帯'
df['時間帯'] = df['hour'].apply(categorize_hour)
# Append the DataFrame to the list
dataframes.append(df)
# Concatenate all DataFrames
all_data = pd.concat(dataframes, ignore_index=True)
# Count the total number of trades per time slot for all data
total_count = all_data.groupby('時間帯').size()
# Count the number of wins per time slot for all data
win_count = all_data[all_data['勝ち負け'] == 1].groupby('時間帯').size()
# Calculate the win rate per time slot and convert it to percentage
win_rate = win_count / total_count
win_rate_percentage = win_rate.apply(lambda x: f'{x * 100:.2f}%')
# Calculate the total profit per time slot
total_profit = all_data[all_data['スポット損益'] > 0].groupby('時間帯')['スポット損益'].sum()
# Calculate the total loss per time slot
total_loss = all_data[all_data['スポット損益'] < 0].groupby('時間帯')['スポット損益'].sum()
# Calculate the net profit per time slot
net_profit = total_profit.fillna(0) + total_loss.fillna(0) # Here, total_loss is already a negative number
# Create a DataFrame to hold the results
results = pd.DataFrame({
'取引回数': total_count,
'勝率(%)': win_rate_percentage,
'利益合計(円)': total_profit,
'損失合計(円)': total_loss,
'純利益(円)': net_profit
})
# Fill NaN with 0
results = results.fillna(0)
# Fix the net profit to be same as total profit when total loss is 0
results.loc[results['損失合計(円)'] == 0, '純利益(円)'] = results['利益合計(円)']
print(results)
input("終了するにはウインドウを閉じてください")
統計を取る時間を変えたい人
if 7 <= hour < 12:
return '07-12'
elif 12 <= hour < 16:
return '12-16'
elif 16 <= hour < 21:
return '16-21'
elif 21 <= hour or hour < 5: # 5時までを含むように変更
return '21-5'
else:
return 'other'
ここをいじると統計を取る時間を変えられます。
スキを押してくれたら震えて喜びます。
よろしくお願いいたします。
追記
Pythonとか面倒くさいしわからんという人のためにexe版を用意しました。
https://90.gigafile.nu/1110-j4905eebb354403830172a9a3b130fc4e
8月2日アップロード(Ver.1)
exeをダウンロードしようとしたり、開こうとすると未知のスクリプトでアラートが出るかもしれません。自己責任で使用してください。
いいなと思ったら応援しよう!
