R parallelism and multithreading - Matlab, R project and Python | futures io social day trading
futures io futures trading


R parallelism and multithreading
Updated: Views / Replies:1,873 / 11
Created: by Big Mike Attachments:0

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
 
Thread Tools Search this Thread
 

R parallelism and multithreading

  #1 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,240 since Jun 2009
Thanks: 29,356 given, 83,237 received

R parallelism and multithreading

CRAN Task View: High-Performance and Parallel Computing with R

Still new to R, and trying to understand how to incorporate parallelism and multithreading into my code.

If anyone has something to contribute please do. I will keep researching more.

Mike

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
The following 2 users say Thank You to Big Mike for this post:
 
  #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)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,240 since Jun 2009
Thanks: 29,356 given, 83,237 received


R/parallel : An easy-to-use toolkit for Parallel Computing in R

Mike

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
The following user says Thank You to Big Mike for this post:
 
  #4 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,240 since Jun 2009
Thanks: 29,356 given, 83,237 received

Tutorial: Parallel programming with foreach

foreach | inside-R | A Community Site for R

Mike

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
The following user says Thank You to Big Mike for this post:
 
  #5 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,240 since Jun 2009
Thanks: 29,356 given, 83,237 received

Here is a multicore example:

Test Drive of Parallel Computing with R | Yet Another Blog in Statistical Computing

 
Code
n <- 20000000
set.seed(2013)
df <- data.frame(id = sample(20, n, replace = TRUE), x = rnorm(n), y = runif(n), z = rpois(n, 1))
 
library(rbenchmark)
benchmark(replications = 5, order = "user.self",
  LAPPLY = {
  cat('LAPPLY...\n')
  df1 <- data.frame(lapply(split(df[-1], df[1]), colMeans))
  },
  SNOW = {
  library(snow)
  cat('SNOW...\n')
  cl <- makeCluster(8, type = "SOCK")
  df2 <- data.frame(parLapply(cl, split(df[-1], df[1]), colMeans))
  stopCluster(cl)
  },
  MULTICORE = {
  cat('MULTICORE...\n')
  library(multicore)
  df3 <- data.frame(mclapply(split(df[-1], df[1]), colMeans, mc.cores = 8))
  }
)
 
library(compare)
all.equal(df1, df2)
all.equal(df1, df3)
However, my results do not match his. I am seeing only single core usage with each method, so 25% utilization on this particular i5-3470 system I am using for this project.

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


Any idea where I went wrong?

 
Code
> version
               _                           
platform       x86_64-pc-linux-gnu         
arch           x86_64                      
os             linux-gnu                   
system         x86_64, linux-gnu           
status                                     
major          3                           
minor          0.2                         
year           2013                        
month          09                          
day            25                          
svn rev        63987                       
language       R                           
version.string R version 3.0.2 (2013-09-25)
nickname       Frisbee Sailing   

> packageVersion("rbenchmark")
[1] ‘1.0.0’
> packageVersion("snow")
[1] ‘0.3.13’
> packageVersion("multicore")
[1] ‘0.1.7’
Mike

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
The following user says Thank You to Big Mike for this post:
 
  #6 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,240 since Jun 2009
Thanks: 29,356 given, 83,237 received

I found another simpler example

 
Code
unlist(mclapply(1:32, function(x) sum(rnorm(1e7))))
But, unfortunately this still is limited to 1 core even though it has spawned subprocesses. I am not understanding why this isn't working...

Mike

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
 
  #7 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,240 since Jun 2009
Thanks: 29,356 given, 83,237 received

I ran it outside of RStudio and this time was able to see it was throwing exceptions, so... not sure if this is because I am running R 3.0 or because of the multicore package.

Mike

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
The following user says Thank You to Big Mike for this post:
 
  #8 (permalink)
Elite Member
Cary, NC
 
Futures Experience: Advanced
Platform: MC, NT, Python, R
Broker/Data: FXCM, IB, Oanda, IQFeed
Favorite Futures: 6E, CL, EUR/USD
 
Fu510n's Avatar
 
Posts: 96 since Oct 2009
Thanks: 729 given, 81 received


Big Mike View Post
I ran it outside of RStudio and this time was able to see it was throwing exceptions, so... not sure if this is because I am running R 3.0 or because of the multicore package.

Mike

Mike...

Have you tried one of the newer R distributions and seen better results (or for that matter, ever resolved the parallelism/threading issues you seemed to be having)? From what I've read, it sounds like separate instances of an "R service" would need to be started with work distributed to each; i.e. specify a date range to run TA/trades against with results aggregated across the multiple instances at the end of the test run. I haven't done much of a deep dive yet as I'm only now just taking the time to learn R but as you've experienced, it's a journey worth pursuing .

-Guy

Reply With Quote
 
  #9 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,240 since Jun 2009
Thanks: 29,356 given, 83,237 received


Fu510n View Post
Mike...

Have you tried one of the newer R distributions and seen better results (or for that matter, ever resolved the parallelism/threading issues you seemed to be having)? From what I've read, it sounds like separate instances of an "R service" would need to be started with work distributed to each; i.e. specify a date range to run TA/trades against with results aggregated across the multiple instances at the end of the test run. I haven't done much of a deep dive yet as I'm only now just taking the time to learn R but as you've experienced, it's a journey worth pursuing .

-Guy

I'm using the latest build but haven't really noticed dramatic speed differences.

I resolved the threading issues a long long time ago, it was a bad R install and was corrected with a new deployment.

Sent from my phone

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
The following user says Thank You to Big Mike for this post:
 
  #10 (permalink)
Elite Member
san francisco california USA
 
Futures Experience: Intermediate
Platform: Custom
Favorite Futures: emini
 
Posts: 5 since Jan 2016
Thanks: 2 given, 4 received


I know I'm a bit late to the party here, and all of this you may already know, but FWIW.

The thing about R is that it was never intended to be multi-core; this must be kept in mind whenever you are thinking about how to make something run faster.

Another aspect, and this is true of any language, is that the cleanest, most stable use cases of multi-threading are where the code was written from the ground up with multi-core top of mind. Not saying this is always the case, but I know from having taken both the fresh-start and retrofit path, the former is much easier, reliable, and performant.

Also, it will often be the case that the time spent loading the parallel code and data eclipses any time savings from making it parallel. The only way to know this for sure is empirically, but if the work in each thread is fairly small, more time will be spent monitoring the threads than getting anything productive out of them. Related to this is knowing whether the cpu is the bottleneck, and not i/o or network latency.

For my own needs, writing the resource-intensive stuff in C/C++ has been the right solution. Dealing with 20 years of 1 minute data is a challenge, but it can be done.

Reply With Quote
The following user says Thank You to Quantifiably for this post:

Reply



futures io > > > > R parallelism and multithreading

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
     


All times are GMT -4. The time now is 09:01 AM.

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-18 in 0.13 seconds with 18 queries on phoenix via your IP 107.20.115.174