Welcome to the Traders Laboratory Forums.
Market Profile Are you a market profile trader? Post here.

Reply
Old 08-21-2007, 08:50 AM   #65

BlowFish's Avatar

Join Date: Mar 2007
Location: In Da House
Posts: 3,292
Ignore this user

Thanks: 129
Thanked 1,054 Times in 702 Posts

Re: Trading with Market Statistics. IV Standard Deviation

Thanks, I figured that was the case just wanted to be sure. I have used and alternate algorithm from the signal processing world. I'll post in DBtinas thread but would welcome your expert opinion. It has a couple of advantages.

Cheers,
Nick.
BlowFish is offline  
Reply With Quote
Old 08-22-2007, 11:32 AM   #66

BlowFish's Avatar

Join Date: Mar 2007
Location: In Da House
Posts: 3,292
Ignore this user

Thanks: 129
Thanked 1,054 Times in 702 Posts

Re: Trading with Market Statistics. IV Standard Deviation

OK I've been tearing my hair out with this. Basically I coded all 4 different text book algorithms for calculating Variance. See

http://en.wikipedia.org/wiki/Algorit...ating_variance

I added in the volume weighting (using a couple of methods) but could make none match exactly with method one. I hesitate to say this but I wonder if multiplying the squares by the barvolume/total sample volume is mathematically 'valid'? The more pressing question is should the ratio Bar Vol/Tot Vol use the complete sample size volume for its calculation I guess the answer is yes again. Does it make sense (math wise) to multiply the Square by price too?

I favour the last algorithm however the bands seem slightly narrower than looping through the sample each time. X is the price and mean is the VWAP which plots perfectly.

n = 0
mean = 0
S = 0

foreach x in data:...//i.e each time we get a new bar
..n = n + 1
..delta = x - mean
..mean = mean + delta * Weight
..S = S + delta*(x - mean) ........... // Note This expression uses the new value of mean
end for

variance = S/(n - 1)

Anyone have any ideas? BTW I have lots of great code but am loath to post it until I resolve this issue. BTW above Weight is Volume/TotalVolume. BUT Total Volume is the total for the series to that point. I am convinced if it is mathematically valid there must be a way to calculate variance correctly as each bar arrives without scaning the whole series. I can do that for the VWAP and a regular SD its just the weighting that causes issues.

Cheers,
Nick.

Cheers.
BlowFish is offline  
Reply With Quote
Old 08-22-2007, 12:26 PM   #67

jperl's Avatar

Join Date: Sep 2006
Location: Rochester,NY
Posts: 359
Ignore this user

Thanks: 2
Thanked 362 Times in 74 Posts

Re: Trading with Market Statistics. IV Standard Deviation

Quote:
Originally Posted by BlowFish »
I hesitate to say this but I wonder if multiplying the squares by the barvolume/total sample volume is mathematically 'valid'?
If you want to weight the variance computation by the volume, that's exactly what you would do as described in Part IV.
Think of it this way. A 10 contract trade can be thought of as ten 1-contract trades. To compute the variance you would have to include all 10 contract trades in the variance computation. That's identical to multiplying the square by 10.


Quote:
Originally Posted by BlowFish »
The more pressing question is should the ratio Bar Vol/Tot Vol use the complete sample size volume for its calculation I guess the answer is yes again.
correct

Quote:
Originally Posted by BlowFish »
Does it make sense (math wise) to multiply the Square by price too?
no
__________________
JERRY

---I'm going to trade til I'm 100, or die trying----
jperl is offline  
Reply With Quote
Old 08-22-2007, 12:55 PM   #68

BlowFish's Avatar

Join Date: Mar 2007
Location: In Da House
Posts: 3,292
Ignore this user

Thanks: 129
Thanked 1,054 Times in 702 Posts

Re: Trading with Market Statistics. IV Standard Deviation

Hi jerry,

The last question was meant to be "does it make sense to multiply the square by volume as well". Multiplying the price by normalised volume makes sense as you illustrated above it is the whole basis for the VWAP. You can see what it actually is and why its done. Multiplying the square by the normalised volume I can't get my head round. The square is just an intermediate number used in the calculation. In fact if you are multiplying the sum by vol and the sum of the squares when you take the difference they largely cancel out (but not completely). Why not divide the sum by normalised volume or multiply and then square?

The other thing is that all of the ways of calculating variance (except just re totalling the series when you get a new data point) seem to produce a slightly different (but consistent result). I presume there are proofs for all these formula adding in the weighting seems to break them all. Unless I am doing it wrong which is highly likely.

Still kinda tearing my hair out.

