R Volume Profile, Volume at Price - Matlab, R project and Python | futures io social day trading
futures io futures trading


R Volume Profile, Volume at Price
Updated: Views / Replies:4,332 / 11
Created: by Big Mike 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 Volume Profile, Volume at Price

  #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,354 given, 83,235 received

R Volume Profile, Volume at Price

We'll I've been trying to get R to plot a volume at price histogram. I have had limited success.

Here is the function for calculating volume at price, tested the best I could so far:

 
Code
vp <- function(symbol){
  df = data.frame(Date=index(symbol), Adjusted=symbol$Adjusted, Volume=symbol$Volume)
  dt <- as.data.table(unique(df,by=Date))
  vol <- aggregate(cbind(Volume) ~ Adjusted, sum, data=dt)
  vol <- data.frame(vol$Volume, vol$Adjusted)
  hist(vol)
  return(vol)
}
Produces:

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


A quick glance seems to indicate that the profile is shaped roughly correct, with most of the volume taking place around the 30-40 price range (this is a chart of USO for the last 1910 days.

However, I cannot figure out how to rotate the histogram so the price axis is on left and the profile is drawn left-to-right. Putting the price on the left isn't the issue, it's drawing the histogram left to right instead of bottom to top.

Any assistance?

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:
 
  #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,354 given, 83,235 received


One step closer to horizontal profile. For some reason, I am having a lot of trouble getting the y axis to show the prices.

 
Code
vp2 <- function(symbol){
  df = data.frame(Date=index(symbol), Adjusted=symbol$Adjusted, Volume=symbol$Volume)
  dt <- as.data.table(unique(df,by=Date))
  vol <- aggregate(cbind(Volume) ~ Adjusted, sum, data=dt)
  hmatrix <- as.matrix(vol$Volume)
  par(bg=NA)
  colnamesbarplot <- c("Adjusted","Volume")
  options(scipen=50,digits=10)
  barplot(hmatrix,beside=TRUE,horiz=TRUE,axes=TRUE,legend.text=TRUE,xlab="Volume",ylab="Price")
  return(vol)
}
Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


Any help is much appreciated.

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
 
  #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,354 given, 83,235 received

Tried it on a small dataseries as well (9 points) just to make sure. No joy.

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


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
 
  #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,354 given, 83,235 received

Dun dun duuuunnnnnnn

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


More work, but getting closer...

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,354 given, 83,235 received

100,000 tick sampling from the ES (older date), aggregated into a volume profile.

I need to do some testing on this data to make sure the calculations are right.

Also, it is painfully slow. The issue seems to be the creation of the data frame with the data, and not anything else. I will look into that more.

 
Code
> vpticks(ES)
      last lastsize
1  1400.50      343
2  1400.75     4180
3  1401.00    14457
4  1401.25    28990
5  1401.50    21590
6  1401.75    10856
7  1402.00    11574
8  1402.25    12364
9  1402.50    15770
10 1402.75    20707
11 1403.00    32397
12 1403.25    19562
13 1403.50    13850
14 1403.75    13009
15 1404.00    16513
16 1404.25    12641
17 1404.50     7146
18 1404.75     3277
19 1405.00     5616
20 1405.25     4873
21 1405.50    12408
22 1405.75     7768
23 1406.00    13534
24 1406.25    13380
25 1406.50    11146
26 1406.75     2027
27 1407.00       66
28 1407.50      223
29 1407.75     4552
30 1408.00     6816
31 1408.25     8289
32 1408.50     4048
33 1408.75     8062
34 1409.00     4240
35 1409.25     4024
36 1409.50     3027
37 1409.75     3355
38 1410.00      996
Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


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:
 
  #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,354 given, 83,235 received

I just did a quick basic test, with the idea of using MySQL to aggregate the ticks before spitting out the completed data to R, like so:

 
Code
      last lastsize
1  1400.50      343
2  1400.75     4180
3  1401.00    14457
4  1401.25    28990
5  1401.50    21590
6  1401.75    10856
7  1402.00    11574
8  1402.25    12364
9  1402.50    15770
10 1402.75    20707
11 1403.00    32397
12 1403.25    19562
13 1403.50    13850
14 1403.75    13009
15 1404.00    16513
16 1404.25    12641
17 1404.50     7146
18 1404.75     3277
19 1405.00     5616
20 1405.25     4873
So instead of millions or hundreds of millions of ticks going to R and being loaded into a data frame (which is what is so slow), I could crunch it in SQL and just send back a very short list of maybe 1000-2000 data points even for a year long pull.

The wrench in this plan, however, was my planned migration away from MySQL for the actual raw tick data. I was going to just store the data itself in binary format (ie HDF5) and just a single locator record in MySQL per day per ticker to point to the binary file and cover basic identifying info.

If I go that route, it would mean I would be back to having to process all the data 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
 
  #8 (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,354 given, 83,235 received

Happy to report I solved the time problem. I realized I was still using XTS instead of Data Frame. I eliminated that, so now I can create the profile instantly. Obviously still learning my way around R...

I ran a volume profile on 10 million ticks at once in 15 seconds. Not a speed demon but good enough.

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:
 
  #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,354 given, 83,235 received

Attached are functions for returning a Volume Profile based on tick data and based on minute (less accurate) data.

> vp <- calcVPOHLCV("@ES#","2013-11-26 09:30:00","2013-11-26 16:15:00",0.25,"minutes")

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


You can find the VPOC by doing:

> which(vp == max(vp), arr.ind=TRUE)
row col
[1,] 10 2

> vp[10,]
Mean Volume
10 1802 135025

Then for tick data:

> vp <- calcVPTicks("@ES#","2013-11-26 09:30:00","2013-11-26 16:15:00",0.25,"ticks")

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


Again, VPOC:

> which(vp == max(vp), arr.ind=TRUE)
row col
[1,] 15 2

> vp[15,]
Last LastSize
15 1802.25 23280

My functions query my database for the input data. Modify accordingly for your input data. Here is a sample of my tick database for reference:

 
Code
MariaDB [ticks]> SELECT * FROM `@ES#` WHERE `Date` >= '2013-11-26 09:30:00' AND `Date` <= '2013-11-26 16:15:00' order by 1 limit 10;
+-------------------------+------------+----------+------------+------------+---------+--------------+-------------------+-----------------+
| Date                    | Last       | LastSize | Bid        | Ask        | TickID  | BasisForLast | TradeMarketCenter | TradeConditions |
+-------------------------+------------+----------+------------+------------+---------+--------------+-------------------+-----------------+
| 2013-11-26 09:30:00.006 | 1802.25000 |        3 | 1802.00000 | 1802.25000 | 2647248 | C            |                43 | 01              |
| 2013-11-26 09:30:00.007 | 1802.25000 |        6 | 1802.00000 | 1802.25000 | 2647276 | C            |                43 | 01              |
| 2013-11-26 09:30:00.009 | 1802.25000 |        6 | 1802.00000 | 1802.25000 | 2647299 | C            |                43 | 01              |
| 2013-11-26 09:30:00.010 | 1802.25000 |      116 | 1802.00000 | 1802.25000 | 2647301 | C            |                43 | 01              |
| 2013-11-26 09:30:00.011 | 1802.25000 |        1 | 1802.00000 | 1802.25000 | 2647305 | C            |                43 | 01              |
| 2013-11-26 09:30:00.013 | 1802.00000 |        1 | 1802.00000 | 1802.25000 | 2647326 | C            |                43 | 01              |
| 2013-11-26 09:30:00.019 | 1802.00000 |        4 | 1802.00000 | 1802.25000 | 2647344 | C            |                43 | 01              |
| 2013-11-26 09:30:00.020 | 1802.25000 |        1 | 1802.00000 | 1802.25000 | 2647385 | C            |                43 | 01              |
| 2013-11-26 09:30:00.021 | 1802.25000 |        2 | 1802.00000 | 1802.25000 | 2647416 | C            |                43 | 01              |
| 2013-11-26 09:30:00.022 | 1802.25000 |        3 | 1802.25000 | 1802.50000 | 2647439 | C            |                43 | 01              |
+-------------------------+------------+----------+------------+------------+---------+--------------+-------------------+-----------------+
10 rows in set (0.00 sec)
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.

Attached Files
Register to download File Type: r R-VolumeProfile.R (1.6 KB, 144 views)
Reply With Quote
The following 14 users say Thank You to Big Mike for this post:
 
  #10 (permalink)
Elite Member
Stockholm
 
Futures Experience: Advanced
Platform: NinjaTrader,Sierra Chart, Python
Broker/Data: IB
Favorite Futures: ES & Stocks
 
Posts: 86 since Apr 2013
Thanks: 80 given, 71 received



Big Mike View Post
Attached are functions for returning a Volume Profile based on tick data and based on minute (less accurate) data.

> vp <- calcVPOHLCV("@ES#","2013-11-26 09:30:00","2013-11-26 16:15:00",0.25,"minutes")

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


You can find the VPOC by doing:

> which(vp == max(vp), arr.ind=TRUE)
row col
[1,] 10 2

> vp[10,]
Mean Volume
10 1802 135025

Then for tick data:

> vp <- calcVPTicks("@ES#","2013-11-26 09:30:00","2013-11-26 16:15:00",0.25,"ticks")

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


Again, VPOC:

> which(vp == max(vp), arr.ind=TRUE)
row col
[1,] 15 2

> vp[15,]
Last LastSize
15 1802.25 23280

My functions query my database for the input data. Modify accordingly for your input data. Here is a sample of my tick database for reference:

 
Code
MariaDB [ticks]> SELECT * FROM `@ES#` WHERE `Date` >= '2013-11-26 09:30:00' AND `Date` <= '2013-11-26 16:15:00' order by 1 limit 10;
+-------------------------+------------+----------+------------+------------+---------+--------------+-------------------+-----------------+
| Date                    | Last       | LastSize | Bid        | Ask        | TickID  | BasisForLast | TradeMarketCenter | TradeConditions |
+-------------------------+------------+----------+------------+------------+---------+--------------+-------------------+-----------------+
| 2013-11-26 09:30:00.006 | 1802.25000 |        3 | 1802.00000 | 1802.25000 | 2647248 | C            |                43 | 01              |
| 2013-11-26 09:30:00.007 | 1802.25000 |        6 | 1802.00000 | 1802.25000 | 2647276 | C            |                43 | 01              |
| 2013-11-26 09:30:00.009 | 1802.25000 |        6 | 1802.00000 | 1802.25000 | 2647299 | C            |                43 | 01              |
| 2013-11-26 09:30:00.010 | 1802.25000 |      116 | 1802.00000 | 1802.25000 | 2647301 | C            |                43 | 01              |
| 2013-11-26 09:30:00.011 | 1802.25000 |        1 | 1802.00000 | 1802.25000 | 2647305 | C            |                43 | 01              |
| 2013-11-26 09:30:00.013 | 1802.00000 |        1 | 1802.00000 | 1802.25000 | 2647326 | C            |                43 | 01              |
| 2013-11-26 09:30:00.019 | 1802.00000 |        4 | 1802.00000 | 1802.25000 | 2647344 | C            |                43 | 01              |
| 2013-11-26 09:30:00.020 | 1802.25000 |        1 | 1802.00000 | 1802.25000 | 2647385 | C            |                43 | 01              |
| 2013-11-26 09:30:00.021 | 1802.25000 |        2 | 1802.00000 | 1802.25000 | 2647416 | C            |                43 | 01              |
| 2013-11-26 09:30:00.022 | 1802.25000 |        3 | 1802.25000 | 1802.50000 | 2647439 | C            |                43 | 01              |
+-------------------------+------------+----------+------------+------------+---------+--------------+-------------------+-----------------+
10 rows in set (0.00 sec)
Mike

@Big Mike,

Just curious. Have you been able to integrate this volume profile to a chart?

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

Reply



futures io > > > > R Volume Profile, Volume at Price

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
Volume Profile/Market Profile Snapshot Indicator djkiwi The Elite Circle 63 March 4th, 2015 01:25 AM
TOS Monkey Bars (Mkt Profile) & Volume Profile TonyB ThinkOrSwim 39 November 29th, 2013 11:13 AM
Possible Volume Delta, CD, Volume Profile in NT8, vs MC8.5 ilikeread NinjaTrader 9 April 2nd, 2013 02:54 PM
Do you use Market Profile or Volume Profile? Big Mike Traders Hideout 25 December 8th, 2012 02:05 AM
Best Platform for Volume Profile & Volume Delta Papa Lazarou Platforms and Indicators 2 October 11th, 2012 05:16 PM


All times are GMT -4. The time now is 11:03 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-16 in 0.18 seconds with 20 queries on phoenix via your IP 54.226.34.209