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/future_china.py CHANGED
@@ -149,8 +149,13 @@ def future_type_china_2(df,code):
149
149
 
150
150
  contract='合约'
151
151
  print(contract+' '*(maxlen-hzlen(contract))+':',code)
152
+ import numpy as np
152
153
  for c in cols:
153
- print(c+' '*(maxlen-hzlen(c))+':',df1[c].values[0])
154
+ value=df1[c].values[0]
155
+ if value != np.nan:
156
+ print(c+' '*(maxlen-hzlen(c))+':',df1[c].values[0])
157
+ else:
158
+ continue
154
159
 
155
160
  import datetime
156
161
  today = datetime.date.today()
@@ -163,14 +168,14 @@ if __name__=='__main__':
163
168
 
164
169
  #======================================================================================
165
170
  if __name__=='__main__':
166
- code='BX2007'
167
171
  tradedate=''
168
- tradedate='2023-6-10'
172
+ tradedate='2025-6-12'
173
+
174
+ future_type_china(tradedate)
169
175
 
170
- def future_type_china(code='',tradedate=''):
176
+ def future_type_china(tradedate=''):
171
177
  """
172
- 综合程序:
173
- 合约code为空或品种symbol不存在时列示中国内盘期货的全部代码,否则列示该合约品种明细
178
+ 功能:中国内盘期货的常见品种,含合约品种明细
174
179
  """
175
180
 
176
181
  # 检查交易日期
@@ -195,36 +200,33 @@ def future_type_china(code='',tradedate=''):
195
200
  while df is None:
196
201
  today=date_adjust(today, adjust=-1)
197
202
  df=future_type_china_0(today)
198
-
199
- symbol=get_future_symbol(code)
200
- df1=df[df['代码']==symbol]
201
-
202
- if len(df1)==0:
203
- if not (code==''):
204
- print(" Warning(future_type_china):",code,'not found')
205
- future_type_china_1(df)
206
- return df
207
203
 
208
- future_type_china_2(df,code)
209
- return df1
204
+ df.drop(['调整备注','特殊合约参数调整'], axis=1, inplace=True)
205
+ titletxt="中国内盘常见期货品种"
206
+ footnote="数据来源:国泰君安, "+str(tradedate)
207
+ df_display_CSS(df,titletxt=titletxt,footnote=footnote,facecolor='papayawhip', \
208
+ first_col_align='center',second_col_align='center', \
209
+ last_col_align='center',other_col_align='center')
210
+
211
+ return df
210
212
 
211
- if __name__=='__main__':
212
- code='Bx2007'
213
- df=future_type_china(code)
214
213
 
215
214
  #======================================================================================
216
215
  if __name__=='__main__':
217
216
  code='PG'
218
- start='2023-5-1'
219
- end='2023-5-18'
220
- power=0
217
+ start='2025-5-1'
218
+ end='2025-5-30'
219
+ power=1
221
220
 
222
- def future_price_china(code,start,end,power=0):
221
+ def future_price_china(code,start='MRM',end='today', \
222
+ power=0,loc1='upper left',loc2='upper right'):
223
223
  """
224
224
  综合程序:
225
225
  绘制内盘期货交易曲线:收盘价vs结算价vs成交量
226
226
  """
227
- print("Searching for contract "+code+", it may cost great deal of time, take a break ...")
227
+ start,end=start_end_preprocess(start,end)
228
+
229
+ print("Searching for contract "+code+", it may take time ...")
228
230
  #日期变换
229
231
  start1=convert_date_ts(start)
230
232
  end1=convert_date_ts(end)
@@ -265,7 +267,7 @@ def future_price_china(code,start,end,power=0):
265
267
  p=ak.get_futures_daily(start_date=start1,end_date=end1,market=market)
266
268
  except:
267
269
  print(" #Warning(future_price_china): data source has no response at the moment for",code)
268
- print(" Try another type of future, or try it later")
270
+ print(" Solution: make date period shorter (e.g. within same month), and try again")
269
271
  return None
270
272
 
271
273
  if p is None:
@@ -279,7 +281,8 @@ def future_price_china(code,start,end,power=0):
279
281
  contracts=set(list(p[p['variety']==variety]['symbol']))
280
282
  contracts1=sorted(contracts)
281
283
  print("\n提示:当前可用的"+varietyname+variety+'期货合约:'+mktnamefull+', '+str(end))
