siat 3.10.125__py3-none-any.whl → 3.10.126__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.
Files changed (87) hide show
  1. siat/common.py +106 -2
  2. siat/exchange_bond_china.pickle +0 -0
  3. siat/fund_china.pickle +0 -0
  4. siat/stock.py +10 -2
  5. siat/stock_info.pickle +0 -0
  6. {siat-3.10.125.dist-info → siat-3.10.126.dist-info}/METADATA +234 -226
  7. siat-3.10.126.dist-info/RECORD +76 -0
  8. {siat-3.10.125.dist-info → siat-3.10.126.dist-info}/WHEEL +1 -1
  9. {siat-3.10.125.dist-info → siat-3.10.126.dist-info/licenses}/LICENSE +0 -0
  10. {siat-3.10.125.dist-info → siat-3.10.126.dist-info}/top_level.txt +0 -0
  11. siat/__init__ -20240701.py +0 -65
  12. siat/__init__.py.backup_20250214.py +0 -73
  13. siat/alpha_vantage_test.py +0 -24
  14. siat/assets_liquidity_test.py +0 -44
  15. siat/barrons_scraping_test.py +0 -276
  16. siat/beta_adjustment_test.py +0 -77
  17. siat/bond_test.py +0 -142
  18. siat/capm_beta_test.py +0 -49
  19. siat/cmat_commons.py +0 -961
  20. siat/compare_cross_test.py +0 -117
  21. siat/concepts_iwencai.py +0 -86
  22. siat/concepts_kpl.py +0 -93
  23. siat/cryptocurrency_test.py +0 -71
  24. siat/derivative.py +0 -1111
  25. siat/economy-20230125.py +0 -1206
  26. siat/economy_test.py +0 -360
  27. siat/esg_test.py +0 -63
  28. siat/fama_french_test.py +0 -115
  29. siat/financial_statements_test.py +0 -31
  30. siat/financials2 - /321/205/320/231/320/277/321/206/320/254/320/274.py" +0 -341
  31. siat/financials_china2_test.py +0 -67
  32. siat/financials_china2_test2.py +0 -88
  33. siat/financials_china2_test3.py +0 -87
  34. siat/financials_china_test.py +0 -475
  35. siat/financials_china_test2.py +0 -197
  36. siat/financials_china_test2_fin_indicator.py +0 -197
  37. siat/financials_test.py +0 -713
  38. siat/fred_test.py +0 -40
  39. siat/fund_china_test.py +0 -175
  40. siat/fund_test.py +0 -40
  41. siat/future_china_test.py +0 -37
  42. siat/global_index_test.py +0 -66
  43. siat/grafix_test.py +0 -112
  44. siat/holding_risk_test.py +0 -13
  45. siat/local_debug_test.py +0 -100
  46. siat/markowitz2-20240620.py +0 -2614
  47. siat/markowitz_ccb_test.py +0 -37
  48. siat/markowitz_ef_test.py +0 -136
  49. siat/markowitz_old.py +0 -871
  50. siat/markowitz_simple-20230709.py +0 -370
  51. siat/markowitz_test.py +0 -164
  52. siat/markowitz_test2.py +0 -69
  53. siat/ml_cases_example1.py +0 -60
  54. siat/option_china_test.py +0 -447
  55. siat/option_pricing_test.py +0 -81
  56. siat/option_sina_api_test.py +0 -112
  57. siat/proxy_test.py +0 -84
  58. siat/quandl_test.py +0 -39
  59. siat/risk_adjusted_return_test.py +0 -81
  60. siat/risk_evaluation_test.py +0 -96
  61. siat/risk_free_rate_test.py +0 -127
  62. siat/sector_china_test.py +0 -203
  63. siat/security_price.py +0 -831
  64. siat/security_prices_test.py +0 -310
  65. siat/security_trend2-20240620.py +0 -493
  66. siat/setup.py +0 -41
  67. siat/shenwan index history test.py +0 -41
  68. siat/stock_china_test.py +0 -38
  69. siat/stock_info_test.py +0 -189
  70. siat/stock_list_china_test.py +0 -33
  71. siat/stock_technical-20240620.py +0 -2736
  72. siat/stock_test.py +0 -487
  73. siat/temp.py +0 -36
  74. siat/test2_graphviz.py +0 -484
  75. siat/test_graphviz.py +0 -411
  76. siat/test_markowitz_simple.py +0 -198
  77. siat/test_markowitz_simple_revised.py +0 -215
  78. siat/test_markowitz_simple_revised2.py +0 -218
  79. siat/transaction_test.py +0 -436
  80. siat/translate-20230125.py +0 -2107
  81. siat/translate-20230206.py +0 -2109
  82. siat/translate-20230215.py +0 -2158
  83. siat/translate_20240606.py +0 -4206
  84. siat/translate_241003_keep.py +0 -4300
  85. siat/universal_test.py +0 -100
  86. siat/valuation_market_china_test.py +0 -36
  87. siat-3.10.125.dist-info/RECORD +0 -152
