129 строки
3 КиБ
Python
129 строки
3 КиБ
Python
import pandas as pd
|
|
import matplotlib.pyplot as plt
|
|
import os
|
|
|
|
# --- folder for charts
|
|
output_dir = "C:\\data\\charts\\"
|
|
os.makedirs(output_dir, exist_ok=True)
|
|
|
|
|
|
symbol = "EURUSD"
|
|
name_strategy = "EMA"
|
|
file_strategy = name_strategy+"_"+symbol
|
|
title_strategy = " ("+symbol+" "+name_strategy+" strategy+filters)"
|
|
file_prefix = symbol+"_"+name_strategy+"_"
|
|
|
|
# --- files
|
|
files = [
|
|
"C:\\data\\0_"+file_strategy+".txt",
|
|
"C:\\data\\1_"+file_strategy+".txt",
|
|
"C:\\data\\2_"+file_strategy+".txt",
|
|
"C:\\data\\3_"+file_strategy+".txt"
|
|
]
|
|
|
|
# --- labels
|
|
labels = [
|
|
"No filters",
|
|
"Open L1 filter",
|
|
"Close L1 filter",
|
|
"Open+Close L1 filter"
|
|
]
|
|
|
|
# --- load data
|
|
def load_file(filename):
|
|
df = pd.read_csv(
|
|
filename,
|
|
sep=";",
|
|
header=None,
|
|
names=[
|
|
"time",
|
|
"balance",
|
|
"equity",
|
|
"margin",
|
|
"free_margin",
|
|
"margin_level",
|
|
"volume",
|
|
"close"
|
|
]
|
|
)
|
|
df["time"] = pd.to_datetime(df["time"])
|
|
return df
|
|
|
|
# --- close price chart
|
|
plt.figure(figsize=(10,6), dpi=100)
|
|
for file, label in zip(files, labels):
|
|
df = load_file(file)
|
|
plt.plot(df["time"], df["close"], color='gray')
|
|
plt.title(symbol+" Close Price")
|
|
plt.xlabel("Time")
|
|
plt.ylabel("Close price")
|
|
plt.legend()
|
|
plt.grid()
|
|
plt.tight_layout()
|
|
plt.savefig(output_dir + file_prefix+"close_price.png", dpi=100)
|
|
plt.show()
|
|
|
|
# --- balance chart
|
|
plt.figure(figsize=(10,6), dpi=100)
|
|
for file, label in zip(files, labels):
|
|
df = load_file(file)
|
|
plt.plot(df["time"], df["balance"], label=label)
|
|
plt.title("Balance" + title_strategy)
|
|
plt.xlabel("Time")
|
|
plt.ylabel("Balance")
|
|
plt.legend()
|
|
plt.grid()
|
|
plt.tight_layout()
|
|
plt.savefig(output_dir + file_prefix+"balance.png", dpi=100)
|
|
plt.show()
|
|
plt.close()
|
|
|
|
# --- equity chart
|
|
plt.figure(figsize=(10,6), dpi=100)
|
|
for file, label in zip(files, labels):
|
|
df = load_file(file)
|
|
plt.plot(df["time"], df["equity"], label=label)
|
|
plt.title("Equity" + title_strategy)
|
|
plt.xlabel("Time")
|
|
plt.ylabel("Equity")
|
|
plt.legend()
|
|
plt.grid()
|
|
plt.tight_layout()
|
|
plt.savefig(output_dir + file_prefix+"equity.png", dpi=100)
|
|
plt.show()
|
|
plt.close()
|
|
|
|
|
|
#--- balance + equity chart
|
|
plt.figure(figsize=(10,6), dpi=100)
|
|
for i, (file, label) in enumerate(zip(files, labels)):
|
|
|
|
df = load_file(file)
|
|
# --- get matplotlib color
|
|
color = plt.rcParams["axes.prop_cycle"].by_key()["color"][i % 10]
|
|
#--- equity — solid line
|
|
plt.plot(
|
|
df["time"],
|
|
df["equity"],
|
|
color=color,
|
|
linestyle="-",
|
|
label=f"{label} equity"
|
|
)
|
|
#--- balance — dashed line
|
|
plt.plot(
|
|
df["time"],
|
|
df["balance"],
|
|
color=color,
|
|
linestyle="--",
|
|
label=f"{label} balance"
|
|
)
|
|
plt.title("Balance + Equity" + title_strategy)
|
|
plt.xlabel("Time")
|
|
plt.ylabel("Value")
|
|
plt.legend()
|
|
plt.grid()
|
|
plt.tight_layout()
|
|
plt.savefig(output_dir+file_prefix+"balance_equity.png", dpi=100)
|
|
plt.show()
|
|
plt.close()
|
|
|