Skip to content

Commit

Permalink
finish joinquant stock valuation recorder
Browse files Browse the repository at this point in the history
  • Loading branch information
foolcage committed Dec 31, 2019
1 parent e90ee4d commit 482bcb7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion init_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if ! which python > /dev/null; then
fi

pip_opt=''
#pip_opt='-i http://pypi.douban.com/simple --trusted-host pypi.douban.com'
pip_opt='-i http://pypi.douban.com/simple --trusted-host pypi.douban.com'

if ! which virtualenv > /dev/null; then
echo -e "virtualenv not found! Install? (y/n) \c"
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tzlocal == 1.5.1
xlrd == 1.1.0
apscheduler == 3.4.0
# TA-Lib
jqdatasdk
jqdatasdk == 1.7.8
demjson == 2.2.4
marshmallow-sqlalchemy == 0.19.0
marshmallow == 3.2.2
Expand Down
5 changes: 4 additions & 1 deletion zvt/domain/valuation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ class Valuation(ValuationBase, Mixin):

code = Column(String(length=32))
name = Column(String(length=32))

# 总股本(股)
capitalization = Column(Float)
# 公司已发行的普通股股份总数(包含A股,B股和H股的总股本)
circulating_cap = Column(Float)
# 市值
market_cap = Column(Float)
# 流通市值
Expand Down
23 changes: 18 additions & 5 deletions zvt/recorders/joinquant/fundamental/stock_valuation_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,24 @@ def record(self, entity, start, end, size, timestamps):
valuation.code == to_jq_entity_id(entity)
)
count: pd.Timedelta = now_pd_timestamp() - start
panel = get_fundamentals_continuously(q, end_date=now_time_str(), count=count.days + 1)
if not panel.empty:
print(panel)
df = panel.to_frame()
df_to_db(df=df, data_schema=self.data_schema, provider=self.provider, force_update=self.force_update)
df = get_fundamentals_continuously(q, end_date=now_time_str(), count=count.days + 1, panel=False)
df['entity_id'] = entity.id
df['timestamp'] = pd.to_datetime(df['day'])
df['code'] = entity.code
df['name'] = entity.name
df['id'] = df[['timestamp']].apply(lambda x: "{}_{}".format(entity.id, x), axis=1)
df = df.rename({'pe_ratio_lyr': 'pe',
'pe_ratio': 'pe_ttm',
'pb_ratio': 'pb',
'ps_ratio': 'ps',
'pcf_ratio': 'pcf'},
axis='columns')

df['market_cap'] = df['market_cap'] * 100000000
df['circulating_cap'] = df['circulating_cap'] * 100000000
df['capitalization'] = df['capitalization'] * 10000
df['circulating_cap'] = df['circulating_cap'] * 10000
df_to_db(df=df, data_schema=self.data_schema, provider=self.provider, force_update=self.force_update)

return None

Expand Down

0 comments on commit 482bcb7

Please sign in to comment.