今天分析了一下通达信行情软件的股票日线数据格式,通达信的股票日线数据文件保存在 VipDoc 中,上海的股票日线数据在目录 vipdoc\sh\lday 下,深圳的在vipdoc\sz\lday 下;编写了一个提取日线数据的例子程序。但奇怪的是,找了好久,都没有发现除权和分红的数据保存在哪里。所以对于股票的复权,计算就比较麻烦了
今天分析了一下通达信行情软件的股票日线数据格式,通达信的股票日线数据文件保存在 VipDoc 中,上海的股票日线数据在目录 vipdoc\sh\lday 下,深圳的在vipdoc\sz\lday 下;编写了一个提取日线数据的例子程序。但奇怪的是,找了好久,都没有发现除权和分红的数据保存在哪里。所以对于股票的复权,计算就比较麻烦了,原来还以为可以通过将每日的昨日收盘价跟前一天的收盘价对比来发现除权呢,但是读取出来的数据发现,每日的昨收数据并不正确,经常缺失数据,所以无法使用这种方法进行复权计算了。
代码例子如下:
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using StockAnalysisApplication.Entity;
namespace StockAnalysisApplication
{
public partial class TdxDataReaderSample : Form
{
public TdxDataReaderSample()
{
InitializeComponent();
}
private void toolStripButton1_Click(object sender, EventArgs e)
{
//char[] aa={'1','2'};
//this.Text =aa.ToString();
//MessageBox.Show(new string(aa));
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string filename =openFileDialog1.FileName;
FileStream fs = File.OpenRead(filename);
BinaryReader br = new BinaryReader(fs);
int days = (int)fs.Length / 32 ;
List<StockDayData> list = new List<StockDayData>();
for (int i = 0; i < days; i++)
{
StockDayData item = new StockDayData();
//item.DataDate =DateTime.Parse(new string(br.ReadChars(8)));
int date = br.ReadInt32();
int year = date / 10000;
int month = int.Parse(date.ToString().Substring(4, 2));
int day = int.Parse(date.ToString().Substring(6, 2));
//item.DataDate = new DateTime(year, month, day);
int open = br.ReadInt32();
int high = br.ReadInt32();
int low = br.ReadInt32();
int close = br.ReadInt32();
Single amount = br.ReadSingle();
//Int32 amount = br.ReadInt32();
decimal am = Convert.ToDecimal(amount);
long amstr = Convert.ToInt64(amount);
int vol = br.ReadInt32();
int preclose = br.ReadInt32();
//Decimal open = Convert.ToDecimal(br.ReadSingle());
item.Date = date;
item.Open = Convert.ToDecimal (open / 100m);
item.High = Convert.ToDecimal(high / 100m);
item.Low = Convert.ToDecimal(low / 100m);
item.Close = Convert.ToDecimal(close / 100m);
item.Amount = amstr;
item.Vol = vol;
item.PreClose = Convert.ToDecimal(preclose / 100m);
list.Add(item);
}
br.Close();
fs.Close();
this.dataGridView1.DataSource = list;
}
}
}
public class StockDayData
{
private int mDate;
public int Date
{
get { return mDate; }
set { mDate = value; }
}
private decimal mOpen;
public decimal Open
{
get { return mOpen; }
set { mOpen = value; }
}
private decimal mHigh;
public decimal High
{
get { return mHigh; }
set { mHigh = value; }
}
private decimal mLow;
public decimal Low
{
get { return mLow; }
set { mLow = value; }
}
private decimal mClose;
public decimal Close
{
get { return mClose; }
set { mClose = value; }
}
private long mAmount;
public long Amount
{
get { return mAmount; }
set { mAmount = value; }
}
private int mVol;
public int Vol
{
get { return mVol; }
set { mVol = value; }
}
private decimal mPreClose;
public decimal PreClose
{
get { return mPreClose; }
set { mPreClose = value; }
}
}
}
图片如下: