siat 2.11.14__py3-none-any.whl → 2.12.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.
siat/option_china.py CHANGED
@@ -388,18 +388,70 @@ def option_comm_contract_decode_china(contract):
388
388
  return contract2,contract_notes
389
389
  #==============================================================================
390
390
  #==============================================================================
391
+ #==============================================================================
392
+ #==============================================================================
393
+ #==============================================================================
391
394
  # 以上为商品期权,以下为金融期权
392
395
  #==============================================================================
393
396
  #==============================================================================
397
+ #==============================================================================
398
+ #==============================================================================
399
+ #==============================================================================
394
400
  if __name__=='__main__':
395
401
  detail=True
396
402
  detail=False
397
403
 
398
- # 定义中国当前金融期权的所有品种
399
- option_fin_list=["华夏上证50ETF期权","华泰柏瑞沪深300ETF期权","嘉实沪深300ETF期权", \
400
- "沪深300股指期权"]
401
- underlying_fin_list=["510050.SS","510300.SS","159919.SZ","000300.SS"]
404
+ # 定义中国当前金融期权的所有品种
405
+ option_fin_list_sse=["华夏上证50ETF期权","华夏科创50ETF期权","易方达科创50ETF期权", \
406
+ "华泰柏瑞沪深300ETF期权","南方中证500ETF期权"]
407
+ underlying_fin_list_sse=["510050.SS","588000.SS","588080.SS", \
408
+ "510300.SS","510500.SS"]
409
+
410
+ option_fin_list_szse=["易方达深证100ETF期权","易方达创业板ETF期权","嘉实沪深300ETF期权", \
411
+ "嘉实中证500ETF期权"]
412
+ underlying_fin_list_szse=["159901.SZ","159915.SZ","159919.SZ", \
413
+ "159922.SZ"]
414
+
415
+ option_fin_list_cffe=["上证50股指期权","沪深300股指期权","中证1000股指期权"]
416
+ underlying_fin_list_cffe=["000016.SS","000300.SS","000852.SS"]
417
+
418
+ option_fin_list=option_fin_list_sse + option_fin_list_szse + option_fin_list_cffe
419
+ underlying_fin_list=underlying_fin_list_sse + underlying_fin_list_szse + underlying_fin_list_cffe
420
+
421
+ """
422
+ option_fin_list=["华夏上证50ETF期权","华夏科创50ETF期权","易方达科创50ETF期权", \
423
+ "华泰柏瑞沪深300ETF期权","南方中证500ETF期权", \
424
+ "易方达深证100ETF期权","易方达创业板ETF期权","嘉实沪深300ETF期权", \
425
+ "嘉实中证500ETF期权", \
426
+ "上证50股指期权","沪深300股指期权","中证1000股指期权"]
427
+ underlying_fin_list=["510050.SS","588000.SS","588080.SS", \
428
+ "510300.SS","510500.SS",
429
+ "159901.SZ","159915.SZ","159919.SZ", \
430
+ "159922.SZ", \
431
+ "000016.SS","000300.SS","000852.SS"]
432
+ """
433
+ if __name__=='__main__':
434
+ option="华夏上证50ETF期权"
435
+ option_fin_underlying(option)
436
+
437
+
438
+ def option_fin_underlying(option):
439
+ """
440
+ 功能:给定金融期权名称,返回标的物证券代码
441
+ """
442
+ import pandas as pd
443
+ df=pd.DataFrame()
444
+ df['option_name']=option_fin_list
445
+ df['underlying_code']=underlying_fin_list
402
446
 
447
+ try:
448
+ underlying=df[df['option_name']==option]['underlying_code'].values[0]
449
+ except:
450
+ underlying=None
451
+
452
+ return underlying
453
+
454
+
403
455
  def option_fin_china(detail=False):
