siat 2.14.1__py3-none-any.whl → 3.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.
siat/security_trend2.py CHANGED
@@ -68,6 +68,7 @@ if __name__=='__main__':
68
68
  loc1='upper left'
69
69
  loc2='lower right'
70
70
  source='auto'
71
+ ticker_type='auto'
71
72
 
72
73
  df=security_trend(ticker,indicator=indicator)
73
74
 
@@ -78,7 +79,6 @@ if __name__=='__main__':
78
79
  end="2020-6-30"
79
80
 
80
81
 
81
-
82
82
  def security_trend(ticker,indicator='Close', \
83
83
  start='default',end='default', \
84
84
 
@@ -97,7 +97,8 @@ def security_trend(ticker,indicator='Close', \
97
97
  preprocess='none',scaling_option='start', \
98
98
  annotate=False,annotate_value=False, \
99
99
  printout=False,source='auto', \
100
- mark_top=1,mark_bottom=1,mark_end=False):
100
+ mark_top=True,mark_bottom=True,mark_end=False, \
101
+ ticker_type='auto'):
101
102
 
102
103
  """
103
104
  功能:组合指令,分析证券指标走势,支持多个证券、多个指标和多种绘图方式。
@@ -164,6 +165,7 @@ def security_trend(ticker,indicator='Close', \
164
165
  若指定雅虎财经数据源,需要拥有访问该网站的权限。
165
166
  """
166
167
  portfolio_flag=False #标志:ticker中是否含有投资组合
168
+ ticker=tickers_cvt2yahoo(ticker) #支持多种形式证券代码格式
167
169
 
168
170
  # 检查证券代码
169
171
  if isinstance(ticker,str):
@@ -193,7 +195,7 @@ def security_trend(ticker,indicator='Close', \
193
195
  # 处理K线图=================================================================
194
196
  if kline and not kline_demo:
195
197
  if portfolio_flag:
196
- print(" #Error(security_trend): ticker of or with portfolio portfolio does not support for K line")
198
+ print(" #Warning(security_trend): ticker of or with portfolio does not support for K line")
197
199
  return None
198
200
 
199
201
  # 跟踪
@@ -202,24 +204,24 @@ def security_trend(ticker,indicator='Close', \
202
204
  fromdate=date_adjust(todate,adjust=-60)
203
205
  if not isinstance(mav,list):
204
206
  mav=[mav]
205
- df=candlestick(stkcd=tickers[0],fromdate=fromdate,todate=todate,mav=mav)
207
+ df=candlestick(stkcd=tickers[0],fromdate=fromdate,todate=todate,mav=mav,ticker_type=ticker_type)
206
208
  return df
207
209
 
208
210
  if kline and kline_demo:
209
211
  if portfolio_flag:
210
- print(" #Error(security_trend): ticker of or with portfolio portfolio does not support for K line")
212
+ print(" #Warning(security_trend): ticker of or with portfolio does not support for K line")
211
213
  return None
212
214
 
213
215
  if start in ['default']:
214
216
  fromdate=date_adjust(todate,adjust=-7)
215
217
 
216
- df=candlestick_demo(tickers[0],fromdate=fromdate,todate=todate)
218
+ df=candlestick_demo(tickers[0],fromdate=fromdate,todate=todate,ticker_type=ticker_type)
217
219
  return df
218
220
 
219
221
  # 处理股票分红和股票分拆:需要访问雅虎财经=====================================
220
222
  if stock_dividend:
221
223
  if portfolio_flag:
222
- print(" #Error(security_trend): ticker of or with portfolio portfolio does not support for stock dividend")
224
+ print(" #Warning(security_trend): ticker of or with portfolio does not support for stock dividend")
223
225
  return None
224
226
 
225
227
  if start in ['default']:
@@ -230,7 +232,7 @@ def security_trend(ticker,indicator='Close', \
230
232
 
231
233
  if stock_split:
232
234
  if portfolio_flag:
233
- print(" #Error(security_trend): ticker of or with portfolio does not support for stock split")
235
+ print(" #Warning(security_trend): ticker of or with portfolio does not support for stock split")
234
236
  return None
235
237
 
236
238
  if start in ['default']:
@@ -331,10 +333,11 @@ def security_trend(ticker,indicator='Close', \
331
333
  return None
332
334
 
333
335
  #检查指标是否支持投资组合:暂不支持组1/3的指标
336
+ """
334
337
  if portfolio_flag and (indicator_group1 or indicator_group3):
335
- print(" #Error(security_trend): ticker of or with portfolio does not support indicator",list2str(measures))
338
+ print(" #Warning(security_trend): ticker of or with portfolio does not support indicator",list2str(measures))
336
339
  return None
337
-
340
+ """
338
341
  # 情形1:单个证券,单个普通指标===============================================
339
342
  # 绘制横线
340
343
  zeroline=False
@@ -348,15 +351,17 @@ def security_trend(ticker,indicator='Close', \
348
351
  zeroline=zeroline, \
349
352
  average_value=average_value, \
350
353
  datatag=datatag,power=power,graph=graph, \
351
- source=source,
352
- mark_top=mark_top,mark_bottom=mark_bottom)
354
+ source=source, \
355
+ mark_top=mark_top,mark_bottom=mark_bottom, \
356
+ mark_end=mark_end,ticker_type=ticker_type)
353
357
  return df
354
358
 
355
359
  # 情形2:单个证券,两个普通指标,twinx==True =================================
356
360
  if ticker_num==1 and indicator_num == 2 and indicator_group1 and twinx:
357
361
  df=compare_security(tickers=tickers[0],measures=measures[:2], \
358
362
  fromdate=fromdate,todate=todate,twinx=twinx, \
359
- loc1=loc1,loc2=loc2,graph=graph,source=source)
363
+ loc1=loc1,loc2=loc2,graph=graph,source=source, \
364
+ ticker_type=ticker_type)
360
365
  return df
361
366
 
362
367
  # 情形3:单个证券,两个及以上普通指标=========================================
@@ -367,14 +372,16 @@ def security_trend(ticker,indicator='Close', \
367
372
  date_range=date_range,date_freq=date_freq, \
368
373
  annotate=annotate,annotate_value=annotate_value, \
369
374
  source=source,
370
- mark_top=mark_top,mark_bottom=mark_bottom)
375
+ mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
376
+ ticker_type=ticker_type)
371
377
  return df
372
378
 
373
379
  # 情形4:两个证券,取第一个普通指标,twinx==True =============================
374
380
  if ticker_num==2 and indicator_group1 and twinx:
375
381
  df=compare_security(tickers=tickers,measures=measures[0], \
376
382
  fromdate=fromdate,todate=todate,twinx=twinx, \
377
- loc1=loc1,loc2=loc2,graph=graph,source=source)
383
+ loc1=loc1,loc2=loc2,graph=graph,source=source, \
384
+ ticker_type=ticker_type)
378
385
  return df
