-
Notifications
You must be signed in to change notification settings - Fork 440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update of xueqiu API paramters #186
base: master
Are you sure you want to change the base?
Changes from all commits
2377cc9
eb4137f
824def5
ae4b70a
077005a
c5ccaea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import logging | ||
import pandas as pd | ||
from pyecharts import options as opts | ||
from pyecharts.charts import Pie, ThemeRiver | ||
|
||
from xalpha.cons import convert_date, myround, yesterdaydash, yesterdayobj | ||
from xalpha.evaluate import evaluate | ||
from xalpha.exceptions import FundTypeError, TradeBehaviorError | ||
from xalpha.record import record, irecord | ||
from xalpha.indicator import indicator | ||
from xalpha.info import cashinfo, fundinfo, mfundinfo, get_fund_holdings | ||
from xalpha.trade import ( | ||
bottleneck, | ||
trade, | ||
turnoverrate, | ||
vtradevolume, | ||
xirrcal, | ||
itrade, | ||
vtradecost, | ||
) | ||
from xalpha.multiple import mul,mulfix | ||
from xalpha.universal import get_fund_type, ttjjcode, get_rt, get_industry_fromxq | ||
import xalpha.universal as xu | ||
|
||
#status = pd.DataFrame([ | ||
# ['2019-12-31',-0.04], | ||
# ['2020-06-09',2738.22], | ||
# ['2020-08-05',3668.81], | ||
# ['2020-08-10',793.97], | ||
# ['2020-12-31',83.93], | ||
# ['2021-12-16',1271.55], | ||
# ['2021-12-31',111.29] | ||
#],columns=['date','mf']) | ||
#status["date"] = pd.to_datetime(status['date']) | ||
#cashobj = cashinfo(start='2019-04-24') | ||
#trade(cashobj,status) | ||
|
||
status = pd.DataFrame([ | ||
['2012-02-17',100000.0], | ||
['2012-03-15',-0.005], | ||
['2012-03-27',103902.230], | ||
['2012-03-29',-0.005], | ||
],columns=['date','159915']) | ||
status["date"] = pd.to_datetime(status['date']) | ||
infoobj = fundinfo('F159915') | ||
trade(infoobj,status) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,15 +218,14 @@ def max_drawdown(self, date=yesterdayobj()): | |
:returns: three elements tuple, the first two are the date obj of | ||
start and end of the time window, the third one is the drawdown amplitude in unit 1. | ||
""" | ||
li = [ | ||
(row["date"], row["netvalue"]) | ||
for i, row in self.price[self.price["date"] <= date].iterrows() | ||
] | ||
res = [] | ||
for i, _ in enumerate(li): | ||
for j in range(i + 1, len(li)): | ||
res.append((li[i][0], li[j][0], (li[j][1] - li[i][1]) / li[i][1])) | ||
return min(res, key=lambda x: x[2]) | ||
tmpprice = self.price.loc[:,:] | ||
tmpprice.loc[:,'drawdown'] = (tmpprice['netvalue']-tmpprice['netvalue'].expanding(1).max())/tmpprice['netvalue'].expanding(1).max() | ||
tmpprice = tmpprice.loc[tmpprice['date']<=date,:] | ||
iid = tmpprice.loc[:,'drawdown'].argmin() | ||
lastrow = tmpprice.iloc[iid] | ||
newhigh = tmpprice.loc[tmpprice.loc[:,'drawdown']>=-0.0001,:] | ||
beginrow = newhigh.loc[newhigh['date']<=lastrow['date'],:].iloc[-1] | ||
return beginrow['date'],lastrow['date'],lastrow['drawdown'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个计算的是单日回撤而不是一个时间段的最大回撤?drawdown 列的定义是 L222,计算的是相较前一日的回撤百分比或0(当日新高)。那返回的某一列的 drawdown 值似乎对应了单日回撤? |
||
|
||
## 以上基本为聚宽提供的整体量化指标,以下是其他短线技术面指标 | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -935,11 +935,16 @@ def update(self): | |
if self.code.startswith("96"): | ||
return self._hk_update() | ||
lastdate = self.price.iloc[-1].date | ||
diffdays = (yesterdayobj() - lastdate).days | ||
if ( | ||
diffdays == 0 | ||
): ## for some QDII, this value is 1, anyways, trying update is compatible (d+2 update) | ||
return None | ||
if dt.datetime.today().time()>=dt.time(20,00): | ||
# if over 20:00, update today's netvalue | ||
# diffdays = (today_obj() - lastdate).days | ||
diffdays = 0 | ||
else: | ||
diffdays = (yesterdayobj() - lastdate).days | ||
if ( | ||
diffdays == 0 | ||
): ## for some QDII, this value is 1, anyways, trying update is compatible (d+2 update) | ||
return None | ||
self._updateurl = ( | ||
"http://fund.eastmoney.com/f10/F10DataApi.aspx?type=lsjz&code=" | ||
+ self.code | ||
|
@@ -1004,7 +1009,8 @@ def update(self): | |
df = df.iloc[::-1] ## reverse the time order | ||
df = df[df["date"].isin(opendate)] | ||
df = df.reset_index(drop=True) | ||
df = df[df["date"] <= yesterdayobj()] | ||
#df = df[df["date"] <= yesterdayobj()] | ||
df = df[df["date"] <= today_obj()] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. info 文件里的改动我建议在 PR 里去掉,因为为了开发方便,依赖于”数据只更新到昨天”逻辑的地方非常多,不确定只单独将这一个地方改到可以更新当日数据会不会出其他潜在 issue |
||
if len(df) != 0: | ||
self.price = self.price.append(df, ignore_index=True, sort=True) | ||
return df | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,7 +142,7 @@ def get_token(): | |
:return: | ||
""" | ||
r = rget("https://xueqiu.com", headers={"user-agent": "Mozilla"}) | ||
return r.cookies["xq_a_token"] | ||
return r.cookies["xq_a_token"],r.cookies["u"] | ||
|
||
|
||
def get_historical_fromxq(code, count, type_="before", full=False): | ||
|
@@ -162,7 +162,7 @@ def get_historical_fromxq(code, count, type_="before", full=False): | |
url.format( | ||
code=code, tomorrow=int(tomorrow_ts() * 1000), count=count, type_=type_ | ||
), | ||
cookies={"xq_a_token": get_token()}, | ||
cookies={"xq_a_token": get_token()[0],"u":get_token()[1]}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 该文件中还涉及雪球实时数据和 bar 数据函数的爬取,是否也应该更新 cookies 添加 “u” |
||
headers={"user-agent": "Mozilla/5.0"}, | ||
) | ||
df = pd.DataFrame(data=r["data"]["item"], columns=r["data"]["column"]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
请在 pr 中删除该 debug 文件