R newbee q. - Matlab, R project and Python | futures io social day trading
futures io futures trading


R newbee q.
Updated: Views / Replies:2,010 / 20
Created: by giladbi Attachments:3

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 3  
 
Thread Tools Search this Thread
 

R newbee q.

  #1 (permalink)
Elite Member
tel aviv
 
Futures Experience: Advanced
Platform: Multicharts, SC
Favorite Futures: es
 
Posts: 34 since Jun 2009
Thanks: 4 given, 1 received

R newbee q.

Hi
I am trying to run some R code for loading data from files and than do some trails with pair trading.
this is my code:
 
Code
library("quantmod")
library("PerformanceAnalytics")
XG1min <-read.csv("XG#-1min 22122011-10102014 BarData.txt", header=TRUE)
XG1min = data.frame(DateTime=as.POSIXct(paste(XG1min$Date, XG1min$Time)), XG1min)      
XG1min <- xts(XG1min[,-1], order.by=XG1min[,1])
sym1<-XG1min
startTraining  <- "2013-05-29 02:00:00"
endTraining    <- "2013-05-30 18:00:00"
rangeTraining  <- paste(startTraining,"::",endTraining,sep ="")
trainsym1   <- sym1[,6][rangeTraining]
pdtsym1 <- diff(trainsym1)[-1]
I have this data in XG1min (after running the above):

Quoting 
row.names Date Time Open High Low Close Volume NumberOfTrades
2011-12-22 2011/12/22 02:00:00 5805.5 5820.5 5804 5820.5 253 96
2011-12-22 2011/12/22 02:01:00 5819.0 5820.0 5813 5817.0 77 57

1. When creating trainsym1 from XG1min I get only the First and 6th Column (close values), but because it's intraday, I need the index of both be a concatenate of Date + time together and I am failing doing so.
2. at the last line of the above code, I get an error:

Quoting 
Error in -.default(x, lag.xts(x, k = lag, na.pad = na.pad)) :
non-numeric argument to binary operator

so I used the following to change the close column to numeric
 
Code
trainsym1[1] <- lapply(trainsym1[1], as.numeric)
but there is no change with the error

I appriciate any help!
Thanks!

Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
Rristocrat
zurich
 
Futures Experience: Advanced
Platform: Sierra ahRrrr CQG ...
Favorite Futures: Bund, ES, ...
 
puma's Avatar
 
Posts: 963 since Aug 2010
Thanks: 7,268 given, 1,489 received


I am a newbie too - so be warned

from the error you posted, xts seems to be an issue.

some ideas:

after this:
 
Code
XG1min <- xts(XG1min[,-1], order.by=XG1min[,1])
is XG1min a xts class object ?

did you try
 
Code
diff.xts
instead of
 
Code
diff
I dont understand yet, what you want to do.

Can you post your data source file
"XG#-1min 22122011-10102014 BarData.txt"

Reply With Quote
 
  #4 (permalink)
Elite Member
tel aviv
 
Futures Experience: Advanced
Platform: Multicharts, SC
Favorite Futures: es
 
Posts: 34 since Jun 2009
Thanks: 4 given, 1 received

XG1min is an xts object bt this line
 
Code
XG1min <- xts(XG1min[,-1], order.by=XG1min[,1])
I am attaching the file to load the data from (only a part of it).
using
 
Code
diff.xts
is giving the same error:
Quoting 
Error in `-.default`(x, lag.xts(x, k = lag, na.pad = na.pad)) :
non-numeric argument to binary operator


Attached Files
Register to download File Type: txt XG#-1min 22122011-10102014 BarData2.txt (167.5 KB, 5 views)
Reply With Quote
The following user says Thank You to giladbi for this post:
 
  #5 (permalink)
Rristocrat
zurich
 
Futures Experience: Advanced
Platform: Sierra ahRrrr CQG ...
Favorite Futures: Bund, ES, ...
 
puma's Avatar
 
Posts: 963 since Aug 2010
Thanks: 7,268 given, 1,489 received

I found the problem.

after your

 
Code
XG1min = data.frame(DateTime=as.POSIXct(paste(XG1min$Date, XG1min$Time)), XG1min)
insert (yes twice - to delete the residue columns Date and Time - you have DateTime)
 
Code
XG1min[,2] <- NULL
XG1min[,2] <- NULL
then will
 
Code
XG1min <- xts(XG1min[,-1], order.by=XG1min[,1])
keep the format numeric for the rest of the data.

xts can only hold one data type (e.g. numeric)
And since the old columns Date and Time were of type character,
xts "chooses" type of the first column for all the rest of the data.
getting rid of these two solves the issue.

Reply With Quote
The following user says Thank You to puma for this post:
 
  #6 (permalink)
Elite Member
tel aviv
 
Futures Experience: Advanced
Platform: Multicharts, SC
Favorite Futures: es
 
Posts: 34 since Jun 2009
Thanks: 4 given, 1 received

your sugestion clears column 2 (Date) and than again clears the time (which was 3 and now moved to 2)
yet, the first column (Datetime) has only date data but no time
something in this line is not working properly:
 
