[转载]用分笔数据文本文件制作 通达信的一分钟图,五分钟图
(2014-11-03 22:19:50)
标签:
转载 |
分类: 数据源、指标和公式 |
原文地址:用分笔数据文本文件制作 通达信的一分钟图,五分钟图 作者:厚朴
说明:适用通达信,别的没测试,
使用:python 文件名.py -t 999999 20070101 20070131 表示 用文本文件转化为1分钟5分钟的数据文件,代码是上证指数,日期 20070101到20070131 生成的5分钟数据文件为 sh999999.lc5 ,一分钟文件为 sh999999.lc1
注意:能直接看5分钟的数据,但不能直接看1分钟的,可能的原因是1分钟的数据文件不是sh999999.lc1形式的,有知道的请告知;但是可以换个方法看1分钟的图,方法是sh999999.lc1更名为 sh999999.lc5 ,然后在5分钟图下看1分钟的K线了。
以下是代码
#!/usr/bin/python
#-*- encoding: gbk -*-
from __future__ import division
from
struct
import *
import os,time ,datetime,string,sys,math,re,shutil,glob
import zipfile,StringIO,getopt
#from readths2 import *
# 2010-09-02 by 厚朴
basedir = r'D:2965guosen' #如果你的安装路径不同,请改这里
exp_dir =
basedir + r'T0002export'
#exp_dir =
basedir + r'T0002export_back'
lc5_dir_sh = basedir + r'Vipdocshfzline'
#lc5_dir_sh =
r'D:2965ydzqwsjyVipdocshfzline'
lc5_dir_sz = basedir + r'Vipdocszfzline'
day_dir_sh = basedir + r'Vipdocshlday'
day_dir_sz = basedir + r'Vipdocszlday'
stkdict = {} #存储股票ID和上海市、深圳市的对照
#############################################################
# read 通达信分笔数据
# example readfbtxt(readlines(),'20100831-600000.TXT')
# 返回的data格式为
# (stkid,datetime,price,amount,vol(股数),笔数,buy or sale) 的list
#############################################################
def readfbtxt(p_lines,p_name):
"""读通达信分笔数据
"""
data =
[]
shortname =
os.path.split(p_name)[1]
shortname =
os.path.splitext(shortname)[0]
sDay,stkID =
shortname.split('-')
if len(sDay)
!= 8 : return data
stky =
int(sDay[0:4])
stkm =
int(sDay[4:6])
stkd =
int(sDay[6:8])
line_no =
0
for l in
p_lines:
line_no += 1
if line_no <=3: continue
l = l.strip()
t = re.split('s+',l)
k =
datetime.datetime(stky,stkm,stkd,int(t[0][0:2]),int(t[0][3:5]))
p =
float(t[1])
#price
vol = int(t[2])*100 #股数
amt = p *
vol
#成交量
bscnt =
0
#笔数
bstag =
''
#buy or sale
try:
bscnt =
int(t[3])
#笔数
bstag =
t[4]
#buy or sale
except IndexError,e:
pass
data.append((stkID,k,p,amt,vol,bscnt,bstag))
return
data
#############################################################
# 将分笔数据转化为分笔数据
# p_data:传入参数 为readfbtxt所返回
# data: 返回的数据格式为
# [stkid,datetime,open,high,low,close,amt,vol(股)]
#############################################################
def fbtxt2lc0(p_data):
"""分笔数据转化为1分钟数据"""
data =
[]
for i in
p_data:
t =
i[1]
#datetime
使用:python 文件名.py -t 999999 20070101 20070131 表示 用文本文件转化为1分钟5分钟的数据文件,代码是上证指数,日期 20070101到20070131 生成的5分钟数据文件为 sh999999.lc5 ,一分钟文件为 sh999999.lc1
注意:能直接看5分钟的数据,但不能直接看1分钟的,可能的原因是1分钟的数据文件不是sh999999.lc1形式的,有知道的请告知;但是可以换个方法看1分钟的图,方法是sh999999.lc1更名为 sh999999.lc5 ,然后在5分钟图下看1分钟的K线了。
以下是代码
#!/usr/bin/python
#-*- encoding: gbk -*-
from __future__ import division
from
import os,time ,datetime,string,sys,math,re,shutil,glob
import zipfile,StringIO,getopt
#from readths2 import *
# 2010-09-02 by 厚朴
basedir = r'D:2965guosen' #如果你的安装路径不同,请改这里
exp_dir
#exp_dir
lc5_dir_sh = basedir + r'Vipdocshfzline'
#lc5_dir_sh =
lc5_dir_sz = basedir + r'Vipdocszfzline'
day_dir_sh = basedir + r'Vipdocshlday'
day_dir_sz = basedir + r'Vipdocszlday'
stkdict = {} #存储股票ID和上海市、深圳市的对照
#############################################################
# read 通达信分笔数据
# example readfbtxt(readlines(),'20100831-600000.TXT')
# 返回的data格式为
# (stkid,datetime,price,amount,vol(股数),笔数,buy or sale) 的list
#############################################################
def readfbtxt(p_lines,p_name):
#############################################################
# 将分笔数据转化为分笔数据
# p_data:传入参数 为readfbtxt所返回
# data:
# [stkid,datetime,open,high,low,close,amt,vol(股)]
#############################################################
def fbtxt2lc0(p_data):