siat 3.0.38__py3-none-any.whl → 3.0.41__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/common.py CHANGED
@@ -1594,7 +1594,8 @@ def print_progress_percent(current,total,steps=5,leading_blanks=2):
1594
1594
  pct=pct_list[pos]
1595
1595
 
1596
1596
  if pct=="100%":
1597
- print("100% completing")
1597
+ #print("100% completing")
1598
+ print("100%, wrapping up ...")
1598
1599
  else:
1599
1600
  print(pct,end=' ')
1600
1601
 
@@ -1905,7 +1906,8 @@ if __name__=='__main__':
1905
1906
  footnote="This is the footnote"
1906
1907
 
1907
1908
  def descriptive_statistics(df,titletxt,footnote,decimals=4,sortby='tpw_mean', \
1908
- recommend_only=False,trailing=7,trend_threshhold=0.01):
1909
+ recommend_only=False,trailing=7,trend_threshhold=0.01, \
1910
+ facecolor='papayawhip',font_size='16px'):
1909
1911
  """
1910
1912
  功能:进行描述性统计,并打印结果
1911
1913
  df的要求:
@@ -2140,6 +2142,7 @@ def descriptive_statistics(df,titletxt,footnote,decimals=4,sortby='tpw_mean', \
2140
2142
  dst6.reset_index(drop=True,inplace=True)
2141
2143
  dst6.index=dst6.index+1
2142
2144
 
2145
+ """
2143
2146
  print("\n"+titletxt+"\n")
2144
2147
  #alignlist=['right','left']+['center']*(len(list(dst4))-1)
2145
2148
  alignlist=['right','left']+['center']*(len(list(dst6))-3)+['center','left']