EDIT: Another thought wherever you normalise price with the VWAP (Price-VWAP) You are taking into account the volume as it is already factored into the VWAP. I wish my maths was better to actually work through the proofs.

Last edited by BlowFish; 08-22-2007 at 01:08 PM.
BlowFish is offline  
Reply With Quote
Old 08-22-2007, 03:45 PM   #69

jperl's Avatar

Join Date: Sep 2006
Location: Rochester,NY
Posts: 359
Ignore this user

Thanks: 2
Thanked 362 Times in 74 Posts

Re: Trading with Market Statistics. IV Standard Deviation

Quote:
Originally Posted by BlowFish »
Hi jerry,

Multiplying the square by the normalised volume I can't get my head round. The square is just an intermediate number used in the calculation. In fact if you are multiplying the sum by vol and the sum of the squares when you take the difference they largely cancel out (but not completely). Why not divide the sum by normalised volume or multiply and then square?
I looked at some of those algorithms. With an unweighted variance, they are simple. The computation with a weighted variance is a messy business and not worth the effort. I don't think they will improve computation speed.
__________________
JERRY

---I'm going to trade til I'm 100, or die trying----
jperl is offline  
Reply With Quote
Old 08-22-2007, 04:22 PM   #70

BlowFish's Avatar

Join Date: Mar 2007
Location: In Da House
Posts: 3,292
Ignore this user

Thanks: 129
Thanked 1,054 Times in 702 Posts

Re: Trading with Market Statistics. IV Standard Deviation

Jerry,

Thanks for your indulgence on this. I appreciate it. On the plus side I understand a lot more about the math behind things! (Clearly still not enough). I am hunting for an arithmetician as I type.

Let me just say how I got started on this. It was precisely because of performance issues. Basically using the code by Dbtina and Nick the code was too slow when loading on a tick chart. It takes about 10 minutes to process a few days of ticks. Once running its OK but for every tick it needs to process every bar back to the start of the day. Having re-done the PvP code (that used to have the same speed issues) and getting pretty massive performance gains, I figured I would try this. A lot tougher!

Actually on YM the various results are close enough and I think the difference can be attributed to rounding errors (again the non-iterative code is superior in this respect). I'll post a couple of screens and challenge anyone to detect which is which. I would have said I was done...except....

The DAX subjectively looks 'different'. The lines track but sometimes end up a handful of ticks apart. Its perplexing.

I think I'll go ahead and 'publish' I reckon its solid code and there are a couple of neat bits.

Next thing a super efficient histogram (again the plan is to make it tick precise and perform OK) I have a couple of ideas how to approach that without iteration too.

So which is the real SD blue plot or yellow plot? Actually I think I can spot them apart but i have been staring at these things for 2 days now.
Attached Thumbnails
Trading with Market Statistics. IV Standard Deviation-sdbands3.png   Trading with Market Statistics. IV Standard Deviation-methods.png   Trading with Market Statistics. IV Standard Deviation-methods1.png  
BlowFish is offline  
Reply With Quote
Old 08-22-2007, 05:17 PM   #71

BlowFish's Avatar

Join Date: Mar 2007
Location: In Da House
Posts: 3,292
Ignore this user

Thanks: 129
Thanked 1,054 Times in 702 Posts

Re: Trading with Market Statistics. IV Standard Deviation

Here is the dax seems the difference is more pronounced. (gives the game away) I am not sure why.
Attached Thumbnails
Trading with Market Statistics. IV Standard Deviation-methodsdax.png  
BlowFish is offline  
Reply With Quote
Old 08-22-2007, 09:17 PM   #72

Join Date: Mar 2007
Location: OKC
Posts: 61
Ignore this user

Thanks: 0
Thanked 36 Times in 10 Posts

Re: Trading with Market Statistics. IV Standard Deviation

Blowfish,

How did you get the volume histogram...is that multicharts or something else?

dbntina
dbntina is offline  
Reply With Quote

Reply

Thread Tools
Display Modes Help Others By Rating This Thread
Help Others By Rating This Thread:


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trading With Market Statistics.II The Volume Weighted Average Price (VWAP). jperl Market Profile 65 02-25-2012 04:02 PM
Trading With Market Statistics I. Volume Histogram jperl Market Profile 36 02-21-2012 06:23 PM
Trading with Market Statistics III. Basics of VWAP Trading jperl Market Profile 73 01-03-2012 08:06 AM
Standard deviations & Odds rayk Market Profile 2 10-07-2006 11:13 AM
Trading in a Dull Market Soultrader Technical Analysis 0 09-06-2006 11:44 AM

All times are GMT -4. The time now is 03:43 PM.
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
CS to VB integration by DeskLancer
©2006-2011 Traders Laboratory, All Rights Reserved.