siat/option_china_test.py DELETED
@@ -1,447 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- #==============================================================================
4
- #测试方法:先卸载siat:pip uninstall siat
5
- import os; os.chdir('S:/siat')
6
- from siat import *
7
- #==============================================================================
8
- import akshare as ak
9
- ak.option_sina_commodity_dict(symbol=" Gold options ")
10
-
11
-
12
-
13
-
14
-
15
-
16
- #==============================================================================
17
- #中金所,沪深300指数期权日频行情
18
- import akshare as ak
19
- """
20
- 目标地址: https://stock.finance.sina.com.cn/view/optionsCffexDP.php
21
- 描述: 获取中金所-沪深300指数-指定合约-日频行情
22
- """
23
- #期权列表
24
- df1 = ak.option_sina_cffex_hs300_list()
25
- """
26
- {'沪深300指数': ['io2112', 'io2201', 'io2203', 'io2206', 'io2209', 'io2202']}
27
- """
28
-
29
- #最新行情价格:可获得合约标识,例如io2206C5800
30
- #df2 = ak.option_sina_cffex_hs300_spot(contract="io2206")
31
- df2 = ak.option_sina_cffex_hs300_spot()
32
-
33
- [ '看涨合约_最新价',
34
- ['看涨合约_最新价','行权价','看涨合约_标识','看跌合约_最新价','看跌合约_标识']
35
- '看跌合约_卖价',
36
- '看跌合约_卖量',
37
- '看跌合约_持仓量',
38
- '看跌合约_涨跌',
39
- '看跌合约_标识']
40
- """
41
- """
42
- df2s=df2[['看涨合约_最新价','行权价','看涨合约_标识','看跌合约_最新价','看跌合约_标识']]
43
-
44
- #日频行情:注意到期月份,过了到期月份就没有数据了
45
- df3 = ak.option_sina_cffex_hs300_daily()
46
- df3s=df3[['date','close']]
47
-
48
- #标的物价格:沪深300指数
49
- df4=get_prices("000300.SS","2021-11-1","2021-11-25")
50
-
51
- #==============================================================================
52
- #上交所,金融期货日频行情
53
- #合约到期月份列表
54
- df11 = ak.option_sina_sse_list(symbol="50ETF", exchange="null")
55
- """
56
- ['202112', '202201', '202203', '202206']
57
- """
58
-
59
- #合约到期日:注意过了到期月份就没有数据了
60
- df12_50etf = ak.option_sina_sse_expire_day(trade_date="202206", symbol="50ETF", exchange="null")
61
- """
62
- #返回:到期日,剩余到期天数
63
- ('2022-06-22', 208)
64
- """
65
- df12_300etf = ak.option_sina_sse_expire_day(trade_date="202206", symbol="300ETF", exchange="null")
66
-
67
- #所有合约的代码
68
- df13 = ak.option_sina_sse_codes(trade_date="202206", underlying="510300")
69
- #所有看涨合约代码
70
- df13[0]
71
- """
72
- ['10003705','10003687','10003688','10003689','10003690','10003691','10003692','10003693','10003694','10003695']
73
- """
74
- #所有看跌合约代码
75
- df13[1]
76
- ['10003706','10003696','10003697','10003698','10003699','10003700','10003701','10003702','10003703','10003704']
77
-
78
- #合约实时价格:注意过了到期月份就没有数据了
79
- code1="10003689"
80
- df14 = ak.option_sina_sse_spot_price(code=code1)
81
- rowlist14=['最新价','行权价','昨收价','主力合约标识','标的股票','期权合约简称']
82
- df14s=df14[df14['字段'].apply(lambda x: x in rowlist14)]
83
-
84
- #标的物的实时价格
85
- df15 = ak.option_sina_sse_underlying_spot_price(code="sh510300")
86
- rowlist15=['证券简称','昨日收盘价','最近成交价','行情日期']
87
- df15s=df15[df15['字段'].apply(lambda x: x in rowlist15)]
88
-
89
- df15b = ak.option_sina_sse_underlying_spot_price(code="sh510050")
90
- df15bs=df15b[df15b['字段'].apply(lambda x: x in rowlist15)]
91
-
92
- #希腊字母:仅支持上交所50ETF、300ETF期权
93
- df16 = ak.option_sina_sse_greeks(code=code1)
94
- rowlist16=['期权合约简称','Delta','Gamma','Theta','Vega','隐含波动率','交易代码','行权价','最新价','理论价值']
95
- df16s=df16[df16['字段'].apply(lambda x: x in rowlist16)]
96
-
97
- #期权行情日数据
98
- df17 = ak.option_sina_sse_daily(code=code1)
99
- df17s=df17[['日期','收盘']]
100
-
101
- #==============================================================================
102
- #商品期权:新浪,历史行情
103
- #查看合约代码和到期月份
104
- df20=ak.option_sina_commodity_dict(symbol="黄金期权")
105
- """
106
- {'黄金期权': ['au2202', 'au2204', 'au2206', 'au2201']}
107
- """
108
-
109
- #查看合约代码
110
- df21=ak.option_sina_commodity_contract_list(symbol="黄金期权", contract="au2201")
111
- list(df21)
112
- """
113
- ['买量',
114
- '买价',
115
- '最新价',
116
- '卖价',
117
- '卖量',
118
- '持仓量',
119
- '涨跌',
120
- '行权价',
121
- '看涨期权合约',
122
- '买量',
123
- '买价',
124
- '最新价',
125
- '卖价',
126
- '卖量',
127
- '持仓量',
128
- '涨跌',
129
- '看跌期权合约']
130
- """
131
- df21s=df21.drop(['买量','买价','卖价','卖量','持仓量','涨跌'], axis=1)
132
- list(df21s)
133
- collist=['看涨期权最新价', '行权价', '看涨期权合约', '看跌期权最新价', '看跌期权合约']
134
- df21s.columns=collist
135
-
136
- #合约历史行情:有的数据很少!
137
- """
138
- 新浪财经,商品期权
139
- https://stock.finance.sina.com.cn/futures/view/optionsDP.php/au_o/shfe
140
- 豆粕期权:m
141
- 玉米期权:c
142
- 铁矿石期权:i
143
- 棉花期权:cf
144
- 白糖期权:sr
145
- PTA期权:ta
146
- 甲醇期权:ma
147
- 橡胶期权:ru
148
- 沪铜期权:cu
149
- 黄金期权:au
150
- 菜籽粕期权:rm
151
- 液化石油气期权:pg
152
- 动力煤期权:zc
153
- """
154
- df22 = ak.option_sina_commodity_hist(contract="au2202C392")
155
- df22s=df22[['date','close']]
156
-
157
- #==============================================================================
158
- #商品期权:上海期货交易所
159
- """
160
- 交易所 对应名称 上市时间
161
- 上海期货交易所 铜期权 2018-09-21
162
- 上海期货交易所 天胶期权 2019-01-28
163
- 上海期货交易所 黄金期权 2019-12-20
164
- 上海期货交易所 铝期权 2020-08-10
165
- 上海期货交易所 锌期权 2020-08-10
166
- """
167
-
168
- """
169
- 交易所 对应名称 上市时间
170
- 大连商品交易所 豆粕期权 2017-03-31
171
- 大连商品交易所 玉米期权 2019-01-28
172
- 大连商品交易所 铁矿石期权 2019-12-09
173
- 大连商品交易所 液化石油气期权 2020-03-30
174
- 大连商品交易所 聚乙烯期权 2020-07-06
175
- 大连商品交易所 聚氯乙烯期权 2020-07-06
176
- 大连商品交易所 聚丙烯期权 2020-07-06
177
- """
178
-
179
-
180
- """
181
- 交易所 对应名称 上市时间
182
- 郑州商品交易所 白糖期权 2017-04-19
183
- 郑州商品交易所 棉花期权 2019-01-28
184
- 郑州商品交易所 PTA期权 2019-12-16
185
- 郑州商品交易所 甲醇期权 2019-12-16
186
- 郑州商品交易所 菜籽粕期权 2020-01-16
187
- 郑州商品交易所 动力煤期权 2020-06-30
188
-
189
- 郑州商品交易所 白糖期权 2017-04-19 SR
190
- 郑州商品交易所 棉花期权 2019-01-28 CF
191
- 郑州商品交易所 PTA期权 2019-12-16 TA
192
- 郑州商品交易所 甲醇期权 2019-12-16 MA
193
- 郑州商品交易所 菜籽粕期权 2020-01-16 RM
194
- """
195
- df50 = ak.option_czce_hist(symbol="RM", year="2021")
196
- df50s=df50[['交易日期 ','合约代码 ','昨结算 ','今收盘 ','今结算 ','DELTA ','隐含波动率']]
197
-
198
- df50s[df50s['合约代码 ']=='RM209P2450']
199
-
200
- #==============================================================================
201
-
202
-
203
- #==============================================================================
204
- #==============================================================================
205
- #==============================================================================
206
- #==============================================================================
207
-
208
-
209
-
210
- #==============================================================================
211
- #第一步:查询金融期权期权
212
- #查看中国当前的金融期权品种
213
- option_fin_china()
214
-
215
- #如果希望查看更多内容:
216
- option_fin_china(detail=True)
217
-
218
- #查看某个金融期权品种的到期月份:以华夏上证50ETF期权为例
219
- option="华夏上证50ETF期权"
220
- option_fin_month_china(option)
221
-
222
- #查看某个金融期权在某个到期月份的具体合约:以华夏上证50ETF期权2022年6月到期的看涨合约为例
223
- end_month='2206'
224
- direction='call'
225
- #脚本默认是看涨期权合约
226
- contracts=option_fin_contracts(option,end_month,direction)
227
-
228
- #如果希望查看看跌期权合约
229
- contracts=option_fin_contracts(option,end_month,'put')
230
-
231
- #如果希望查看看涨和看跌期权的全部合约:发现看涨和看跌合约都是配对出现的
232
- contracts=option_fin_contracts(option,end_month,'both')
233
-
234
- #第二步:查找计算金融期权预期价格所需要的参数
235
- #以2022年6月份到期的华夏上证50ETF期权合约510050C2206M02900为例
236
- contract='510050C2206M02900'
237
- ua,maturity,x=option_fin_contract_parms(option,end_month,contract,direction)
238
- print("underlying asset is",ua)
239
- print("maturity date is",maturity)
240
- print("strike price is",x)
241
- #其到期日是2022-6-28
242
-
243
- #计算期权标的证券(510050.SS)价格的历史波动率:
244
- #假定今日是2021-11-19,使用历史样本的期间长度为日历日180天(可更改)
245
- today='2021-11-19'
246
- hist_sample_len=180
247
- sigma,s0,_=underlying_sigma(ua,today,days=hist_sample_len)
248
- print("annualized_sigma is",round(sigma,5))
249
- print("underlying security price is",s0)
250
-
251
- #查找年化无风险利率:基于SHIBOR三个月期利率(3M),默认是近30天内的最新利率
252
- rate_period='3M'
253
- rf=shibor_rate(today,rate_period)
254
- print("risk-free interest rate is",rf)
255
-
256
- #如果未找到,可以扩大查找范围,例如扩大到近期60天内的最新利率
257
- daysahead=60
258
- rf=shibor_rate(today,rate_period,daysahead)
259
-
260
- #计算当前日期距离合约到期日的天数
261
- days,_=calc_days(today,maturity)
262
- print("days is",days)
263
-
264
- #第三步:计算期权合约的预期价格
265
- #中国目前金融期权均为无红利的欧式期权,可以直接采用Black-Scholes期权定价模型
266
- expected_price=bs_pricing(s0,x,days,rf,sigma,direction)
267
- #计算的预期结果:0.44,实际价格0.4411
268
- #==============================================================================
269
- #==============================================================================
270
- from siat import *
271
-
272
- #第一步:查询金融期权期权
273
- #查看中国当前的金融期权品种
274
- option_fin_china()
275
-
276
- #如果希望查看更多内容:
277
- option_fin_china(detail=True)
278
-
279
- #查看某个金融期权品种的到期月份:以上交所沪深30050ETF期权(即华泰柏瑞沪深300ETF期权)为例
280
- option="华泰柏瑞沪深300ETF期权"
281
- option_fin_month_china(option)
282
-
283
- #查看某个金融期权在某个到期月份的具体合约:
284
- #以华泰柏瑞沪深300ETF期权2022年6月到期的看涨合约为例
285
- end_month='2206'
286
- direction='call'
287
- #脚本默认是看涨期权合约
288
- contracts=option_fin_contracts(option,end_month,direction)
289
-
290
- #如果希望查看看跌期权合约
291
- contracts=option_fin_contracts(option,end_month,'put')
292
-
293
- #如果希望查看看涨和看跌期权的全部合约:发现看涨和看跌合约都是配对出现的
294
- contracts=option_fin_contracts(option,end_month,'both')
295
-
296
- #第二步:查找计算金融期权预期价格所需要的参数
297
- #以2022年6月份到期的华夏上证50ETF期权合约510300C2206M04500为例
298
- contract='510300C2206M04500'
299
- ua,maturity,x=option_fin_contract_parms(option,end_month,contract,direction)
300
- print("underlying asset is",ua)
301
- print("maturity date is",maturity)
302
- print("strike price is",x)
303
- #其到期日是2022-6-28
304
-
305
- #计算期权标的证券(510050.SS)价格的历史波动率:
306
- #假定今日是2021-11-19,使用历史样本的期间长度为日历日30天(可更改)
307
- today='2021-11-19'
308
- hist_sample_len=30
309
- sigma,s0,_=underlying_sigma(ua,today,days=hist_sample_len)
310
- print("annualized_sigma is",round(sigma,5))
311
- print("underlying security price is",s0)
312
-
313
- #查找年化无风险利率:基于SHIBOR三个月期利率(3M),默认是近30天内的最新利率
314
- rate_period='3M'
315
- rf=shibor_rate(today,rate_period)
316
- print("risk-free interest rate is",rf)
317
-
318
- #如果未找到,可以扩大查找范围,例如扩大到近期60天内的最新利率
319
- daysahead=60
320
- rf=shibor_rate(today,rate_period,daysahead)
321
-
322
- #计算当前日期距离合约到期日的天数
323
- days,_=calc_days(today,maturity)
324
- print("days is",days)
325
-
326
- #第三步:计算期权合约的预期价格
327
- #中国目前金融期权均为无红利的欧式期权,可以直接采用Black-Scholes期权定价模型
328
- expected_price=bs_pricing(s0,x,days,rf,sigma,direction)
329
- #计算的预期结果:0.55,实际价格0.51
330
- #==============================================================================
331
-
332
-
333
- # 绝对引用指定目录中的模块
334
- import sys
335
- sys.path.insert(0,r'S:\siat\siat')
336
- from option_china import *
337
- #==============================================================================
338
- def option_fin_china():
339
- """
340
- 查找中国金融期权列表
341
- """
342
- option_fin_list=['华夏上证50ETF期权','华泰柏瑞沪深300ETF期权', \
343
- '嘉实沪深300ETF期权','沪深300股指期权']
344
- num=len(option_fin_list)
345
-
346
- print(" There are",num,"financial options in China mainland at present:")
347
- for i in option_fin_list:
348
- print(' ',i)
349
-
350
- return option_fin_list
351
-
352
-
353
-
354
- import akshare as ak
355
- #横截面数据
356
- df1 = ak.option_finance_board(symbol="华夏上证50ETF期权", end_month="2112")
357
- list(df1)
358
- #['合约交易代码', '当前价', '涨跌幅', '前结价', '行权价', '数量']
359
-
360
- df2 = ak.option_finance_board(symbol="嘉实沪深300ETF期权", end_month="2112")
361
- list(df2)
362
- ['合约编码', '合约简称', '标的名称', '类型', '行权价', '合约单位', '期权行权日', '行权交收日']
363
-
364
- df3 = ak.option_finance_board(symbol="华泰柏瑞沪深300ETF期权", end_month="2112")
365
- list(df3)
366
- #['合约交易代码', '当前价', '涨跌幅', '前结价', '行权价', '数量']
367
-
368
- df4 = ak.option_finance_board(symbol="沪深300股指期权", end_month="2112")
369
- list(df4)
370
- #['instrument',
371
- 'position',
372
- 'volume',
373
- 'lastprice',
374
- 'updown',
375
- 'bprice',
376
- 'bamount',
377
- 'sprice',
378
- 'samount']
379
-
380
-
381
-
382
-
383
-
384
-
385
-
386
-
387
- #沪深300指数期权
388
- df10 = ak.option_sina_cffex_hs300_list()
389
- #实时行情
390
- df11 = ak.option_sina_cffex_hs300_spot(contract="io2112")
391
- df12 = ak.option_sina_cffex_hs300_daily(contract="io2004C4450")
392
-
393
- #==============================================================================
394
- #查找中国商品期权的常见品种
395
- df1=option_comm_china()
396
-
397
- #查找中国黄金期权的可用合约
398
- df2=option_comm_china('黄金')
399
-
400
- #查找中国黄金期权au2112和au2202的具体合约(看涨/看跌合约)
401
- df3=option_comm_china('黄金','au2112')
402
- df3b=option_comm_china('黄金','au2202')
403
- #同一时刻行权价对期权合约的影响:行权价越高,看涨期权合约价格越低,看跌期权合约价越高
404
-
405
- #单一期权合约价格的运动趋势:默认不带趋势线
406
- df4=option_comm_trend_china('au2202C364','2021-9-1','2021-9-30',power=4)
407
-
408
- #期权方向对合约价格走势的影响:看涨/看跌期权合约的价格走势正好相反
409
- df5=option_comm_trend_china(['au2202C364','au2202P364'],'2021-8-1','2021-9-30')
410
-
411
- #行权价对合约价格时间序列走势的影响:看涨期权,行权价低者合约价高
412
- df6=option_comm_trend_china(['au2112C328','au2112C364'],'2021-8-1','2021-9-30')
413
- #行权价对合约价格时间序列走势的影响:看跌期权,行权价低者合约价低,与看涨期权正好相反
414
- df6b=option_comm_trend_china(['au2112P328','au2112P364'],'2021-8-1','2021-9-30')
415
-
416
- #到期时间对合约价格走势的影响:看涨期权,到期日近者合约价低(时间价值少)
417
- df7=option_comm_trend_china(['au2112C364','au2202C364'],'2021-8-1','2021-9-30')
418
- #到期时间对合约价格走势的影响:看跌期权,到期日近者合约价低,与看涨期权一致
419
- df7b=option_comm_trend_china(['au2112P364','au2202P364'],'2021-8-1','2021-9-30')
420
-
421
-
422
-
423
- #==============================================================================
424
-
425
- import os; os.chdir('S:/siat')
426
- from siat import *
427
-
428
- import warnings
429
-
430
- with warnings.catch_warnings():
431
- warnings.simplefilter('ignore')
432
- lg = bs.login()
433
-
434
- disable_prints()
435
- #==============================================================================
436
- import akshare as ak
437
- ak.option_sina_commodity_dict(symbol="黄金期权")
438
- ak.option_sina_commodity_contract_list(symbol="黄金期权", contract="au2022")
439
- df = ak.option_finance_board(symbol="华夏上证50ETF期权", end_month="2202")
440
- df = ak.option_sina_commodity_contract_list(symbol="黄金期权", contract="au2012")
441
- df=option_comm_trend_china('au2205C364','2021-9-1','2021-9-30')
442
-
443
-
444
-
445
-
446
-
447
-
@@ -1,81 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- import os; os.chdir("S:/siat")
4
- from siat import *
5
-
6
- #==============================================================================
7
-
8
-
9
-
10
- #==============================================================================
11
- df=stock_trend_by_option('JD')
12
-
13
- c=bs_call(51100,51000,25,0.02828,0.1792)
14
-
15
- datelist=option_maturity('MSFT')
16
-
17
- dfc,dfp=option_chain('MSFT','2022-6-17')
18
- dfc,dfp=option_chain('AAPL','2022-6-17')
19
-
20
- datelist=option_maturity('^XSP')
21
- dfc,dfp=option_chain('^XSP','2021-12-17')
22
-
23
- datelist=option_maturity('TLT')
24
- dfc,dfp=option_chain('TLT','2022-12-16')
25
-
26
- df=stock_trend_by_option('JD')
27
-
28
- from siat.transaction import *
29
- df=security_price('JD','2020-12-1','2021-1-31')
30
-
31
-
32
- bsm_aprice([30,50],42,183,0.015,0.23,90,1.5)
33
- df=bsm_maturity(40,42,[200,100],0.015,0.23,90,1.5)
34
- bsm_sigma(40,42,183,0.015,[0.1,0.4],90,1.5)
35
-
36
- df=stock_trend_by_option('AAPL',7)
37
- df=stock_trend_by_option('JD',7)
38
- df=stock_trend_by_option('MSFT',7)
39
- df=stock_trend_by_option('BABA',7)
40
- df=stock_trend_by_option('GS',7)
41
- df=stock_trend_by_option('PDD',7)
42
-
43
- df=recent_stock_split('AAPL')
44
- df=recent_stock_split('MSFT')
45
-
46
- get_last_close('AAPL')
47
- get_last_close('MSFT')
48
-
49
- import time
50
- tupTime = time.localtime(1604350755)#秒时间戳
51
- stadardTime = time.strftime("%Y-%m-%d %H:%M:%S", tupTime)
52
- print(stadardTime)
53
-
54
-
55
- ticker="AAPL"
56
- mdate="2020-11-06"
57
- opt_call, opt_put=option_chain(ticker,mdate,printout=False)
58
-
59
-
60
- from siat.stock import *
61
- div=stock_dividend('AAPL','2020-1-1','2020-11-3')
62
- splt=stock_split('AAPL','2020-1-1','2020-11-3')
63
-
64
-
65
- df=predict_stock_trend_by_option('AAPL')
66
-
67
- df=predict_stock_trend_by_option('02020.HK',lastndays=7)
68
- df=predict_stock_trend_by_option('2331.HK',lastndays=7)
69
- df=predict_stock_trend_by_option('1368.HK',lastndays=7)
70
-
71
- splt=stock_split('NKE','2020-1-1','2020-11-3')
72
- df=predict_stock_trend_by_option('NKE',lastndays=30)
73
-
74
- splt=stock_split('ADS.DE','2020-1-1','2020-11-3')
75
- df=predict_stock_trend_by_option('ADS.DE',lastndays=30)
76
-
77
- splt=stock_split('JD','2020-1-1','2020-11-3')
78
- df=predict_stock_trend_by_option('JD')
79
-
80
- splt=stock_split('BABA','2020-1-1','2020-11-3')
81
- df=predict_stock_trend_by_option('BABA',lastndays=30)
@@ -1,112 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- # python3
4
- from json import loads
5
- from requests import get
6
-
7
-
8
- def get_option_dates(cate='50ETF', exchange='null'):
9
- url = f"http://stock.finance.sina.com.cn/futures/api/openapi.php/StockOptionService.getStockName?" \
10
- f"exchange={exchange}&cate={cate}"
11
- dates = get(url).json()['result']['data']['contractMonth']
12
- return [''.join(i.split('-')) for i in dates][1:]
13
-
14
-
15
- def get_option_expire_day(date, cate='50ETF', exchange='null'):
16
- url = "http://stock.finance.sina.com.cn/futures/api/openapi.php/StockOptionService.getRemainderDay?" \
17
- "exchange={exchange}&cate={cate}&date={year}-{month}"
18
- url2 = url.format(year=date[:4], month=date[4:], cate=cate, exchange=exchange)
19
- data = get(url2).json()['result']['data']
20
- if int(data['remainderDays']) < 0:
21
- url2 = url.format(year=date[:4], month=date[4:], cate='XD' + cate, exchange=exchange)
22
- data = get(url2).json()['result']['data']
23
- return data['expireDay'], int(data['remainderDays'])
24
-
25
-
26
- def get_option_codes(date, underlying='510050'):
27
- url_up = ''.join(["http://hq.sinajs.cn/list=OP_UP_", underlying, str(date)[-4:]])
28
- url_down = ''.join(["http://hq.sinajs.cn/list=OP_DOWN_", underlying, str(date)[-4:]])
29
- data_up = str(get(url_up).content).replace('"', ',').split(',')
30
- codes_up = [i[7:] for i in data_up if i.startswith('CON_OP_')]
31
- data_down = str(get(url_down).content).replace('"', ',').split(',')
32
- codes_down = [i[7:] for i in data_down if i.startswith('CON_OP_')]
33
- return codes_up, codes_down
34
-
35
-
36
- def get_option_price(code):
37
- url = "http://hq.sinajs.cn/list=CON_OP_{code}".format(code=code)
38
- data = get(url).content.decode('gbk')
39
- data = data[data.find('"') + 1: data.rfind('"')].split(',')
40
- fields = ['买量', '买价', '最新价', '卖价', '卖量', '持仓量', '涨幅', '行权价', '昨收价', '开盘价', '涨停价',
41
- '跌停价', '申卖价五', '申卖量五', '申卖价四', '申卖量四', '申卖价三', '申卖量三', '申卖价二',
42
- '申卖量二', '申卖价一', '申卖量一', '申买价一', '申买量一 ', '申买价二', '申买量二', '申买价三',
43
- '申买量三', '申买价四', '申买量四', '申买价五', '申买量五', '行情时间', '主力合约标识', '状态码',
44
- '标的证券类型', '标的股票', '期权合约简称', '振幅', '最高价', '最低价', '成交量', '成交额',
45
- '分红调整标志', '昨结算价', '认购认沽标志', '到期日', '剩余天数', '虚实值标志', '内在价值', '时间价值']
46
- result = list(zip(fields, data))
47
- return result
48
-
49
-
50
- def get_underlying_security_price(code='sh510050'):
51
- url = "http://hq.sinajs.cn/list=" + code
52
- data = get(url).content.decode('gbk')
53
- data = data[data.find('"') + 1: data.rfind('"')].split(',')
54
- fields = ['证券简称', '今日开盘价', '昨日收盘价', '最近成交价', '最高成交价', '最低成交价', '买入价',
55
- '卖出价', '成交数量', '成交金额', '买数量一', '买价位一', '买数量二', '买价位二', '买数量三',
56
- '买价位三', '买数量四', '买价位四', '买数量五', '买价位五', '卖数量一', '卖价位一', '卖数量二',
57
- '卖价位二', '卖数量三', '卖价位三', '卖数量四', '卖价位四', '卖数量五', '卖价位五', '行情日期',
58
- '行情时间', '停牌状态']
59
- return list(zip(fields, data))
60
-
61
-
62
- def get_option_greek_alphabet(code):
63
- url = "http://hq.sinajs.cn/list=CON_SO_{code}".format(code=code)
64
- data = get(url).content.decode('gbk')
65
- data = data[data.find('"') + 1: data.rfind('"')].split(',')
66
- fields = ['期权合约简称', '成交量', 'Delta', 'Gamma', 'Theta', 'Vega', '隐含波动率', '最高价', '最低价',
67
- '交易代码', '行权价', '最新价', '理论价值']
68
- return list(zip(fields, [data[0]] + data[4:]))
69
-
70
-
71
- def get_option_time_line(code):
72
- url = f"https://stock.finance.sina.com.cn/futures/api/openapi.php/StockOptionDaylineService.getOptionMinline?" \
73
- f"symbol=CON_OP_{code}"
74
- data = get(url).json()['result']['data']
75
- return data
76
-
77
-
78
- def get_option_day_kline(code):
79
- url = f"http://stock.finance.sina.com.cn/futures/api/jsonp_v2.php//StockOptionDaylineService.getSymbolInfo?" \
80
- f"symbol=CON_OP_{code}"
81
- data = get(url).content
82
- data = loads(data[data.find(b'(') + 1: data.rfind(b')')])
83
- return data
84
-
85
-
86
- def my_test():
87
- dates = get_option_dates(cate='300ETF')
88
- print('期权合约月份:{}'.format(dates))
89
- for date in dates:
90
- print('期权月份{}:到期日{} 剩余天数{}'.format(date, *get_option_expire_day(date, cate='300ETF')))
91
- demo_code = '10002180'
92
- for date in dates:
93
- call_codes, put_codes = get_option_codes(date, underlying='510300')
94
- print('期权月份{} 看涨期权代码:{}\n期权月份{} 看跌期权代码:{}'.format(date, call_codes, date, put_codes))
95
- demo_code = call_codes[0]
96
- for index, i in enumerate(get_option_price(demo_code)):
97
- print('期权' + demo_code, index, *i)
98
- for index, i in enumerate(get_underlying_security_price(code='sh510300')):
99
- print(index, *i)
100
- for index, i in enumerate(get_option_greek_alphabet(demo_code)):
101
- print('期权' + demo_code, index, *i)
102
- time_line = get_option_time_line(demo_code)
103
- for i in time_line[-10:]:
104
- print('时间:{i}, 价格:{p}, 成交:{v}, 持仓:{t}, 均价:{a}'.format(**i))
105
- day_kline = get_option_day_kline(demo_code)
106
- for i in day_kline:
107
- print('日期:{d}, 开盘:{o}, 最高:{h}, 最低:{l}, 收盘:{c}, 成交:{v}'.format(**i))
108
-
109
-
110
- if __name__ == '__main__':
111
- my_test()
112
-