siat 3.6.7__py3-none-any.whl → 3.6.8__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_pricing.py +49 -24
- siat/yf_name.py +1 -1
- {siat-3.6.7.dist-info → siat-3.6.8.dist-info}/METADATA +1 -1
- {siat-3.6.7.dist-info → siat-3.6.8.dist-info}/RECORD +7 -7
- {siat-3.6.7.dist-info → siat-3.6.8.dist-info}/LICENSE +0 -0
- {siat-3.6.7.dist-info → siat-3.6.8.dist-info}/WHEEL +0 -0
- {siat-3.6.7.dist-info → siat-3.6.8.dist-info}/top_level.txt +0 -0
siat/option_pricing.py
CHANGED
@@ -20,6 +20,7 @@ from siat.translate import *
|
|
20
20
|
from siat.grafix import *
|
21
21
|
from siat.security_prices import *
|
22
22
|
from siat.security_trend2 import *
|
23
|
+
from siat.yf_name import *
|
23
24
|
#==============================================================================
|
24
25
|
import matplotlib.pyplot as plt
|
25
26
|
|
@@ -1160,11 +1161,17 @@ def binomial_american_put(S0,X,Days,r0,sigma,q0=0,steps=200,printout=True):
|
|
1160
1161
|
#==============================================================================
|
1161
1162
|
if __name__=='__main__':
|
1162
1163
|
ticker="AAPL"
|
1164
|
+
ticker="SPY"
|
1163
1165
|
|
1164
1166
|
def option_maturity(ticker,printout=True):
|
1165
1167
|
"""
|
1166
1168
|
功能:获得期权的各个到期日期
|
1167
1169
|
"""
|
1170
|
+
"""
|
1171
|
+
if not test_yahoo_access():
|
1172
|
+
print(" #Warning(option_maturity): failed to access data source Yahoo Finance")
|
1173
|
+
return None
|
1174
|
+
"""
|
1168
1175
|
import yfinance as yf
|
1169
1176
|
opt = yf.Ticker(ticker)
|
1170
1177
|
|
@@ -1172,8 +1179,10 @@ def option_maturity(ticker,printout=True):
|
|
1172
1179
|
try:
|
1173
1180
|
exp_dates=opt.options
|
1174
1181
|
except:
|
1175
|
-
print("#Error(option_maturity): failed to get maturity dates for
|
1182
|
+
print(" #Error(option_maturity): failed to get option maturity dates for underlying",ticker)
|
1183
|
+
print(" Reasons: either",ticker,"does not exist or Yahoo Finance is currently inaccessible")
|
1176
1184
|
return None
|
1185
|
+
|
1177
1186
|
datelist=list(exp_dates)
|
1178
1187
|
if not printout:
|
1179
1188
|
return datelist
|
@@ -1231,7 +1240,8 @@ def option_chain(ticker,maturity_date='today',printout=True):
|
|
1231
1240
|
try:
|
1232
1241
|
optlist = opt.option_chain(mdate3)
|
1233
1242
|
except:
|
1234
|
-
|
1243
|
+
if printout:
|
1244
|
+
print(" #Error(option_chain): failed to get option chain for",ticker,'\b@',mdate)
|
1235
1245
|
return None,None
|
1236
1246
|
|
1237
1247
|
opt_call=optlist.calls
|
@@ -1332,7 +1342,7 @@ if __name__ =="__main__":
|
|
1332
1342
|
#def predict_stock_trend_by_option(ticker,lastndays=7,power=4):
|
1333
1343
|
def market_prospect_via_option(ticker,lastdays=7):
|
1334
1344
|
"""
|
1335
|
-
|
1345
|
+
功能:根据期权行权价及交易量预测标的物价格
|
1336
1346
|
注意:本函数与price_prospect_via_option内容基本一致,图示方式略有不同
|
1337
1347
|
"""
|
1338
1348
|
lastndays=lastdays
|
@@ -1423,7 +1433,7 @@ def market_prospect_via_option(ticker,lastdays=7):
|
|
1423
1433
|
|
1424
1434
|
#绘图2:OTM Calls vs OTM Puts相对比例
|
1425
1435
|
colname1='OTM in Calls%'
|
1426
|
-
label1='OTM in Calls
|
1436
|
+
label1='OTM in Calls%'
|
1427
1437
|
colname2='OTM in Puts%'
|
1428
1438
|
label2='OTM in Puts%'
|
1429
1439
|
ylabeltxt='Percentage'
|
@@ -1436,7 +1446,7 @@ def market_prospect_via_option(ticker,lastdays=7):
|
|
1436
1446
|
|
1437
1447
|
#绘图3:OTM Calls vs OTM Puts绝对比例
|
1438
1448
|
colname1='OTM Calls in Total%'
|
1439
|
-
label1='OTM Calls in Total
|
1449
|
+
label1='OTM Calls in Total%'
|
1440
1450
|
colname2='OTM Puts in Total%'
|
1441
1451
|
label2='OTM Puts in Total%'
|
1442
1452
|
ylabeltxt='Percentage'
|
@@ -1447,7 +1457,7 @@ def market_prospect_via_option(ticker,lastdays=7):
|
|
1447
1457
|
df2,ticker,colname2,label2, \
|
1448
1458
|
ylabeltxt,titletxt,footnote)
|
1449
1459
|
|
1450
|
-
#绘图4
|
1460
|
+
#绘图4:标的物价格预测
|
1451
1461
|
df2x=df2.drop(df2[df2['Total Options']<=1].index)
|
1452
1462
|
"""
|
1453
1463
|
colname='WA Strike'
|
@@ -1613,14 +1623,14 @@ if __name__ =="__main__":
|
|
1613
1623
|
|
1614
1624
|
def price_prospect_via_option(ticker,lastdays=7,cutoff=[1.1,5.0,10.0]):
|
1615
1625
|
"""
|
1616
|
-
|
1626
|
+
功能:根据股票期权预测标的物价格
|
1617
1627
|
算法:
|
1618
1628
|
1、计算虚值看涨/看跌期权数量比例
|
1619
1629
|
2、计算虚值看涨/看跌期权交易金额比例
|
1620
|
-
3
|
1621
|
-
4
|
1630
|
+
3、若虚值看涨期权占优,为看涨,并据此估计未来标的物价格;
|
1631
|
+
4、若虚值看跌期权占优,为看跌,并据此估计未来标的物价格;
|
1622
1632
|
5、否则,为不明确
|
1623
|
-
|
1633
|
+
返回:期权明细
|
1624
1634
|
"""
|
1625
1635
|
lastndays=lastdays
|
1626
1636
|
|
@@ -1637,7 +1647,7 @@ def price_prospect_via_option(ticker,lastdays=7,cutoff=[1.1,5.0,10.0]):
|
|
1637
1647
|
return None
|
1638
1648
|
print("found",len(datelist),"maturity dates of options")
|
1639
1649
|
|
1640
|
-
|
1650
|
+
#最新的标的物价格
|
1641
1651
|
#print("Searching recent close price for",ticker,'...',end='')
|
1642
1652
|
try:
|
1643
1653
|
#lastsdate,lastsprice=get_last_close1(ticker)
|
@@ -1661,10 +1671,25 @@ def price_prospect_via_option(ticker,lastdays=7,cutoff=[1.1,5.0,10.0]):
|
|
1661
1671
|
|
1662
1672
|
if DEBUG: print("Analyzing options matured on",d,'...')
|
1663
1673
|
opt_call,opt_put=option_chain(ticker,d,printout=False)
|
1664
|
-
|
1665
|
-
|
1674
|
+
|
1675
|
+
if (opt_call is None) or (opt_put is None):
|
1676
|
+
if DEBUG:
|
1677
|
+
print(" #Warning(price_prospect_via_option): failed in retrieving options matured on",d)
|
1678
|
+
"""
|
1666
1679
|
break
|
1667
1680
|
return None
|
1681
|
+
"""
|
1682
|
+
continue
|
1683
|
+
|
1684
|
+
if (len(opt_call) == 0) or (len(opt_put) == 0):
|
1685
|
+
if DEBUG:
|
1686
|
+
print(" #Warning(price_prospect_via_option): retrieved zero options matured on",d)
|
1687
|
+
"""
|
1688
|
+
break
|
1689
|
+
return None
|
1690
|
+
"""
|
1691
|
+
continue
|
1692
|
+
|
1668
1693
|
currency=list(opt_call['currency'])[0]
|
1669
1694
|
|
1670
1695
|
##########处理看涨期权##########
|
@@ -1820,13 +1845,13 @@ def price_prospect_via_option(ticker,lastdays=7,cutoff=[1.1,5.0,10.0]):
|
|
1820
1845
|
df2,ticker,colname2,label2, \
|
1821
1846
|
ylabeltxt,titletxt,footnote)
|
1822
1847
|
|
1823
|
-
#绘图3
|
1848
|
+
#绘图3:预测的标的物价格
|
1824
1849
|
df2['Benchmark']=lastsprice
|
1825
1850
|
colname1='Estimated Price'
|
1826
|
-
label1='
|
1851
|
+
label1='预期价格'
|
1827
1852
|
colname2='Benchmark'
|
1828
|
-
label2='
|
1829
|
-
ylabeltxt='
|
1853
|
+
label2='当前价格'
|
1854
|
+
ylabeltxt='价格('+currency+')'
|
1830
1855
|
titletxt="期权链与标的价格预期: "+tname
|
1831
1856
|
|
1832
1857
|
plot_line2(df2,ticker,colname1,label1, \
|
@@ -1844,22 +1869,22 @@ def price_prospect_via_option(ticker,lastdays=7,cutoff=[1.1,5.0,10.0]):
|
|
1844
1869
|
pd.set_option('display.max_colwidth', 1000)
|
1845
1870
|
pd.set_option('display.unicode.ambiguous_as_wide', True)
|
1846
1871
|
pd.set_option('display.unicode.east_asian_width', True)
|
1847
|
-
df3.columns=['日期','
|
1872
|
+
df3.columns=['日期','标的物价格走势','标的物价格预期','虚值看涨/看跌合约数量比例','虚值看涨/看跌交易金额比例']
|
1848
1873
|
print(df3.to_string(index=False))
|
1849
1874
|
|
1850
1875
|
print(" 注:")
|
1851
|
-
print(" 1)
|
1852
|
-
print(" 2) +(-)
|
1876
|
+
print(" 1) 当前价格: "+currency+str(lastsprice),"\b,",lastsdate,'\b.')
|
1877
|
+
print(" 2) +(-)表示价格将比当前变高(低), +/-表示趋势不明朗.")
|
1853
1878
|
print(" 3) 期权交易样本期间: 最近"+str(lastndays)+"个日历日,且期间内未发生分拆.")
|
1854
|
-
print(" 4)
|
1879
|
+
print(" 4) 价格估计可能随时变化,越远期的估计可能准确度越欠佳.")
|
1855
1880
|
print(" "+footnote+'.')
|
1856
1881
|
"""
|
1857
1882
|
titletxt="期权链与标的价格预期: "+tname
|
1858
1883
|
footnote1="注:\n"
|
1859
|
-
footnote2="1
|
1860
|
-
footnote3="2、+(-)
|
1884
|
+
footnote2="1、当前价格: "+currency+str(lastsprice)+", "+lastsdate+'\n'
|
1885
|
+
footnote3="2、+(-)表示价格将比当前变高(低), +/-表示趋势不明朗\n"
|
1861
1886
|
footnote4="3、期权交易样本期间: 最近"+str(lastndays)+"个日历日,且期间内未发生分拆\n"
|
1862
|
-
footnote5="4)
|
1887
|
+
footnote5="4) 价格价格估计可能随时变化,越远期的估计可能准确度越欠佳\n"
|
1863
1888
|
|
1864
1889
|
footnote9=footnote1+footnote2+footnote3+footnote4+footnote5+footnote
|
1865
1890
|
|
siat/yf_name.py
CHANGED
@@ -44,7 +44,7 @@ def test_website(url):
|
|
44
44
|
#print(f"Website {url} access failed,Code:{response.status_code}")
|
45
45
|
return False
|
46
46
|
except requests.exceptions.RequestException:
|
47
|
-
print(f"
|
47
|
+
print(f" #Warning: website {url} is inaccessible")
|
48
48
|
return False
|
49
49
|
|
50
50
|
if __name__=='__main__':
|
@@ -82,7 +82,7 @@ siat/ml_cases_example.py,sha256=xRGb3YTQEDTOnaWNzZN_myU5umQnA2RdMNiPrxTmn9c,1673
|
|
82
82
|
siat/ml_cases_example1.py,sha256=xRGb3YTQEDTOnaWNzZN_myU5umQnA2RdMNiPrxTmn9c,1673
|
83
83
|
siat/option_china.py,sha256=vPALLZDN_oIOmwpaLdB5V6dH4OuA4Q4rSy1K0ADkqYI,120954
|
84
84
|
siat/option_china_test.py,sha256=UQ-YUHUjoGBQyanLcM-yzqeEIUQP_gCQIeT0W6rnUnA,16355
|
85
|
-
siat/option_pricing.py,sha256=
|
85
|
+
siat/option_pricing.py,sha256=vyQNgBsjcJi70Pa-fJTVVIGK_3jWh80tkd1ESnn3sE4,74069
|
86
86
|
siat/option_pricing_test.py,sha256=eeorV5Ja5vjlRXnP6fWJHetGU5Vb8SnLopkC6RV3GfA,2203
|
87
87
|
siat/option_sina_api_test.py,sha256=dn-k_wrQnAaNKHoROvWJEc7lqlU0bwiV2Aa4usWAFGM,5908
|
88
88
|
siat/proxy_test.py,sha256=erQJrmGs2X46z8Gb1h-7GYQ0rTUcaR8dxHExWoBz2eM,2610
|
@@ -139,9 +139,9 @@ siat/valuation.py,sha256=o5FsEBkYGCgyEg2m9oF3_KdTzUxPIsEeJCYtsTDZ8OE,50514
|
|
139
139
|
siat/valuation_china.py,sha256=CVp1IwIsF3Om0J29RGkyxZLt4n9Ug-ua_RKhLwL9fUQ,69624
|
140
140
|
siat/valuation_market_china_test.py,sha256=gbJ0ioauuo4koTPH6WKUkqcXiQPafnbhU5eKJ6lpdLA,1571
|
141
141
|
siat/var_model_validation.py,sha256=R0caWnuZarrRg9939hxh3vJIIpIyPfvelYmzFNZtPbo,14910
|
142
|
-
siat/yf_name.py,sha256=
|
143
|
-
siat-3.6.
|
144
|
-
siat-3.6.
|
145
|
-
siat-3.6.
|
146
|
-
siat-3.6.
|
147
|
-
siat-3.6.
|
142
|
+
siat/yf_name.py,sha256=r0Q67cSMMlfebEkI9h9pdGlJCooEq7hw_3M5IUs4cSI,20081
|
143
|
+
siat-3.6.8.dist-info/LICENSE,sha256=NTEMMROY9_4U1szoKC3N2BLHcDd_o5uTgqdVH8tbApw,1071
|
144
|
+
siat-3.6.8.dist-info/METADATA,sha256=cdP7kLCCwd-OeNJEGGyCsdPWIQW1xXZ2OQrhcrW2N1g,8009
|
145
|
+
siat-3.6.8.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
146
|
+
siat-3.6.8.dist-info/top_level.txt,sha256=r1cVyL7AIKqeAmEJjNR8FMT20OmEzufDstC2gv3NvEY,5
|
147
|
+
siat-3.6.8.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|