404
456
  """
405
457
  功能:描述当前中国市场中的金融期权,标注日期
@@ -411,57 +463,186 @@ def option_fin_china(detail=False):
411
463
  heading=' '
412
464
  lead_blanks=' '*3
413
465
 
414
- print("===== 中国金融期权表 =====")
466
+ print("\n===== 中国金融期权一览表 =====")
467
+
468
+ #=====上交所
469
+ print("\n----- 上交所 -----")
415
470
  #华夏上证50ETF期权
416
471
  print(heading,"华夏上证50ETF期权")
417
472
  if detail:
418
- print(lead_blanks,"其他名称:上证50ETF期权")
419
- print(lead_blanks,"类别 :欧式期权,无红利")
473
+ print(lead_blanks,"俗称 :上证50ETF期权")
474
+ print(lead_blanks,"类别 :欧式期权")
420
475
  print(lead_blanks,"标的证券:华夏上证50ETF基金(510050.SS)")
421
- #print(lead_blanks,"行权价格:1个平值合约、4个虚值合约、4个实值合约")
476
+ print(lead_blanks,"行权价格:9个(1个平值合约、4个虚值合约、4个实值合约)")
477
+ print(lead_blanks,"合约单位:10000份,1手期权=10000份基金,实物交割")
478
+ print(lead_blanks,"合约交易代码:xCyMz,xPyMz,x-标的代码,y-到期年月,z-行权指数点位")
422
479
  print(lead_blanks,"上市日期:2015-2-9")
423
480
  print(lead_blanks,"到期月份:当月、下月及随后两个季月(季度末月)")
424
481
  print(lead_blanks,"到期日期:到期月份的第四个星期三(节假日顺延)")
425
482
  print(lead_blanks,"交易所 :上海证券交易所")
426
483
 
484
+ #华夏科创50ETF期权
485
+ print(heading,"华夏科创50ETF期权")
486
+ if detail:
487
+ print(lead_blanks,"俗称 :科创50ETF期权")
488
+ print(lead_blanks,"类别 :欧式期权")
489
+ print(lead_blanks,"标的证券:华夏科创50ETF基金(588000.SS)")
490
+ print(lead_blanks,"上市日期:2023-6-5")
491
+ print(lead_blanks,"行权价格:9个(1个平值合约、4个虚值合约、4个实值合约)")
492
+ print(lead_blanks,"合约单位:10000份,1手期权=10000份基金,实物交割")
493
+ print(lead_blanks,"合约交易代码:xCyMz,xPyMz,x-标的代码,y-到期年月,z-行权指数点位")
494
+ print(lead_blanks,"到期月份:当月、下月及随后两个季月(季度末月)")
495
+ print(lead_blanks,"到期日期:到期月份的第四个星期三(节假日顺延)")
496
+ print(lead_blanks,"交易所 :上海证券交易所")
497
+
498
+ #易方达科创50ETF期权
499
+ print(heading,"易方达科创50ETF期权")
500
+ if detail:
501
+ print(lead_blanks,"俗称 :科创板50ETF期权")
502
+ print(lead_blanks,"类别 :欧式期权")
503
+ print(lead_blanks,"标的证券:易方达科创50ETF基金(588080.SS)")
504
+ print(lead_blanks,"上市日期:2023-6-5")
505
+ print(lead_blanks,"行权价格:9个(1个平值合约、4个虚值合约、4个实值合约)")
506
+ print(lead_blanks,"合约单位:10000份,1手期权=10000份基金,实物交割")
507
+ print(lead_blanks,"合约交易代码:xCyMz,xPyMz,x-标的代码,y-到期年月,z-行权指数点位")
508
+ print(lead_blanks,"到期月份:当月、下月及随后两个季月(季度末月)")
509
+ print(lead_blanks,"到期日期:到期月份的第四个星期三(节假日顺延)")
510
+ print(lead_blanks,"交易所 :上海证券交易所")
511
+
427
512
  #华泰柏瑞沪深300ETF期权
428
513
  print(heading,"华泰柏瑞沪深300ETF期权")
429
514
  if detail:
430
- print(lead_blanks,"其他名称:上证沪深300ETF期权")
431
- print(lead_blanks,"类别 :欧式期权,无红利")
515
+ print(lead_blanks,"俗称 :(上证)沪深300ETF期权")
516
+ print(lead_blanks,"类别 :欧式期权")
432
517
  print(lead_blanks,"标的证券:华泰柏瑞沪深300ETF基金(510300.SS)")
433
518
  print(lead_blanks,"上市日期:2019-12-23")
434
- #print(lead_blanks,"行权价格:1个平值合约、4个虚值合约、4个实值合约")
519
+ print(lead_blanks,"行权价格:9个(1个平值合约、4个虚值合约、4个实值合约)")
520
+ print(lead_blanks,"合约单位:10000份,1手期权=10000份基金,实物交割")
521
+ print(lead_blanks,"合约交易代码:xCyMz,xPyMz,x-标的代码,y-到期年月,z-行权指数点位")
435
522
  print(lead_blanks,"到期月份:当月、下月及随后两个季月(季度末月)")
436
523
  print(lead_blanks,"到期日期:到期月份的第四个星期三(节假日顺延)")
437
524
  print(lead_blanks,"交易所 :上海证券交易所")
438
525
 
526
+ #南方中证500ETF期权
527
+ print(heading,"南方中证500ETF期权")
528
+ if detail:
529
+ print(lead_blanks,"俗称 :(上证)中证500ETF期权")
530
+ print(lead_blanks,"类别 :欧式期权")
531
+ print(lead_blanks,"标的证券:南方中证500ETF基金(510500.SS)")
532
+ print(lead_blanks,"上市日期:2022-9-19")
533
+ print(lead_blanks,"行权价格:9个(1个平值合约、4个虚值合约、4个实值合约)")
534
+ print(lead_blanks,"合约单位:10000份,1手期权=10000份基金,实物交割")
535
+ print(lead_blanks,"合约交易代码:xCyMz,xPyMz,x-标的代码,y-到期年月,z-行权指数点位")
536
+ print(lead_blanks,"到期月份:当月、下月及随后两个季月(季度末月)")
537
+ print(lead_blanks,"到期日期:到期月份的第四个星期三(节假日顺延)")
538
+ print(lead_blanks,"交易所 :上海证券交易所")
539
+
540
+
541
+ #=====深交所
542
+ print("\n----- 深交所 -----")
543
+ #易方达深证100ETF期权
544
+ print(heading,"易方达深证100ETF期权")
545
+ if detail:
546
+ print(lead_blanks,"俗称 :深证100ETF期权")
547
+ print(lead_blanks,"类别 :欧式期权")
548
+ print(lead_blanks,"标的证券:易方达深证100ETF基金(159901.SZ)")
549
+ print(lead_blanks,"行权价格:9个(1个平值合约、4个虚值合约、4个实值合约)")
550
+ print(lead_blanks,"合约单位:10000份,1手期权=10000份基金,实物交割")
551
+ print(lead_blanks,"合约编码:9000xxxx,后4位为合约序号")
552
+ print(lead_blanks,"合约简称:x购y月z,x沽y月z,x-标的名称,y-到期月,z-行权指数点位")
553
+ print(lead_blanks,"上市日期:2022-12-12")
554
+ print(lead_blanks,"到期月份:当月、下月及随后两个季月(季度末月)")
555
+ print(lead_blanks,"到期日期:到期月份的第四个星期三(节假日顺延)")
556
+ print(lead_blanks,"交易所 :深圳证券交易所")
557
+
558
+ #易方达创业板ETF期权
559
+ print(heading,"易方达创业板ETF期权")
560
+ if detail:
561
+ print(lead_blanks,"俗称 :创业板ETF")
562
+ print(lead_blanks,"类别 :欧式期权")
563
+ print(lead_blanks,"标的证券:易方达创业板ETF基金(159915.SZ)")
564
+ print(lead_blanks,"行权价格:9个(1个平值合约、4个虚值合约、4个实值合约)")
565
+ print(lead_blanks,"合约单位:10000份,1手期权=10000份基金,实物交割")
566
+ print(lead_blanks,"合约编码:9000xxxx,后4位为合约序号")
567
+ print(lead_blanks,"合约简称:x购y月z,x沽y月z,x-标的名称,y-到期月,z-行权指数点位")
568
+ print(lead_blanks,"上市日期:2022-9-19")
569
+ print(lead_blanks,"到期月份:当月、下月及随后两个季月(季度末月)")
570
+ print(lead_blanks,"到期日期:到期月份的第四个星期三(节假日顺延)")
571
+ print(lead_blanks,"交易所 :深圳证券交易所")
572
+
439
573
  #嘉实沪深300ETF期权
440
574
  print(heading,"嘉实沪深300ETF期权")
441
575
  if detail:
442
- print(lead_blanks,"其他名称:深交所沪深300ETF期权")
443
- print(lead_blanks,"类别 :欧式期权,无红利")
576
+ print(lead_blanks,"俗称 :(深证)沪深300ETF期权")
577
+ print(lead_blanks,"类别 :欧式期权")
444
578
  print(lead_blanks,"标的证券:嘉实沪深300ETF基金(159919.SZ)")
445
579
  print(lead_blanks,"上市日期:2019-12-23")
446
- #print(lead_blanks,"行权价格:1个平值合约、4个虚值合约、4个实值合约")
447
- print(lead_blanks,"到期月份:1、2、3、6月")
448
- print(lead_blanks,"到期日期:到期月份的第四个星期三(遇法定节假日顺延)")
580
+ print(lead_blanks,"行权价格:9个(1个平值合约、4个虚值合约、4个实值合约)")
581
+ print(lead_blanks,"合约单位:10000份,1手期权=10000份基金,实物交割")
582
+ print(lead_blanks,"合约编码:9000xxxx,后4位为合约序号")
583
+ print(lead_blanks,"合约简称:x购y月z,x沽y月z,x-标的名称,y-到期月,z-行权指数点位")
584
+ print(lead_blanks,"到期月份:当月、下月及随后两个季月(季度末月)")
585
+ print(lead_blanks,"到期日期:到期月份的第四个星期三(节假日顺延)")
449
586
  print(lead_blanks,"交易所 :深圳证券交易所")
587
+
588
+
589
+ #嘉实中证500ETF期权
590
+ print(heading,"嘉实中证500ETF期权")
591
+ if detail:
592
+ print(lead_blanks,"俗称 :(深证)中证500ETF期权")
593
+ print(lead_blanks,"类别 :欧式期权")
594
+ print(lead_blanks,"标的证券:嘉实中证500ETF基金(159922.SZ)")
595
+ print(lead_blanks,"行权价格:9个(1个平值合约、4个虚值合约、4个实值合约)")
596
+ print(lead_blanks,"合约单位:10000份,1手期权=10000份基金,实物交割")
597
+ print(lead_blanks,"合约编码:9000xxxx,后4位为合约序号")
598
+ print(lead_blanks,"合约简称:x购y月z,x沽y月z,x-标的名称,y-到期月,z-行权指数点位")
599
+ print(lead_blanks,"上市日期:2022-9-19")
600
+ print(lead_blanks,"到期月份:当月、下月及随后两个季月(季度末月)")
601
+ print(lead_blanks,"到期日期:到期月份的第四个星期三(节假日顺延)")
602
+ print(lead_blanks,"交易所 :深圳证券交易所")
603
+
604
+
605
+ #=====中金所
606
+ print("\n----- 中金所 -----")
607
+ #上证50股指期权
608
+ print(heading,"上证50股指期权")
609
+ if detail:
610
+ print(lead_blanks,"类别 :欧式期权")
611
+ print(lead_blanks,"标的证券:上证50指数(000016.SS)")
612
+ print(lead_blanks,"上市日期:2022-12-19")
613
+ print(lead_blanks,"合约乘数:现金交割,每点人民币100元")
614
+ print(lead_blanks,"交易代码:HO合约月份-C-行权价格,HO合约月份-P-行权价格")
615
+ print(lead_blanks,"到期月份:当月、下2个月、随后3个季月(季度末月)")
616
+ print(lead_blanks,"到期日期:到期月份的第三个星期五(节假日顺延)")
617
+ print(lead_blanks,"交易所 :中国金融期货交易所")
450
618
 
451
619
  #沪深300股指期权
452
620
  print(heading,"沪深300股指期权")
453
621
  if detail:
454
- print(lead_blanks,"其他名称:中金所沪深300股指期权")
455
- print(lead_blanks,"类别 :欧式期权,无红利")
622
+ print(lead_blanks,"类别 :欧式期权")
456
623
  print(lead_blanks,"标的证券:沪深300指数(000300.SS,399300.SZ)")
457
624
  print(lead_blanks,"上市日期:2019-12-23")
458
- #print(lead_blanks,"行权价格:1个平值合约、4个虚值合约、4个实值合约")
625
+ print(lead_blanks,"合约乘数:现金交割,每点人民币100元")
626
+ print(lead_blanks,"交易代码:IO合约月份-C-行权价格,IO合约月份-P-行权价格")
459
627
  print(lead_blanks,"到期月份:当月、下2个月、随后3个季月(季度末月)")
460
628
  print(lead_blanks,"到期日期:到期月份的第三个星期五(节假日顺延)")
461
629
  print(lead_blanks,"交易所 :中国金融期货交易所")
462
630
 
631
+ #中证1000股指期权
632
+ print(heading,"中证1000股指期权")
633
+ if detail:
634
+ print(lead_blanks,"类别 :欧式期权")
635
+ print(lead_blanks,"标的证券:中证1000指数(000852.SS)")
636
+ print(lead_blanks,"上市日期:2022-7-22")
637
+ print(lead_blanks,"合约乘数:现金交割,每点人民币100元")
638
+ print(lead_blanks,"交易代码:MO合约月份-C-行权价格,MO合约月份-P-行权价格")
639
+ print(lead_blanks,"到期月份:当月、下2个月、随后3个季月(季度末月)")
640
+ print(lead_blanks,"到期日期:到期月份的第三个星期五(节假日顺延)")
641
+ print(lead_blanks,"交易所 :中国金融期货交易所")
642
+
463
643
  import datetime as dt; today=str(dt.date.today())
464
- print('\n',heading,"来源:上交所/深交所/中金所,",today)
644
+ if not detail: print('')
645
+ print(heading,"来源:上交所/深交所/中金所,",today)
465
646
  return
466
647
 
467
648
  if __name__=='__main__':
@@ -529,55 +710,68 @@ if __name__=='__main__':
529
710
  symbol="华泰柏瑞沪深300ETF期权"
530
711
  symbol="嘉实沪深300ETF期权"
531
712
  symbol="沪深300股指期权"
532
- num=24
713
+ num=9
533
714
 
534
- def option_fin_month_china(symbol,num=24):
715
+ def option_fin_month_china(symbol,num=12):
535
716
  """
