capdata 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- capdata-0.1.0/PKG-INFO +7 -0
- capdata-0.1.0/README.md +11 -0
- capdata-0.1.0/capdata.egg-info/PKG-INFO +7 -0
- capdata-0.1.0/capdata.egg-info/SOURCES.txt +22 -0
- capdata-0.1.0/capdata.egg-info/dependency_links.txt +1 -0
- capdata-0.1.0/capdata.egg-info/requires.txt +2 -0
- capdata-0.1.0/capdata.egg-info/top_level.txt +2 -0
- capdata-0.1.0/data/__init__.py +2 -0
- capdata-0.1.0/data/curve.py +48 -0
- capdata-0.1.0/data/market.py +42 -0
- capdata-0.1.0/data/pricing.py +49 -0
- capdata-0.1.0/data/refer.py +44 -0
- capdata-0.1.0/data/risk.py +107 -0
- capdata-0.1.0/data/token.py +7 -0
- capdata-0.1.0/request/__init__.py +4 -0
- capdata-0.1.0/request/request.py +36 -0
- capdata-0.1.0/setup.cfg +4 -0
- capdata-0.1.0/setup.py +24 -0
- capdata-0.1.0/test/test_auth.py +8 -0
- capdata-0.1.0/test/test_curve.py +31 -0
- capdata-0.1.0/test/test_market.py +21 -0
- capdata-0.1.0/test/test_pricing.py +25 -0
- capdata-0.1.0/test/test_refer.py +37 -0
- capdata-0.1.0/test/test_risk.py +60 -0
capdata-0.1.0/PKG-INFO
ADDED
capdata-0.1.0/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
setup.py
|
|
3
|
+
capdata.egg-info/PKG-INFO
|
|
4
|
+
capdata.egg-info/SOURCES.txt
|
|
5
|
+
capdata.egg-info/dependency_links.txt
|
|
6
|
+
capdata.egg-info/requires.txt
|
|
7
|
+
capdata.egg-info/top_level.txt
|
|
8
|
+
data/__init__.py
|
|
9
|
+
data/curve.py
|
|
10
|
+
data/market.py
|
|
11
|
+
data/pricing.py
|
|
12
|
+
data/refer.py
|
|
13
|
+
data/risk.py
|
|
14
|
+
data/token.py
|
|
15
|
+
request/__init__.py
|
|
16
|
+
request/request.py
|
|
17
|
+
test/test_auth.py
|
|
18
|
+
test/test_curve.py
|
|
19
|
+
test/test_market.py
|
|
20
|
+
test/test_pricing.py
|
|
21
|
+
test/test_refer.py
|
|
22
|
+
test/test_risk.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import request.request as rq
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
获取债券收益率曲线
|
|
5
|
+
参数:
|
|
6
|
+
curve -- 曲线编码
|
|
7
|
+
start -- 开始时间
|
|
8
|
+
end -- 结束时间
|
|
9
|
+
freq -- 频率(1m, 1d, 1w)
|
|
10
|
+
window -- 时间窗口 ['10:00:00','10:30:00']
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def get_bond_curve(curve, start, end, token, freq='1d', window=None):
|
|
15
|
+
data_json = {'curve': curve, 'start': start, 'end': end, 'freq': freq, 'window': window}
|
|
16
|
+
return rq.post("/capdata/get/bond/curve", data_json, token)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
"""
|
|
20
|
+
获取信用利差曲线
|
|
21
|
+
参数:
|
|
22
|
+
curve -- 曲线编码
|
|
23
|
+
start -- 开始时间
|
|
24
|
+
end -- 结束时间
|
|
25
|
+
freq -- 频率(1m, 1d, 1w)
|
|
26
|
+
window -- 时间窗口 ['10:00:00','10:30:00']
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def get_credit_curve(curve, start, end, token, freq='1d', window=None):
|
|
31
|
+
data_json = {'curve': curve, 'start': start, 'end': end, 'freq': freq, 'window': window}
|
|
32
|
+
return rq.post("/capdata/get/credit/curve", data_json, token)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
"""
|
|
36
|
+
获取利率收益率曲线
|
|
37
|
+
参数:
|
|
38
|
+
curve -- 曲线编码
|
|
39
|
+
start -- 开始时间
|
|
40
|
+
end -- 结束时间
|
|
41
|
+
freq -- 频率(1m, 1d, 1w)
|
|
42
|
+
window -- 时间窗口 ['10:00:00','10:30:00']
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def get_ir_curve(curve, start, end, token, freq='1d', window=None):
|
|
47
|
+
data_json = {'curve': curve, 'start': start, 'end': end, 'freq': freq, 'window': window}
|
|
48
|
+
return rq.post("/capdata/get/ir/curve", data_json, token)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import request.request as rq
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
获取历史行情数据
|
|
5
|
+
参数:
|
|
6
|
+
inst -- 产品编码列表 ['200310.IB', '190008.IB']
|
|
7
|
+
|
|
8
|
+
start -- 开始时间 2024-05-09
|
|
9
|
+
|
|
10
|
+
end -- 结束时间 2024-05-10
|
|
11
|
+
|
|
12
|
+
fields -- 需要返回的字段(open、close、high、low、pre_adj_close、post_adj_close、volume、turnover、num_trades、settlement、
|
|
13
|
+
open_interest、bid、ask、bid_size、ask_size、trade、trade_size、level1、level2、level2_5、level2_10、lix) ['bid','ask']
|
|
14
|
+
|
|
15
|
+
freq -- 频率( 1m, 1d, 1w)
|
|
16
|
+
|
|
17
|
+
window -- 时间窗口 ['10:00:00','10:30:00']
|
|
18
|
+
|
|
19
|
+
mkt -- 市场
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def get_hist_mkt(inst, start, end, fields, token, window=None, mkt=None, freq="1d"):
|
|
24
|
+
data_json = {'inst': inst, 'start': start, 'end': end, 'freq': freq, 'window': window, 'mkt': mkt,
|
|
25
|
+
'fields': fields}
|
|
26
|
+
return rq.post("/capdata/get/hist/mkt", data_json, token)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
"""
|
|
30
|
+
获取日内实时行情数据
|
|
31
|
+
参数:
|
|
32
|
+
inst -- 产品编码列表 ['200310.IB', '190008.IB']
|
|
33
|
+
|
|
34
|
+
fields -- 需要返回的字段(bid、ask、level1、level2、level2_5、level2_10、lix) ['bid','ask']
|
|
35
|
+
|
|
36
|
+
mkt -- 市场
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def get_live_mkt(inst, fields, token, mkt=""):
|
|
41
|
+
data_json = {'inst': inst, 'mkt': mkt, 'fields': fields}
|
|
42
|
+
return rq.post("/capdata/get/live/mkt", data_json, token)
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import request.request as rq
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
获取产品定价数据
|
|
5
|
+
参数:
|
|
6
|
+
inst -- 产品编码列表 ['2292030.IB', '2292012.IB']
|
|
7
|
+
|
|
8
|
+
start -- 开始时间 2024-05-26
|
|
9
|
+
|
|
10
|
+
end -- 结束时间 2024-05-29
|
|
11
|
+
|
|
12
|
+
fields -- 需要返回的字段(price、duration、modified_duration、macaulay_duration、convexity、z_spread、dv01、bucket_dv01、cs01、
|
|
13
|
+
bucket_cs01、delta、gamma、vega、term_bucket_vega、term_strike_bucket_vega、volga、term_bucket_volga、term_strike_bucket_volga、
|
|
14
|
+
vanna、term_bucket_vanna、term_strike_bucket_vanna、rho) ['duration','modified_duration']
|
|
15
|
+
|
|
16
|
+
freq -- 频率( 1m, 1d, 1w)
|
|
17
|
+
|
|
18
|
+
window -- 时间窗口 ['10:00:00','10:30:00']
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def get_pricing(inst, start, end, fields, token, window=None, mkt=None, freq="1d"):
|
|
23
|
+
data_json = {'inst': inst, 'start': start, 'end': end, 'freq': freq, 'window': window, 'mkt': mkt,
|
|
24
|
+
'fields': fields}
|
|
25
|
+
return rq.post("/capdata/get/pricing", data_json, token)
|
|
26
|
+
|
|
27
|
+
"""
|
|
28
|
+
获取产品估值数据
|
|
29
|
+
参数:
|
|
30
|
+
inst -- 产品编码列表 ['2292030.IB', '2292012.IB']
|
|
31
|
+
|
|
32
|
+
start -- 开始时间 2024-05-26
|
|
33
|
+
|
|
34
|
+
end -- 结束时间 2024-05-29
|
|
35
|
+
|
|
36
|
+
fields -- 需要返回的字段(present_value、dv01、bucket_dv01、frtb_bucket_dv01、cs01、bucket_cs01、frtb_bucket_cs01、delta、frtb_delta、
|
|
37
|
+
gamma、frtb_curvature、vega、term_bucket_vega、term_strike_bucket_vega、frtb_vega、volga、term_bucket_volga、term_strike_bucket_volga、
|
|
38
|
+
vanna、term_bucket_vanna、term_strike_bucket_vanna、rho) ['dv01','cs01']
|
|
39
|
+
|
|
40
|
+
freq -- 频率( 1m, 1d, 1w)
|
|
41
|
+
|
|
42
|
+
window -- 时间窗口 ['10:00:00','10:30:00']
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def get_valuation(inst, start, end, fields, token, window=None, mkt=None, freq="1d"):
|
|
47
|
+
data_json = {'inst': inst, 'start': start, 'end': end, 'freq': freq, 'window': window, 'mkt': mkt,
|
|
48
|
+
'fields': fields}
|
|
49
|
+
return rq.post("/capdata/get/valuation", data_json, token)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import request.request as rq
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
获取指定日历下的假期数据
|
|
5
|
+
参数:
|
|
6
|
+
calendar -- 日历 CFETS
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def get_holidays(calendar, token):
|
|
11
|
+
return rq.post("/capdata/get/holidays/" + calendar, None, token)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
"""
|
|
15
|
+
获取基准利率定义数据
|
|
16
|
+
参数:
|
|
17
|
+
ir_index -- 基准利率编码列表 ['USDLIBOR_2W','SIBOR_12M']
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def get_ir_index(ir_index, token):
|
|
22
|
+
return rq.post("/capdata/get/ir/index", ir_index, token)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
"""
|
|
26
|
+
获取产品信息参考数据
|
|
27
|
+
参数:
|
|
28
|
+
inst -- 产品编码列表 ['zc17060604.SH','zc17021505.SH']
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def get_instrument(inst, token):
|
|
33
|
+
return rq.post("/capdata/get/instrument", inst, token)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
"""
|
|
37
|
+
获取产品模板参考数据
|
|
38
|
+
参数:
|
|
39
|
+
inst -- 模板编码列表 ['CNY_FR_007_SWAP','SHIBOR_USDLIBOR_3M_SWAP','USDCNY_CASH','CN_TREAS_ZERO','EUR_CASH_DEPO']
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def get_inst_template(inst, token):
|
|
44
|
+
return rq.post("/capdata/get/inst/template", inst, token)
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import request.request as rq
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
获取历史模拟的利率收益率曲线数据
|
|
5
|
+
参数:
|
|
6
|
+
curve -- 曲线编码 CN_TREAS_STD
|
|
7
|
+
sim_date -- 情景时间 2024-05-28
|
|
8
|
+
num_sims -- 情景数 200
|
|
9
|
+
base_date -- 基础时间 2024-05-27
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def get_hist_sim_ir_curve(curve, sim_date, base_date, token, num_sims=200):
|
|
14
|
+
data_json = {'curve': curve, 'simDate': sim_date, 'baseDate': base_date, 'numSims': num_sims}
|
|
15
|
+
return rq.post("/capdata/get/hist/sim/ir/curve", data_json, token)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
"""
|
|
19
|
+
获取历史模拟的信用利差曲线数据
|
|
20
|
+
参数:
|
|
21
|
+
curve -- 曲线编码 CN_CORP_AAA_SPRD_STD
|
|
22
|
+
sim_date -- 情景时间 2024-05-28
|
|
23
|
+
num_sims -- 情景数 200
|
|
24
|
+
base_date -- 基础时间 2024-05-27
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def get_hist_sim_credit_curve(curve, sim_date, base_date, token, num_sims=200):
|
|
29
|
+
data_json = {'curve': curve, 'simDate': sim_date, 'baseDate': base_date, 'numSims': num_sims}
|
|
30
|
+
return rq.post("/capdata/get/hist/sim/credit/curve", data_json, token)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
"""
|
|
34
|
+
获取历史压力情景下利率收益率曲线数据
|
|
35
|
+
参数:
|
|
36
|
+
curve -- 曲线编码 CN_TREAS_STD
|
|
37
|
+
sim_date -- 情景时间 2024-05-28
|
|
38
|
+
num_sims -- 情景数 200
|
|
39
|
+
base_date -- 基础时间 2024-05-27
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def get_hist_stressed_ir_curve(curve, sim_date, base_date, token, num_sims=200):
|
|
44
|
+
data_json = {'curve': curve, 'simDate': sim_date, 'baseDate': base_date, 'numSims': num_sims}
|
|
45
|
+
return rq.post("/capdata/get/hist/stressed/ir/curve", data_json, token)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
"""
|
|
49
|
+
获取历史压力情景下信用利差曲线数据
|
|
50
|
+
参数:
|
|
51
|
+
curve -- 曲线编码 CN_CORP_AAA_SPRD_STD
|
|
52
|
+
sim_date -- 情景时间 2024-05-28
|
|
53
|
+
num_sims -- 情景数 200
|
|
54
|
+
base_date -- 基础时间 2024-05-27
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def get_hist_stressed_credit_curve(curve, sim_date, base_date, token, num_sims=200):
|
|
59
|
+
data_json = {'curve': curve, 'simDate': sim_date, 'baseDate': base_date, 'numSims': num_sims}
|
|
60
|
+
return rq.post("/capdata/get/hist/stressed/credit/curve", data_json, token)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
"""
|
|
64
|
+
获取产品模拟情景下损益数据
|
|
65
|
+
参数:
|
|
66
|
+
inst -- 产品编码 ['2171035.IB','2105288.IB']
|
|
67
|
+
sim_date -- 情景时间 2024-05-28
|
|
68
|
+
num_sims -- 情景数 200
|
|
69
|
+
base_date -- 基础时间 2024-05-27
|
|
70
|
+
"""
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def get_hist_sim_pnl(inst, sim_date, base_date, token, num_sims=200):
|
|
74
|
+
data_json = {'inst': inst, 'simDate': sim_date, 'baseDate': base_date, 'numSims': num_sims}
|
|
75
|
+
return rq.post("/capdata/get/inst/sim/pnl", data_json, token)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
"""
|
|
79
|
+
获取产品模拟情景下损益数据
|
|
80
|
+
参数:
|
|
81
|
+
inst -- 产品编码 ['2171035.IB','2105288.IB']
|
|
82
|
+
sim_date -- 情景时间 2024-05-28
|
|
83
|
+
num_sims -- 情景数 200
|
|
84
|
+
base_date -- 基础时间 2024-05-27
|
|
85
|
+
"""
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def get_hist_stressed_pnl(inst, sim_date, base_date, token, num_sims=200):
|
|
89
|
+
data_json = {'inst': inst, 'simDate': sim_date, 'baseDate': base_date, 'numSims': num_sims}
|
|
90
|
+
return rq.post("/capdata/get/inst/stressed/pnl", data_json, token)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
"""
|
|
94
|
+
获取产品Value-at-Risk数据
|
|
95
|
+
参数:
|
|
96
|
+
inst -- 产品编码 2171035.IB
|
|
97
|
+
sim_date -- 情景时间 2024-05-28
|
|
98
|
+
base_date -- 基础时间 2024-05-27
|
|
99
|
+
fields -- 响应字段 (var, mirror_var, stressed_var, mirror_stressed_var, es, mirror_es, stressed_es, mirror_stressed_es) ['var','es']
|
|
100
|
+
confidence_interval -- 置信区间 0.95
|
|
101
|
+
"""
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def get_hist_var(inst, sim_date, base_date, fields, token, confidence_interval=0.95):
|
|
105
|
+
data_json = {'inst': inst, 'simDate': sim_date, 'baseDate': base_date, 'fields': fields,
|
|
106
|
+
'confidenceInterval': confidence_interval}
|
|
107
|
+
return rq.post("/capdata/get/inst/var", data_json, token)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
import json
|
|
3
|
+
|
|
4
|
+
from request import PATH
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# get 请求
|
|
8
|
+
def get(url, params, token):
|
|
9
|
+
headers = {'Accept': 'application/json', 'content-type': 'application/json', 'x-access-token': token}
|
|
10
|
+
response = requests.get(PATH + url, json=params, headers=headers).text
|
|
11
|
+
res = json.loads(response)
|
|
12
|
+
code = res["respCode"]
|
|
13
|
+
if str(code) == 'SUCCEED':
|
|
14
|
+
if 'data' in res:
|
|
15
|
+
return res["data"]
|
|
16
|
+
else:
|
|
17
|
+
return None
|
|
18
|
+
else:
|
|
19
|
+
raise Exception(res["message"])
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# post 请求
|
|
23
|
+
def post(url, params, token=""):
|
|
24
|
+
headers = {'Accept': 'application/json', 'content-type': 'application/json'}
|
|
25
|
+
if token.strip() != "":
|
|
26
|
+
headers.setdefault('x-access-token', token)
|
|
27
|
+
response = requests.post(PATH + url, json=params, headers=headers).text
|
|
28
|
+
res = json.loads(response)
|
|
29
|
+
code = res["respCode"]
|
|
30
|
+
if str(code) == 'SUCCEED':
|
|
31
|
+
if 'data' in res:
|
|
32
|
+
return res["data"]
|
|
33
|
+
else:
|
|
34
|
+
return None
|
|
35
|
+
else:
|
|
36
|
+
raise Exception(res["message"])
|
capdata-0.1.0/setup.cfg
ADDED
capdata-0.1.0/setup.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
from sys import version_info
|
|
4
|
+
|
|
5
|
+
from setuptools import setup, find_packages
|
|
6
|
+
|
|
7
|
+
__version__ = '0.1.0' # 版本号
|
|
8
|
+
requirements = open('requirements.txt').readlines() # 依赖文件
|
|
9
|
+
|
|
10
|
+
if version_info < (3, 8, 0):
|
|
11
|
+
raise SystemExit('Sorry! dqlib requires python 3.8.0 or later.')
|
|
12
|
+
|
|
13
|
+
setup(
|
|
14
|
+
name='capdata',
|
|
15
|
+
description='capdata data api',
|
|
16
|
+
long_description='',
|
|
17
|
+
license='',
|
|
18
|
+
version=__version__,
|
|
19
|
+
author='zbz',
|
|
20
|
+
url='',
|
|
21
|
+
packages=find_packages(exclude=["test"]),
|
|
22
|
+
python_requires='>= 3.8.0',
|
|
23
|
+
install_requires=requirements
|
|
24
|
+
)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
|
|
3
|
+
import data.curve as curve
|
|
4
|
+
from test import TOKEN
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class TestCurveFunctions(unittest.TestCase):
|
|
8
|
+
def test_get_bond_curve(self):
|
|
9
|
+
curve_data = curve.get_bond_curve("CN_TREAS_STD", '2024-05-27 00:00:00', '2024-05-27 18:00:00', TOKEN, '1m')
|
|
10
|
+
if curve_data is not None:
|
|
11
|
+
for data in curve_data:
|
|
12
|
+
print(data)
|
|
13
|
+
else:
|
|
14
|
+
print(curve_data)
|
|
15
|
+
|
|
16
|
+
def test_get_credit_curve(self):
|
|
17
|
+
curve_data = curve.get_credit_curve("CN_RAILWAY_SPRD_STD", '2024-05-27 00:00:00', '2024-05-27 18:00:00', TOKEN,
|
|
18
|
+
'1m')
|
|
19
|
+
if curve_data is not None:
|
|
20
|
+
for data in curve_data:
|
|
21
|
+
print(data)
|
|
22
|
+
else:
|
|
23
|
+
print(curve_data)
|
|
24
|
+
|
|
25
|
+
def test_get_ir_curve(self):
|
|
26
|
+
curve_data = curve.get_ir_curve("CNY_FR_007", '2024-05-22 00:00:00', '2024-05-27 18:00:00', TOKEN, '1d')
|
|
27
|
+
if curve_data is not None:
|
|
28
|
+
for data in curve_data:
|
|
29
|
+
print(data)
|
|
30
|
+
else:
|
|
31
|
+
print(curve_data)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
import data.market as market
|
|
3
|
+
import pandas
|
|
4
|
+
|
|
5
|
+
from test import TOKEN
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class TestMarketFunctions(unittest.TestCase):
|
|
9
|
+
def test_get_hist_mkt(self):
|
|
10
|
+
market_data = market.get_hist_mkt(['200310.IB', '190008.IB'], '2024-05-09', '2024-05-10 00:00:00',
|
|
11
|
+
['bid', 'ask'],
|
|
12
|
+
TOKEN, )
|
|
13
|
+
market_data = pandas.DataFrame(market_data)
|
|
14
|
+
print(market_data)
|
|
15
|
+
|
|
16
|
+
def test_get_live_mkt(self):
|
|
17
|
+
market_data = market.get_live_mkt(['200310.IB', '190008.IB'], ['bid', 'ask'],
|
|
18
|
+
TOKEN, )
|
|
19
|
+
|
|
20
|
+
market_data = pandas.DataFrame(market_data)
|
|
21
|
+
print(market_data)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
import data.pricing as pricing
|
|
3
|
+
from test import TOKEN
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class TestPricingFunctions(unittest.TestCase):
|
|
7
|
+
def test_get_pricing(self):
|
|
8
|
+
pricing_data = pricing.get_pricing(['2292030.IB', '2292012.IB'], '2024-05-26', '2024-05-29 00:00:00',
|
|
9
|
+
['duration', 'modified_duration'],
|
|
10
|
+
TOKEN, freq='1m')
|
|
11
|
+
if pricing_data is not None:
|
|
12
|
+
for data in pricing_data:
|
|
13
|
+
print(data)
|
|
14
|
+
else:
|
|
15
|
+
print(pricing_data)
|
|
16
|
+
|
|
17
|
+
def test_get_valuation(self):
|
|
18
|
+
pricing_data = pricing.get_valuation(['2292030.IB', '2292012.IB'], '2024-05-26', '2024-05-29 00:00:00',
|
|
19
|
+
['present_value', 'dv01', 'cs01'],
|
|
20
|
+
TOKEN, freq='1m')
|
|
21
|
+
if pricing_data is not None:
|
|
22
|
+
for data in pricing_data:
|
|
23
|
+
print(data)
|
|
24
|
+
else:
|
|
25
|
+
print(pricing_data)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
import data.refer as refer
|
|
3
|
+
from test import TOKEN
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class TestReferFunctions(unittest.TestCase):
|
|
7
|
+
def test_get_holidays(self):
|
|
8
|
+
calendar = refer.get_holidays('CFETS', TOKEN)
|
|
9
|
+
if calendar is not None:
|
|
10
|
+
print(calendar)
|
|
11
|
+
else:
|
|
12
|
+
print(calendar)
|
|
13
|
+
|
|
14
|
+
def test_get_ir_index(self):
|
|
15
|
+
ir_index_data = refer.get_ir_index(['USDLIBOR_2W', 'SIBOR_12M'], TOKEN)
|
|
16
|
+
if ir_index_data is not None:
|
|
17
|
+
for data in ir_index_data:
|
|
18
|
+
print(data)
|
|
19
|
+
else:
|
|
20
|
+
print(ir_index_data)
|
|
21
|
+
|
|
22
|
+
def test_get_instrument(self):
|
|
23
|
+
instrument_data = refer.get_instrument(['zc17060604.SH', 'zc17021505.SH'], TOKEN)
|
|
24
|
+
if instrument_data is not None:
|
|
25
|
+
for data in instrument_data:
|
|
26
|
+
print(data)
|
|
27
|
+
else:
|
|
28
|
+
print(instrument_data)
|
|
29
|
+
|
|
30
|
+
def test_get_inst_template(self):
|
|
31
|
+
template_data = refer.get_inst_template(
|
|
32
|
+
['CNY_FR_007_SWAP', 'SHIBOR_USDLIBOR_3M_SWAP', 'USDCNY_CASH', 'CN_TREAS_ZERO', 'EUR_CASH_DEPO'], TOKEN)
|
|
33
|
+
if template_data is not None:
|
|
34
|
+
for data in template_data:
|
|
35
|
+
print(data)
|
|
36
|
+
else:
|
|
37
|
+
print(template_data)
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
import data.risk as risk
|
|
3
|
+
from test import TOKEN
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class TestRiskFunctions(unittest.TestCase):
|
|
7
|
+
def test_get_hist_sim_ir_curve(self):
|
|
8
|
+
risk_data = risk.get_hist_sim_ir_curve('CN_TREAS_STD', '2024-05-28', '2024-05-27', TOKEN)
|
|
9
|
+
if risk_data is not None:
|
|
10
|
+
for data in risk_data:
|
|
11
|
+
print(data)
|
|
12
|
+
else:
|
|
13
|
+
print(risk_data)
|
|
14
|
+
|
|
15
|
+
def test_get_hist_sim_credit_curve(self):
|
|
16
|
+
risk_data = risk.get_hist_sim_credit_curve('CN_CORP_AAA_SPRD_STD', '2024-05-28', '2024-05-27', TOKEN)
|
|
17
|
+
if risk_data is not None:
|
|
18
|
+
for data in risk_data:
|
|
19
|
+
print(data)
|
|
20
|
+
else:
|
|
21
|
+
print(risk_data)
|
|
22
|
+
|
|
23
|
+
def test_get_hist_stressed_ir_curve(self):
|
|
24
|
+
risk_data = risk.get_hist_stressed_ir_curve('CN_TREAS_PRIME', '2024-05-11', '2024-05-10', TOKEN)
|
|
25
|
+
if risk_data is not None:
|
|
26
|
+
for data in risk_data:
|
|
27
|
+
print(data)
|
|
28
|
+
else:
|
|
29
|
+
print(risk_data)
|
|
30
|
+
|
|
31
|
+
def test_get_hist_stressed_credit_curve(self):
|
|
32
|
+
risk_data = risk.get_hist_stressed_credit_curve('CN_SP_MTN_AAA_SPRD_STD', '2024-05-11', '2024-05-10', TOKEN)
|
|
33
|
+
if risk_data is not None:
|
|
34
|
+
for data in risk_data:
|
|
35
|
+
print(data)
|
|
36
|
+
else:
|
|
37
|
+
print(risk_data)
|
|
38
|
+
|
|
39
|
+
def test_get_hist_sim_pnl(self):
|
|
40
|
+
risk_data = risk.get_hist_sim_pnl(['2171035.IB', '2105288.IB'], '2024-05-28', '2024-05-27', TOKEN)
|
|
41
|
+
if risk_data is not None:
|
|
42
|
+
for data in risk_data:
|
|
43
|
+
print(data)
|
|
44
|
+
else:
|
|
45
|
+
print(risk_data)
|
|
46
|
+
|
|
47
|
+
def test_get_hist_stressed_pnl(self):
|
|
48
|
+
risk_data = risk.get_hist_stressed_pnl(['2171035.IB', '2105288.IB'], '2024-05-28', '2024-05-27', TOKEN)
|
|
49
|
+
if risk_data is not None:
|
|
50
|
+
for data in risk_data:
|
|
51
|
+
print(data)
|
|
52
|
+
else:
|
|
53
|
+
print(risk_data)
|
|
54
|
+
|
|
55
|
+
def test_get_hist_var(self):
|
|
56
|
+
risk_data = risk.get_hist_var("2171035.IB", '2024-05-28', '2024-05-27', ['var', 'es'], TOKEN)
|
|
57
|
+
if risk_data is not None:
|
|
58
|
+
print(risk_data)
|
|
59
|
+
else:
|
|
60
|
+
print(risk_data)
|