-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbacktest.py
More file actions
20 lines (16 loc) · 774 Bytes
/
backtest.py
File metadata and controls
20 lines (16 loc) · 774 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Backtrading:
def __init__(self, cash, commission, equity=0):
self.cash = cash # баланс в деньгах
self.equity = equity # кол-во манеток в портфеле
self.commission = commission # комиссия
# self.buy_trades_x = []
# self.buy_trades_y = []
# self.sell_trades_x = []
# self.sell_trades_y = []
def buy(self, quantity, price):
self.cash = self.cash - price * quantity - price * quantity * self.commission
self.equity = self.equity + quantity
def sell(self, quantity, price):
self.cash = self.cash + price * quantity - price * quantity * self.commission
self.equity = self.equity - quantity
#def imitation_step(self,step):