Code
XG1min = data.frame(DateTime=as.POSIXct(paste(XG1min_read_from_file$Date, XG1min_read_from_file$Time)), XG1min_read_from_file)
Also this not solving the numeric issue

Reply With Quote
 
  #7 (permalink)
Rristocrat
zurich
 
Futures Experience: Advanced
Platform: Sierra ahRrrr CQG ...
Favorite Futures: Bund, ES, ...
 
puma's Avatar
 
Posts: 963 since Aug 2010
Thanks: 7,268 given, 1,489 received

here is the full script - it runs without error:

 
Code
library("quantmod")
library("PerformanceAnalytics")

# I defined the colClasses - to make sure the type is o.k
XG1min <-read.csv("XG#-1min 22122011-10102014 BarData2.txt",
                  header=TRUE, 
                  colClasses=c("Date","character","numeric","numeric","numeric",
                               "numeric","numeric","numeric","numeric","numeric")
                  )

XG1min = data.frame(DateTime=as.POSIXct(paste(XG1min$Date, XG1min$Time)), XG1min) 
XG1min[,2] <- NULL
XG1min[,2] <- NULL

XG1min <- xts(XG1min[,-1], order.by=XG1min[,1])

sym1 <- XG1min

#startTraining  <- "2013-05-29 02:00:00"
#endTraining    <- "2013-05-30 18:00:00"

# I use "/" you used "::" - dont know if important
#rangeTraining  <- paste(startTraining,"/",endTraining,sep ="")

# I dont have your above sample window, so I use this time window
trainsym1   <- sym1[,6]
trainsym1["2011-12-22 02:00:00/2011-12-22 02:05:00"]

# I dont understand yet, what this line does - but it runs without error
pdtsym1 <- diff(trainsym1)[-1]
Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).

Reply With Quote
The following user says Thank You to puma for this post:
 
  #8 (permalink)
Elite Member
tel aviv
 
Futures Experience: Advanced
Platform: Multicharts, SC
Favorite Futures: es
 
Posts: 34 since Jun 2009
Thanks: 4 given, 1 received

nice....
yet when i run it i get this:

head(trainsym1)
Close
2011-12-22 5820.5
2011-12-22 5817.0
2011-12-22 5819.0
2011-12-22 5821.0
2011-12-22 5822.5
2011-12-22 5828.0

for some reasone the minutes are not shown....

Reply With Quote
 
  #9 (permalink)
Elite Member
Philadelphia + NJ/US
 
Futures Experience: Beginner
Platform: quantstrat
Favorite Futures: ETFs
 
Posts: 52 since Aug 2014
Thanks: 4 given, 39 received

In RStudio, type ?strptime

You may very well have a formatting issue. Be sure you read that help file thoroughly.

Reply With Quote
The following user says Thank You to IlyaKipnis for this post:
 
  #10 (permalink)
Elite Member
tel aviv
 
Futures Experience: Advanced
Platform: Multicharts, SC
Favorite Futures: es
 
Posts: 34 since Jun 2009
Thanks: 4 given, 1 received


as wrote before when i use poma's code i get a bad result
but when i use this code it's ok...

 
Code
SYM1min1_read_from_file <-read.csv("XG#-1min 22122011-10102014 BarData.txt", header=TRUE)
colClasses=c("Date","character","numeric","numeric","numeric","numeric","numeric","numeric","numeric","numeric"))
SYM1min1_read_from_file$DateTime <- as.POSIXct(paste(SYM1min1_read_from_file$Date, SYM1min1_read_from_file$Time), format="%Y/%m/%d %H:%M:%S") 
SYM1min1_read_from_file$Date <- as.Date(SYM1min1_read_from_file$Date, "%Y/%m/%d")
SYM1min1_read_from_file <- SYM1min1_read_from_file[ ,c(11,1:10)]
SYM1min1_read_from_file[,2] <- NULL
SYM1min1_read_from_file[,2] <- NULL
 
Code
head(SYM1min1_read_from_file)

Quoting 
DateTime Open High Low Close Volume NumberOfTrades BidVolume AskVolume
1 2011-12-22 02:00:00 5805.5 5820.5 5804.0 5820.5 253 96 161 71
2 2011-12-22 02:01:00 5819.0 5820.0 5813.0 5817.0 77 57 43 23
3 2011-12-22 02:02:00 5816.5 5820.0 5816.0 5819.0 30 22 9 14
4 2011-12-22 02:03:00 5818.5 5822.0 5818.5 5821.0 32 30 6 19
5 2011-12-22 02:04:00 5821.5 5825.0 5821.0 5822.5 85 44 45 34
6 2011-12-22 02:05:00 5822.5 5828.0 5821.5 5828.0 51 36 22 20

but if i use this code than the
 
Code
 pdtsym1 <- diff(trainsym1)[-1]
isn't working...

so or i use puma's code and get an answer but can't view the date time or i use my format and get a view but not an answer

Reply With Quote

Reply



futures io > > > > R newbee q.

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
few GOM (ladder/recording) q. for newbee giladbi The Elite Circle 2 December 21st, 2011 06:56 PM


All times are GMT -4. The time now is 07:46 PM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts
Page generated 2017-12-17 in 0.11 seconds with 20 queries on phoenix via your IP 54.163.209.109