536
717
  功能:遍历并显示一个金融期货品种的到期年月YYMM
718
+ 未来到期日:当月,下月,下两个季月
537
719
  """
538
720
 
539
721
  if not (symbol in option_fin_list):
540
- print(" #Warning(option_fin_month_china): info not found for",symbol)
722
+ print(" #Warning(option_fin_month_china): info not found / unaccessible for",symbol)
541
723
  return None
542
724
 
543
725
  #当前年月开始的年月列表
544
- import datetime as dt; today=str(dt.date.today())
545
- yymm_list=get_yymm_list(today,num=num)
726
+ import datetime as dt; todaydt=str(dt.date.today())
727
+ yymm_list=get_yymm_list(todaydt,num=num)
546
728
 
547
729
  import akshare as ak
548
730
  end_month_list=[]
731
+
732
+ #临时措施:深交所期权只能找到"嘉实沪深300ETF期权",其他的找不到但实际存在
733
+ if symbol in option_fin_list_szse: symbol="嘉实沪深300ETF期权"
734
+
549
735
  for yymm in yymm_list:
550
- #print('Scanning',yymm)
736
+ print(' ... Scanning option maturity',yymm,end=', ')
737
+
551
738
  try:
552
- df = ak.option_finance_board(symbol=symbol, end_month=yymm)
739
+ df = ak.option_finance_board(symbol=symbol,end_month=yymm)
553
740
  except:
741
+ print("failed!")
742
+ #print(" #Warning(option_fin_month_china): something went wrong in akshare, try upgrade it")
554
743
  continue
744
+
745
+ if df is None:
746
+ print("not found")
747
+ continue
748
+ if len(df)==0:
749
+ print("not found")
750
+ continue
751
+
752
+ print("seems found, checking",end=', ')
753
+ if symbol in option_fin_list_sse:
754
+ y2m2=df['合约交易代码'][:1].values[0][7:11]
755
+
756
+ if symbol in option_fin_list_szse:
757
+ d1=df['期权行权日'][:1].values[0]
758
+ d2=d1.astype('str')
759
+ yy=d2[2:4]; mm=d2[5:7]; y2m2=yy+mm
760
+
761
+ if symbol in option_fin_list_cffe:
762
+ y2m2=df['instrument'][:1].values[0][2:6]
763
+
764
+ if y2m2==yymm:
765
+ print("confirmed found")
766
+ end_month_list=end_month_list+[yymm]
555
767
  else:
556
- if len(df)==0: continue
557
-
558
- if symbol=="华夏上证50ETF期权":
559
- y2m2=df['合约交易代码'][:1].values[0][7:11]
560
-
561
- if symbol=="华泰柏瑞沪深300ETF期权":
562
- y2m2=df['合约交易代码'][:1].values[0][7:11]
563
-
564
- if symbol=="嘉实沪深300ETF期权":
565
- d1=df['期权行权日'][:1].values[0]
566
- d2=d1.astype('str')
567
- yy=d2[2:4]; mm=d2[5:7]; y2m2=yy+mm
568
-
569
- if symbol=="沪深300股指期权":
570
- y2m2=df['instrument'][:1].values[0][2:6]
571
-
572
- if y2m2==yymm:
573
- end_month_list=end_month_list+[yymm]
768
+ print("fake")
574
769
 
575
- print("\n=== 中国金融期权品种的到期日(YYMM) ===")
770
+ print("\n=== 中国金融期权品种的到期日(年月) ===")
576
771
  print(symbol+':')
577
772
  print(end_month_list)
578
773
 
579
- import datetime as dt; today=str(dt.date.today())
580
- print("来源:上交所/深交所/中金所,",today)
774
+ print("来源:上交所/深交所/中金所,",todaydt)
581
775
 
582
776
  return
583
777
 
@@ -645,7 +839,10 @@ def option_fin_contracts(symbol,end_month,direction='call',printout=True):
645
839
  try:
646
840
  df = ak.option_finance_board(symbol=symbol, end_month=end_month)
647
841
  except:
648
- print(" #Error(option_fin_contracts): info unavailable for",symbol,'on maturity',end_month)
842
+ print(" #Error(option_fin_contracts): info unaccessible for",symbol,'on maturity',end_month)
843
+ return None
844
+ if df is None:
845
+ print(" #Error(option_fin_contracts): none found for",symbol,'on maturity',end_month)
649
846
  return None
650
847
 
651
848
  #检查期权方向
@@ -659,7 +856,7 @@ def option_fin_contracts(symbol,end_month,direction='call',printout=True):
659
856
  import pandas as pd
660
857
  contracts=pd.DataFrame()
661
858
  #==================================================================
662
- if symbol in ["华夏上证50ETF期权","华泰柏瑞沪深300ETF期权"]:
859
+ if symbol in option_fin_list_sse:
663
860
  #期权方向标志
664
861
  df['direction']=df['合约交易代码'].apply(lambda x:x[6:7])
665
862
  if utype=='CALL':
@@ -693,7 +890,7 @@ def option_fin_contracts(symbol,end_month,direction='call',printout=True):
693
890
  contracts['underlying']=ua
694
891
 
695
892
  #=================================================================
696
- if symbol in ["嘉实沪深300ETF期权"]:
893
+ if symbol in option_fin_list_szse:
697
894
  #期权方向标志
698
895
  df['direction']=df['类型'].apply(lambda x:'C' if x in ["认购"] else 'P')
699
896
  if utype=='CALL':
@@ -728,7 +925,7 @@ def option_fin_contracts(symbol,end_month,direction='call',printout=True):
728
925
  contracts['date']=pd.to_datetime(today)
729
926
 
730
927
  #=================================================================
731
- if symbol in ["沪深300股指期权"]:
928
+ if symbol in option_fin_list_cffe:
732
929
  """
