Skip to content

Instantly share code, notes, and snippets.

@adxrgh
adxrgh / function.py
Created April 16, 2019 00:14
[函数]定义格式值得关注
def format(x):
if x ==1:
template = '{} song'
else:
template = '{} songs'
return template.format(x)
@adxrgh
adxrgh / lowest.sql
Created June 15, 2017 07:52
[选取历史最低价]#tags:sql
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';
@adxrgh
adxrgh / update.py
Last active June 14, 2017 14:30
[wind添加当天的a股收盘数据]#tags:wind,IO
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))
@adxrgh
adxrgh / wind.py
Created June 11, 2017 15:52
[wind自动获取数据]#tags:wind,IO
# -*- 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中获取股票列表,独立运行;增加日志和参数处理
@adxrgh
adxrgh / low.py
Last active May 29, 2017 06:23
[寻找一组股票的历史最低价 并和现价比较]#tags:wind,IO
#连接数据库
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=[]
@adxrgh
adxrgh / a.py
Last active May 25, 2017 15:31
[wind获取行业所有股票历史数据]#tags:wind
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("""
@adxrgh
adxrgh / pm.py
Last active May 24, 2017 07:53
[加权排序盘面]#tags:看盘
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)
@adxrgh
adxrgh / db.py
Created May 22, 2017 17:15
[double charts]
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
@adxrgh
adxrgh / sql.py
Last active June 12, 2017 23:55
[单表sql,sql table读写]#tags:IO,sql
###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')
@adxrgh
adxrgh / ftca.py
Created May 19, 2017 07:48
[wind.selected.FTCA]
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')