@@ -2150,8 +2153,16 @@ def descriptive_statistics(df,titletxt,footnote,decimals=4,sortby='tpw_mean', \
2150
2153
  dst7=dst6.to_markdown(index=True,tablefmt='plain',colalign=alignlist)
2151
2154
  dst8=dst7.encode("utf-8",errors="strict")
2152
2155
  print(dst8)
2153
-
2154
2156
  print("\n"+footnote)
2157
+ """
2158
+
2159
+ #确定表格字体大小
2160
+ titile_font_size=font_size
2161
+ heading_font_size=data_font_size=str(int(font_size.replace('px',''))-1)+'px'
2162
+
2163
+ df_display_CSS(dst6,titletxt=titletxt,footnote=footnote,facecolor=facecolor, \
2164
+ titile_font_size=titile_font_size,heading_font_size=heading_font_size, \
2165
+ data_font_size=data_font_size)
2155
2166
 
2156
2167
  return dst5
2157
2168
 
@@ -2175,8 +2186,8 @@ if __name__=='__main__':
2175
2186
 
2176
2187
  def descriptive_statistics2(df,titletxt,footnote,decimals=4,sortby='tpw_mean', \
2177
2188
  recommend_only=False,trailing=7,trend_threshhold=0.01, \
2178
- printout=True,style_print=False, \
2179
- facecolor='whitesmoke',fontcolor='black'):
2189
+ printout=True,style_print=True, \
2190
+ facecolor='whitesmoke',font_size='16px'):
2180
2191
  """
2181
2192
  功能:进行描述性统计,并打印结果
2182
2193
  df的要求:
@@ -2386,7 +2397,7 @@ def descriptive_statistics2(df,titletxt,footnote,decimals=4,sortby='tpw_mean', \
2386
2397
  pass
2387
2398
  #确保display显示时不再自动在数值尾部添加零至6位小数
2388
2399
  dst6[c]=dst6[c].apply(lambda x: str(x))
2389
-
2400
+ """
2390
2401
  if not style_print: #markdown打印
2391
2402
  print("\n"+titletxt+"\n")
2392
2403
  #如果index=True则显示index,这样alignlist的长度就需要dst6列数+1
@@ -2401,14 +2412,11 @@ def descriptive_statistics2(df,titletxt,footnote,decimals=4,sortby='tpw_mean', \
2401
2412
  print("\n"+footnote)
2402
2413
 
2403
2414
  else: #style打印
2404
- """
2405
2415
  print("\n"+titletxt)
2406
2416
  dst6sd= dst6.style.set_properties(**{'text-align': 'center'})
2407
2417
  from IPython.display import display
2408
2418
  display(dst6sd)
2409
2419
  print(footnote+"\n")
2410
- """
2411
-
2412
2420
  disph=dst6.style.hide() #不显示索引列
2413
2421
  dispp=disph.format(precision=3) #设置带有小数点的列精度调整为小数点后3位
2414
2422
  #设置标题/列名
@@ -2422,15 +2430,22 @@ def descriptive_statistics2(df,titletxt,footnote,decimals=4,sortby='tpw_mean', \
2422
2430
  dispf=dispt1.set_properties(**{'text-align':'center'})
2423
2431
  #设置前景背景颜色
2424
2432
  try:
2425
- dispf2=dispf.set_properties(**{'background-color':facecolor,'color':fontcolor})
2433
+ dispf2=dispf.set_properties(**{'background-color':facecolor,'color':'black'})
2426
2434
  except:
2427
2435
  print(" #Warning(descriptive_statistics2): color",facecolor,"is unsupported, changed to default setting")
2428
2436
  dispf2=dispf.set_properties(**{'background-color':'whitesmoke','color':'black'})
2429
2437
 
2430
2438
  from IPython.display import display
2431
2439
  display(dispf2)
2432
-
2433
2440
  print(footnote+"\n")
2441
+ """
2442
+ #确定表格字体大小
2443
+ titile_font_size=font_size
2444
+ heading_font_size=data_font_size=str(int(font_size.replace('px',''))-1)+'px'
2445
+
2446
+ df_display_CSS(dst6,titletxt=titletxt,footnote=footnote,facecolor=facecolor, \
2447
+ titile_font_size=titile_font_size,heading_font_size=heading_font_size, \
2448
+ data_font_size=data_font_size)
2434
2449
 
2435
2450
  return dst5
2436
2451
 
@@ -3774,7 +3789,7 @@ if __name__=='__main__':
3774
3789
  upgrade_siat()
3775
3790
 
3776
3791
  def upgrade_siat(module_list=['siat','akshare','pandas','pandas_datareader', \
3777
- 'yfinance','yahooquery','urllib3','tabulate','twine','mplfinance'], \
3792
+ 'yfinance','yahooquery','urllib3','tabulate','twine','mplfinance','openpyxl'], \
3778
3793
  pipcmd="pip install --upgrade"):
3779
3794
  """
3780
3795
  功能:一次性升级siat及其相关插件
Binary file
siat/fund_china.pickle CHANGED
Binary file
@@ -181,7 +181,7 @@ def get_expanding_sharpe_sortino(ticker,start,end,rar_name="sharpe", \
181
181
  #增加距离开始日期的天数
182
182
  date0=pd.to_datetime(rardf2.index[0])
183
183
  if 'date' not in list(rardf2):
184
- if 'Date' not in list(rardf2):
184
+ if 'Date' in list(rardf2):
185
185
  rardf2['date']=rardf2['Date']
186
186
  else:
187
187
  rardf2['date']=rardf2.index
@@ -204,6 +204,7 @@ def get_expanding_sharpe_sortino(ticker,start,end,rar_name="sharpe", \
204
204
 
205
205
  #rardf2[risk_type]=rardf2[ret_type].expanding(min_periods=1).apply(lambda x: np.std(x,ddof=1)*np.sqrt(len(x)-1))
206
206
  rardf2[risk_type]=rardf2[ret_type].expanding(min_periods=1).apply(lambda x: np.std(x,ddof=1))
207
+ #rardf2[risk_type]=rardf2[ret_type].expanding(min_periods=5).apply(lambda x: np.std(x,ddof=1))
207
208
  elif 'sortino' in rar_name_lower:
208
209
  risk_type=ret_type_nopct+' LPSD'
209
210
  if pct_flag:
@@ -211,6 +212,7 @@ def get_expanding_sharpe_sortino(ticker,start,end,rar_name="sharpe", \
211
212
 
212
213
  #rardf2[risk_type]=rardf2[ret_type].expanding(min_periods=1).apply(lambda x: lpsd(x)*np.sqrt(len(x)-1))
213
214
  rardf2[risk_type]=rardf2[ret_type].expanding(min_periods=1).apply(lambda x: lpsd(x))
215
+ #rardf2[risk_type]=rardf2[ret_type].expanding(min_periods=5).apply(lambda x: lpsd(x))
214
216
 
215
217
 
216
218
  #计算RAR
@@ -399,18 +401,21 @@ def get_expanding_treynor_alpha(ticker,start,end,rar_name="alpha", \
399
401
  RF_daily=RF/365 * 100
400
402
  pretdf[lndretx]=pretdf[lagdretx].apply(lambda x: np.log(1+x/100))
401
403
  pretdf[lndrety]=pretdf[lagdrety].apply(lambda x: np.log(1+x/100))
402
-
403
404
  pretdf[varx]=pretdf[lndretx].expanding(min_periods=1).apply(lambda x: (np.exp(sum(x))-1)*100)
404
405
  pretdf[vary]=pretdf[lndrety].expanding(min_periods=1).apply(lambda x: (np.exp(sum(x))-1)*100)
405
-
406
+ """
407
+ pretdf[varx]=pretdf[lndretx].expanding(min_periods=5).apply(lambda x: (np.exp(sum(x))-1)*100)
408
+ pretdf[vary]=pretdf[lndrety].expanding(min_periods=5).apply(lambda x: (np.exp(sum(x))-1)*100)
409
+ """
406
410
  else:
407
411
  pretdf[lndretx]=pretdf[pretdfcols[0]].apply(lambda x: np.log(1+x))
408
412
  pretdf[lndrety]=pretdf[pretdfcols[1]].apply(lambda x: np.log(1+x))
409
-
410
413
  pretdf[varx]=pretdf[lndretx].expanding(min_periods=1).apply(lambda x: (np.exp(sum(x))-1))
411
414
  pretdf[vary]=pretdf[lndrety].expanding(min_periods=1).apply(lambda x: (np.exp(sum(x))-1))
412
-
413
-
415
+ """
416
+ pretdf[varx]=pretdf[lndretx].expanding(min_periods=5).apply(lambda x: (np.exp(sum(x))-1))
417
+ pretdf[vary]=pretdf[lndrety].expanding(min_periods=5).apply(lambda x: (np.exp(sum(x))-1))
418
+ """
414
419
  pretdf['Date']=pretdf.index
415
420
  pretdf['days']=pretdf['Date'].apply(lambda x: days_between_dates(date0,pd.to_datetime(x)))
416
421