-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path1minute_dataset.sas
More file actions
152 lines (125 loc) · 3.34 KB
/
1minute_dataset.sas
File metadata and controls
152 lines (125 loc) · 3.34 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
libname tf "C:\...\sas dataset";
libname tf "H:\...\sas dataset";
***************************************;
* 3. creazione intervalli GIORNALIERI *;
***************************************;
options nocenter;
*******************************************************;
* Define fifteen minute intervals in a CNTLIN data set *;
*******************************************************;
data work.int1m;
retain label "ddmmmyy:00:00:00-ddmmmyy:00:00:00"
fmtname "int1m"
type "N"
start 0
end 0
eexcl "Y";
do start = "01JAN09:00:00:00"dt to "16DEC14:00:00:00"dt by 60;
end = start + 60;
label = put(start,datetime.)/*||"-"||put(end,datetime.)*/;
/*label = put(start,tod8.0)||"-"||put(end,tod8.0);*/
output;
end;
hlo = "O";
label = "***OTHER***";
output;
format start end datetime.;
run;
********************************************************;
* Use the CNTLIN data set to create the interval format *;
********************************************************;
proc format cntlin = work.int1m;
run;
/*MACRO*/
%macro dataset1m (dati);
data work.&dati ; /*CAMBIA NOME*/
%let _EFIERR_ = 0; /* set the ERROR detection macro variable */
/*infile 'C:\Users\feder_000\Documents\Tesi\dati originali\.mtgoxEUR.csv' delimiter = ','*/
infile "H:\Tesi\dataset originali\.&dati..csv" delimiter = ','
MISSOVER DSD lrecl=32767 ;
informat timestamp best32. ;
informat price best32. ;
informat size best32. ;
format timestamp best12. ;
format price best12. ;
format size best12. ;
input
timestamp
price
size
;
if _ERROR_ then call symputx('_EFIERR_',1); /* set ERROR detection macro variable */
run;
*******************************;
* 2. from utc to sas datetime *;
*******************************;
data &dati.2; /*CAMBIA NOME*/
set &dati; /*CAMBIA NOME*/
/* The INTNX function accounts for leap years. */
datetime = intnx('DTyear',timestamp,10,'s');
format datetime datetime.;
run;
*****************************;
* 5. creazione dataset OHLC *;
*****************************;
proc sort data=&dati.2;
by datetime;
run;
data &dati.3; /*CAMBIA NOME*/
set &dati.2 (keep = price size datetime); /*CAMBIA NOME*/
by datetime;
Int1M = put(datetime,int1m.);
CT_RowNum + 1;
run;
proc sort data=&dati.3; /*CAMBIA NOME*/
by int1M;
run;
data tf.&dati.1m (drop = Price size); /*CAMBIA NOME*/
set &dati.3 ; /*CAMBIA NOME*/
by Int1M;
retain Open
High
Low
Close
Volume
Trades .;
if first.datetime or first.Int1M then do ;
Open = .;
High = .;
Low = .;
Close = .;
Volume = .;
Trades = .;
end;
if Open = . then Open = Price;
High = max(Price ,High);
Low = min(Price ,Low );
Volume = sum(Volume,Size);
Close = Price;
Trades + 1;
if last.Int1m then output;
run;
proc sort data=tf.&dati.1m; /*CAMBIA NOME*/
by datetime;
run;
/*cambio formato a int1m*/
data tf.&dati.1m;
set tf.&dati.1m;
datetimevar1 =input(int1m,anydtdtm20.);
format datetimevar1 datetime20.;
drop int1m;
rename datetimevar1=Int1m;
run;
/*mantengo solo il prezzo close e restringo le osservazioni*/
data tf.&dati.1mclose;
set tf.&dati.1m;
keep close Int1m;
rename close=&dati._close;
if int1m < "30APR2013:23:00:00"dt then delete; /*fatto per non avere missing in bitfinex*/
if int1m > "10DEC2014:23:59:00"dt then delete;
run;
/*proc datasets library=tf;
delete &dati.1m;
run;*/
%mend dataset1m;
/* fine macro*/