733
930
  字段解读:
734
931
  instrument:合约编号
@@ -824,6 +1021,11 @@ if __name__=='__main__':
824
1021
  end_month='2206'
825
1022
  direction='call'
826
1023
 
1024
+ symbol="中证1000股指期权"
1025
+ end_month='2312'
1026
+ contract='MO2312-P-5800'
1027
+ direction='put'
1028
+
827
1029
  def option_fin_contract_parms(symbol,end_month,contract,direction='call'):
828
1030
  """
829
1031
  功能:抓取期权合约的到期日、行权价和标的证券
@@ -850,6 +1052,11 @@ if __name__=='__main__':
850
1052
  underlying='510050.SS'
851
1053
  date='2021-11-19'
852
1054
  days=30
1055
+
1056
+ underlying='000852.SS'
1057
+ date='2023-12-1'
1058
+ days=183
1059
+
853
1060
 
854
1061
  def underlying_sigma(underlying,date,days=30):
855
1062
  """
@@ -893,7 +1100,7 @@ def underlying_sigma(underlying,date,days=30):
893
1100
 
894
1101
  #采用对数收益率
895
1102
  df['Close_lag']=df['Close'].shift(1)
896
- df.dropna(inplace=True)
1103
+ df['Close_lag'].dropna(inplace=True)
897
1104
  import numpy as np
