-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtrader.py
More file actions
49 lines (46 loc) · 2.13 KB
/
trader.py
File metadata and controls
49 lines (46 loc) · 2.13 KB
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
from account_models import TopstepAccount
class Trader:
def __init__(self, strat, acct_rules, acct_fees):
self.strategy = strat
self.fees = acct_fees
self.PnL = -acct_fees['Eval Acct Cost']
self.account = TopstepAccount(acct_rules)
self.per_side_cost = acct_fees['Per Side Trade Cost']
self.entry_slippage = acct_fees['Trade Entry Slippage']
self.stop_slippage = acct_fees['Trade Stop Slippage']
self.months_traded = 0
self.running_balance = []
self.passed_eval = False
def trade_for_day(self):
finished_day_without_stop_condition = True
if ((self.account.total_days // 30) > self.months_traded) and self.account.in_eval:
self.months_traded += 1
self.PnL -= self.fees['Monthly Eval Cost']
for i in range(self.strategy.trades_per_day):
trade_return = self.strategy.simulate_return(self.per_side_cost, self.entry_slippage, self.stop_slippage)
sim_mfe = 0
if self.account.in_eval and trade_return < 0:
sim_mfe = self.strategy.simulate_favorable_excursion()
result = self.account.trade(trade_return, sim_mfe)
if result == 'PASS EVAL':
self.PnL -= self.fees['Funded Acct Setup Cost']
finished_day_without_stop_condition = False
self.passed_eval = True
break
elif result == 'FAIL':
finished_day_without_stop_condition = False
break
elif result == 'DAILY LOSS LIMIT STOP':
finished_day_without_stop_condition = False
break
elif result == 'DAILY WIN STOP':
finished_day_without_stop_condition = False
break
elif result == 'SUCCEED':
self.PnL += self.account.funded_full_payout()
finished_day_without_stop_condition = False
break
if finished_day_without_stop_condition:
self.account.end_of_day_update()
if not self.account.in_eval:
self.running_balance.append(self.account.balance)