-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaccount.py
75 lines (60 loc) · 2.06 KB
/
account.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
68
69
70
71
72
73
74
75
import numpy as np
import pandas as pd
pd.set_option('expand_frame_repr', False)
pd.set_option('display.max_rows', 20000)
class QTAccount:
def __init__(self, init_settings=None):
"""
账户信息的初始化定义
"""
if not init_settings:
init_settings = {'date': 'init', 'cash': 0}
self.df = pd.DataFrame(data=None,
index=[0],
columns=['date', # 日期
'total_asset', # 总资产
'market_value', # 总市值
'float_profit_loss', # 浮动盈亏
'daily_profit_loss', # 当日盈亏
'cash', # 现金
]
)
self.df.loc[0, 'date'] = init_settings['date']
self.df.loc[0, 'cash'] = init_settings['cash']
self.df.loc[0, 'total_asset'] = init_settings['cash']
self.df.loc[0, 'market_value'] = 0
self.df.loc[0, 'float_profit_loss'] = 0
self.df.loc[0, 'daily_profit_loss'] = 0
def init_set(self, init_settings):
"""账户的初始化设置"""
self.set_cash(cash=init_settings['cash']) # 现金设置
def set_cash(self, cash):
"""更改最后一行的 cash 数据"""
self.df.loc[self.df.index[-1], 'cash'] = cash
def set_date(self, date):
"""更改最后一行的 date 数据"""
self.df.loc[self.df.index[-1], 'date'] = date
def update(self, new_line: pd.Series):
"""新增一行数据"""
self.df = self.df.append(other=new_line, ignore_index=True)
def buy(self, price, volume):
"""
发起多单委托
"""
pass
def sell(self, price, volume):
"""
发起空单委托
"""
pass
def clear(self, volume):
"""
发起平仓委托
"""
pass
if __name__ == '__main__':
qt_account_01 = QTAccount()
print(qt_account_01.df)
given_init_settings = {'date': '2021-01-01', 'cash': 10000}
qt_account_02 = QTAccount(init_settings=given_init_settings)
print(qt_account_02.df)