[tech-spec] Date question
- From: James Sogi <jsogi@xxxxxxxxxxxxx>
- To: tech-spec@xxxxxxxxxxxxx
- Date: Thu, 23 Dec 2004 10:46:46 -1000
Here is a little afternoon trade I came up with as an example to ask a
"how to" question which is eludes me. How do I ask in R whether:
day before yesterday close is higher than yesterday, and
close two days before yesterday is higher than close day before
yesterday and
11 am is higher than open today.
but without using the lagged columns, and by using dates x-1, x-2, x+3
etc?
The lag columns seem so cumbersome.
Thanks for your help.
Test: If change morning session (open to 11) > change overnight
session, buy 2:30, sell at close.
## get data with read.csv; pick columns; use data.frame(x,y)
Julian<-as.Date(ES3$date) ## convert dates to Date class
jd<-julian(ES3$date, origin = as.Date("1970-01-01"),
abbreviate=FALSE)##convert date to julian dates class
## get change in price with diff
##convert regular times to 1:4 and substitute columns with factor
rep(1:4,1633)
d jd dw t p c c1 c2 c3 c4
1 1998-06-11 10388 Thu 1 1321.25 0.00 -6.00 -7.00 -8.00 1.75
2 1998-06-11 10388 Thu 2 1315.25 -6.00 -7.00 -8.00 1.75 -3.25
3 1998-06-11 10388 Thu 3 1308.25 -7.00 -8.00 1.75 -3.25 -6.00
4 1998-06-11 10388 Thu 4 1300.25 -8.00 1.75 -3.25 -6.00 15.75
5 1998-06-12 10389 Fri 1 1302.00 1.75 -3.25 -6.00 15.75 -14.50
6 1998-06-12 10389 Fri 2 1298.75 -3.25 -6.00 15.75 -14.50 6.75
7 1998-06-12 10389 Fri 3 1292.75 -6.00 15.75 -14.50 6.75 -4.75
8 1998-06-12 10389 Fri 4 1308.50 15.75 -14.50 6.75 -4.75 -15.25
9 1998-06-15 10392 Mon 1 1294.00 -14.50 6.75 -4.75 -15.25 8.50
a<-subset(ES3, t == 1 & c < c1 , select = c3)
> t.test(a) One Sample t-test
t = 2.1246, df = 185, p-value = 0.03495
mean 1.323925
sd 8.5
summary(a)
c3
Min. :-38.500
1st Qu.: -2.750
Median : 1.500
Mean : 1.324
3rd Qu.: 5.438
Max. : 33.000
ES Data at : http://home.hawaii.rr.com/zephyr/ES_3barsdaily.txt
Other related posts:
- » [tech-spec] Date question