898
1105
  df['ret']=np.log(df['Close']/df['Close_lag'])
899
1106
  sigma=df['ret'].std()
@@ -1354,6 +1561,109 @@ def hs300option_exercise(maturity,direction="Call",printout=True):
1354
1561
 
1355
1562
  if __name__=='__main__':
1356
1563
  elist=exerciselist=hs300option_exercise(maturity="2306",direction="Call")
1564
+ #==============================================================================
1565
+
1566
+
1567
+ def get_price_option_fin_china(option,contract):
1568
+ """
1569
+ 功能:获得金融期权option的合约contract全部历史行情
1570
+ """
1571
+ import akshare as ak
1572
+
1573
+ #变换中金所期权合约格式为新浪格式
1574
+ if option in option_fin_list_cffe:
1575
+ clist=contract.split('-')
1576
+ contract1=''
1577
+ for c in clist:
1578
+ contract1=contract1+c
1579
+
1580
+ #获得期权合约历史行情
1581
+ if option in ['沪深300股指期权']:
1582
+ try:
1583
+ df1t = ak.option_cffex_hs300_daily_sina(symbol=contract1)
1584
+ except:
1585
+ print(" #Error(index_option_price_china2): contract",contract,"not found or expired in",option)
1586
+ return None
1587
+
1588
+ if option in ['上证50股指期权']:
1589
+ try:
1590
+ df1t = ak.option_cffex_sz50_daily_sina(symbol=contract1)
1591
+ except:
1592
+ print(" #Error(index_option_price_china2): contract",contract,"not found or expired in",option)
1593
+ return None
1594
+
1595
+
1596
+ if option in ['中证1000股指期权']:
1597
+ try:
1598
+ df1t = ak.option_cffex_zz1000_daily_sina(symbol=contract1)
1599
+ except:
1600
+ print(" #Error(index_option_price_china2): contract",contract,"not found or expired in",option)
1601
+ return None
1602
+
1603
+ import pandas as pd
1604
+ df1t['Date']=df1t['date'].apply(lambda x: pd.to_datetime(x))
1605
+ df1t.set_index('Date',inplace=True)
1606
+
1607
+ df1=df1t[['date','close']]
1608
+
1609
+ return df1
1610
+
1611
+
1612
+
1613
+ #==============================================================================
1614
+
1615
+ if __name__=='__main__':
1616
+ option="沪深300股指期权"
1617
+ contract='IO2403-P-4000'
1618
+ contract='IO2403P3900'
1619
+
1620
+ loc1='best';loc2='best';graph=True
1621
+
1622
+
1623
+ def index_option_price_china2(option,contract, \
1624
+ loc1='best',loc2='best',graph=True):
1625
+ """
1626
+ 功能:绘制期权合约与其标的证券价格的双轴对照图,支持中金所三种股指期权
1627
+ """
1628
+ #获取期权合约的历史行情
1629
+ df1=get_price_option_fin_china(option,contract)
1630
+ start=df1['date'].values[0].strftime('%Y-%m-%d')
1631
+ end=df1['date'].values[-1].strftime('%Y-%m-%d')
1632
+
1633
+ #获得标的证券历史行情
1634
+ ua=option_fin_underlying(option)
1635
+ df2t=get_price(ua,start,end)
1636
+ df2=df2t[['date','Close','ticker']]
1637
+
1638
+ #绘制双轴图
1639
+ if graph:
1640
+ #获取股指历史价格
1641
+ collabel_so='期权价格'
1642
+ collabel_si=codetranslate(ua)
1643
+ if ('P' in contract) or ('p' in contract):
1644
+ direction='Put'
1645
+ else:
1646
+ direction='Call'
1647
+
1648
+ titletxt_so_si=option+':期权价格 vs 标的指数,'+ectranslate(direction)
1649
+ colname='Close'; ylabeltxt=''
1650
+
1651
+ maturity=contract[2:6]
1652
+ exercisestr=contract[-4:]
1653
+
1654
+ #footnote1="新浪期权代码:"+symbol+",到期日"+maturity+",行权股指点位"+exercisestr
1655
+ footnote1="期权代码:"+contract+",到期日"+maturity+",行权股指点位"+exercisestr
1656
+ import datetime; todaydt = datetime.date.today()
1657
+ footnote2="数据来源: 新浪财经/东方财富, "+str(todaydt)
1658
+ footnote=footnote1+"\n"+footnote2
1659
+
1660
+ plot_line2_twinx(df1,'','close',collabel_so, \
1661
+ df2,'','Close',collabel_si, \
1662
+ titletxt_so_si,footnote,loc1=loc1,loc2=loc2)
1663
+
1664
+ return df1,df2
1665
+
1666
+
1357
1667
  #=============================================================================
