-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
67 lines (60 loc) · 2.04 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os
import sys
sys.path.append(os.getcwd())
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from src.DataReader import *
from src.Visualiser import *
from src.Trader import *
from test.MCS import *
reader = DataReader("./resources/DAT_XLSX_USDZAR_M1_2019.csv")
# reader = DataReader("./resources/SPY.csv")
# reader = DataReader("./resources/gemini_BTCUSD_1hr.csv")
indicators = pd.DataFrame()
mac = MovingAverageCrossover(reader.data["Close"], 10, 30)
# bbs = BollingerBand(reader.data["Close"], 90, 1)
# rsi = RelativeStrengthIndex(reader.data["Close"], 20)
# mom = Momentum(reader.data["Close"], 150)
idtf = IntradayTimeFilter("00:00", "00:00")
slp = 0.3*100
tlp = 0.8*100
tpp = 1.5*100
print("** Starting Trader ***")
trader = Trader(reader.data, starting_capital=1000, trading_mechanism=mac, intraday_time_filter=idtf,
stop_loss_percent=slp, trailing_loss_percent=tlp, take_profit_percent=tpp)
output_title = f"../nmrqltrading_results/results/{trader.trading_mechanism.fast_length}_{trader.trading_mechanism.slow_length}_{trader.stop_loss_percent}_{trader.trailing_loss_percent}_{trader.take_profit_percent}"
os.makedirs(output_title, exist_ok=True)
print("** Processing trades **")
tr = process_trade_results(trader)
f = open(f"{output_title}/trade_results.txt", 'w')
f.write(tr)
f.flush()
f.close()
print("** Running MCS **")
mcs = MCS(trader, 3)
print("** Plotting Trades Made **")
plot_made_trades(trader)
plt.savefig(f"{output_title}/made_trades.png")
plt.close()
print("** Plotting Equity Curve **")
plot_equity(trader)
plt.savefig(f"{output_title}/equity_curve.png")
plt.close()
print("** Plotting Drawdown Curve **")
plot_drawdown(trader)
plt.savefig(f"{output_title}/drawdown_curve.png")
plt.close()
print("** Plotting MCS **")
plot_monte_carlo(mcs)
plt.savefig(f"{output_title}/mcs.png")
plt.close()
print("** Plotting MAE **")
plot_mae(trader)
plt.savefig(f"{output_title}/mae.png")
plt.close()
print("** Plotting MFE **")
plot_mfe(trader)
plt.savefig(f"{output_title}/mfe.png")
plt.close()
print("** Plots completed **")