Skip to content

Instantly share code, notes, and snippets.

@adxrgh
adxrgh / snippet.py
Created April 30, 2017 14:29
[for i,r in t.iterrows():]
t = pd.DataFrame({'a': range(0, 10000), 'b': range(10000, 20000)})
B = []
C = []
A = time.time()
for i,r in t.iterrows():
C.append((r['a'], r['b']))
B.append(time.time()-A)
C = []
A = time.time()
@adxrgh
adxrgh / k.py
Created May 2, 2017 12:08
tushare 画k线图
tushare 数据规整画图
from matplotlib.pylab import date2num
import datetime
# 对tushare获取到的数据转换成candlestick_ohlc()方法可读取的格式
data_list = []
hist_data = ts.get_hist_data('600199')
for dates,row in hist_data.iterrows():
# 将时间转换为数字
date_time = datetime.datetime.strptime(dates,'%Y-%m-%d')
@adxrgh
adxrgh / gp.py
Created May 2, 2017 13:14
[IO]wind引入代码及股票名 #tags:wind,code
import pandas as pd
from pandas import DataFrame
fro WindPy import *
w.start
###
t1=w.wset('sectorconstituent','date=20170501;sector=全部A股')
a=DataFrame({'code':t1.Data[1],'name':t1.Data[2]})
@adxrgh
adxrgh / dict.py
Created May 3, 2017 14:57
[构造字典] 使用两个列表 #dict:list
>>> keys = ['a', 'b', 'c']
>>> values = [1, 2, 3]
>>> dictionary = dict(zip(keys, values))
>>> print(dictionary)
{'a': 1, 'b': 2, 'c': 3}
@adxrgh
adxrgh / tp.py
Last active May 21, 2017 04:54
[tp.收益曲线]获得突破个股的今年以来的收益比较图 #wind
from WindPy import *
import pandas as pd
from pandas import DataFrame
w.start()
all_data={}
a=w.weqs('tp')
for ticker in a.Data[0]:
all_data[ticker]=w.wsd(ticker,'close','20170101')
price=DataFrame({tic:data.Data[0] for tic,data in all_data.items()},index=all_data[next(iter(all_data))].Times) # next (iter(my_dict))get firt key of a dict
@adxrgh
adxrgh / g.py
Last active May 27, 2017 06:03
[get a buntch of data from wind]#tags:input,wind,收益曲线,plot
import WindPy
from WindPy import *
import pandas as pd
from pandas import DataFrame
w.start()
all_data={}
a=w.weqs('tp')
for ticker in a.Data[0]:
all_data[ticker]=w.wsd(ticker,'close','20170101')
@adxrgh
adxrgh / k.py
Last active May 25, 2017 16:51
[k线 with pynance] #tags:ts,plot
#coding:utf-8
import tushare as ts
import pynance as pn
ticker=input('input your ticker:')
t=ts.get_k_data(ticker)
x=t.set_index('date')#设置日期为索引
x.index=x.index.to_datetime()#将索引转为日期格式
x.index.names=['Date']#为索引指定名称
@adxrgh
adxrgh / a.py
Last active May 24, 2017 15:13
[wind获取全部A股数据并存储]#tags:wind,
# -*- coding:utf-8 -*-
# Author:jqzhang
# Editdate:2015-12-21
from WindPy import w
import pymssql
from datetime import datetime
server = 'WIND-PUB010\SQLEXPRESS'
user = 'jqzhang'
password = 'wind'
@adxrgh
adxrgh / ggplot.py
Last active June 5, 2017 07:58
plot 详解
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib
matplotlib.style.use('ggplot') ## 采用ggplot格式
@adxrgh
adxrgh / cd.py
Created May 16, 2017 07:15
[pn.ts.selected candles chart]
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import tushare as ts
import pynance as pn
from pandas import DataFrame,Series
a=ts.get_today_all()
b=a[(a.nmc>5e+5)&(a.nmc<15e+5)&(a.changepercent>5)&(a.turnoverratio>2)]# 涨幅大于5%且自由流通市值在50到150亿之间的个股