1358
1668
  if __name__=='__main__':
1359
1669
  maturity="2306"
@@ -1363,13 +1673,14 @@ if __name__=='__main__':
1363
1673
  option=["2306",4500,'Call']
1364
1674
 
1365
1675
  variety='hs300'
1676
+
1366
1677
 
1367
1678
  def index_option_price_china(option,variety='hs300', \
1368
1679
  loc1='best',loc2='best',graph=True):
1369
1680
  """
1370
1681
  功能:套壳函数hs300option_price,维持旧版兼容性
1371
1682
  """
1372
- varietylist=['hs300']
1683
+ varietylist=['hs300']+option_fin_list
1373
1684
  if not (variety in varietylist):
1374
1685
  print(" #Error(index_option_price_china): unsupported option variety",variety)
1375
1686
  print(" Currently supported option variety",varietylist,"\b, and may support more in the future")
@@ -1578,6 +1889,64 @@ if __name__=='__main__':
1578
1889
  df=hs300option_compare(option1,option2,loc1='upper center',loc2='lower center')
1579
1890
 
1580
1891
  #==============================================================================
1892
+ if __name__=='__main__':
1893
+ option="沪深300股指期权"
1894
+ contract1="IO2403-P-3700"
1895
+ contract2="IO2403-P-3900"
1896
+
1897
+ def index_option_compare_china2(option,contract1,contract2,loc1='best',loc2='best',twinx=False):
1898
+ """
1899
+ 功能:比较两个股指期权合约的价格曲线
1900
+ """
1901
+
1902
+ #获取期权价格
1903
+ print(" Searching prices for",option,"contract",contract1,"...")
1904
+ df1=get_price_option_fin_china(option,contract1)
1905
+ if df1 is None:
1906
+ print(" Sorry, found none info for contract",contract1)
1907
+ return None,None
1908
+
1909
+ print(" Searching prices for",option,"contract",contract2,"...")
1910
+ df2=get_price_option_fin_china(option,contract2)
1911
+ if df2 is None:
1912
+ print(" Sorry, found none info for contract",contract2)
1913
+ return None,None
1914
+
1915
+ print(" Rendering graphics ...")
1916
+ ylabeltxt="期权价格"
1917
+ titletxt=option+':价格运动与影响因素'
1918
+
1919
+ import datetime; todaydt = datetime.date.today()
1920
+ footnote="数据来源: 新浪财经/东方财富, "+str(todaydt)
1921
+
1922
+ plot2_line2(df1,contract1,'close','', \
1923
+ df2,contract2,'close','', \
1924
+ ylabeltxt,titletxt,footnote, \
1925
+ twinx=twinx, \
1926
+ loc1=loc1,loc2=loc2)
1927
+
1928
+ return df1,df2
1929
+
1930
+ if __name__=='__main__':
1931
+ option="沪深300股指期权"
1932
+ #不同到期日
1933
+ contract1="IO2403-C-3900"
1934
+ contract2="IO2406-C-3900"
1935
+ df=index_option_compare_china2(option,contract1,contract2)
1936
+
1937
+ #不同行权点位
1938
+ contract1="IO2403-C-3900"
1939
+ contract2="IO2403-C-4400"
1940
+ df=index_option_compare_china2(option,contract1,contract2)
1941
+
1942
+ #不同方向:看涨vs看跌
1943
+ contract1="IO2403-C-3300"
1944
+ contract2="IO2403-P-3300"
1945
+ df=index_option_compare_china2(option,contract1,contract2,twinx=True)
1946
+
1947
+ #==============================================================================
1948
+
1949
+
1581
1950
  if __name__=='__main__':
