Advertisement
Guest User

R test

a guest
Feb 10th, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. library(R.utils)
  2. library(lubridate)
  3.  
  4. eu <- read.csv(file.choose(), header=F)
  5. head(eu)
  6. time.date <- unique(eu[,1])
  7.  
  8. Test <- data.frame(
  9.     str(10),
  10.     numeric(),
  11.     numeric(),
  12.     numeric(),
  13.     numeric(),
  14.     str(5),
  15.     str(5),
  16.     stringsAsFactors=FALSE)
  17.  
  18. x = 1
  19. pb <- txtProgressBar(min = 0, max = length(time.date), style = 3)
  20. for (x in 1:length(time.date)) {
  21.       cur_day <- eu[eu[,1] == time.date[x],]
  22.  
  23.     nHigh = max(cur_day[,4])
  24.     nLow = min(cur_day[,5])
  25.    
  26.     nHighAtnr = which.max(cur_day[,4])
  27.     nLowAtnr  = which.min(cur_day[,5])
  28.  
  29.     nHighAt = cur_day[nHighAtnr,2]
  30.     nLowAt = cur_day[nLowAtnr,2]
  31.  
  32.     Test[x,1] = as.character(time.date[x])
  33.     Test[x,2] = cur_day[1,3]
  34.     Test[x,3] = nHigh
  35.     Test[x,4] = nLow
  36.     Test[x,5] = cur_day[length(cur_day),6]
  37.     Test[x,6] = nHighAt
  38.     Test[x,7] = nLowAt
  39.     setTxtProgressBar(pb,x )
  40. }
  41. colnames(Test) <- c('Date','Open','High','Low','Close','HighAt','LowAt')
  42.  
  43.  
  44. #a <- df[!(df$plan==0 & df$sevk==0),]
  45. #Remove Saturday and Sunday candles
  46. Test <- Test[!(wday(as.Date(Test$Date,"%Y.%m.%d"))==7 || wday(as.Date(Test$Date,"%Y.%m.%d"))==1 ),]
  47.  
  48. Test2 <- data.frame(str(5))
  49. x = 1
  50. for (x in 1:length(Test$Date)) {
  51.     if (Test$Open[x] <= Test$Close[x]) {
  52.         #UP DAY
  53.         Test2[x,1] <- lapply(Test$LowAt[x], as.character)
  54.  
  55.     }else {
  56.         #Down Day
  57.         Test2[x,1] <- lapply(Test$HighAt[x], as.character)
  58.  
  59.     }
  60. }
  61. colnames(Test2)[1] <- "Time"
  62.  
  63. Test3 <- unique(Test2$Time)
  64. Test4 <- 1
  65. x = 1
  66.  
  67. for (x in 1:length(Test3)) {
  68.     Test4[x] = match(Test3[x], Test2$Time)
  69. }
  70.  
  71. write.csv(Test5,"test.csv",row.names=FALSE,na="")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement