akshare-one 0.3.0__py3-none-any.whl → 0.3.1__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.
Files changed (39) hide show
  1. akshare_one/__init__.py +31 -31
  2. akshare_one/financial.py +46 -46
  3. akshare_one/indicators.py +395 -395
  4. akshare_one/insider.py +33 -33
  5. akshare_one/modules/cache.py +9 -9
  6. akshare_one/modules/eastmoney/client.py +88 -88
  7. akshare_one/modules/eastmoney/utils.py +104 -104
  8. akshare_one/modules/financial/base.py +22 -22
  9. akshare_one/modules/financial/factory.py +44 -44
  10. akshare_one/modules/financial/sina.py +273 -273
  11. akshare_one/modules/historical/base.py +47 -47
  12. akshare_one/modules/historical/eastmoney.py +241 -241
  13. akshare_one/modules/historical/eastmoney_direct.py +79 -79
  14. akshare_one/modules/historical/factory.py +48 -48
  15. akshare_one/modules/historical/sina.py +254 -218
  16. akshare_one/modules/indicators/base.py +158 -158
  17. akshare_one/modules/indicators/factory.py +33 -33
  18. akshare_one/modules/indicators/simple.py +230 -230
  19. akshare_one/modules/indicators/talib.py +263 -263
  20. akshare_one/modules/insider/base.py +28 -28
  21. akshare_one/modules/insider/factory.py +44 -44
  22. akshare_one/modules/insider/xueqiu.py +115 -115
  23. akshare_one/modules/news/base.py +22 -22
  24. akshare_one/modules/news/eastmoney.py +47 -47
  25. akshare_one/modules/news/factory.py +44 -44
  26. akshare_one/modules/realtime/base.py +27 -27
  27. akshare_one/modules/realtime/eastmoney.py +57 -57
  28. akshare_one/modules/realtime/eastmoney_direct.py +37 -37
  29. akshare_one/modules/realtime/factory.py +48 -48
  30. akshare_one/modules/realtime/xueqiu.py +60 -60
  31. akshare_one/modules/utils.py +10 -10
  32. akshare_one/news.py +27 -27
  33. akshare_one/stock.py +78 -78
  34. {akshare_one-0.3.0.dist-info → akshare_one-0.3.1.dist-info}/METADATA +70 -70
  35. akshare_one-0.3.1.dist-info/RECORD +39 -0
  36. {akshare_one-0.3.0.dist-info → akshare_one-0.3.1.dist-info}/licenses/LICENSE +21 -21
  37. akshare_one-0.3.0.dist-info/RECORD +0 -39
  38. {akshare_one-0.3.0.dist-info → akshare_one-0.3.1.dist-info}/WHEEL +0 -0
  39. {akshare_one-0.3.0.dist-info → akshare_one-0.3.1.dist-info}/top_level.txt +0 -0
