siat 3.10.25__py3-none-any.whl → 3.10.125__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/assets_liquidity.py +168 -30
- siat/bond.py +91 -30
- siat/capm_beta.py +36 -10
- siat/capm_beta2.py +34 -3
- siat/common.py +95 -8
- siat/economy.py +3 -3
- siat/economy2.py +75 -1
- siat/exchange_bond_china.pickle +0 -0
- siat/fama_french.py +292 -12
- siat/financial_statements.py +26 -85
- siat/financials.py +156 -20
- siat/financials_china.py +1 -1
- siat/fund_china.py +52 -22
- siat/future_china.py +53 -59
- siat/grafix.py +218 -155
- siat/holding_risk.py +38 -31
- siat/market_china.py +22 -11
- siat/markowitz2.py +72 -10
- siat/option_china.py +93 -31
- siat/option_pricing.py +16 -6
- siat/other_indexes.py +16 -3
- siat/risk_adjusted_return.py +283 -164
- siat/risk_adjusted_return2.py +3 -1
- siat/risk_evaluation.py +298 -25
- siat/sector_china.py +24 -11
- siat/security_price2.py +19 -4
- siat/security_prices.py +228 -28
- siat/security_trend2.py +14 -14
- siat/stock.py +38 -3
- siat/translate.py +20 -10
- siat/var_model_validation.py +59 -0
- {siat-3.10.25.dist-info → siat-3.10.125.dist-info}/METADATA +1 -1
- {siat-3.10.25.dist-info → siat-3.10.125.dist-info}/RECORD +36 -36
- {siat-3.10.25.dist-info → siat-3.10.125.dist-info}/LICENSE +0 -0
- {siat-3.10.25.dist-info → siat-3.10.125.dist-info}/WHEEL +0 -0
- {siat-3.10.25.dist-info → siat-3.10.125.dist-info}/top_level.txt +0 -0
siat/fama_french.py
CHANGED
@@ -32,14 +32,211 @@ if czxt in ['linux']: #website Jupyter
|
|
32
32
|
# 解决保存图像时'-'显示为方块的问题
|
33
33
|
plt.rcParams['axes.unicode_minus'] = False
|
34
34
|
#==============================================================================
|
35
|
+
def convert2freq(df,new_freq='daily'):
|
36
|
+
"""
|
37
|
+
功能:将月度或年度频度的数据均匀化为日度数据
|
38
|
+
"""
|
39
|
+
dfcols=list(df)
|
40
|
+
|
41
|
+
import pandas as pd
|
42
|
+
df['datetmp']=df.index
|
43
|
+
df['Date']=df['datetmp'].apply(lambda x: x.to_timestamp())
|
44
|
+
df.set_index('Date',inplace=True)
|
45
|
+
#df['Date']=df['date']
|
46
|
+
if not isinstance(df.index, pd.DatetimeIndex):
|
47
|
+
df.index = pd.to_datetime(df.index)
|
48
|
+
|
49
|
+
if new_freq == 'daily':
|
50
|
+
df = df.asfreq('D')
|
51
|
+
elif new_freq == 'monthly':
|
52
|
+
df = df.asfreq('M')
|
53
|
+
else:
|
54
|
+
df = df.asfreq('Y')
|
55
|
+
|
56
|
+
for c in dfcols:
|
57
|
+
df[c] = df[c].ffill()
|
58
|
+
df[c] = df[c].bfill()
|
59
|
+
|
60
|
+
df.drop(columns=['datetmp'], inplace=True)
|
61
|
+
|
62
|
+
#df=df[['Date']+dfcols]
|
63
|
+
|
64
|
+
return df
|
65
|
+
#==============================================================================
|
66
|
+
#==============================================================================
|
35
67
|
if __name__=='__main__':
|
36
|
-
start='
|
37
|
-
|
68
|
+
start='auto'; end='today'
|
69
|
+
|
70
|
+
scope='US'
|
71
|
+
factor='FF3'
|
72
|
+
freq='yearly'
|
73
|
+
|
74
|
+
show_ff_factors(ticker='US',indicator='FF3',freq='yearly')
|
75
|
+
|
76
|
+
def show_ff_factors(market='US',indicator='FF3', \
|
77
|
+
start='auto',end='today',freq='yearly'):
|
78
|
+
"""
|
79
|
+
功能:套壳函数get_ff3_factors/get_ffc4_factors/get_ff5_factors
|
80
|
+
|
81
|
+
【支持的因子种类(factor)】
|
82
|
+
FF3: FF3各个因子
|
83
|
+
FFC4: FFC4各个因子
|
84
|
+
FF5: FF5各个因子
|
85
|
+
|
86
|
+
【支持的国家/地区(scope)】
|
87
|
+
US: 美国
|
88
|
+
North_America:北美(美国+加拿大)
|
89
|
+
Global: 全球
|
90
|
+
Global_ex_US: 全球(除美国外)
|
91
|
+
Asia_Pacific_ex_Japan: 亚太(除日本外)
|
92
|
+
China: 中国
|
93
|
+
Japan: 日本
|
94
|
+
Europe: 欧洲
|
95
|
+
|
96
|
+
【支持的取样频率(freq)】
|
97
|
+
yearly: 年
|
98
|
+
monthly: 月
|
99
|
+
daily: 日
|
100
|
+
"""
|
101
|
+
ticker=market
|
102
|
+
|
103
|
+
indicator1=indicator.lower()
|
104
|
+
factorlist=['ff3','ffc4','ff5']
|
105
|
+
if not (indicator1 in factorlist):
|
106
|
+
print(f" #Error(show_ff_factors): unsupported factor {indicator}")
|
107
|
+
print(f" Supported factors for FF models: {factorlist}")
|
108
|
+
return
|
109
|
+
|
110
|
+
import datetime; todaydt = datetime.date.today(); todaystr=str(todaydt)
|
111
|
+
if end == 'today': end=todaystr
|
112
|
+
|
113
|
+
if start == 'auto':
|
114
|
+
if freq == 'yearly':
|
115
|
+
start=date_adjust(end,adjust=-365*5)
|
116
|
+
elif freq == 'monthly':
|
117
|
+
start=date_adjust(end,adjust=-31*8)
|
118
|
+
else: #freq=='daily'
|
119
|
+
start=date_adjust(end,adjust=-60)
|
120
|
+
|
121
|
+
start,end=start_end_preprocess(start,end)
|
122
|
+
|
123
|
+
freq=freq.lower()
|
124
|
+
if freq == 'daily':
|
125
|
+
print("Looking for daily factors, it may take time ...")
|
126
|
+
|
127
|
+
if indicator1=='ff3':
|
128
|
+
df=get_ff3_factors(start=start,end=end,scope=ticker,freq=freq)
|
129
|
+
elif indicator1=='ffc4':
|
130
|
+
df=get_ffc4_factors(start=start,end=end,scope=ticker,freq=freq)
|
131
|
+
elif indicator1=='ff5':
|
132
|
+
df=get_ff5_factors(start=start,end=end,scope=ticker,freq=freq)
|
133
|
+
else:
|
134
|
+
pass
|
135
|
+
|
136
|
+
#处理无数据情形
|
137
|
+
if df is None:
|
138
|
+
print(f" #Warning(show_ff_factors): got none data from {start} to {end}")
|
139
|
+
print(f" Suggestion: may specify an earlier start date and try again")
|
140
|
+
return
|
141
|
+
if len(df) == 0:
|
142
|
+
print(f" #Warning(show_ff_factors): got zero data from {start} to {end}")
|
143
|
+
print(f" Suggestion: may specify an earlier start date and try again")
|
144
|
+
return
|
145
|
+
|
146
|
+
#处理RF小数位数
|
147
|
+
df['RF']=df['RF'].apply(lambda x: str(round(x,4)))
|
148
|
+
|
149
|
+
#titletxt="Asset Pricing Factors: "+indicator.upper()+'Model, '+freq+' @ '+ticker
|
150
|
+
titletxt=indicator.upper()+'模型定价因子:'+freq.title()+' @'+ticker
|
151
|
+
|
152
|
+
if freq == 'yearly':
|
153
|
+
ft0="说明:RF为年化无风险利率%(美短债收益率)"
|
154
|
+
elif freq == 'monthly':
|
155
|
+
ft0="说明:RF为月度无风险利率%(美短债收益率)"
|
156
|
+
else:
|
157
|
+
ft0="说明:RF为日频无风险利率%(基于短期美债收益率)"
|
158
|
+
|
159
|
+
#footnote="Data source: Dartmouth College, "+todaystr
|
160
|
+
footnote=ft0+'\n'+"数据来源:Dartmouth College,"+todaystr
|
161
|
+
|
162
|
+
df_display_CSS(df,titletxt=titletxt,footnote=footnote,facecolor='papayawhip', \
|
163
|
+
decimals=2, \
|
164
|
+
first_col_align='center',second_col_align='center', \
|
165
|
+
last_col_align='center',other_col_align='center')
|
166
|
+
|
167
|
+
return
|
168
|
+
|
169
|
+
#==============================================================================
|
170
|
+
if __name__=='__main__':
|
171
|
+
start='2020-1-1'; end='2025-4-30'
|
172
|
+
|
38
173
|
scope='Europe'
|
39
174
|
factor='Mom'
|
40
175
|
freq='yearly'
|
176
|
+
|
177
|
+
scope='US'
|
178
|
+
factor='FF3'
|
179
|
+
freq='yearly'
|
180
|
+
freq='daily'
|
181
|
+
|
182
|
+
ff3d=get_ff_factors(start,end,scope,factor,freq='daily')
|
183
|
+
ff3mth=get_ff_factors(start,end,scope,factor,freq='monthly')
|
184
|
+
ff3y=get_ff_factors(start,end,scope,factor,freq='yearly')
|
185
|
+
|
186
|
+
def get_ff_factors(start,end,scope='US',factor='FF3',freq='monthly',retry=10):
|
187
|
+
"""
|
188
|
+
功能:套壳函数get_ff_factors0,应对freq='daily'经常失败的变通方法
|
189
|
+
"""
|
190
|
+
import pandas as pd
|
191
|
+
startpd=pd.to_datetime(start)
|
192
|
+
endpd=pd.to_datetime(end)
|
193
|
+
|
194
|
+
fff=None
|
195
|
+
for i in range(retry):
|
196
|
+
if not (fff is None): break
|
197
|
+
fff=get_ff_factors0(start=start,end=end,scope=scope,factor=factor,freq=freq)
|
198
|
+
|
199
|
+
#多次尝试后仍未成功做变通处理:针对日度数据,使用月/年数据均匀化为日度数据
|
200
|
+
if fff is None:
|
201
|
+
if freq == 'daily':
|
202
|
+
start1=date_adjust(start,adjust=-31)
|
203
|
+
end1=date_adjust(end,adjust=31)
|
204
|
+
fff=get_ff_factors0(start=start1,end=end1,scope=scope,factor=factor,freq='monthly')
|
205
|
+
if not (fff is None):
|
206
|
+
ff_factors0=convert2freq(fff,new_freq='daily')
|
207
|
+
ff_factors=ff_factors0[(ff_factors0.index >=startpd) & (ff_factors0.index <=endpd)]
|
208
|
+
else:
|
209
|
+
ff_factors=fff
|
210
|
+
|
211
|
+
elif freq == 'monthly':
|
212
|
+
start1=date_adjust(start,adjust=-365)
|
213
|
+
end1=date_adjust(end,adjust=365)
|
214
|
+
fff=get_ff_factors0(start=start1,end=end1,scope=scope,factor=factor,freq='yearly')
|
215
|
+
if not (fff is None):
|
216
|
+
ff_factors=convert2freq(fff,new_freq='monthly')
|
217
|
+
else:
|
218
|
+
ff_factors=fff
|
219
|
+
|
220
|
+
else:
|
221
|
+
start1=date_adjust(start,adjust=-365)
|
222
|
+
end1=date_adjust(end,adjust=365)
|
223
|
+
fff=get_ff_factors0(start=start1,end=end1,scope=scope,factor=factor,freq='yearly')
|
224
|
+
ff_factors=fff
|
225
|
+
else:
|
226
|
+
ff_factors=fff
|
227
|
+
|
228
|
+
#加入日期
|
229
|
+
cols=list(ff_factors)
|
230
|
+
ff_factors['Date']=ff_factors.index
|
231
|
+
if freq == 'daily':
|
232
|
+
ff_factors['Date']=ff_factors['Date'].apply(lambda x: x.strftime("%Y-%m-%d"))
|
233
|
+
|
234
|
+
ff_factors=ff_factors[['Date']+cols]
|
235
|
+
|
236
|
+
return ff_factors
|
41
237
|
|
42
|
-
|
238
|
+
|
239
|
+
def get_ff_factors0(start,end,scope='US',factor='FF3',freq='yearly'):
|
43
240
|
"""
|
44
241
|
【支持的因子种类(factor)】
|
45
242
|
FF3: FF3各个因子
|
@@ -167,7 +364,7 @@ def get_ff_factors(start,end,scope='US',factor='FF3',freq='yearly'):
|
|
167
364
|
try:
|
168
365
|
ds = web.DataReader(symbol, source, start, end)
|
169
366
|
except:
|
170
|
-
print(" #
|
367
|
+
print(f" #Warning(get_ff_factors): time out to get {freq} data, working around ...")
|
171
368
|
return None
|
172
369
|
|
173
370
|
#提取希望的资产定价因子
|
@@ -731,7 +928,8 @@ def get_ffc4_factors(start,end,scope='US',freq='yearly'):
|
|
731
928
|
Mom['date']=pd.to_datetime(Mom['date'].astype('str'))
|
732
929
|
Mom.set_index('date',drop=True, inplace=True)
|
733
930
|
|
734
|
-
ffc4_factors=pd.merge(ff3,Mom,how='left',left_index=True,right_index=True)
|
931
|
+
#ffc4_factors=pd.merge(ff3,Mom,how='left',left_index=True,right_index=True)
|
932
|
+
ffc4_factors=pd.merge(ff3,Mom,how='inner',on='Date')
|
735
933
|
#del ffc4_factors['date']
|
736
934
|
|
737
935
|
return ffc4_factors
|
@@ -887,7 +1085,14 @@ if __name__=='__main__':
|
|
887
1085
|
|
888
1086
|
|
889
1087
|
#==============================================================================
|
890
|
-
|
1088
|
+
if __name__=='__main__':
|
1089
|
+
ticker='BIDU'
|
1090
|
+
start='2025-1-1'
|
1091
|
+
end='2025-5-30'
|
1092
|
+
scope='US'
|
1093
|
+
graph=True
|
1094
|
+
|
1095
|
+
|
891
1096
|
def reg_ff3_betas(ticker,start,end,scope='US',graph=True):
|
892
1097
|
"""
|
893
1098
|
功能:测试一只股票对于FF3各个因子的系数大小、符号方向和显著性
|
@@ -915,11 +1120,15 @@ def reg_ff3_betas(ticker,start,end,scope='US',graph=True):
|
|
915
1120
|
ret=ret.rename(columns={'Close':'dRet'})
|
916
1121
|
|
917
1122
|
#抓取FF3因子
|
1123
|
+
print(" Looking for factors for FF3 model ...")
|
918
1124
|
freq='daily'
|
919
1125
|
ff3=get_ff3_factors(start,end,scope,freq)
|
920
1126
|
if ff3 is None:
|
921
1127
|
print(" #Warning(reg_ff3_betas): factors unavailable for",scope,freq,'from',start,'to',end)
|
922
1128
|
return None
|
1129
|
+
if len(ff3) == 0:
|
1130
|
+
print(" #Warning(reg_ff3_betas): zero factors retrieved for",scope,freq,'from',start,'to',end)
|
1131
|
+
return None
|
923
1132
|
|
924
1133
|
#改造索引类型为时间戳索引(DatetimeIndex),便于与ret合成
|
925
1134
|
ff3['Date']=ff3.index.strftime("%m/%d/%Y")
|
@@ -944,7 +1153,7 @@ def reg_ff3_betas(ticker,start,end,scope='US',graph=True):
|
|
944
1153
|
#输出结果并绘制横向柱状图
|
945
1154
|
if graph == True:
|
946
1155
|
gparms=parms.iloc[[1,2,3]]
|
947
|
-
print("\n",parms)
|
1156
|
+
#print("\n",parms)
|
948
1157
|
title=ticker_name(ticker)+": FF3模型的贝塔系数"
|
949
1158
|
plt.title(title,fontsize=12,fontweight='bold')
|
950
1159
|
plt.ylabel("贝塔系数",fontsize=12,fontweight='bold')
|
@@ -1005,6 +1214,13 @@ if __name__=='__main__':
|
|
1005
1214
|
|
1006
1215
|
|
1007
1216
|
#==============================================================================
|
1217
|
+
if __name__=='__main__':
|
1218
|
+
ticker='MSFT'
|
1219
|
+
start='2022-5-1'; end='2025-4-30'
|
1220
|
+
scope='US'; graph=True
|
1221
|
+
|
1222
|
+
|
1223
|
+
|
1008
1224
|
def reg_ffc4_betas(ticker,start,end,scope='US',graph=True):
|
1009
1225
|
"""
|
1010
1226
|
功能:测试一只股票对于FFC4各个因子的系数大小、符号方向和显著性
|
@@ -1033,16 +1249,20 @@ def reg_ffc4_betas(ticker,start,end,scope='US',graph=True):
|
|
1033
1249
|
ret=ret.rename(columns={'Close':'dRet'})
|
1034
1250
|
|
1035
1251
|
#抓取每日FFC4因子
|
1252
|
+
print(" Looking for factors for FFC4 model ...")
|
1036
1253
|
freq='daily'
|
1037
1254
|
ffc4=get_ffc4_factors(start,end,scope,freq)
|
1038
1255
|
if ffc4 is None:
|
1039
1256
|
print(" #Warning(reg_ffc4_betas): factors not available for",scope,freq,'from',start,'to',end)
|
1040
1257
|
return None
|
1258
|
+
if len(ffc4) == 0:
|
1259
|
+
print(" #Warning(reg_ffc4_betas): zero factors retrieved for",scope,freq,'from',start,'to',end)
|
1260
|
+
return None
|
1041
1261
|
|
1042
1262
|
#改造索引类型为时间戳索引(DatetimeIndex),便于与ret合成
|
1043
|
-
ffc4['Date']=ffc4.index.strftime("%m/%d/%Y")
|
1263
|
+
#ffc4['Date']=ffc4.index.strftime("%m/%d/%Y")
|
1044
1264
|
ffc4['Date']=pd.to_datetime(ffc4['Date'])
|
1045
|
-
ffc4.set_index('Date',inplace=True)
|
1265
|
+
ffc4.set_index('Date',drop=True,inplace=True)
|
1046
1266
|
|
1047
1267
|
#合成股票日收益率+每日FF3因子
|
1048
1268
|
sample=pd.merge(ret,ffc4,how='inner',left_index=True,right_index=True)
|
@@ -1051,7 +1271,10 @@ def reg_ffc4_betas(ticker,start,end,scope='US',graph=True):
|
|
1051
1271
|
#回归FF3模型
|
1052
1272
|
import statsmodels.api as sm
|
1053
1273
|
y=sample['dRet']
|
1054
|
-
|
1274
|
+
try:
|
1275
|
+
X=sample[['Mkt-RF','SMB','HML','MOM']]
|
1276
|
+
except:
|
1277
|
+
X=sample[['Mkt-RF','SMB','HML','Mom']]
|
1055
1278
|
X1=sm.add_constant(X)
|
1056
1279
|
results=sm.OLS(y,X1).fit()
|
1057
1280
|
|
@@ -1122,6 +1345,11 @@ if __name__=='__main__':
|
|
1122
1345
|
test_ffc4_betas()
|
1123
1346
|
|
1124
1347
|
#==============================================================================
|
1348
|
+
if __name__=='__main__':
|
1349
|
+
ticker='MSFT'
|
1350
|
+
start='2024-5-1'; end='2025-4-30'
|
1351
|
+
scope='US'; graph=True
|
1352
|
+
|
1125
1353
|
def reg_ff5_betas(ticker,start,end,scope='US',graph=True):
|
1126
1354
|
"""
|
1127
1355
|
功能:测试一只股票对于FF5各个因子的系数大小、符号方向和显著性
|
@@ -1149,12 +1377,16 @@ def reg_ff5_betas(ticker,start,end,scope='US',graph=True):
|
|
1149
1377
|
#命名日收益率字段为dRet
|
1150
1378
|
ret=ret.rename(columns={'Close':'dRet'})
|
1151
1379
|
|
1152
|
-
#抓取每日
|
1380
|
+
#抓取每日FF5因子
|
1381
|
+
print(" Looking for factors for FF5 model ...")
|
1153
1382
|
freq='daily'
|
1154
1383
|
ff5=get_ff5_factors(start,end,scope,freq)
|
1155
1384
|
if ff5 is None:
|
1156
1385
|
print(" #Warning(reg_ff5_betas): factors not available for",scope,freq,'from',start,'to',end)
|
1157
1386
|
return None
|
1387
|
+
if len(ff5) is None:
|
1388
|
+
print(" #Warning(reg_ff5_betas): zero factors retrieved for",scope,freq,'from',start,'to',end)
|
1389
|
+
return None
|
1158
1390
|
|
1159
1391
|
#改造索引类型为时间戳索引(DatetimeIndex),便于与ret合成
|
1160
1392
|
ff5['Date']=ff5.index.strftime("%m/%d/%Y")
|
@@ -1238,4 +1470,52 @@ def test_ff5_betas():
|
|
1238
1470
|
if __name__=='__main__':
|
1239
1471
|
test_ff5_betas()
|
1240
1472
|
|
1241
|
-
#==============================================================================
|
1473
|
+
#==============================================================================
|
1474
|
+
|
1475
|
+
|
1476
|
+
|
1477
|
+
def reg_ff_betas(ticker,start,end='today',indicator='FF3',market='US'):
|
1478
|
+
"""
|
1479
|
+
功能:套壳函数reg_ff3_betas/reg_ffc4_betas/reg_ff5_betas
|
1480
|
+
参数:
|
1481
|
+
indicator:默认'FF3',还可为'FFC4'或'FF5'
|
1482
|
+
scope:默认'US',还可为'China'或'Japan'或'Europe'等
|
1483
|
+
"""
|
1484
|
+
scope=market
|
1485
|
+
|
1486
|
+
start,end=start_end_preprocess(start,end)
|
1487
|
+
|
1488
|
+
indicator1=indicator.lower()
|
1489
|
+
factorlist=['ff3','ffc4','ff5']
|
1490
|
+
if not (indicator1 in factorlist):
|
1491
|
+
print(f" #Error(show_ff_factors): unsupported factor {indicator}")
|
1492
|
+
print(f" Supported factors for FF models: {factorlist}")
|
1493
|
+
return
|
1494
|
+
|
1495
|
+
if indicator1=='ff3':
|
1496
|
+
df=reg_ff3_betas(ticker=ticker,start=start,end=end,scope=scope)
|
1497
|
+
elif indicator1=='ffc4':
|
1498
|
+
df=reg_ffc4_betas(ticker=ticker,start=start,end=end,scope=scope)
|
1499
|
+
elif indicator1=='ff5':
|
1500
|
+
df=reg_ff5_betas(ticker=ticker,start=start,end=end,scope=scope)
|
1501
|
+
else:
|
1502
|
+
pass
|
1503
|
+
|
1504
|
+
#打印回归结果
|
1505
|
+
cols=list(df)
|
1506
|
+
df['const']=df.index
|
1507
|
+
df=df[['const']+cols]
|
1508
|
+
|
1509
|
+
titletxt=ticker_name(ticker)+":"+indicator.upper()+'模型回归结果'
|
1510
|
+
import datetime; todaydt = datetime.date.today(); todaystr=str(todaydt)
|
1511
|
+
footnote="数据来源:Dartmouth College/sina/stooq/Yahoo等,"+todaystr
|
1512
|
+
|
1513
|
+
df.rename(columns={'const':'Constant','coef':'Coefficient', \
|
1514
|
+
'sig':'Significance'},inplace=True)
|
1515
|
+
|
1516
|
+
df_display_CSS(df,titletxt=titletxt,footnote=footnote,facecolor='papayawhip', \
|
1517
|
+
decimals=4, \
|
1518
|
+
first_col_align='center',second_col_align='center', \
|
1519
|
+
last_col_align='center',other_col_align='center')
|
1520
|
+
|
1521
|
+
return df
|
siat/financial_statements.py
CHANGED
@@ -52,14 +52,8 @@ def get_balance_sheet(symbol):
|
|
52
52
|
try:
|
53
53
|
stmta=stock.balance_sheet() # Defaults to Annual
|
54
54
|
except:
|
55
|
-
print("
|
56
|
-
|
57
|
-
|
58
|
-
try:
|
59
|
-
stmta=stock.balance_sheet()
|
60
|
-
except:
|
61
|
-
print(" #Warning(get_balance_sheet): no annual info available for",symbol)
|
62
|
-
return None
|
55
|
+
print(" #Warning(get_balance_sheet): no annual info available for",symbol)
|
56
|
+
return None
|
63
57
|
|
64
58
|
if isinstance(stmta,dict):
|
65
59
|
print(" #Warning(get_balance_sheet): Yahoo Finance currently unaccessable for",symbol)
|
@@ -76,14 +70,8 @@ def get_balance_sheet(symbol):
|
|
76
70
|
try:
|
77
71
|
stmtq=stock.balance_sheet(frequency="q")
|
78
72
|
except:
|
79
|
-
print("
|
80
|
-
|
81
|
-
|
82
|
-
try:
|
83
|
-
stmtq=stock.balance_sheet(frequency="q")
|
84
|
-
except:
|
85
|
-
print(" #Warning(get_balance_sheet): no quarterly info available for",symbol)
|
86
|
-
return None
|
73
|
+
print(" #Warning(get_balance_sheet): no quarterly info available for",symbol)
|
74
|
+
return None
|
87
75
|
|
88
76
|
if isinstance(stmtq,dict):
|
89
77
|
print(" #Warning(get_balance_sheet): Yahoo Finance currently unaccessable for",symbol)
|
@@ -196,17 +184,12 @@ def get_income_statements(symbol):
|
|
196
184
|
try:
|
197
185
|
stmta=stock.income_statement() # Defaults to Annual
|
198
186
|
except:
|
199
|
-
print("
|
200
|
-
|
201
|
-
try:
|
202
|
-
stmta=stock.income_statement()
|
203
|
-
except:
|
204
|
-
print(" #Warning(get_income_statements): no annual info available for",symbol)
|
205
|
-
return None
|
187
|
+
print(" #Warning(get_income_statements): no annual info available for",symbol)
|
188
|
+
return None
|
206
189
|
|
207
190
|
if isinstance(stmta,dict):
|
208
|
-
|
209
|
-
|
191
|
+
print(" #Warning(get_balance_sheet): Yahoo Finance currently unaccessable for",symbol)
|
192
|
+
return None
|
210
193
|
|
211
194
|
"""
|
212
195
|
#判断是否抓取到了数据
|
@@ -219,17 +202,12 @@ def get_income_statements(symbol):
|
|
219
202
|
try:
|
220
203
|
stmtq=stock.income_statement(frequency="q")
|
221
204
|
except:
|
222
|
-
print("
|
223
|
-
|
224
|
-
try:
|
225
|
-
stmtq=stock.income_statement(frequency="q")
|
226
|
-
except:
|
227
|
-
print(" #Warning(get_income_statements): no quarterly info available for",symbol)
|
228
|
-
return None
|
205
|
+
print(" #Warning(get_income_statements): no quarterly info available for",symbol)
|
206
|
+
return None
|
229
207
|
|
230
208
|
if isinstance(stmtq,dict):
|
231
|
-
|
232
|
-
|
209
|
+
print(" #Warning(get_balance_sheet): Yahoo Finance currently unaccessable for",symbol)
|
210
|
+
return None
|
233
211
|
|
234
212
|
"""
|
235
213
|
if (len(stmta)==0) and (len(stmtq)==0):
|
@@ -311,17 +289,12 @@ def get_cashflow_statements(symbol):
|
|
311
289
|
try:
|
312
290
|
stmta=stock.cash_flow() # Defaults to Annual
|
313
291
|
except:
|
314
|
-
print("
|
315
|
-
|
316
|
-
try:
|
317
|
-
stmta=stock.cash_flow()
|
318
|
-
except:
|
319
|
-
print(" #Warning(get_cashflow_statements): no annual info available for",symbol)
|
320
|
-
return None
|
292
|
+
print(" #Warning(get_cashflow_statements): no annual info available for",symbol)
|
293
|
+
return None
|
321
294
|
|
322
295
|
if isinstance(stmta,dict):
|
323
|
-
|
324
|
-
|
296
|
+
print(" #Warning(get_balance_sheet): Yahoo Finance currently unaccessable for",symbol)
|
297
|
+
return None
|
325
298
|
|
326
299
|
"""
|
327
300
|
#判断是否抓取到了数据
|
@@ -334,17 +307,12 @@ def get_cashflow_statements(symbol):
|
|
334
307
|
try:
|
335
308
|
stmtq=stock.cash_flow(frequency="q")
|
336
309
|
except:
|
337
|
-
print("
|
338
|
-
|
339
|
-
try:
|
340
|
-
stmtq=stock.cash_flow(frequency="q")
|
341
|
-
except:
|
342
|
-
print(" #Warning(get_cashflow_statements): no quarterly info available for",symbol)
|
343
|
-
return None
|
310
|
+
print(" #Warning(get_cashflow_statements): no quarterly info available for",symbol)
|
311
|
+
return None
|
344
312
|
|
345
313
|
if isinstance(stmtq,dict):
|
346
|
-
|
347
|
-
|
314
|
+
print(" #Warning(get_balance_sheet): Yahoo Finance currently unaccessable for",symbol)
|
315
|
+
return None
|
348
316
|
|
349
317
|
"""
|
350
318
|
if (len(stmta)==0) and (len(stmtq)==0):
|
@@ -408,17 +376,8 @@ def get_financial_statements(ticker):
|
|
408
376
|
try:
|
409
377
|
fbs = get_balance_sheet(ticker)
|
410
378
|
except:
|
411
|
-
print("
|
412
|
-
|
413
|
-
try:
|
414
|
-
fbs = get_balance_sheet(ticker)
|
415
|
-
except:
|
416
|
-
sleep_random(max_sleep=60)
|
417
|
-
try:
|
418
|
-
fbs = get_balance_sheet(ticker)
|
419
|
-
except:
|
420
|
-
print(" #Error(get_financial_statements): balance sheet not available for",ticker)
|
421
|
-
return None
|
379
|
+
print(" #Error(get_financial_statements): balance sheet not available for",ticker)
|
380
|
+
return None
|
422
381
|
if fbs is None:
|
423
382
|
print(" #Error(get_financial_statements): financial statements not available for",ticker)
|
424
383
|
return None
|
@@ -427,17 +386,8 @@ def get_financial_statements(ticker):
|
|
427
386
|
try:
|
428
387
|
fis = get_income_statements(ticker)
|
429
388
|
except:
|
430
|
-
print("
|
431
|
-
|
432
|
-
try:
|
433
|
-
fis = get_income_statements(ticker)
|
434
|
-
except:
|
435
|
-
sleep_random(max_sleep=60)
|
436
|
-
try:
|
437
|
-
fis = get_income_statements(ticker)
|
438
|
-
except:
|
439
|
-
print(" #Error(get_financial_statements): income info not available for",ticker)
|
440
|
-
return None
|
389
|
+
print(" #Error(get_financial_statements): income info not available for",ticker)
|
390
|
+
return None
|
441
391
|
if fis is None:
|
442
392
|
print(" #Error(get_financial_statements): financial statements not available for",ticker)
|
443
393
|
return None
|
@@ -446,17 +396,8 @@ def get_financial_statements(ticker):
|
|
446
396
|
try:
|
447
397
|
fcf = get_cashflow_statements(ticker)
|
448
398
|
except:
|
449
|
-
print("
|
450
|
-
|
451
|
-
try:
|
452
|
-
fcf = get_cashflow_statements(ticker)
|
453
|
-
except:
|
454
|
-
sleep_random(max_sleep=60)
|
455
|
-
try:
|
456
|
-
fcf = get_cashflow_statements(ticker)
|
457
|
-
except:
|
458
|
-
print(" #Error(get_financial_statements): cash flow info not available for",ticker)
|
459
|
-
return None
|
399
|
+
print(" #Error(get_financial_statements): cash flow info not available for",ticker)
|
400
|
+
return None
|
460
401
|
if fcf is None:
|
461
402
|
print(" #Error(get_financial_statements): financial statements not available for",ticker)
|
462
403
|
return None
|