This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def format(x): | |
if x ==1: | |
template = '{} song' | |
else: | |
template = '{} songs' | |
return template.format(x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create view lowest1 as | |
select * from stockprice where low in (select min(low) from stockprice group by secid) | |
group by secid; | |
select * from lowest1 | |
where tradedate>'20170501'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from WindPy import * | |
w.start() | |
today=dt.datetime.now().strftime('%Y%m%d') | |
a=w.wset("sectorconstituent","date=%s;sectorid=%s" % (today,'a001010100000000')) | |
all_A_code=a.Data[1] | |
#获取当天的股票收盘价 | |
ohlc=w.wss(all_A_code, "open,high,low,close,volume,amt","tradeDate=%s;priceAdj=F;cycle=D" % today) | |
ohlc | |
a=DataFrame(np.matrix(ohlc.Data)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding:utf-8 -*- | |
#################################################################################################################### | |
''' | |
程序:Wind股票数据下载 | |
功能:从Wind终端或者Wind资讯量化接口个人免费版中下载股票相关数据,保存至本地MySQL数据库,以进一步加工处理和分析 | |
创建时间:2016/01/15 V1.01 创建版本,Python2.7 | |
更新历史:2017/01/06 V1.02 从本地文件读取股票代码列表;升级到Python3.5版本 | |
2017/01/07 V1.03 封装为函数,便于调试和代码管理 | |
2017/01/08 V1.04 封装为类,为后续完善功能准备。自动从Wind中获取股票列表,独立运行;增加日志和参数处理 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#连接数据库 | |
conn = pymysql.connect(host='localhost',user='root',password='1235', db='wind',charset="utf8") | |
#从数据库查询数据,构建dataframe | |
cur = conn.cursor() | |
cur.execute("select tradedate,secid,closeprice,volume from stockprice;") #调整sql字段顺序即可获得不同顺序的【】 | |
cur.scroll(0,"absolute") | |
ohlc=[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from WindPy import w | |
w.start() | |
from datetime import datetime | |
dt=datetime.now() | |
#连接WIND数据库 execute内要用三个引号 | |
import pymysql #python2要使用其他接口 | |
conn = pymysql.connect(host='localhost',user='root',password='1235', db='wind',charset="utf8") | |
cursor = conn.cursor() | |
cursor.execute(""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tushare as ts | |
a=ts.get_today_all() | |
x=(a.changepercent*a.nmc)/a.nmc.sum() | |
a['weight']=x | |
a.sort(['weight'],ascending=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import datetime as dt | |
from pandas import Series,DataFrame | |
from datetime import datetime | |
from dateutil.parser import parse | |
import time | |
from pandas.tseries.offsets import Hour,Minute,Day,MonthEnd | |
import pytz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###sql文件信息读写 | |
import tushare as ts | |
import pymysql | |
import pandas as pd | |
from pandas import DataFrame as df | |
#下载数据并写入 | |
a=ts.get_today_all() | |
from sqlalchemy import create_engine | |
e=create_engine('mysql+pymysql://'+'root:1235@localhost/yaotest?charset=utf8') | |
a.to_sql('a',e,if_exists='replace') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from WindPy import * | |
import pandas as pd | |
from pandas import DataFrame | |
import ffn | |
w.start() | |
all_data={} | |
a=w.weqs('tp')#筛选出自由流通市值在50-200亿元之间,成交量增加50%,涨幅大于4%,且不为今年上市的新股 | |
for ticker in a.Data[0]: | |
all_data[ticker]=w.wsd(ticker,'close','20170101') |