1582
1951
  option=["2306",3900,"Call"]
1583
1952
 
siat/valuation.py CHANGED
@@ -22,6 +22,7 @@ from siat.translate import *
22
22
  from siat.stock import *
23
23
  from siat.security_prices import *
24
24
  from siat.sector_china import *
25
+ from siat.valuation_china import *
25
26
  from siat.grafix import *
26
27
 
27
28
  import pandas as pd
@@ -778,7 +779,17 @@ def get_valuation(tickers,indicators,start,end):
778
779
 
779
780
  # 申万指数代码?
780
781
  if not gotit and (result and suffix in ['SW']):
781
- dft=get_index_valuation_funddb(t1,indicators1,start,end)
782
+ #dft=get_index_valuation_funddb(t1,indicators1,start,end)
783
+ indicator1=indicators1[0]
784
+ dft0=industry_valuation_history_sw(industry=t1,
785
+ start=start,end=end,
786
+ vtype=indicator1,
787
+ graph=False)
788
+ dft0[indicator1]=dft0[list(dft0)[0]]
789
+ dft0['name']=industry_sw_name(t1)
790
+ dft0['currency']=''
791
+ dft=dft0[[indicator1,'name','currency']]
792
+
782
793
  if dft is not None:
783
794
  gotit=True
784
795
  iname=industry_sw_name(t1)
@@ -829,6 +840,7 @@ def get_valuation(tickers,indicators,start,end):
829
840
  df1_collist=df1_collist+[cx] #列表中必须为元组
830
841
 
831
842
  df1.columns=pd.MultiIndex.from_tuples(df1_collist) #统一修改元组型列名
843
+ df1.dropna(inplace=True)
832
844
 
833
845
  return df1
834
846