-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathpanelDataDailySimulate.dos
54 lines (46 loc) · 1.58 KB
/
panelDataDailySimulate.dos
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//创建库表定义,如若已存在,则会drop已有的库重新建库建表
def createDayDbTable(dbName, tbName){
if(existsDatabase(dbName)){
dropDatabase(dbName)
}
db = database(dbName, RANGE, 2000.01M + (0..30)*12 )
t =table(1:0, `securityid`tradetime`open`close`high`low`vol`val`vwap, [SYMBOL,TIMESTAMP,DOUBLE,DOUBLE,DOUBLE,DOUBLE,INT,DOUBLE,DOUBLE])
db.createPartitionedTable(t, tbName, `tradetime)
}
//模拟数据数据定义
def genKday(n){
tradetime = select * from table(timestamp(distinct(businessDay(temporalAdd(2010.01.01,n, "y")..yearEnd(temporalAdd(2010.01.01,n, "y"))))).sort() as tradetime) where tradetime >=temporalAdd(2010.01.01,n, "y")
securityid ="sz"+lpad(string(000001..004000), 6, `0)
tmpTable = cj(table(securityid as securityid),tradetime)
open = rand(100.0, size(tradetime)*4000)
high = open + rand(1.0,size(tradetime)*4000)
low = high - rand(2.0,size(tradetime)*4000)
close = open + norm(0,2,size(tradetime)*4000)
vol = rand(100000,size(tradetime)*4000)
val = close*vol
vwap = close
resTable = tmpTable join table(open,close, high, low, vol, val, vwap)
tradeDate=NULL
tradeMin = NULL
tradetime =NULL
securityid =NULL
tmpTable = NULL
open =NULL
high = NULL
low = NULL
close =NULL
vol = NULL
val = NULL
vwap = NULL
db = loadTable("dfs://k_day_level","k_day")
db.append!(resTable)
}
def writeInDayByYear(numOfYear){
for (n in 0..(numOfYear-1)){
submitJob("genKday_"+string(n),"genKday_"+string(n),genKday,n)
}
}
//1. 创建分钟频数据库表
createDayDbTable("dfs://k_day_level","k_day")
//2. 模拟写入1年数据
writeInDayByYear(1)