- 金币:
-
- 奖励:
-
- 热心:
-
- 注册时间:
- 2009-11-11
|
|
我也在做这个,刚刚把数据格式分析出来,以每月的5分钟安装文件为例:
前20个字节为文件头。随后28个字节为股票头,之后每32个字节为一条5分钟行情记录,此股票行情会以"FF FF FF FF"结尾(不包括在32个字节的行情记录内)。"FF FF FF FF"为下一个股票的股票头(28字节),然后继续每32个字节一条5分钟行情记录,...,直到文件结束。
水平有限,若有错漏,欢迎指正。
附VBA程序如下
Option Explicit
Type fxjHeadType
w1 As Single
w2 As Single
numStocks As Long
w4 As Single
w5 As Single
End Type
Type fxjStockDefType
code As String * 8
w3 As Single
w4 As Single
name As String * 12
End Type
Type fxj5minQuoteType
w1 As Long 'date
open As Single
high As Single
low As Single
close As Single
volume As Single
amount As Single
w8 As Long
End Type
Public Sub test()
Dim filename As String
Dim fxjHead As fxjHeadType
Dim fxjStockDef As fxjStockDefType
Dim fxj5minQuote As fxj5minQuoteType
Dim d1 As Long
Dim d2 As Single
Dim currentDate As Date
Dim i, anchor As Long
filename = "D:\my own research\trading data\fxj5min\200904.DAD"
Open filename For Binary As #1
Get #1, , fxjHead
anchor = 21
Do While True
Seek #1, anchor
Get #1, , fxjStockDef
anchor = anchor + 28
Do While True
Get #1, , fxj5minQuote
anchor = anchor + 32
If fxj5minQuote.w1 = -1 Then
anchor = anchor - 32 + 4
Exit Do
End If
currentDate = CDate("1970-1-1") + fxj5minQuote.w1 / 86400
Debug.Print fxjStockDef.code & currentDate & fxj5minQuote.close
Loop
Loop
Close #1
End Sub
附2:SAS读取的程序
libname HF "D:\my own research\trading data\";
run;
%let FinDataDataSet=HF.fxj5min;
%let FxjDataFile = D:\my own research\trading data\fxj5min\200801.DAD;
filename FxjFile "&FxjDataFile.";
data ResultTable;
format code $8. datetime datetime. date yymmdd10. time time.;
infile FxjFile recfm=n end=eof;
p=21;
i=0;
do while (not(eof));
input @(p) code $8. @(p+16) name $10;
p=p+28;
flag=0;
do while (flag ne -1 and not(eof));
input @(p+0) date ib4. @(p+4) TOpen float4. @(p+8) high float4. @(p+12) low float4.
@(p+16) TClose float4. @(p+20) volume float4. @(p+24) amount float4.;
time=floor(date/86400);
datetime = date+(DHMS(MDY(1,1,1970),0,0,0)-DHMS(MDY(1,1,1960),0,0,0) );
date=datepart(datetime);
time=timepart(datetime);
if code in:('SH50','SH51','SZ184','SZ15','SZ16','SH58','SZ03') and date>mdy(3,3,2003) then
roundunit=0.001; else roundunit=0.01;
TOpen=round(TOpen,roundunit);
high=round(high,roundunit);
low=round(low,roundunit);
TClose=round(TClose,roundunit);
volume=round(volume*100,1);
amount=round(amount,0.01);
input @(p+32) flag ib4.;
output;
if not(flag=-1) then do;
p=p+32;
end;
else do;
p=p+36;
end;
i=i+1;
end;
end;
stop;
keep code date time TOpen high low TClose volume amount;
run; |
|
|