siat 3.10.132__py3-none-any.whl → 3.11.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/__init__.py +0 -0
- siat/allin.py +8 -0
- siat/assets_liquidity.py +0 -0
- siat/beta_adjustment.py +0 -0
- siat/beta_adjustment_china.py +0 -0
- siat/blockchain.py +0 -0
- siat/bond.py +0 -0
- siat/bond_base.py +0 -0
- siat/bond_china.py +0 -0
- siat/bond_zh_sina.py +0 -0
- siat/capm_beta.py +0 -0
- siat/capm_beta2.py +4 -4
- siat/common.py +9 -6
- siat/compare_cross.py +0 -0
- siat/copyrights.py +0 -0
- siat/cryptocurrency.py +0 -0
- siat/economy.py +0 -0
- siat/economy2.py +0 -0
- siat/esg.py +0 -0
- siat/event_study.py +0 -0
- siat/exchange_bond_china.pickle +0 -0
- siat/fama_french.py +0 -0
- siat/fin_stmt2_yahoo.py +0 -0
- siat/financial_base.py +0 -0
- siat/financial_statements.py +0 -0
- siat/financials.py +0 -0
- siat/financials2.py +0 -0
- siat/financials_china.py +0 -0
- siat/financials_china2.py +0 -0
- siat/fund.py +0 -0
- siat/fund_china.pickle +0 -0
- siat/fund_china.py +0 -0
- siat/future_china.py +0 -0
- siat/google_authenticator.py +0 -0
- siat/grafix.py +55 -4
- siat/holding_risk.py +0 -0
- siat/luchy_draw.py +0 -0
- siat/market_china.py +0 -0
- siat/markowitz.py +0 -0
- siat/markowitz2.py +1 -0
- siat/markowitz2_20250704.py +0 -0
- siat/markowitz2_20250705.py +0 -0
- siat/markowitz_simple.py +0 -0
- siat/ml_cases.py +0 -0
- siat/ml_cases_example.py +0 -0
- siat/option_china.py +0 -0
- siat/option_pricing.py +0 -0
- siat/other_indexes.py +0 -0
- siat/risk_adjusted_return.py +0 -0
- siat/risk_adjusted_return2.py +8 -4
- siat/risk_evaluation.py +0 -0
- siat/risk_free_rate.py +0 -0
- siat/save2docx.py +345 -0
- siat/save2pdf.py +145 -0
- siat/sector_china.py +0 -0
- siat/security_price2.py +0 -0
- siat/security_prices.py +168 -6
- siat/security_trend.py +0 -0
- siat/security_trend2.py +2 -2
- siat/stock.py +11 -1
- siat/stock_advice_linear.py +0 -0
- siat/stock_base.py +0 -0
- siat/stock_china.py +0 -0
- siat/stock_info.pickle +0 -0
- siat/stock_prices_kneighbors.py +0 -0
- siat/stock_prices_linear.py +0 -0
- siat/stock_profile.py +0 -0
- siat/stock_technical.py +0 -0
- siat/stooq.py +0 -0
- siat/transaction.py +0 -0
- siat/translate.py +0 -0
- siat/valuation.py +0 -0
- siat/valuation_china.py +0 -0
- siat/var_model_validation.py +0 -0
- siat/yf_name.py +0 -0
- {siat-3.10.132.dist-info/licenses → siat-3.11.1.dist-info}/LICENSE +0 -0
- {siat-3.10.132.dist-info → siat-3.11.1.dist-info}/METADATA +234 -235
- siat-3.11.1.dist-info/RECORD +80 -0
- {siat-3.10.132.dist-info → siat-3.11.1.dist-info}/WHEEL +1 -1
- {siat-3.10.132.dist-info → siat-3.11.1.dist-info}/top_level.txt +0 -1
- build/lib/build/lib/siat/__init__.py +0 -75
- build/lib/build/lib/siat/allin.py +0 -137
- build/lib/build/lib/siat/assets_liquidity.py +0 -915
- build/lib/build/lib/siat/beta_adjustment.py +0 -1058
- build/lib/build/lib/siat/beta_adjustment_china.py +0 -548
- build/lib/build/lib/siat/blockchain.py +0 -143
- build/lib/build/lib/siat/bond.py +0 -2900
- build/lib/build/lib/siat/bond_base.py +0 -992
- build/lib/build/lib/siat/bond_china.py +0 -100
- build/lib/build/lib/siat/bond_zh_sina.py +0 -143
- build/lib/build/lib/siat/capm_beta.py +0 -783
- build/lib/build/lib/siat/capm_beta2.py +0 -887
- build/lib/build/lib/siat/common.py +0 -5360
- build/lib/build/lib/siat/compare_cross.py +0 -642
- build/lib/build/lib/siat/copyrights.py +0 -18
- build/lib/build/lib/siat/cryptocurrency.py +0 -667
- build/lib/build/lib/siat/economy.py +0 -1471
- build/lib/build/lib/siat/economy2.py +0 -1853
- build/lib/build/lib/siat/esg.py +0 -536
- build/lib/build/lib/siat/event_study.py +0 -815
- build/lib/build/lib/siat/fama_french.py +0 -1521
- build/lib/build/lib/siat/fin_stmt2_yahoo.py +0 -982
- build/lib/build/lib/siat/financial_base.py +0 -1160
- build/lib/build/lib/siat/financial_statements.py +0 -598
- build/lib/build/lib/siat/financials.py +0 -2339
- build/lib/build/lib/siat/financials2.py +0 -1278
- build/lib/build/lib/siat/financials_china.py +0 -4433
- build/lib/build/lib/siat/financials_china2.py +0 -2212
- build/lib/build/lib/siat/fund.py +0 -629
- build/lib/build/lib/siat/fund_china.py +0 -3307
- build/lib/build/lib/siat/future_china.py +0 -551
- build/lib/build/lib/siat/google_authenticator.py +0 -47
- build/lib/build/lib/siat/grafix.py +0 -3636
- build/lib/build/lib/siat/holding_risk.py +0 -867
- build/lib/build/lib/siat/luchy_draw.py +0 -638
- build/lib/build/lib/siat/market_china.py +0 -1168
- build/lib/build/lib/siat/markowitz.py +0 -2363
- build/lib/build/lib/siat/markowitz2.py +0 -3150
- build/lib/build/lib/siat/markowitz2_20250704.py +0 -2969
- build/lib/build/lib/siat/markowitz2_20250705.py +0 -3158
- build/lib/build/lib/siat/markowitz_simple.py +0 -373
- build/lib/build/lib/siat/ml_cases.py +0 -2291
- build/lib/build/lib/siat/ml_cases_example.py +0 -60
- build/lib/build/lib/siat/option_china.py +0 -3069
- build/lib/build/lib/siat/option_pricing.py +0 -1925
- build/lib/build/lib/siat/other_indexes.py +0 -409
- build/lib/build/lib/siat/risk_adjusted_return.py +0 -1576
- build/lib/build/lib/siat/risk_adjusted_return2.py +0 -1900
- build/lib/build/lib/siat/risk_evaluation.py +0 -2218
- build/lib/build/lib/siat/risk_free_rate.py +0 -351
- build/lib/build/lib/siat/sector_china.py +0 -4140
- build/lib/build/lib/siat/security_price2.py +0 -727
- build/lib/build/lib/siat/security_prices.py +0 -3408
- build/lib/build/lib/siat/security_trend.py +0 -402
- build/lib/build/lib/siat/security_trend2.py +0 -646
- build/lib/build/lib/siat/stock.py +0 -4284
- build/lib/build/lib/siat/stock_advice_linear.py +0 -934
- build/lib/build/lib/siat/stock_base.py +0 -26
- build/lib/build/lib/siat/stock_china.py +0 -2095
- build/lib/build/lib/siat/stock_prices_kneighbors.py +0 -910
- build/lib/build/lib/siat/stock_prices_linear.py +0 -386
- build/lib/build/lib/siat/stock_profile.py +0 -707
- build/lib/build/lib/siat/stock_technical.py +0 -3305
- build/lib/build/lib/siat/stooq.py +0 -74
- build/lib/build/lib/siat/transaction.py +0 -347
- build/lib/build/lib/siat/translate.py +0 -5183
- build/lib/build/lib/siat/valuation.py +0 -1378
- build/lib/build/lib/siat/valuation_china.py +0 -2076
- build/lib/build/lib/siat/var_model_validation.py +0 -444
- build/lib/build/lib/siat/yf_name.py +0 -811
- build/lib/siat/__init__.py +0 -75
- build/lib/siat/allin.py +0 -137
- build/lib/siat/assets_liquidity.py +0 -915
- build/lib/siat/beta_adjustment.py +0 -1058
- build/lib/siat/beta_adjustment_china.py +0 -548
- build/lib/siat/blockchain.py +0 -143
- build/lib/siat/bond.py +0 -2900
- build/lib/siat/bond_base.py +0 -992
- build/lib/siat/bond_china.py +0 -100
- build/lib/siat/bond_zh_sina.py +0 -143
- build/lib/siat/capm_beta.py +0 -783
- build/lib/siat/capm_beta2.py +0 -887
- build/lib/siat/common.py +0 -5360
- build/lib/siat/compare_cross.py +0 -642
- build/lib/siat/copyrights.py +0 -18
- build/lib/siat/cryptocurrency.py +0 -667
- build/lib/siat/economy.py +0 -1471
- build/lib/siat/economy2.py +0 -1853
- build/lib/siat/esg.py +0 -536
- build/lib/siat/event_study.py +0 -815
- build/lib/siat/fama_french.py +0 -1521
- build/lib/siat/fin_stmt2_yahoo.py +0 -982
- build/lib/siat/financial_base.py +0 -1160
- build/lib/siat/financial_statements.py +0 -598
- build/lib/siat/financials.py +0 -2339
- build/lib/siat/financials2.py +0 -1278
- build/lib/siat/financials_china.py +0 -4433
- build/lib/siat/financials_china2.py +0 -2212
- build/lib/siat/fund.py +0 -629
- build/lib/siat/fund_china.py +0 -3307
- build/lib/siat/future_china.py +0 -551
- build/lib/siat/google_authenticator.py +0 -47
- build/lib/siat/grafix.py +0 -3636
- build/lib/siat/holding_risk.py +0 -867
- build/lib/siat/luchy_draw.py +0 -638
- build/lib/siat/market_china.py +0 -1168
- build/lib/siat/markowitz.py +0 -2363
- build/lib/siat/markowitz2.py +0 -3150
- build/lib/siat/markowitz2_20250704.py +0 -2969
- build/lib/siat/markowitz2_20250705.py +0 -3158
- build/lib/siat/markowitz_simple.py +0 -373
- build/lib/siat/ml_cases.py +0 -2291
- build/lib/siat/ml_cases_example.py +0 -60
- build/lib/siat/option_china.py +0 -3069
- build/lib/siat/option_pricing.py +0 -1925
- build/lib/siat/other_indexes.py +0 -409
- build/lib/siat/risk_adjusted_return.py +0 -1576
- build/lib/siat/risk_adjusted_return2.py +0 -1900
- build/lib/siat/risk_evaluation.py +0 -2218
- build/lib/siat/risk_free_rate.py +0 -351
- build/lib/siat/sector_china.py +0 -4140
- build/lib/siat/security_price2.py +0 -727
- build/lib/siat/security_prices.py +0 -3408
- build/lib/siat/security_trend.py +0 -402
- build/lib/siat/security_trend2.py +0 -646
- build/lib/siat/stock.py +0 -4284
- build/lib/siat/stock_advice_linear.py +0 -934
- build/lib/siat/stock_base.py +0 -26
- build/lib/siat/stock_china.py +0 -2095
- build/lib/siat/stock_prices_kneighbors.py +0 -910
- build/lib/siat/stock_prices_linear.py +0 -386
- build/lib/siat/stock_profile.py +0 -707
- build/lib/siat/stock_technical.py +0 -3305
- build/lib/siat/stooq.py +0 -74
- build/lib/siat/transaction.py +0 -347
- build/lib/siat/translate.py +0 -5183
- build/lib/siat/valuation.py +0 -1378
- build/lib/siat/valuation_china.py +0 -2076
- build/lib/siat/var_model_validation.py +0 -444
- build/lib/siat/yf_name.py +0 -811
- siat-3.10.132.dist-info/RECORD +0 -218
@@ -1,551 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
"""
|
3
|
-
本模块功能:中国大陆的内盘和外盘期货
|
4
|
-
所属工具包:证券投资分析工具SIAT
|
5
|
-
SIAT:Security Investment Analysis Tool
|
6
|
-
创建日期:2021年9月26日
|
7
|
-
最新修订日期:2021年9月28日
|
8
|
-
作者:王德宏 (WANG Dehong, Peter)
|
9
|
-
作者单位:北京外国语大学国际商学院
|
10
|
-
版权所有:王德宏
|
11
|
-
用途限制:仅限研究与教学使用,不可商用!商用需要额外授权。
|
12
|
-
特别声明:作者不对使用本工具进行证券投资导致的任何损益负责!
|
13
|
-
"""
|
14
|
-
|
15
|
-
#==============================================================================
|
16
|
-
#关闭所有警告
|
17
|
-
import warnings; warnings.filterwarnings('ignore')
|
18
|
-
from siat.common import *
|
19
|
-
from siat.grafix import *
|
20
|
-
#==========================================================================================
|
21
|
-
if __name__=='__main__':
|
22
|
-
trade_date='2023-5-18'
|
23
|
-
|
24
|
-
def future_type_china_0(trade_date):
|
25
|
-
"""
|
26
|
-
中国内盘期货:代码和品种的基础数据
|
27
|
-
"""
|
28
|
-
#日期变换
|
29
|
-
trade_date1=convert_date_ts(trade_date)
|
30
|
-
|
31
|
-
import akshare as ak
|
32
|
-
df=ak.futures_rule(date=trade_date1)
|
33
|
-
|
34
|
-
try:
|
35
|
-
cols = df.columns.tolist()
|
36
|
-
except:
|
37
|
-
return None
|
38
|
-
cols1 = cols[2:3] + cols[1:2] + cols[0:1] + cols[3:] # 将基金代码列名放前面
|
39
|
-
|
40
|
-
#改变字段顺序
|
41
|
-
df1=df[cols1]
|
42
|
-
|
43
|
-
#去掉期权项目
|
44
|
-
df2=df1[~df1['品种'].str.contains("期权")]
|
45
|
-
df2.sort_values(by=['代码'],ascending=True,inplace=True)
|
46
|
-
df2.reset_index(inplace=True)
|
47
|
-
del df2['index']
|
48
|
-
|
49
|
-
return df2
|
50
|
-
|
51
|
-
#======================================================================================
|
52
|
-
def SBC2DBC(ustring):
|
53
|
-
"""
|
54
|
-
字符串转换:半角转全角,便于打印对齐
|
55
|
-
"""
|
56
|
-
rstring = ''
|
57
|
-
for uchar in ustring:
|
58
|
-
inside_code = ord(uchar)
|
59
|
-
if inside_code == 0x0020:
|
60
|
-
inside_code = 0x3000
|
61
|
-
else:
|
62
|
-
if not (0x0021 <= inside_code and inside_code <= 0x7e):
|
63
|
-
rstring += uchar
|
64
|
-
continue
|
65
|
-
inside_code += 0xfee0
|
66
|
-
rstring += chr(inside_code)
|
67
|
-
return rstring
|
68
|
-
#======================================================================================
|
69
|
-
if __name__=='__main__':
|
70
|
-
trade_date='2020-7-13'
|
71
|
-
df=future_type_china_0(trade_date)
|
72
|
-
|
73
|
-
def future_type_china_1(df):
|
74
|
-
"""
|
75
|
-
列示中国内盘期货的全部代码和品种,每4个一行
|
76
|
-
"""
|
77
|
-
print("\n===== 中国内盘期货代码品种一览表 =====\n")
|
78
|
-
#遍历,合成一行
|
79
|
-
itemlist=[]
|
80
|
-
for row in df.itertuples():
|
81
|
-
code=SBC2DBC(getattr(row,'代码'))
|
82
|
-
name=SBC2DBC(getattr(row,'品种'))
|
83
|
-
itemlist=itemlist+[code+'('+name+')']
|
84
|
-
|
85
|
-
maxlen=0
|
86
|
-
for i in itemlist:
|
87
|
-
ilen=len(i)
|
88
|
-
if maxlen < ilen: maxlen=ilen
|
89
|
-
maxlen=maxlen+1
|
90
|
-
|
91
|
-
rownum=0
|
92
|
-
linetxt=''
|
93
|
-
iteminline=3
|
94
|
-
for i in itemlist:
|
95
|
-
if rownum < iteminline:
|
96
|
-
ifull=i+SBC2DBC('.')*(maxlen-len(i))
|
97
|
-
linetxt=linetxt+ifull
|
98
|
-
rownum=rownum+1
|
99
|
-
else:
|
100
|
-
print(linetxt)
|
101
|
-
rownum=0; linetxt=''
|
102
|
-
|
103
|
-
import datetime
|
104
|
-
today = datetime.date.today()
|
105
|
-
print('\n*** 数据来源:国泰君安,',today)
|
106
|
-
|
107
|
-
return
|
108
|
-
|
109
|
-
if __name__=='__main__':
|
110
|
-
future_type_china_1(df)
|
111
|
-
#======================================================================================
|
112
|
-
if __name__=='__main__':
|
113
|
-
code='BB2007'
|
114
|
-
df=future_type_china_0(trade_date)
|
115
|
-
|
116
|
-
def get_future_symbol(code):
|
117
|
-
"""
|
118
|
-
获得一个具体期货合约的品种代码
|
119
|
-
"""
|
120
|
-
code1=code.upper()
|
121
|
-
|
122
|
-
letterlist=[chr(i).upper() for i in range(97,123)]
|
123
|
-
symbol=''
|
124
|
-
|
125
|
-
for ch in code1:
|
126
|
-
if ch in letterlist:
|
127
|
-
symbol=symbol+ch
|
128
|
-
else:
|
129
|
-
break
|
130
|
-
|
131
|
-
return symbol
|
132
|
-
#======================================================================================
|
133
|
-
|
134
|
-
def future_type_china_2(df,code):
|
135
|
-
"""
|
136
|
-
列示中国内盘期货的品种明细
|
137
|
-
"""
|
138
|
-
symbol=get_future_symbol(code)
|
139
|
-
|
140
|
-
df1=df[df['代码']==symbol]
|
141
|
-
cols=list(df1)
|
142
|
-
cols.pop()
|
143
|
-
|
144
|
-
print("\n===== 中国内盘期货品种概况 =====\n")
|
145
|
-
maxlen=0
|
146
|
-
for c in cols:
|
147
|
-
clen=hzlen(c)
|
148
|
-
if maxlen < clen: maxlen=clen
|
149
|
-
|
150
|
-
contract='合约'
|
151
|
-
print(contract+' '*(maxlen-hzlen(contract))+':',code)
|
152
|
-
import numpy as np
|
153
|
-
for c in cols:
|
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
|
159
|
-
|
160
|
-
import datetime
|
161
|
-
today = datetime.date.today()
|
162
|
-
print('\n数据来源:国泰君安,',today)
|
163
|
-
|
164
|
-
return
|
165
|
-
|
166
|
-
if __name__=='__main__':
|
167
|
-
future_type_china_2(df,'BB2007')
|
168
|
-
|
169
|
-
#======================================================================================
|
170
|
-
if __name__=='__main__':
|
171
|
-
tradedate=''
|
172
|
-
tradedate='2025-6-12'
|
173
|
-
|
174
|
-
future_type_china(tradedate)
|
175
|
-
|
176
|
-
def future_type_china(tradedate=''):
|
177
|
-
"""
|
178
|
-
功能:中国内盘期货的常见品种,含合约品种明细
|
179
|
-
"""
|
180
|
-
|
181
|
-
# 检查交易日期
|
182
|
-
import datetime
|
183
|
-
import calendar
|
184
|
-
if tradedate=='':
|
185
|
-
tradedate = datetime.date.today()
|
186
|
-
|
187
|
-
result,fdate=check_date2(tradedate)
|
188
|
-
year=fdate[:4]; month=fdate[5:7]; day=fdate[8:10]
|
189
|
-
date_week = calendar.weekday(int(year),int(month),int(day))
|
190
|
-
weekday=calendar.day_name[date_week]
|
191
|
-
|
192
|
-
if weekday in ['Saturday','Sunday']:
|
193
|
-
print(" #Warning(future_type_china):",tradedate,"is not a working day")
|
194
|
-
print(" Solution: specify a working date of market using tradedate option")
|
195
|
-
return None
|
196
|
-
else:
|
197
|
-
today=year+month+day
|
198
|
-
|
199
|
-
df=future_type_china_0(today)
|
200
|
-
while df is None:
|
201
|
-
today=date_adjust(today, adjust=-1)
|
202
|
-
df=future_type_china_0(today)
|
203
|
-
|
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
|
212
|
-
|
213
|
-
|
214
|
-
#======================================================================================
|
215
|
-
if __name__=='__main__':
|
216
|
-
code='PG'
|
217
|
-
start='2025-5-1'
|
218
|
-
end='2025-5-30'
|
219
|
-
power=1
|
220
|
-
|
221
|
-
def future_price_china(code,start='MRM',end='today', \
|
222
|
-
power=0,loc1='upper left',loc2='upper right'):
|
223
|
-
"""
|
224
|
-
综合程序:
|
225
|
-
绘制内盘期货交易曲线:收盘价vs结算价vs成交量
|
226
|
-
"""
|
227
|
-
start,end=start_end_preprocess(start,end)
|
228
|
-
|
229
|
-
print("Searching for contract "+code+", it may take time ...")
|
230
|
-
#日期变换
|
231
|
-
start1=convert_date_ts(start)
|
232
|
-
end1=convert_date_ts(end)
|
233
|
-
|
234
|
-
#获得中国内盘期货品种代码
|
235
|
-
try:
|
236
|
-
varietydf=future_type_china_0(end1)
|
237
|
-
except:
|
238
|
-
print(" #Error(future_price_china): no info for the end date", end, "\b, try an earlier date")
|
239
|
-
return None
|
240
|
-
|
241
|
-
#获得期货合约code的品种代码
|
242
|
-
variety=get_future_symbol(code)
|
243
|
-
#variety=get_future_symbol(code).lower()
|
244
|
-
|
245
|
-
try:
|
246
|
-
vdf=varietydf[varietydf['代码']==variety]
|
247
|
-
except:
|
248
|
-
print(" #Error(future_price_china): the end date", end, "shall not be later than today")
|
249
|
-
return None
|
250
|
-
|
251
|
-
if len(vdf)==0:
|
252
|
-
print(" #Error(future_price_china): future variety",variety,'not found')
|
253
|
-
return None
|
254
|
-
varietyname=vdf['品种'].values[0]
|
255
|
-
|
256
|
-
#查找交易所代码
|
257
|
-
mktname=vdf['交易所'].values[0]
|
258
|
-
mktnamelist=['大商所','郑商所','上期所','中金所','能源中心']
|
259
|
-
mktnamelistfull=['大连商品交易所','郑州商品交易所','上海期货交易所','中国金融期货交易所','上海国际能源交易中心']
|
260
|
-
mktcodelist=['DCE','CZCE','SHFE','CFFEX','INE']
|
261
|
-
pos=mktnamelist.index(mktname)
|
262
|
-
market=mktcodelist[pos]
|
263
|
-
mktnamefull=mktnamelistfull[pos]
|
264
|
-
|
265
|
-
import akshare as ak
|
266
|
-
try:
|
267
|
-
p=ak.get_futures_daily(start_date=start1,end_date=end1,market=market)
|
268
|
-
except:
|
269
|
-
print(" #Warning(future_price_china): data source has no response at the moment for",code)
|
270
|
-
print(" Solution: make date period shorter (e.g. within same month), and try again")
|
271
|
-
return None
|
272
|
-
|
273
|
-
if p is None:
|
274
|
-
print(" #Error(future_price_china): future transaction info not found from", start, "to",end,"in market",market)
|
275
|
-
print(" Try earlier start date")
|
276
|
-
return None
|
277
|
-
|
278
|
-
p1=p[p['symbol']==code.lower()]
|
279
|
-
if len(p1)==0:
|
280
|
-
print(" #Warning(future_price_china): future contract",code,'not found in market',market)
|
281
|
-
contracts=set(list(p[p['variety']==variety]['symbol']))
|
282
|
-
contracts1=sorted(contracts)
|
283
|
-
print("\n提示:当前可用的"+varietyname+variety+'期货合约:'+mktnamefull+', '+str(end))
|
284
|
-
#print(contracts1)
|
285
|
-
printlist(contracts1,numperline=10,beforehand='',separator=' ')
|
286
|
-
return None
|
287
|
-
|
288
|
-
#转换日期格式
|
289
|
-
import pandas as pd
|
290
|
-
p1['date1']=pd.to_datetime(p1['date'])
|
291
|
-
p2=p1.set_index('date1')
|
292
|
-
|
293
|
-
import pandas as pd
|
294
|
-
p2a=pd.DataFrame(p2['close']) #收盘价
|
295
|
-
p2a['close']=p2a['close'].astype('float')
|
296
|
-
|
297
|
-
p2b=pd.DataFrame(p2['settle']) #结算价
|
298
|
-
p2b['settle']=p2b['settle'].astype('float')
|
299
|
-
|
300
|
-
p2c=pd.DataFrame(p2['volume']) #成交量
|
301
|
-
p2c['volume']=p2c['volume'].astype('int64')
|
302
|
-
|
303
|
-
p2d=pd.DataFrame(p2['turnover']) #成交金额
|
304
|
-
p2d['turnover']=p2d['turnover'].astype('int64')
|
305
|
-
|
306
|
-
p2e=pd.DataFrame(p2['open_interest']) #持仓量
|
307
|
-
p2e['open_interest']=p2e['open_interest'].astype('int64')
|
308
|
-
|
309
|
-
#绘图
|
310
|
-
import datetime
|
311
|
-
today = datetime.date.today()
|
312
|
-
footnote="数据来源:"+mktnamefull+', '+str(today)
|
313
|
-
|
314
|
-
print(" Rendering trading trend graphics ...")
|
315
|
-
titletxt="中国内盘期货交易走势分析:"+varietyname+code
|
316
|
-
#避免code被翻译
|
317
|
-
acode=' '+code
|
318
|
-
#"""
|
319
|
-
#收盘价vs结算价
|
320
|
-
plot_line2(p2a,acode,"close","收盘价", \
|
321
|
-
p2b,acode,"settle","结算价", \
|
322
|
-
'价格',titletxt,footnote, \
|
323
|
-
power=power,twinx=False,loc1=loc1,loc2=loc2)
|
324
|
-
#"""
|
325
|
-
#收盘价vs成交量
|
326
|
-
plot_line2(p2a,acode,"close","收盘价", \
|
327
|
-
p2c,acode,"volume","成交量", \
|
328
|
-
'',titletxt,footnote, \
|
329
|
-
power=power,twinx=True,loc1=loc1,loc2=loc2)
|
330
|
-
#"""
|
331
|
-
#收盘价vs持仓量
|
332
|
-
plot_line2(p2a,acode,"close","收盘价", \
|
333
|
-
p2e,acode,"open_interest","持仓量", \
|
334
|
-
'',titletxt,footnote, \
|
335
|
-
power=power,twinx=True,loc1=loc1,loc2=loc2)
|
336
|
-
#"""
|
337
|
-
return p2
|
338
|
-
|
339
|
-
if __name__=='__main__':
|
340
|
-
code='SC2110'
|
341
|
-
df=future_type_china(code)
|
342
|
-
|
343
|
-
#===========================================================================================
|
344
|
-
if __name__=='__main__':
|
345
|
-
symbol="ZSD"
|
346
|
-
|
347
|
-
def future_type_foreign_0(symbol="ZSD"):
|
348
|
-
"""
|
349
|
-
获得某个外盘期货品种symbol详情
|
350
|
-
"""
|
351
|
-
import akshare as ak
|
352
|
-
try:
|
353
|
-
df=ak.futures_foreign_detail(symbol=symbol)
|
354
|
-
except:
|
355
|
-
print(" #Error(future_type_foreign_0): future variety",symbol,'not found')
|
356
|
-
return None
|
357
|
-
|
358
|
-
#构造df
|
359
|
-
col1=df.iloc[0,0]; col1value=df.iloc[0,1]
|
360
|
-
if "并非期货" in col1value:
|
361
|
-
col1value=col1value.replace("并非期货",'')
|
362
|
-
|
363
|
-
col2=df.iloc[0,2]; col2value=df.iloc[0,3]
|
364
|
-
col3=df.iloc[0,4]; col3value=df.iloc[0,5]
|
365
|
-
|
366
|
-
col4=df.iloc[1,0]; col4value=df.iloc[1,1]
|
367
|
-
col5=df.iloc[1,2]; col5value=df.iloc[1,3]
|
368
|
-
col6=df.iloc[1,4]; col6value=df.iloc[1,5]
|
369
|
-
|
370
|
-
col7=df.iloc[2,0]; col7value=df.iloc[2,1]
|
371
|
-
col8=df.iloc[2,2]; col8value=df.iloc[2,3]
|
372
|
-
|
373
|
-
col9=df.iloc[3,0]; col9value=df.iloc[3,1]
|
374
|
-
col10=df.iloc[3,2]; col10value=df.iloc[3,3]
|
375
|
-
|
376
|
-
future_dict={col9:col9value,col1:col1value,col10:col10value,col2:col2value, \
|
377
|
-
col3:col3value,col4:col4value,col5:col5value,col6:col6value, \
|
378
|
-
col7:col7value,col8:col8value}
|
379
|
-
import pandas as pd
|
380
|
-
df1=pd.DataFrame(future_dict,index=[0])
|
381
|
-
|
382
|
-
return df1
|
383
|
-
|
384
|
-
if __name__=='__main__':
|
385
|
-
df=future_type_foreign_0(symbol="ZSD")
|
386
|
-
print(df.T)
|
387
|
-
#===========================================================================================
|
388
|
-
if __name__=='__main__':
|
389
|
-
symbol="ZSD"
|
390
|
-
|
391
|
-
def future_type_foreign_1():
|
392
|
-
"""
|
393
|
-
获得中国所有外盘期货品种详情
|
394
|
-
"""
|
395
|
-
import akshare as ak
|
396
|
-
varietylist=ak.futures_foreign_commodity_subscribe_exchange_symbol()
|
397
|
-
varietylist.sort()
|
398
|
-
|
399
|
-
try:
|
400
|
-
df=future_type_foreign_0(symbol=varietylist[0])
|
401
|
-
except:
|
402
|
-
pass
|
403
|
-
for v in varietylist:
|
404
|
-
try:
|
405
|
-
df_tmp=future_type_foreign_0(symbol=v)
|
406
|
-
#print(v)
|
407
|
-
try:
|
408
|
-
df=df.append(df_tmp)
|
409
|
-
except:
|
410
|
-
df=df._append(df_tmp)
|
411
|
-
except:
|
412
|
-
pass
|
413
|
-
df.drop_duplicates(inplace=True)
|
414
|
-
|
415
|
-
return df
|
416
|
-
|
417
|
-
#===========================================================================================
|
418
|
-
if __name__=='__main__':
|
419
|
-
symbol="ZSD"
|
420
|
-
df=future_type_foreign_1()
|
421
|
-
|
422
|
-
def future_type_foreign_2(df,symbol="ZSD"):
|
423
|
-
"""
|
424
|
-
打印中国外盘期货某个品种详情
|
425
|
-
"""
|
426
|
-
|
427
|
-
df1=df[df['交易代码']==symbol]
|
428
|
-
cols=list(df1)
|
429
|
-
|
430
|
-
print("\n===== 中国外盘期货品种概况 =====\n")
|
431
|
-
maxlen=0
|
432
|
-
for c in cols:
|
433
|
-
clen=hzlen(c)
|
434
|
-
if maxlen < clen: maxlen=clen
|
435
|
-
|
436
|
-
for c in cols:
|
437
|
-
print(c+' '*(maxlen-hzlen(c))+':',df1[c].values[0])
|
438
|
-
|
439
|
-
import datetime
|
440
|
-
today = datetime.date.today()
|
441
|
-
print('\n*** 数据来源:新浪财经,',today)
|
442
|
-
|
443
|
-
return
|
444
|
-
|
445
|
-
if __name__=='__main__':
|
446
|
-
future_type_foreign_2(df,symbol="ZSD")
|
447
|
-
|
448
|
-
#======================================================================================
|
449
|
-
if __name__=='__main__':
|
450
|
-
|
451
|
-
future_type_foreign()
|
452
|
-
|
453
|
-
def future_type_foreign():
|
454
|
-
"""
|
455
|
-
功能:中国外盘期货的常见品种,含合约明细
|
456
|
-
"""
|
457
|
-
|
458
|
-
df=future_type_foreign_1()
|
459
|
-
#cols=['交易代码','交易品种','上市交易所','交易单位','报价单位','合约交割月份']
|
460
|
-
cols=['交易代码','交易品种','上市交易所','交易单位','报价单位']
|
461
|
-
df1=df[cols]
|
462
|
-
df1.reset_index(drop=True,inplace=True)
|
463
|
-
|
464
|
-
titletxt="中国外盘期货常见品种"
|
465
|
-
import datetime
|
466
|
-
todaydt = datetime.date.today()
|
467
|
-
footnote="数据来源:新浪财经, "+str(todaydt)
|
468
|
-
|
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')
|
473
|
-
|
474
|
-
return df1
|
475
|
-
|
476
|
-
if __name__=='__main__':
|
477
|
-
df=future_type_foreign(code='')
|
478
|
-
df=future_type_foreign(code='CT')
|
479
|
-
df=future_type_foreign(code='OIL')
|
480
|
-
|
481
|
-
#======================================================================================
|
482
|
-
if __name__=='__main__':
|
483
|
-
code='ZSD'
|
484
|
-
start='2021-8-1'
|
485
|
-
end='2021-9-27'
|
486
|
-
power=0
|
487
|
-
|
488
|
-
def future_price_foreign(code,start='MRM',end='today', \
|
489
|
-
power=0,loc1='upper left',loc2='upper right'):
|
490
|
-
"""
|
491
|
-
综合程序:
|
492
|
-
绘制中国外盘期货的交易趋势:收盘价vs成交量
|
493
|
-
"""
|
494
|
-
start,end=start_end_preprocess(start,end)
|
495
|
-
|
496
|
-
print("Searching for contract "+code+", it costs great time, just take a break...")
|
497
|
-
#日期变换
|
498
|
-
flag,start1,end1=check_period(start,end)
|
499
|
-
|
500
|
-
#获得中国外盘期货品种代码
|
501
|
-
varietydf=future_type_foreign_0(symbol=code)
|
502
|
-
#获得期货合约code的品种代码
|
503
|
-
if len(varietydf)==0:
|
504
|
-
print(" #Error(future_price_foreign): future variety",code,'not found')
|
505
|
-
return None
|
506
|
-
varietyname=varietydf['交易品种'].values[0]
|
507
|
-
|
508
|
-
#查找交易所代码
|
509
|
-
mktnamefull=varietydf['上市交易所'].values[0]
|
510
|
-
|
511
|
-
import akshare as ak
|
512
|
-
p0=ak.futures_foreign_hist(symbol=code)
|
513
|
-
p01=p0[p0['date']>=start1]
|
514
|
-
p1=p01[p01['date']<=end1]
|
515
|
-
|
516
|
-
if len(p1)==0:
|
517
|
-
print(" #Error(future_price_foreign): prices not found for",code,'from',start,'to',end)
|
518
|
-
return None
|
519
|
-
|
520
|
-
#转换日期格式
|
521
|
-
p2=p1.set_index('date')
|
522
|
-
|
523
|
-
import pandas as pd
|
524
|
-
p2a=pd.DataFrame(p2['close']) #收盘价
|
525
|
-
p2a['close']=p2a['close'].astype('float')
|
526
|
-
|
527
|
-
p2c=pd.DataFrame(p2['volume']) #成交量
|
528
|
-
p2c['volume']=p2c['volume'].astype('int64')
|
529
|
-
|
530
|
-
#绘图
|
531
|
-
import datetime
|
532
|
-
today = datetime.date.today()
|
533
|
-
footnote="数据来源:新浪财经"+', '+str(today)
|
534
|
-
|
535
|
-
titletxt="中国外盘期货交易走势分析:"+varietyname+code
|
536
|
-
|
537
|
-
#收盘价vs成交量
|
538
|
-
#print("code =",code)
|
539
|
-
#避免code被翻译
|
540
|
-
acode=' '+code
|
541
|
-
plot_line2(p2a,acode,"close","收盘价", \
|
542
|
-
p2c,acode,"volume","成交量", \
|
543
|
-
'',titletxt,footnote, \
|
544
|
-
power=power,twinx=True,loc1=loc1,loc2=loc2)
|
545
|
-
|
546
|
-
return p2
|
547
|
-
|
548
|
-
if __name__=='__main__':
|
549
|
-
df=future_price_foreign('CT','2021-8-1','2021-9-28')
|
550
|
-
|
551
|
-
#===========================================================================================
|
@@ -1,47 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
"""
|
3
|
-
本模块功能:模拟谷歌验证器,Google Authenticator
|
4
|
-
基于电脑时间,以密钥为基准,生成6位数字动态口令
|
5
|
-
"""
|
6
|
-
|
7
|
-
import hmac, base64, struct, hashlib, time
|
8
|
-
|
9
|
-
class CalGoogleCode():
|
10
|
-
"""计算谷歌验证码(秘钥,生成6位验证码)"""
|
11
|
-
|
12
|
-
# 使用静态方法,调用这个方法时,不必对类进行实例化
|
13
|
-
@staticmethod
|
14
|
-
def cal_google_code(secret, current_time=int(time.time()) // 30):
|
15
|
-
"""
|
16
|
-
:param secret: 16位谷歌秘钥
|
17
|
-
:param current_time: 时间(谷歌验证码是30s更新一次)
|
18
|
-
:return: 返回6位谷歌验证码
|
19
|
-
"""
|
20
|
-
key = base64.b32decode(secret)
|
21
|
-
msg = struct.pack(">Q", current_time)
|
22
|
-
google_code = hmac.new(key, msg, hashlib.sha1).digest()
|
23
|
-
o = ord(chr(google_code[19])) & 15 # python3时,ord的参数必须为chr类型
|
24
|
-
google_code = (struct.unpack(">I", google_code[o:o + 4])[0] & 0x7fffffff) % 1000000
|
25
|
-
|
26
|
-
return '%06d' % google_code # 不足6位时,在前面补0
|
27
|
-
|
28
|
-
def signin_binance():
|
29
|
-
secret_key = "HLAT4FZ6IDW53AYD"
|
30
|
-
print(CalGoogleCode.cal_google_code(secret_key))
|
31
|
-
|
32
|
-
return
|
33
|
-
|
34
|
-
def signin_pypi():
|
35
|
-
secret_key = "CYKOJC2LMKOKPD6VGI7CAHDWBP2AVB23"
|
36
|
-
print(CalGoogleCode.cal_google_code(secret_key))
|
37
|
-
|
38
|
-
return
|
39
|
-
|
40
|
-
if __name__ == '__main__':
|
41
|
-
# For Binance
|
42
|
-
secret_key = "HLAT4FZ6IDW53AYD"
|
43
|
-
print(CalGoogleCode.cal_google_code(secret_key))
|
44
|
-
|
45
|
-
# for PyPi
|
46
|
-
secret_key = "CYKOJC2LMKOKPD6VGI7CAHDWBP2AVB23"
|
47
|
-
print(CalGoogleCode.cal_google_code(secret_key))
|