282
- print(contracts1)
284
+ #print(contracts1)
285
+ printlist(contracts1,numperline=10,beforehand='',separator=' ')
283
286
  return None
284
287
 
285
288
  #转换日期格式
@@ -317,19 +320,19 @@ def future_price_china(code,start,end,power=0):
317
320
  plot_line2(p2a,acode,"close","收盘价", \
318
321
  p2b,acode,"settle","结算价", \
319
322
  '价格',titletxt,footnote, \
320
- power=power,twinx=False)
323
+ power=power,twinx=False,loc1=loc1,loc2=loc2)
321
324
  #"""
322
325
  #收盘价vs成交量
323
326
  plot_line2(p2a,acode,"close","收盘价", \
324
327
  p2c,acode,"volume","成交量", \
325
328
  '',titletxt,footnote, \
326
- power=power,twinx=True)
329
+ power=power,twinx=True,loc1=loc1,loc2=loc2)
327
330
  #"""
328
331
  #收盘价vs持仓量
329
332
  plot_line2(p2a,acode,"close","收盘价", \
330
333
  p2e,acode,"open_interest","持仓量", \
331
334
  '',titletxt,footnote, \
332
- power=power,twinx=True)
335
+ power=power,twinx=True,loc1=loc1,loc2=loc2)
333
336
  #"""
334
337
  return p2
335
338
 
@@ -444,41 +447,29 @@ if __name__=='__main__':
444
447
 
445
448
  #======================================================================================
446
449
  if __name__=='__main__':
447
- code='ZSD'
450
+
451
+ future_type_foreign()
448
452
 
449
- def future_type_foreign(code=''):
453
+ def future_type_foreign():
450
454
  """
451
- 综合程序:
452
- 合约code为空或不存在时列示中国外盘期货的所有品种,否则列示一个品种的明细条款
455
+ 功能:中国外盘期货的常见品种,含合约明细
453
456
  """
454
457
 
455
458
  df=future_type_foreign_1()
459
+ #cols=['交易代码','交易品种','上市交易所','交易单位','报价单位','合约交割月份']
460
+ cols=['交易代码','交易品种','上市交易所','交易单位','报价单位']
461
+ df1=df[cols]
462
+ df1.reset_index(drop=True,inplace=True)
456
463
 
457
- df1=df[df['交易代码']==code]
458
-
459
- if len(df1)==0:
460
- if not (code==''):
461
- print(" Warning(future_type_foreign):",code,'not found')
462
-
463
- #设置打印对齐
464
- import pandas as pd
465
- pd.set_option('display.max_columns', 1000)
466
- pd.set_option('display.width', 1000)
467
- pd.set_option('display.max_colwidth', 1000)
468
- pd.set_option('display.unicode.ambiguous_as_wide', True)
469
- pd.set_option('display.unicode.east_asian_width', True)
470
-
471
- print("\n===== 中国外盘期货品种一览表 =====\n")
472
- df2=df[['交易代码','交易品种','上市交易所']]
473
- print(df2.to_string(index=False))
474
-
475
- import datetime
476
- today = datetime.date.today()
477
- print('\n*** 数据来源:新浪财经,',today)
478
-
479
- return df
464
+ titletxt="中国外盘期货常见品种"
465
+ import datetime
466
+ todaydt = datetime.date.today()
467
+ footnote="数据来源:新浪财经, "+str(todaydt)
480
468
 
481
- future_type_foreign_2(df,symbol=code)
469
+ df_display_CSS(df1,titletxt=titletxt,footnote=footnote, \
470
+ facecolor='papayawhip', \
471
+ first_col_align='center',second_col_align='center', \
472
+ last_col_align='center',other_col_align='center')
482
473
 
483
474
  return df1
484
475
 
@@ -494,11 +485,14 @@ if __name__=='__main__':
494
485
  end='2021-9-27'
495
486
  power=0
496
487
 
497
- def future_price_foreign(code,start,end,power=0,loc1='best',loc2='best'):
488
+ def future_price_foreign(code,start='MRM',end='today', \
489
+ power=0,loc1='upper left',loc2='upper right'):
498
490
  """
499
491
  综合程序:
500
492
  绘制中国外盘期货的交易趋势:收盘价vs成交量
501
493
  """
494
+ start,end=start_end_preprocess(start,end)
495
+
502
496
  print("Searching for contract "+code+", it costs great time, just take a break...")
503
497
  #日期变换
504
498
  flag,start1,end1=check_period(start,end)