siat 2.13.43__py3-none-any.whl → 2.14.2__py3-none-any.whl

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.
siat/allin.py CHANGED
@@ -18,6 +18,7 @@ from siat.bond import *
18
18
 
19
19
  # 资本资产定价模型
20
20
  from siat.capm_beta import *
21
+ from siat.capm_beta2 import *
21
22
 
22
23
  # 数字货币
23
24
  from siat.cryptocurrency import *
@@ -69,6 +70,7 @@ from siat.option_pricing import *
69
70
 
70
71
  # 风险调整收益
71
72
  from siat.risk_adjusted_return import *
73
+ from siat.risk_adjusted_return2 import *
72
74
 
73
75
  # 风险评估
74
76
  from siat.risk_evaluation import *
@@ -89,7 +91,7 @@ from siat.security_prices import *
89
91
  from siat.stock import *
90
92
 
91
93
  # 股票趋势分析,集成函数
92
- from siat.security_trend import *
94
+ from siat.security_trend2 import *
93
95
 
94
96
  # 中国的股票
95
97
  from siat.stock_china import *
@@ -112,6 +114,7 @@ from siat.compare_cross import *
112
114
 
113
115
  # 股票技术分析
114
116
  from siat.stock_technical import *
117
+
115
118
  # 2FA: Google Authenticator
116
119
  from siat.google_authenticator import *
117
120
 
