-
Notifications
You must be signed in to change notification settings - Fork 0
/
portfolio.py
53 lines (41 loc) · 1.25 KB
/
portfolio.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
import enum
import pandas as pd
# from strategy import SimpleStrategy
class Portfolio():
def __init__(self, start_cash=1000, broker=None):
self.init_cash = start_cash
self.value = start_cash
self.cash = start_cash
self.history = []
def reset(self):
self.cash = self.init_cash
self.history = []
def setcash(self, value):
self.cash = value
def getcash(self):
return self.cash
def addcash(self, value):
self.cash += value
class Order():
def __init__(self, symbol="", size=0, ordertype=None, delay=0, lossprice=None, target=None, comment=""):
self.size = abs(size)
self.symbol = symbol
self.status = OrderStatus(0)
self.ordertype = ordertype or ("buy","sell")[size<0]
self.limit = None
self.stoploss = None
self.delay = delay
self.lossprice = lossprice
self.target = target
self.comment = comment
class OrderStatus(enum.Enum):
Created = 0
Submitted = 1
Accepted = 2
Completed = 3
Rejected = 4
########################################################
if __name__ == "__main__":
order = Order(size=-10)
print(order.ordertype)
print(OrderStatus(0))