aishare-txt 1.0.0__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.
- AIShareTxt/__init__.py +63 -0
- AIShareTxt/ai/__init__.py +11 -0
- AIShareTxt/ai/client.py +313 -0
- AIShareTxt/ai/providers/__init__.py +8 -0
- AIShareTxt/core/__init__.py +17 -0
- AIShareTxt/core/analyzer.py +495 -0
- AIShareTxt/core/config.py +324 -0
- AIShareTxt/core/data_fetcher.py +466 -0
- AIShareTxt/core/report_generator.py +783 -0
- AIShareTxt/docs/AI_INTEGRATION.md +212 -0
- AIShareTxt/docs/README_/321/211/320/227/320/235/321/206/320/256/320/224/321/210/320/277/342/224/244/321/206/320/250/320/236.md +202 -0
- AIShareTxt/docs//321/211/320/227/320/235/321/206/320/256/320/224/321/205/320/276/320/234/321/206/320/230/320/240/321/206/320/220/342/225/227/321/207/342/225/227/320/243.md +148 -0
- AIShareTxt/examples/legacy_api.py +259 -0
- AIShareTxt/indicators/__init__.py +15 -0
- AIShareTxt/indicators/technical_indicators.py +507 -0
- AIShareTxt/tests/__init__.py +11 -0
- AIShareTxt/utils/__init__.py +17 -0
- AIShareTxt/utils/stock_list.py +305 -0
- AIShareTxt/utils/utils.py +578 -0
- aishare_txt-1.0.0.dist-info/METADATA +395 -0
- aishare_txt-1.0.0.dist-info/RECORD +25 -0
- aishare_txt-1.0.0.dist-info/WHEEL +5 -0
- aishare_txt-1.0.0.dist-info/entry_points.txt +2 -0
- aishare_txt-1.0.0.dist-info/licenses/LICENSE +194 -0
- aishare_txt-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
股票技术指标分析器 (兼容性包装器)
|
|
5
|
+
保持原有接口不变,但内部使用重构后的模块化架构
|
|
6
|
+
支持多种技术指标计算,包括均线、MACD、布林带等
|
|
7
|
+
使用 akshare 获取数据,talib 计算指标
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import warnings
|
|
11
|
+
from ..core.analyzer import StockAnalyzer
|
|
12
|
+
from ..utils.utils import Utils, LoggerManager
|
|
13
|
+
|
|
14
|
+
warnings.filterwarnings('ignore')
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class StockIndicatorsAnalyzer:
|
|
18
|
+
"""股票技术指标分析器 (兼容性包装器)"""
|
|
19
|
+
|
|
20
|
+
def __init__(self):
|
|
21
|
+
"""初始化分析器,使用新的模块化架构"""
|
|
22
|
+
self._analyzer = StockAnalyzer()
|
|
23
|
+
self.logger = LoggerManager.get_logger('compatibility_wrapper')
|
|
24
|
+
|
|
25
|
+
# 保持向后兼容的属性
|
|
26
|
+
self.data = None
|
|
27
|
+
self.stock_code = None
|
|
28
|
+
self.stock_info = None
|
|
29
|
+
|
|
30
|
+
def fetch_stock_data(self, stock_code, period="daily", adjust="qfq", start_date=None):
|
|
31
|
+
"""
|
|
32
|
+
获取股票数据 (兼容性方法)
|
|
33
|
+
|
|
34
|
+
Args:
|
|
35
|
+
stock_code (str): 股票代码,如 '000001'
|
|
36
|
+
period (str): 周期,'daily'=日K线
|
|
37
|
+
adjust (str): 复权类型,''=不复权, 'qfq'=前复权, 'hfq'=后复权
|
|
38
|
+
start_date (str): 开始日期,如 '20230101'
|
|
39
|
+
|
|
40
|
+
Returns:
|
|
41
|
+
bool: 是否成功获取数据
|
|
42
|
+
"""
|
|
43
|
+
try:
|
|
44
|
+
self.data = self._analyzer.data_fetcher.fetch_stock_data(
|
|
45
|
+
stock_code, period, adjust, start_date
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
if self.data is not None:
|
|
49
|
+
self.stock_code = stock_code
|
|
50
|
+
return True
|
|
51
|
+
else:
|
|
52
|
+
return False
|
|
53
|
+
|
|
54
|
+
except Exception as e:
|
|
55
|
+
self.logger.error(f"获取股票数据时出错:{str(e)}")
|
|
56
|
+
return False
|
|
57
|
+
|
|
58
|
+
def get_fund_flow_data(self, stock_code):
|
|
59
|
+
"""
|
|
60
|
+
获取主力资金流数据 (兼容性方法)
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
stock_code (str): 股票代码
|
|
64
|
+
|
|
65
|
+
Returns:
|
|
66
|
+
dict: 资金流数据字典
|
|
67
|
+
"""
|
|
68
|
+
try:
|
|
69
|
+
return self._analyzer.data_fetcher.get_fund_flow_data(stock_code)
|
|
70
|
+
except Exception as e:
|
|
71
|
+
self.logger.error(f"获取主力资金流数据失败:{str(e)}")
|
|
72
|
+
return {}
|
|
73
|
+
|
|
74
|
+
def get_stock_basic_info(self, stock_code):
|
|
75
|
+
"""
|
|
76
|
+
获取股票基本信息 (兼容性方法)
|
|
77
|
+
|
|
78
|
+
Args:
|
|
79
|
+
stock_code (str): 股票代码
|
|
80
|
+
|
|
81
|
+
Returns:
|
|
82
|
+
dict: 股票基本信息字典
|
|
83
|
+
"""
|
|
84
|
+
try:
|
|
85
|
+
self.stock_info = self._analyzer.data_fetcher.get_stock_basic_info(stock_code)
|
|
86
|
+
return self.stock_info
|
|
87
|
+
except Exception as e:
|
|
88
|
+
self.logger.error(f"获取股票基本信息失败:{str(e)}")
|
|
89
|
+
return {}
|
|
90
|
+
|
|
91
|
+
def calculate_bias(self, timeperiod=20):
|
|
92
|
+
"""
|
|
93
|
+
计算乖离率 (兼容性方法)
|
|
94
|
+
|
|
95
|
+
Args:
|
|
96
|
+
timeperiod (int): 计算周期
|
|
97
|
+
|
|
98
|
+
Returns:
|
|
99
|
+
array: 乖离率数组
|
|
100
|
+
"""
|
|
101
|
+
if self.data is None:
|
|
102
|
+
return None
|
|
103
|
+
|
|
104
|
+
try:
|
|
105
|
+
close = self.data['close'].values
|
|
106
|
+
return self._analyzer.indicators_calculator.calculate_bias(close, timeperiod)
|
|
107
|
+
except Exception as e:
|
|
108
|
+
self.logger.error(f"计算乖离率失败:{str(e)}")
|
|
109
|
+
return None
|
|
110
|
+
|
|
111
|
+
def analyze_ma_patterns(self, close):
|
|
112
|
+
"""
|
|
113
|
+
分析均线形态 (兼容性方法)
|
|
114
|
+
|
|
115
|
+
Args:
|
|
116
|
+
close: 收盘价数组
|
|
117
|
+
|
|
118
|
+
Returns:
|
|
119
|
+
dict: 均线形态字典
|
|
120
|
+
"""
|
|
121
|
+
try:
|
|
122
|
+
return self._analyzer.indicators_calculator.analyze_ma_patterns(close)
|
|
123
|
+
except Exception as e:
|
|
124
|
+
self.logger.error(f"分析均线形态失败:{str(e)}")
|
|
125
|
+
return {}
|
|
126
|
+
|
|
127
|
+
def get_latest_indicators(self):
|
|
128
|
+
"""
|
|
129
|
+
计算所有技术指标的最新值 (兼容性方法)
|
|
130
|
+
|
|
131
|
+
Returns:
|
|
132
|
+
dict: 包含所有指标最新值的字典
|
|
133
|
+
"""
|
|
134
|
+
if self.data is None:
|
|
135
|
+
return None
|
|
136
|
+
|
|
137
|
+
try:
|
|
138
|
+
return self._analyzer.indicators_calculator.calculate_all_indicators(self.data)
|
|
139
|
+
except Exception as e:
|
|
140
|
+
self.logger.error(f"计算技术指标失败:{str(e)}")
|
|
141
|
+
return None
|
|
142
|
+
|
|
143
|
+
def format_indicators_report(self, indicators):
|
|
144
|
+
"""
|
|
145
|
+
格式化指标报告 (兼容性方法)
|
|
146
|
+
|
|
147
|
+
Args:
|
|
148
|
+
indicators (dict): 指标数据字典
|
|
149
|
+
|
|
150
|
+
Returns:
|
|
151
|
+
str: 格式化的报告文本
|
|
152
|
+
"""
|
|
153
|
+
if indicators is None:
|
|
154
|
+
return "无法生成指标报告:数据不足"
|
|
155
|
+
|
|
156
|
+
try:
|
|
157
|
+
return self._analyzer.report_generator.generate_report(
|
|
158
|
+
self.stock_code, indicators, self.stock_info
|
|
159
|
+
)
|
|
160
|
+
except Exception as e:
|
|
161
|
+
self.logger.error(f"生成报告失败:{str(e)}")
|
|
162
|
+
return f"生成报告时出错:{str(e)}"
|
|
163
|
+
|
|
164
|
+
def analyze_stock(self, stock_code):
|
|
165
|
+
"""
|
|
166
|
+
分析指定股票的技术指标 (兼容性方法)
|
|
167
|
+
|
|
168
|
+
Args:
|
|
169
|
+
stock_code (str): 股票代码
|
|
170
|
+
|
|
171
|
+
Returns:
|
|
172
|
+
str: 分析报告
|
|
173
|
+
"""
|
|
174
|
+
try:
|
|
175
|
+
# 使用新的分析器
|
|
176
|
+
report = self._analyzer.analyze_stock(stock_code)
|
|
177
|
+
|
|
178
|
+
# 更新兼容性属性
|
|
179
|
+
self.stock_code = stock_code
|
|
180
|
+
self.data = self._analyzer.get_current_stock_data()
|
|
181
|
+
self.stock_info = self._analyzer.get_current_stock_info()
|
|
182
|
+
|
|
183
|
+
return report
|
|
184
|
+
|
|
185
|
+
except Exception as e:
|
|
186
|
+
self.logger.error(f"分析股票失败:{str(e)}")
|
|
187
|
+
return f"分析过程中出错:{str(e)}"
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def quick_test(stock_code):
|
|
191
|
+
"""快速测试单个股票 (兼容性函数)"""
|
|
192
|
+
analyzer = StockIndicatorsAnalyzer()
|
|
193
|
+
logger = LoggerManager.get_logger('compatibility_wrapper')
|
|
194
|
+
|
|
195
|
+
print(f"快速测试股票:{stock_code}")
|
|
196
|
+
print("=" * 50)
|
|
197
|
+
logger.info(f"开始兼容性模式快速测试:{stock_code}")
|
|
198
|
+
|
|
199
|
+
try:
|
|
200
|
+
report = analyzer.analyze_stock(stock_code)
|
|
201
|
+
print("\n" + report)
|
|
202
|
+
logger.info(f"兼容性模式测试完成:{stock_code}")
|
|
203
|
+
return True
|
|
204
|
+
except Exception as e:
|
|
205
|
+
logger.error(f"兼容性模式测试失败:{str(e)}")
|
|
206
|
+
return False
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def main():
|
|
210
|
+
"""主函数 (兼容性版本)"""
|
|
211
|
+
logger = LoggerManager.get_logger('compatibility_wrapper')
|
|
212
|
+
|
|
213
|
+
print("股票技术指标分析器 (兼容性版本)")
|
|
214
|
+
print("=" * 50)
|
|
215
|
+
print("注意:此版本使用重构后的模块化架构")
|
|
216
|
+
print("推荐使用新版本:python stock_analyzer.py")
|
|
217
|
+
print("=" * 50)
|
|
218
|
+
logger.info("启动兼容性版本分析器")
|
|
219
|
+
|
|
220
|
+
analyzer = StockIndicatorsAnalyzer()
|
|
221
|
+
utils = Utils()
|
|
222
|
+
|
|
223
|
+
# 检查命令行参数
|
|
224
|
+
stock_code = utils.parse_command_line_args()
|
|
225
|
+
if stock_code:
|
|
226
|
+
quick_test(stock_code)
|
|
227
|
+
return
|
|
228
|
+
|
|
229
|
+
while True:
|
|
230
|
+
try:
|
|
231
|
+
stock_code = utils.get_user_input(
|
|
232
|
+
"\n请输入股票代码(如:000001,输入 'quit' 退出):",
|
|
233
|
+
['quit', 'exit', 'q']
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
if stock_code is None:
|
|
237
|
+
print("谢谢使用!")
|
|
238
|
+
logger.info("用户退出兼容性版本程序")
|
|
239
|
+
break
|
|
240
|
+
|
|
241
|
+
if not stock_code:
|
|
242
|
+
print("请输入有效的股票代码")
|
|
243
|
+
continue
|
|
244
|
+
|
|
245
|
+
logger.info(f"兼容性版本分析股票:{stock_code}")
|
|
246
|
+
|
|
247
|
+
# 分析股票
|
|
248
|
+
report = analyzer.analyze_stock(stock_code)
|
|
249
|
+
print("\n" + report)
|
|
250
|
+
|
|
251
|
+
except KeyboardInterrupt:
|
|
252
|
+
if utils.handle_keyboard_interrupt():
|
|
253
|
+
break
|
|
254
|
+
except Exception as e:
|
|
255
|
+
utils.log_error(e, "主程序")
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
if __name__ == "__main__":
|
|
259
|
+
main()
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""
|
|
2
|
+
AIShareTxt技术指标模块
|
|
3
|
+
|
|
4
|
+
包含各种技术指标的计算和分析功能。
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from .technical_indicators import TechnicalIndicators
|
|
8
|
+
|
|
9
|
+
__all__ = [
|
|
10
|
+
"TechnicalIndicators",
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
# 这里可以添加更多技术指标实现
|
|
14
|
+
# from .custom_indicators import CustomIndicators
|
|
15
|
+
# __all__.append("CustomIndicators")
|