siat/bond_zh_sina.py ADDED
@@ -0,0 +1,143 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding:utf-8 -*-
3
+ """
4
+ Date: 2024/2/28 23:00
5
+ Desc: 新浪财经-债券-沪深债券-实时行情数据和历史行情数据
6
+ https://vip.stock.finance.sina.com.cn/mkt/#hs_z
7
+ """
8
+ import datetime
9
+ import re
10
+
11
+ import pandas as pd
12
+ import requests
13
+ from py_mini_racer import py_mini_racer
14
+
15
+ from akshare.bond.cons import (
16
+ zh_sina_bond_hs_count_url,
17
+ zh_sina_bond_hs_payload,
18
+ zh_sina_bond_hs_url,
19
+ zh_sina_bond_hs_hist_url,
20
+ )
21
+ from akshare.stock.cons import hk_js_decode
22
+ from akshare.utils import demjson
23
+ from akshare.utils.tqdm import get_tqdm
24
+
25
+
26
+ def get_zh_bond_hs_page_count() -> int:
27
+ """
28
+ 行情中心首页-债券-沪深债券的总页数
29
+ https://vip.stock.finance.sina.com.cn/mkt/#hs_z
30
+ :return: 总页数
31
+ :rtype: int
32
+ """
33
+ params = {
34
+ "node": "hs_z",
35
+ }
36
+ res = requests.get(zh_sina_bond_hs_count_url, params=params)
37
+ page_count = int(re.findall(re.compile(r"\d+"), res.text)[0]) / 80
38
+ if isinstance(page_count, int):
39
+ return page_count
40
+ else:
41
+ return int(page_count) + 1
42
+
43
+
44
+ def bond_zh_hs_spot() -> pd.DataFrame:
45
+ """
46
+ 新浪财经-债券-沪深债券-实时行情数据, 大量抓取容易封IP
47
+ https://vip.stock.finance.sina.com.cn/mkt/#hs_z
48
+ :return: 所有沪深债券在当前时刻的实时行情数据
49
+ :rtype: pandas.DataFrame
50
+ """
51
+ page_count = get_zh_bond_hs_page_count()
52
+ zh_sina_bond_hs_payload_copy = zh_sina_bond_hs_payload.copy()
53
+ tqdm = get_tqdm()
54
+ big_df = pd.DataFrame()
55
+ for page in tqdm(range(1, page_count + 1), leave=False):
56
+ zh_sina_bond_hs_payload_copy.update({"page": page})
57
+ r = requests.get(zh_sina_bond_hs_url, params=zh_sina_bond_hs_payload_copy)
58
+ data_json = demjson.decode(r.text)
59
+ temp_df = pd.DataFrame(data_json)
60
+ big_df = pd.concat(objs=[big_df, temp_df], ignore_index=True)
61
+ big_df.columns = [
62
+ '代码',
63
+ '-',
64
+ '名称',
65
+ '最新价',
66
+ '涨跌额',
67
+ '涨跌幅',
68
+ '买入',
69
+ '卖出',
70
+ '昨收',
71
+ '今开',
72
+ '最高',
73
+ '最低',
74
+ '成交量',
75
+ '成交额',
76
+ '-',
77
+ '-',
78
+ '-',
79
+ '-',
80
+ '-',
81
+ '-',
82
+ ]
83
+ big_df = big_df[[
84
+ '代码',
85
+ '名称',
86
+ '最新价',
87
+ '涨跌额',
88
+ '涨跌幅',
89
+ '买入',
90
+ '卖出',
91
+ '昨收',
92
+ '今开',
93
+ '最高',
94
+ '最低',
95
+ '成交量',
96
+ '成交额',
97
+ ]]
98
+ big_df['买入'] = pd.to_numeric(big_df['买入'], errors="coerce")
99
+ big_df['卖出'] = pd.to_numeric(big_df['卖出'], errors="coerce")
100
+ big_df['昨收'] = pd.to_numeric(big_df['昨收'], errors="coerce")
101
+ big_df['今开'] = pd.to_numeric(big_df['今开'], errors="coerce")
102
+ big_df['最高'] = pd.to_numeric(big_df['最高'], errors="coerce")
103
+ big_df['最低'] = pd.to_numeric(big_df['最低'], errors="coerce")
104
+ big_df['最新价'] = pd.to_numeric(big_df['最新价'], errors="coerce")
105
+ return big_df
106
+
107
+
108
+ def bond_zh_hs_daily(symbol: str = "sh010107") -> pd.DataFrame:
109
+ """
110
+ 新浪财经-债券-沪深债券-历史行情数据, 大量抓取容易封 IP
111
+ https://vip.stock.finance.sina.com.cn/mkt/#hs_z
112
+ :param symbol: 沪深债券代码; e.g., sh010107
113
+ :type symbol: str
114
+ :return: 指定沪深债券代码的日 K 线数据
115
+ :rtype: pandas.DataFrame
116
+ """
117
+ r = requests.get(
118
+ zh_sina_bond_hs_hist_url.format(
119
+ symbol, datetime.datetime.now().strftime("%Y_%m_%d")
120
+ )
121
+ )
122
+ js_code = py_mini_racer.MiniRacer()
123
+ js_code.eval(hk_js_decode)
124
+ dict_list = js_code.call(
125
+ "d", r.text.split("=")[1].split(";")[0].replace('"', "")
126
+ ) # 执行 js 解密代码
127
+ if len(dict_list) == 0: return None
128
+
129
+ data_df = pd.DataFrame(dict_list)
130
+ data_df["date"] = pd.to_datetime(data_df["date"], errors="coerce").dt.date
131
+ data_df['open'] = pd.to_numeric(data_df['open'], errors="coerce")
132
+ data_df['high'] = pd.to_numeric(data_df['high'], errors="coerce")
133
+ data_df['low'] = pd.to_numeric(data_df['low'], errors="coerce")
134
+ data_df['close'] = pd.to_numeric(data_df['close'], errors="coerce")
135
+ return data_df
136
+
137
+
138
+ if __name__ == "__main__":
139
+ bond_zh_hs_spot_df = bond_zh_hs_spot()
140
+ print(bond_zh_hs_spot_df)
141
+
142
+ bond_zh_hs_daily_df = bond_zh_hs_daily(symbol="sh010107")
143
+ print(bond_zh_hs_daily_df)