@@ -1,230 +1,230 @@
1
- import pandas as pd
2
- from .base import BaseIndicatorCalculator
3
-
4
-
5
- class SimpleIndicatorCalculator(BaseIndicatorCalculator):
6
- """Basic pandas-based indicator implementations"""
7
-
8
- def calculate_sma(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
9
- return (
10
- df["close"]
11
- .rolling(window=window, min_periods=window)
12
- .mean()
13
- .to_frame("sma")
14
- )
15
-
16
- def calculate_ema(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
17
- return (
18
- df["close"]
19
- .ewm(span=window, adjust=False, min_periods=window)
20
- .mean()
21
- .to_frame("ema")
22
- )
23
-
24
- def calculate_rsi(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
25
- delta = df["close"].diff()
26
- gain = delta.clip(lower=0)
27
- loss = -delta.clip(upper=0)
28
-
29
- avg_gain = gain.ewm(alpha=1 / window, min_periods=window, adjust=False).mean()
30
- avg_loss = loss.ewm(alpha=1 / window, min_periods=window, adjust=False).mean()
31
-
32
- rs = avg_gain / avg_loss
33
- rsi = 100 - (100 / (1 + rs))
34
-
35
- return rsi.clip(0, 100).to_frame("rsi")
36
-
37
- def calculate_macd(
38
- self, df: pd.DataFrame, fast: int, slow: int, signal: int
39
- ) -> pd.DataFrame:
40
- close = df["close"]
41
- ema_fast = close.ewm(span=fast, adjust=False, min_periods=fast).mean()
42
- ema_slow = close.ewm(span=slow, adjust=False, min_periods=slow).mean()
43
-
44
- macd_line = ema_fast - ema_slow
45
- signal_line = macd_line.ewm(
46
- span=signal, adjust=False, min_periods=signal
47
- ).mean()
48
-
49
- return pd.DataFrame(
50
- {
51
- "macd": macd_line,
52
- "signal": signal_line,
53
- "histogram": macd_line - signal_line,
54
- }
55
- )
56
-
57
- def calculate_bollinger_bands(
58
- self, df: pd.DataFrame, window: int, std: int
59
- ) -> pd.DataFrame:
60
- close = df["close"]
61
- sma = close.rolling(window=window, min_periods=window).mean()
62
- rolling_std = close.rolling(window=window, min_periods=window).std()
63
- upper_band = sma + (rolling_std * std)
64
- lower_band = sma - (rolling_std * std)
65
- return pd.DataFrame(
66
- {"upper_band": upper_band, "middle_band": sma, "lower_band": lower_band}
67
- )
68
-
69
- def calculate_stoch(
70
- self, df: pd.DataFrame, window: int, smooth_d: int, smooth_k: int
71
- ) -> pd.DataFrame:
72
- high = df["high"]
73
- low = df["low"]
74
- close = df["close"]
75
-
76
- lowest_low = low.rolling(window=window).min()
77
- highest_high = high.rolling(window=window).max()
78
-
79
- k = 100 * (close - lowest_low) / (highest_high - lowest_low)
80
- slow_k = k.rolling(window=smooth_k).mean()
81
- slow_d = slow_k.rolling(window=smooth_d).mean()
82
-
83
- return pd.DataFrame({"slow_k": slow_k, "slow_d": slow_d})
84
-
85
- def calculate_atr(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
86
- high = df["high"]
87
- low = df["low"]
88
- close = df["close"]
89
-
90
- tr1 = high - low
91
- tr2 = abs(high - close.shift())
92
- tr3 = abs(low - close.shift())
93
- tr = pd.concat([tr1, tr2, tr3], axis=1).max(axis=1)
94
-
95
- atr = tr.ewm(alpha=1 / window, adjust=False, min_periods=window).mean()
96
- return atr.to_frame("atr")
97
-
98
- def calculate_cci(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
99
- high = df["high"]
100
- low = df["low"]
101
- close = df["close"]
102
-
103
- tp = (high + low + close) / 3
104
- tp_sma = tp.rolling(window=window, min_periods=window).mean()
105
- mean_dev = tp.rolling(window=window, min_periods=window).apply(
106
- lambda x: (x - x.mean()).abs().mean()
107
- )
108
-
109
- cci = (tp - tp_sma) / (0.015 * mean_dev)
110
- return cci.to_frame("cci")
111
-
112
- def calculate_adx(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
113
- high = df["high"]
114
- low = df["low"]
115
- close = df["close"]
116
-
117
- # Calculate +DM, -DM and TR
118
- move_up = high.diff()
119
- move_down = low.diff().apply(abs)
120
-
121
- plus_dm = pd.Series((move_up > move_down) & (move_up > 0)).astype(int) * move_up
122
- minus_dm = (
123
- pd.Series((move_down > move_up) & (move_down > 0)).astype(int) * move_down
124
- )
125
-
126
- tr1 = high - low
127
- tr2 = abs(high - close.shift())
128
- tr3 = abs(low - close.shift())
129
- tr = pd.concat([tr1, tr2, tr3], axis=1).max(axis=1)
130
-
131
- # Smooth +DM, -DM and TR
132
- atr = tr.ewm(alpha=1 / window, adjust=False, min_periods=window).mean()
133
- plus_di = 100 * (
134
- plus_dm.ewm(alpha=1 / window, adjust=False, min_periods=window).mean() / atr
135
- )
136
- minus_di = 100 * (
137
- minus_dm.ewm(alpha=1 / window, adjust=False, min_periods=window).mean()
138
- / atr
139
- )
140
-
141
- # Calculate ADX
142
- dx = 100 * (abs(plus_di - minus_di) / (plus_di + minus_di))
143
- adx = dx.ewm(alpha=1 / window, adjust=False, min_periods=window).mean()
144
-
145
- return adx.to_frame("adx")
146
-
147
- def calculate_willr(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
148
- raise NotImplementedError("WILLR not implemented in simple calculator")
149
-
150
- def calculate_ad(self, df: pd.DataFrame) -> pd.DataFrame:
151
- raise NotImplementedError("AD not implemented in simple calculator")
152
-
153
- def calculate_adosc(
154
- self, df: pd.DataFrame, fast_period: int, slow_period: int
155
- ) -> pd.DataFrame:
156
- raise NotImplementedError("ADOSC not implemented in simple calculator")
157
-
158
- def calculate_obv(self, df: pd.DataFrame) -> pd.DataFrame:
159
- raise NotImplementedError("OBV not implemented in simple calculator")
160
-
161
- def calculate_mom(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
162
- raise NotImplementedError("MOM not implemented in simple calculator")
163
-
164
- def calculate_sar(
165
- self, df: pd.DataFrame, acceleration: float, maximum: float
166
- ) -> pd.DataFrame:
167
- raise NotImplementedError("SAR not implemented in simple calculator")
168
-
169
- def calculate_tsf(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
170
- raise NotImplementedError("TSF not implemented in simple calculator")
171
-
172
- def calculate_apo(
173
- self, df: pd.DataFrame, fast_period: int, slow_period: int, ma_type: int
174
- ) -> pd.DataFrame:
175
- raise NotImplementedError("APO not implemented in simple calculator")
176
-
177
- def calculate_aroon(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
178
- raise NotImplementedError("AROON not implemented in simple calculator")
179
-
180
- def calculate_aroonosc(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
181
- raise NotImplementedError("AROONOSC not implemented in simple calculator")
182
-
183
- def calculate_bop(self, df: pd.DataFrame) -> pd.DataFrame:
184
- raise NotImplementedError("BOP not implemented in simple calculator")
185
-
186
- def calculate_cmo(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
187
- raise NotImplementedError("CMO not implemented in simple calculator")
188
-
189
- def calculate_dx(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
190
- raise NotImplementedError("DX not implemented in simple calculator")
191
-
192
- def calculate_mfi(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
193
- raise NotImplementedError("MFI not implemented in simple calculator")
194
-
195
- def calculate_minus_di(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
196
- raise NotImplementedError("MINUS_DI not implemented in simple calculator")
197
-
198
- def calculate_minus_dm(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
199
- raise NotImplementedError("MINUS_DM not implemented in simple calculator")
200
-
201
- def calculate_plus_di(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
202
- raise NotImplementedError("PLUS_DI not implemented in simple calculator")
203
-
204
- def calculate_plus_dm(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
205
- raise NotImplementedError("PLUS_DM not implemented in simple calculator")
206
-
207
- def calculate_ppo(
208
- self, df: pd.DataFrame, fast_period: int, slow_period: int, ma_type: int
209
- ) -> pd.DataFrame:
210
- raise NotImplementedError("PPO not implemented in simple calculator")
211
-
212
- def calculate_roc(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
213
- raise NotImplementedError("ROC not implemented in simple calculator")
214
-
215
- def calculate_rocp(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
216
- raise NotImplementedError("ROCP not implemented in simple calculator")
217
-
218
- def calculate_rocr(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
219
- raise NotImplementedError("ROCR not implemented in simple calculator")
220
-
221
- def calculate_rocr100(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
222
- raise NotImplementedError("ROCR100 not implemented in simple calculator")
223
-
224
- def calculate_trix(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
225
- raise NotImplementedError("TRIX not implemented in simple calculator")
226
-
227
- def calculate_ultosc(
228
- self, df: pd.DataFrame, window1: int, window2: int, window3: int
229
- ) -> pd.DataFrame:
230
- raise NotImplementedError("ULTOSC not implemented in simple calculator")
1
+ import pandas as pd
2
+ from .base import BaseIndicatorCalculator
3
+
4
+
5
+ class SimpleIndicatorCalculator(BaseIndicatorCalculator):
6
+ """Basic pandas-based indicator implementations"""
7
+
8
+ def calculate_sma(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
9
+ return (
10
+ df["close"]
11
+ .rolling(window=window, min_periods=window)
12
+ .mean()
13
+ .to_frame("sma")
14
+ )
15
+
16
+ def calculate_ema(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
17
+ return (
18
+ df["close"]
19
+ .ewm(span=window, adjust=False, min_periods=window)
20
+ .mean()
21
+ .to_frame("ema")
22
+ )
23
+
24
+ def calculate_rsi(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
25
+ delta = df["close"].diff()
26
+ gain = delta.clip(lower=0)
27
+ loss = -delta.clip(upper=0)
28
+
29
+ avg_gain = gain.ewm(alpha=1 / window, min_periods=window, adjust=False).mean()
30
+ avg_loss = loss.ewm(alpha=1 / window, min_periods=window, adjust=False).mean()
31
+
32
+ rs = avg_gain / avg_loss
33
+ rsi = 100 - (100 / (1 + rs))
34
+
35
+ return rsi.clip(0, 100).to_frame("rsi")
36
+
37
+ def calculate_macd(
38
+ self, df: pd.DataFrame, fast: int, slow: int, signal: int
39
+ ) -> pd.DataFrame:
40
+ close = df["close"]
41
+ ema_fast = close.ewm(span=fast, adjust=False, min_periods=fast).mean()
42
+ ema_slow = close.ewm(span=slow, adjust=False, min_periods=slow).mean()
43
+
44
+ macd_line = ema_fast - ema_slow
45
+ signal_line = macd_line.ewm(
46
+ span=signal, adjust=False, min_periods=signal
47
+ ).mean()
48
+
49
+ return pd.DataFrame(
50
+ {
51
+ "macd": macd_line,
52
+ "signal": signal_line,
53
+ "histogram": macd_line - signal_line,
54
+ }
55
+ )
56
+
57
+ def calculate_bollinger_bands(
58
+ self, df: pd.DataFrame, window: int, std: int
59
+ ) -> pd.DataFrame:
60
+ close = df["close"]
61
+ sma = close.rolling(window=window, min_periods=window).mean()
62
+ rolling_std = close.rolling(window=window, min_periods=window).std()
63
+ upper_band = sma + (rolling_std * std)
64
+ lower_band = sma - (rolling_std * std)
65
+ return pd.DataFrame(
66
+ {"upper_band": upper_band, "middle_band": sma, "lower_band": lower_band}
67
+ )
68
+
69
+ def calculate_stoch(
70
+ self, df: pd.DataFrame, window: int, smooth_d: int, smooth_k: int
71
+ ) -> pd.DataFrame:
72
+ high = df["high"]
73
+ low = df["low"]
74
+ close = df["close"]
75
+
76
+ lowest_low = low.rolling(window=window).min()
77
+ highest_high = high.rolling(window=window).max()
78
+
79
+ k = 100 * (close - lowest_low) / (highest_high - lowest_low)
80
+ slow_k = k.rolling(window=smooth_k).mean()
81
+ slow_d = slow_k.rolling(window=smooth_d).mean()
82
+
83
+ return pd.DataFrame({"slow_k": slow_k, "slow_d": slow_d})
84
+
85
+ def calculate_atr(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
86
+ high = df["high"]
87
+ low = df["low"]
88
+ close = df["close"]
89
+
90
+ tr1 = high - low
91
+ tr2 = abs(high - close.shift())
92
+ tr3 = abs(low - close.shift())
93
+ tr = pd.concat([tr1, tr2, tr3], axis=1).max(axis=1)
94
+
95
+ atr = tr.ewm(alpha=1 / window, adjust=False, min_periods=window).mean()
96
+ return atr.to_frame("atr")
97
+
98
+ def calculate_cci(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
99
+ high = df["high"]
100
+ low = df["low"]
101
+ close = df["close"]
102
+
103
+ tp = (high + low + close) / 3
104
+ tp_sma = tp.rolling(window=window, min_periods=window).mean()
105
+ mean_dev = tp.rolling(window=window, min_periods=window).apply(
106
+ lambda x: (x - x.mean()).abs().mean()
107
+ )
108
+
109
+ cci = (tp - tp_sma) / (0.015 * mean_dev)
110
+ return cci.to_frame("cci")
111
+
112
+ def calculate_adx(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
113
+ high = df["high"]
114
+ low = df["low"]
115
+ close = df["close"]
116
+
117
+ # Calculate +DM, -DM and TR
118
+ move_up = high.diff()
119
+ move_down = low.diff().apply(abs)
120
+
121
+ plus_dm = pd.Series((move_up > move_down) & (move_up > 0)).astype(int) * move_up
122
+ minus_dm = (
123
+ pd.Series((move_down > move_up) & (move_down > 0)).astype(int) * move_down
124
+ )
125
+
126
+ tr1 = high - low
127
+ tr2 = abs(high - close.shift())
128
+ tr3 = abs(low - close.shift())
129
+ tr = pd.concat([tr1, tr2, tr3], axis=1).max(axis=1)
130
+
131
+ # Smooth +DM, -DM and TR
132
+ atr = tr.ewm(alpha=1 / window, adjust=False, min_periods=window).mean()
133
+ plus_di = 100 * (
134
+ plus_dm.ewm(alpha=1 / window, adjust=False, min_periods=window).mean() / atr
135
+ )
136
+ minus_di = 100 * (
137
+ minus_dm.ewm(alpha=1 / window, adjust=False, min_periods=window).mean()
138
+ / atr
139
+ )
140
+
141
+ # Calculate ADX
142
+ dx = 100 * (abs(plus_di - minus_di) / (plus_di + minus_di))
143
+ adx = dx.ewm(alpha=1 / window, adjust=False, min_periods=window).mean()
144
+
145
+ return adx.to_frame("adx")
146
+
147
+ def calculate_willr(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
148
+ raise NotImplementedError("WILLR not implemented in simple calculator")
149
+
150
+ def calculate_ad(self, df: pd.DataFrame) -> pd.DataFrame:
151
+ raise NotImplementedError("AD not implemented in simple calculator")
152
+
153
+ def calculate_adosc(
154
+ self, df: pd.DataFrame, fast_period: int, slow_period: int
155
+ ) -> pd.DataFrame:
156
+ raise NotImplementedError("ADOSC not implemented in simple calculator")
157
+
158
+ def calculate_obv(self, df: pd.DataFrame) -> pd.DataFrame:
159
+ raise NotImplementedError("OBV not implemented in simple calculator")
160
+
161
+ def calculate_mom(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
162
+ raise NotImplementedError("MOM not implemented in simple calculator")
163
+
164
+ def calculate_sar(
165
+ self, df: pd.DataFrame, acceleration: float, maximum: float
166
+ ) -> pd.DataFrame:
167
+ raise NotImplementedError("SAR not implemented in simple calculator")
168
+
169
+ def calculate_tsf(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
170
+ raise NotImplementedError("TSF not implemented in simple calculator")
171
+
172
+ def calculate_apo(
173
+ self, df: pd.DataFrame, fast_period: int, slow_period: int, ma_type: int
174
+ ) -> pd.DataFrame:
175
+ raise NotImplementedError("APO not implemented in simple calculator")
176
+
177
+ def calculate_aroon(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
178
+ raise NotImplementedError("AROON not implemented in simple calculator")
179
+
180
+ def calculate_aroonosc(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
181
+ raise NotImplementedError("AROONOSC not implemented in simple calculator")
182
+
183
+ def calculate_bop(self, df: pd.DataFrame) -> pd.DataFrame:
184
+ raise NotImplementedError("BOP not implemented in simple calculator")
185
+
186
+ def calculate_cmo(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
187
+ raise NotImplementedError("CMO not implemented in simple calculator")
188
+
189
+ def calculate_dx(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
190
+ raise NotImplementedError("DX not implemented in simple calculator")
191
+
192
+ def calculate_mfi(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
193
+ raise NotImplementedError("MFI not implemented in simple calculator")
194
+
195
+ def calculate_minus_di(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
196
+ raise NotImplementedError("MINUS_DI not implemented in simple calculator")
197
+
198
+ def calculate_minus_dm(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
199
+ raise NotImplementedError("MINUS_DM not implemented in simple calculator")
200
+
201
+ def calculate_plus_di(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
202
+ raise NotImplementedError("PLUS_DI not implemented in simple calculator")
203
+
204
+ def calculate_plus_dm(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
205
+ raise NotImplementedError("PLUS_DM not implemented in simple calculator")
206
+
207
+ def calculate_ppo(
208
+ self, df: pd.DataFrame, fast_period: int, slow_period: int, ma_type: int
209
+ ) -> pd.DataFrame:
210
+ raise NotImplementedError("PPO not implemented in simple calculator")
211
+
212
+ def calculate_roc(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
213
+ raise NotImplementedError("ROC not implemented in simple calculator")
214
+
215
+ def calculate_rocp(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
216
+ raise NotImplementedError("ROCP not implemented in simple calculator")
217
+
218
+ def calculate_rocr(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
219
+ raise NotImplementedError("ROCR not implemented in simple calculator")
220
+
221
+ def calculate_rocr100(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
222
+ raise NotImplementedError("ROCR100 not implemented in simple calculator")
223
+
224
+ def calculate_trix(self, df: pd.DataFrame, window: int) -> pd.DataFrame:
225
+ raise NotImplementedError("TRIX not implemented in simple calculator")
226
+
227
+ def calculate_ultosc(
228
+ self, df: pd.DataFrame, window1: int, window2: int, window3: int
229
+ ) -> pd.DataFrame:
230
+ raise NotImplementedError("ULTOSC not implemented in simple calculator")