1 Star 0 Fork 0

jx0913/stock

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
pledged_validation.py 1.99 KB
一键复制 编辑 原始数据 按行查看 历史
Rockyzsu 提交于 2019-08-18 00:02 . 更新readme
#-*-coding=utf-8-*-
import json
import tushare as ts
import pandas as pd
from setting import get_engine
import matplotlib.pyplot as plt
# 股权质押数据整理
with open('codes.txt','r') as f:
# s= f.read()
codes=json.load(f)
stocks=codes.get('example1')
engine=get_engine('db_stock')
# for key in codes.get('example1').keys():
# print(key, codes.get('example1').get(key))
# df1=pd.DataFrame()
def pledge_info():
df=ts.stock_pledged()
df.to_sql('tb_pledged_base',engine,if_exists='replace')
df_list=[]
for stock in stocks:
df_list.append(df[df['code']==stock])
df=pd.concat(df_list)
# print(df)
df=df.reset_index(drop=True)
# print(df)
df= df.sort_values('p_ratio',ascending=False)
df['code']=df['code'].astype('str')
df['rest_ratio']=df['rest_pledged']/df['totals']*100
df['rest_ratio']=map(lambda x:round(x,2),df['rest_ratio'])
df['unrest_ratio']=df['unrest_pledged']/df['totals']*100
df['unrest_ratio']=map(lambda x:round(x,2),df['unrest_ratio'])
# print(df.info())
# print(df)
# print(df.sort_values('deals',ascending=False))
# df.to_csv('pledge_my_stock.csv')
def pledged_detail():
df=ts.pledged_detail()
print(df.tail(10))
# for stock in stocks:
# if len(df[df['code']==stock])!=0:
# print(df[df['code']==stock])
# df.to_csv('pledge_all_stock.csv')
df.to_sql('tb_pledged_detail',engine)
def do_calculation():
df=pd.read_sql('tb_pledged_base',engine,index_col='index')
# print(df)
# df['unrest_ratio']=df['unrest_pledged']/df['totals']*100
# df['rest_ratio']=df['rest_pledged']/df['totals']*100
# df['unrest_ratio']=map(lambda x:round(x,2),df['unrest_ratio'])
# df['rest_ratio']=map(lambda x:round(x,2),df['rest_ratio'])
# df.to_sql('tb_pledged_base',engine,if_exists='replace')
print('median ',df['p_ratio'].median())
print('mean ',df['p_ratio'].mean())
print('std ',df['p_ratio'].std())
print('var ',df['p_ratio'].var())
plt.figure()
plt.hist(df['p_ratio'],20)
# plt.hist(df['p_ratio'],10,normed=True)
plt.show()
# pledge_info()
# pledged_detail()
do_calculation()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jx0913/stock.git
git@gitee.com:jx0913/stock.git
jx0913
stock
stock
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385