379
386
 
380
387
  # 情形5:两个及以上证券,取第一个普通指标=====================================
@@ -403,7 +410,8 @@ def security_trend(ticker,indicator='Close', \
403
410
  annotate=annotate,annotate_value=annotate_value, \
404
411
  smooth=smooth, \
405
412
  source=source, \
406
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end)
413
+ mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
414
+ ticker_type=ticker_type)
407
415
  return df
408
416
 
409
417
  # 情形6:单个或多个证券,单个或多个RAR指标,支持投资组合=======================
@@ -414,48 +422,21 @@ def security_trend(ticker,indicator='Close', \
414
422
  graph=graph,axhline_value=0,axhline_label='', \
415
423
  printout=printout, \
416
424
  sortby=sortby,trailing=trailing,trend_threshhold=trend_threshhold, \
417
- annotate=annotate,mktidx=market_index,source=source)
418
- """
419
- df=compare_1security_mrar(ticker=tickers[0],rar_names=measures, \
420
- start=fromdate,end=todate, \
421
- market=market,market_index=market_index,RF=RF,window=window, \
422
- axhline_value=0,axhline_label='零线',graph=graph,printout=printout, \
423
- sortby=sortby,source=source,trailing=trailing,trend_threshhold=trend_threshhold, \
424
- annotate=annotate)
425
- """
425
+ annotate=annotate,mktidx=market_index,source=source, \
426
+ ticker_type=ticker_type)
426
427
  return df
427
428
 
428
- """
429
- # 情形7:多个证券,取第一个RAR指标===========================================
430
- # 特别注意:与收益率对比时若使用扩展收益率可能导致矛盾,要使用滚动收益率
431
- if indicator_group2 and ticker_num > 1:
432
- df=compare_mrar(tickers=tickers,rar_name=measures[0], \
433
- start=fromdate,end=todate, \
434
- market=market,market_index=market_index,RF=RF,window=window, \
435
- axhline_value=0,axhline_label='零线',graph=graph,printout=printout, \
436
- sortby=sortby,source=source,trailing=trailing,trend_threshhold=trend_threshhold, \
437
- annotate=annotate)
438
- return df
439
- """
440
429
  # 情形7:单个或多个证券,CAPM贝塔系数=========================================
441
430
  if indicator_group4:
442
431
  df=compare_beta_security(ticker=tickers,start=fromdate,end=todate, \
443
432
  RF=RF,regression_period=regression_period, \
444
433
  graph=graph,annotate=annotate, \
445
- mktidx=market_index,source=source)
434
+ mktidx=market_index,source=source,ticker_type=ticker_type)
446
435
 
447
- """
448
- df=compare_mrar(tickers=tickers,rar_name=measures[0], \
449
- start=fromdate,end=todate, \
450
- market=market,market_index=market_index,RF=RF,window=window, \
451
- axhline_value=0,axhline_label='零线',graph=graph,printout=printout, \
452
- sortby=sortby,source=source,trailing=trailing,trend_threshhold=trend_threshhold, \
453
- annotate=annotate)
454
- """
455
436
  return df
456
437
 
457
438
 
458
- # 情形8:估值指标PE/PB/MV/ROE===============================================
439
+ # 情形8:估值指标PE/PB/MV/ROE,仅针对股票,无需ticker_type====================
459
440
  if indicator_group3:
460
441
  df=security_valuation(tickers=tickers,indicators=measures,start=fromdate,end=todate, \
461
442
  preprocess=preprocess,scaling_option=scaling_option, \