Open Side Menu Go to the Top
Register
help:-)-Need to rework a spreadsheet if Poss help:-)-Need to rework a spreadsheet if Poss

11-04-2011 , 10:24 AM
Hello All.
1st post ever here, so please be gentle with me. :-)
1st off; a couple of home truths. I'm not a card player, the only card
game I can play is snap! & I'm not too good at that either :-)
2. I've been reading a few posts here on the forum, namely regarding probability,
here;
http://forumserver.twoplustwo.com/25...oblem-1053105/
and here was a good 1 with a spreadsheet link;
http://wizardofvegas.com/forum/quest...rd-correction/

I read/look at what you guys (& gals) create formula wise and it's just above me.
My counting ability is excellent whilst drinking & working out who's round it is next,, but that's where it ends. :-)
OK,, purpose of my post.
I really really could do with some help here from some of you clever guys as 'Houston, we have a problem.'
(Well, I have a problem). I'll explain.
I really wanted to create a spreadsheet regarding losing streaks. IE,, if there were say 100 run size and I wanted to know what was the probability of getting say 5 losers in a row with a winning % of 65%. (That kind of thing).
Originally I saw a post a few yrs ago on a forex (Trading) website, link here;
http://www.forexfactory.com/showthre...t=12798&page=4
If you scroll down you will see a table made by a guy called 'Hanover.'

Anyway, for some reason,, it just didn't seem quite right to me.
I found an online losing streak calculator here also which seemed really good;
http://www.sbrforum.com/betting-tool...ak-calculator/
& I really wanted to create this kind of thing in excel, but this would have been hard for me as if someone mentions VB in excel I still think this means 'Very Basic' (Me),, my excel skills stop at formatting cells I'm afraid.

So, I put a post up on a excel forum sometime ago,, and a very kind guy who is pretty dam good in excel created something.
His spreadsheet is here (I put it in my dropbox folder).
http://dl.dropbox.com/u/16052166/1-P...es-working.xls
It's really really good. I think he got the formula from a link here;
http://arxiv.org/PS_cache/math/pdf/0511/0511652v1.pdf
It's a paper called, 'The Probability of a Run- By Mark B. Villarino.'

Please; do have a good look at it, it really is a great sheet.
Anyway,,, I thought that was it,,,, but I wanted to see what happened if the spreadsheet was altered to show (not 100 runs,, but up to 1,000).
I managed to alter the 'MC Model' Tab to reflect this.
Thing is,,, the results it now returns aren't correct. :-(
Which probably mean the 100 sample size returns (That look correct) probably aren't either :-(
I did try to see if it's creator could alter it,,, but this was my reply;
John,
The problem is in this routine (slightly modified from the version you have, but to no avail):
Code:
Function Beta(nToss As Long, run As Long, pHeads As Double) As Double
    ' shg 2011
    ' http://arxiv.org/PS_cache/math/pdf/0511/0511652v1.pdf
    Dim k      As Double
    Dim l           As Long
 
    k = (1 - pHeads) * pHeads ^ run
 
    With WorksheetFunction
        For l = nToss \ (run + 1) To 0 Step -1
            Beta = Beta + .Combin(nToss - l * run, l) * (-k) ^ l
        Next l
    End With
End Function
When nToss is large (>300), the value Beta diverges, alternating between positive and negative values as
the loop iterates. I don't see why after a quick look, and don't have more time to spend on it.
=================================================
I really really really need some help here guys (& gals).
It would be such a shame to leave this sheet broken as it is, it's so good; just needs some TLC :-)
I really don't have a clue how to change this myself.
I've read some posts buy some of your contributors;

masque de Z (Had a link to this PDF, 'A Summary Of Recursion Solving Techniques.' Maybe this might help? Maybe I'm way off the mark,,, just typing aloud now :-)
BruceZ (Seems a special kind of clever Bloke) :-)
Aaron Brown (I like his hat) :-)
etc,, and just even reading how they post,, in formula language, I just honestly don't understand it.
(Was no good at maths at school, loved cooking at school though;just because I loved food so much):-)

So,, my question is; is there anybody here that can re breath fire back into this spreadsheet?
I'd love to get this working properly.
If I could, I would, but I can't so hence that's why I'm here posting asking for help.
Need a formula/VB wizard! :-)

I hope all the above makes sense.
Many thanks for all your time reading this (If you've got this far),
& I hope somebody can take a look at this for me, it is a great sheet (If it works) :-)
Many thanks to everyone
TheGhost
help:-)-Need to rework a spreadsheet if Poss Quote
11-04-2011 , 11:06 AM
If you can convert it, here is the algorithm for streaks done in perl (from BruceZ):

Code:
###### Perl Code #####


$p = 1/2083; # Probability of event
$m = 2; # Length of streak
$n = 1000000; # Length of series

print "calculating....\n";

$iter = int( $n/($m+1) ); #ceiling( ($n-$m)/($m+1) )
$last = $n - ($iter-1)*($m+1) - $m - 1;

$c = (1-$p)*$p**$m;

$prob[$m] = $p**$m;

for ($j = 1; $j <= $iter; $j++) {

$prob[0] = $prob[$m] + (1-$prob[0])*$c;
for ($i = 1; $i <= $m; $i++) {
$prob[$i] = $prob[$i-1] + (1-$prob[$i])*$c; 
}

}

print "Probability of ", $m, " events of probability ", $p, " in a row in ", $n, " trials = ", $prob[$last], " \nor ", 1/$prob[$last]-1, " to 1";


###### End Perl Code #####
And here is the algorithm in javascript:

Code:
function calcStreakProb(lSeries, lStreak, dProb) {
	lSeries = lSeries.replace(/,/g, "")
	lStreak = lStreak.replace(/,/g, "")
	lSeries = parseInt(lSeries);
	lStreak = parseInt(lStreak);
	if(dProb.indexOf('%') > -1) {
		dProb = dProb.replace(/%/g, '');
		dProb = parseFloat(0+dProb/100);
	} else {
		dProb = parseFloat(0+dProb);
	}
	if (dProb < 0 || dProb > 1) {
		alert("Probability must be between 0 and 1");
		return;
	}
	if (lStreak > lSeries) {
		return 0;
	}
	var dTotProb = new Array(lSeries);
	dTotProb[lStreak] = Math.pow(dProb, lStreak);
	for (var i = lStreak+1; i<= lSeries; i++) {
		dTotProb[i] = dTotProb[i-1] + Math.pow(dProb, lStreak) * (1-dProb) * (dTotProb[i-lStreak-1] != undefined ? 1-dTotProb[i-lStreak-1] : 1);
	}
	return fmtPercent(dTotProb[lSeries]);
It's pretty easy to just install perl on your PC and use the first script.
help:-)-Need to rework a spreadsheet if Poss Quote
11-04-2011 , 11:46 AM
Many thanks for your swift reply spadebidder,,,
I can't convert it,,, I hope somebody can implement it in the excel sheet in VB language.

The only perl I know is what you wear around your neck :-)

If there is anybody here though that can try and convert this into this spreadsheet I would be over the moon (& drunk probably).
http://dl.dropbox.com/u/16052166/1-P...es-working.xls

Again,, many thanks for your reply, great stuff.

All the best
TheGhost...
PS,,
Does this BruceZ work for NASA or something? :-)

Last edited by TheGhost007; 11-04-2011 at 11:47 AM. Reason: left out link to Spreadsheet :-(
help:-)-Need to rework a spreadsheet if Poss Quote
11-04-2011 , 01:33 PM
Quote:
Originally Posted by TheGhost007
Originally I saw a post a few yrs ago on a forex (Trading) website, link here;
http://www.forexfactory.com/showthre...t=12798&page=4
If you scroll down you will see a table made by a guy called 'Hanover.'

Anyway, for some reason,, it just didn't seem quite right to me.
I found an online losing streak calculator here also which seemed really good;
http://www.sbrforum.com/betting-tool...ak-calculator/
Both of those have errors. Here is one that I know is correct because I fixed it:

http://www.pulcinientertainment.com/...tor-enter.html


Quote:
So, I put a post up on a excel forum sometime ago,, and a very kind guy who is pretty dam good in excel created something.
His spreadsheet is here (I put it in my dropbox folder).
http://dl.dropbox.com/u/16052166/1-P...es-working.xls
It's really really good. I think he got the formula from a link here;
http://arxiv.org/PS_cache/math/pdf/0511/0511652v1.pdf
It's a paper called, 'The Probability of a Run- By Mark B. Villarino.'

Please; do have a good look at it, it really is a great sheet.
Anyway,,, I thought that was it,,,, but I wanted to see what happened if the spreadsheet was altered to show (not 100 runs,, but up to 1,000).
I managed to alter the 'MC Model' Tab to reflect this.
Thing is,,, the results it now returns aren't correct. :-(

Why do you say it isn't correct? I changed the upper limit to 1000, and I checked a few numbers in the column for 11 with my Perl script, and they were correct. To change the upper limit, click on the # Trades cell, then go to the Data->Validation menu and change the upper limit under Settings, and you can change the Error Alert message if you want. For example, for 11 in a row out of 1000 trades and probability of 50%, you should get 22%.
help:-)-Need to rework a spreadsheet if Poss Quote
11-04-2011 , 01:59 PM
Quote:
Originally Posted by BruceZ
Both of those have errors. Here is one that I know is correct because I fixed it:

http://www.pulcinientertainment.com/...tor-enter.html
That's the one I posted the javascript for, the fixed version.
help:-)-Need to rework a spreadsheet if Poss Quote
11-04-2011 , 02:48 PM
Hi BruceZ,, many thanks for your reply! :-)
& Spadebidders.

I'm not quite sure I follow this correctly,, but bear with me here.
You say, "Why do you say it isn't correct?"

Well this is the original sheet,, (with 100max)
http://dl.dropbox.com/u/16052166/1-P...es-working.xls
Yes,, it does seem to work fine,, and yes you can change as you did Cell B5 (#Trades) to 1000.
I uploaded another sheet with this in,, where I also changed the MC Model tab,, which was this sheet;
http://dl.dropbox.com/u/16052166/2-P...ot-working.xls

If you enter say 1000 trades,, there are some cells (It seems with errors?).
I'll attach a screen capture

In the shot above,, cell G11 for example,, -273%??
Surely not correct?

I did post that the guy that created this in excel said;
"When nToss is large (>300), the value Beta diverges, alternating between positive and negative values as the loop iterates. I don't see why after a quick look."

I don't understand what he means,, it's above me Bruce.
If you do try the sheet again (either) that I've posted the links to (preferably the 1000 not working sheet) and try entering say 999 as a number,, and a few more high numbers,, certain cells appear wrong.

Any ideas as to why?
I don't have the skills or knowledge to rectify it in excel.
1st off,, if these sheets are wrong,, (in certain cells showing wrong values), can anybody please explain as to why? Must be an error in the excel formula?

I hope this makes sense.
Many thanks for getting involved on this BruceZ.
Do you work for NASA?
Just wondering :-)
All the best
TheGhost

##(Just a quick note,, seeing as this is a card website, I noticed on the BBC website that Poker has really taken off the last 2 yrs,, seems we have a few good Brits on our way over the pond to take your money :-),, well, the casinos,
http://www.bbc.co.uk/news/magazine-15272675
One of the top guys there,, only 22YRs Old!!
It's called the "World Series of Poker (WSOP) held in Las Vegas."
I've never heard of it,, I'll google it now :-)
I wonder how they do,,,,,

Again, Many thanks
The Ghost
help:-)-Need to rework a spreadsheet if Poss Quote
11-04-2011 , 08:07 PM
Quote:
Originally Posted by TheGhost007
H
If you enter say 1000 trades,, there are some cells (It seems with errors?).
I'll attach a screen capture

In the shot above,, cell G11 for example,, -273%??
Surely not correct?
I see that. If you ignore all the bogus values and only use the lower values up until they become 100% (or a bogus value) then I believe that they are correct. So the bogus values should be taken to be 100%, and that would be an easy enough kludge to just make them 100% if they are out of range. I checked the top 2 valid numbers in each column (<100%), and they all agreed with my script. So I don't think that the bogus values are a huge problem.

As for why the bogus values, I'm still looking into it, but I suspect that they are caused by adding extremely large positive and negative numbers which are too close to each other to resolve, and the result is being lost. This can result in garbage. The values generated by the COMBIN function in that loop can become huge, like close to 10100. For a large enough number of trials, that will eventually overflow, but even before that happens, there can be garbage generated. I will try to confirm what is happening here, but like I said, it doesn't appear to be a critical problem for the values of interest, but it would be a good exercise to understand this and make sure that it doesn't affect other results.

What I could do is just replace their method with my own in Visual Basic. My method doesn't suffer from this problem. It only adds, never subtracts. Subtracting large numbers is not a good thing to do. I also don't use combinations, so I don't generate huge numbers that can overflow when the trials become too large. So we've uncovered a weakness with their method. Maybe that's why no one ever uses it.


Quote:
I did post that the guy that created this in excel said;
"When nToss is large (>300), the value Beta diverges, alternating between positive and negative values as the loop iterates. I don't see why after a quick look."
They are supposed to alternate sign. The method is basically inclusion-exclusion.

Last edited by BruceZ; 11-04-2011 at 10:20 PM.
help:-)-Need to rework a spreadsheet if Poss Quote
11-05-2011 , 04:46 AM
Hello Brucez!
Many thanks again for getting back to me.
8am here in UK,, just reading your reply with a mug of tea. :-)

Trying to take in all you've said here.
First off; I'm glad you can see what I mean with some errors in some cells.
I might have mentioned this before, but the person who created this spreadsheet (SHG,, a really helpful guy by the way,, a great contributor within excel) created the VB code from a PDF that was mentioned somewhere here on this forum I think,, it was this;
http://arxiv.org/PS_cache/math/pdf/0511/0511652v1.pdf
(Probability Of Run)

I'm no coder BruceZ (You've probably guessed that already) :-),, but you mention the formula using a 'COMBIN' function in the loop,,,, I take it that excel,, when it deals with extremely large numbers it can well, muck up,,, maybe round things ,, I take it this is a limitation in excel?
I'm glad you write "it doesn't appear to be a critical problem." We need to stay positive :-),,,
You said also; "What I could do is replace their method with my own in Visual Basic."
If you can do this BruceZ,,,,It would be excellent!,,, what I really would love is for this spreadsheet (Keeping the formatting as it is, so no changes visually) to,, well,,, just work 100% correctly. (So just the changes in code on the backend, I mean in VB).
So I take it it means you recoding your JAVA code to VB?,,, so it works within this spreadsheet,,, this would be the Ideal scenario. (God,, I just had to google how to spell scenario as I typed it so wrong,, thing I need to go onto black coffee, decaf of course). :-)

If you can do this BruceZ,, really,,, it really would be a perfect solution.

Just to mention Bruce,, your Java code;
(Remember,, I'm no coder please :-)
I know it is probably complicated to get this to run correctly, or shall I say to create a formula to get the desired result,, but actually there aren't that many lines of code.
(KISS) :-)
I mean I don't see huge calculations,, large strings of text,, just a few > or < signs,,I see the word 'ARRAY' only mentioned once also. Hell, I can't remember/ know exactly what an array does,, but I remember something in excel,, to enter an array I think you had to use something like CTRL/SHIFT/ENTER to get the funny looking brackets to show ,, so it is an array.

If it takes too long to explain Brucez no worries,,, but your JAVA code,,any change in PURE Laymans terms explaining what the lines of code do?
No worries if it's too time consuming,, just that,, well, to be honest I don't understand it,,, (Ignorance is bliss' spings to mind) :-)

Again, many thanks for your reply BruceZ.
If you can alter my sheet so it works with your Java Code in the VB,, rather than what's already there,,, that really would be perfect.
Many thanks BruceZ
All the best
A very Grateful
TheGhost. :-)

***Just to add,,, I will post now what my present formula is in my spreadsheet,, just in case anybody is reading this,,,and so they can see things like 'Combin' in the formula,, that you mentioned BruceZ.
Below:-spreadsheet formula returning slight errors. Thank you.
Code:
Option Explicit

Function ProbRun(n As Long, r As Long, p As Double)
    ' shg 2011
    ' http://arxiv.org/PS_cache/math/pdf/0511/0511652v1.pdf

    ' Probability of a r or more consecutive heads in n tosses
    ' of a coin having probability p of heads
    ProbRun = 1 - (Beta(n, r, p) - p ^ r * Beta(n - r, r, p))
End Function

Function Beta(n As Long, r As Long, p As Double) As Double
    ' shg 2011
    ' http://arxiv.org/PS_cache/math/pdf/0511/0511652v1.pdf

    Dim q           As Double
    Dim l           As Long
    
    q = 1 - p   ' = probability of tails

    With WorksheetFunction
        For l = 0 To n \ (r + 1)
            Beta = Beta + (-1) ^ l * .Combin(n - l * r, l) * (q * p ^ r) ^ l
        Next l
    End With
End Function

Sub MonteCarlo()
    Dim rCal        As Range    ' area to calculate on MC sheet based on # trades
    Dim rTry        As Range    ' results each trial
    Dim rInp        As Range    ' range with run calculations
    Dim rOut        As Range    ' cumulative results of trials
    Dim nTry        As Long     ' number of trials
    Dim iTry        As Long     ' index to trials

    With Application
        .Calculation = xlCalculationManual
        .ScreenUpdating = False

        nTry = Sheet1.Range("Trials").Value
        Set rCal = Sheet2.Range("rgnCalc")
        Set rInp = Sheet2.Range("rgnInp")
        Set rOut = Sheet1.Range("rgnOut")
        rOut.ClearContents

        For iTry = 1 To nTry
            rCal.Calculate
            rInp.Copy
            rOut.PasteSpecial Paste:=xlPasteValues, _
                              Operation:=xlPasteSpecialOperationAdd, _
                              Transpose:=True
        Next iTry

        Sheet1.Range("Trials").Copy
        rOut.PasteSpecial Paste:=xlPasteValues, _
                          Operation:=xlPasteSpecialOperationDivide

        .CutCopyMode = False
        .Calculation = xlCalculationAutomatic
        .ScreenUpdating = True
    End With

    Beep
End Sub
help:-)-Need to rework a spreadsheet if Poss Quote
11-05-2011 , 08:32 AM
Quote:
Originally Posted by TheGhost007
Trying to take in all you've said here.
First off; I'm glad you can see what I mean with some errors in some cells.
I might have mentioned this before, but the person who created this spreadsheet (SHG,, a really helpful guy by the way,, a great contributor within excel) created the VB code from a PDF that was mentioned somewhere here on this forum I think,, it was this;
http://arxiv.org/PS_cache/math/pdf/0511/0511652v1.pdf
(Probability Of Run)
I'm familiar with that paper. The formula is correct, but it is starting to look like it's an ill-conditioned calculation. The roundoff error is inherent to the calculation, not to Excel or VB. I can get different answers just by grouping the terms slightly differently. Perhaps it could be made to work, but it would be easier just to use my solution. My solution won't have that problem. It's also easier to understand.


Quote:
I'm no coder BruceZ (You've probably guessed that already) :-),, but you mention the formula using a 'COMBIN' function in the loop,,,, I take it that excel,, when it deals with extremely large numbers it can well, muck up,,, maybe round things ,, I take it this is a limitation in excel?
This is something you always have to watch out for, not just in Excel. I used their formula directly in Excel without using VB, and I also see bogus answers in the same places, but the bogus numbers are different than VB produces. I also see right answers most of the time.


Quote:
You said also; "What I could do is replace their method with my own in Visual Basic."
If you can do this BruceZ,,,,It would be excellent!,,, what I really would love is for this spreadsheet (Keeping the formatting as it is, so no changes visually) to,, well,,, just work 100% correctly. (So just the changes in code on the backend, I mean in VB).
There will be no visual changes or formating changes.


Quote:
So I take it it means you recoding your JAVA code to VB?
Yes, I will port my Perl script to VB.


Quote:
Hell, I can't remember/ know exactly what an array does
It's just a list of numbers.


Quote:
If it takes too long to explain Brucez no worries,,, but your JAVA code,,any change in PURE Laymans terms explaining what the lines of code do?
The main part of the javascript code is a single line in a loop. My Perl script uses the same formula, but it is slightly more complicated in order to use the shortest possible array. It is based on a simple concept which I explained in some of the links that you were reading.

Last edited by BruceZ; 11-05-2011 at 08:52 AM.
help:-)-Need to rework a spreadsheet if Poss Quote
11-05-2011 , 10:48 AM
Hi BruceZ! :-)

Many thanks for your reply.
So,, Mr. M. Villarino didn't test his PDF calculations thoroughly it seems?
I see he referenced in the bottom of his PDF that cool search engine 'Wolfram Alpha'
http://mathworld.wolfram.com/Run.html

I'm not 100% with you here BruceZ when you say, "The formula is correct, but it is starting to look like it's an ill-conditioned calculation."

You mean,,, I'm not trying to contradict you here BruceZ,,, but the formula isn't/can't be correct, or there wouldn't be errors?
Or,,, are you trying to say,, mathematically the formula is correct,, but the Software,, IE Excel,, or different coding scripts interpret his mathematical formula slightly differently,,,a bit like making a cake? (:-))
I mean,,, 3 people can have the same ingredients,,but,, if they add things in the wrong order, they could all come out differently.
So excel/perl/JAVA etc might just do the inputs slightly differently,, which causes these errors?
(My layman's metaphor with the cake,, I said before I love cooking). :-)

I'm really grateful BruceZ for your help,, at least you sound really optimistic with the outcome,, well,, actually you sound certain you can get the spreadsheet to work with your code.

I'll leave it in your hands BruceZ,, sorry I can't help in anyway,,

That said,, maybe my persistence with not letting/ wanting this spreadsheet to die has made a few people think/question some of these Probability formulas,, and how they are calculated. So,, although I don't have the answers,, I do have the questions. :-)
I'm reminded of a quote here,, not sure why;
"We cannot solve our problems with the same thinking we used when we created them."
Albert Einstein


I really really look forward to your solution BruceZ and a functional spreadsheet with no errors.

Many thanks again for all your efforts.
Best regards;
TheGhost. :-)
help:-)-Need to rework a spreadsheet if Poss Quote
11-05-2011 , 11:04 AM
Quote:
Originally Posted by TheGhost007
Hi BruceZ! :-)

Many thanks for your reply.
So,, Mr. M. Villarino didn't test his PDF calculations thoroughly it seems?
I see he referenced in the bottom of his PDF that cool search engine 'Wolfram Alpha'
http://mathworld.wolfram.com/Run.html

I'm not 100% with you here BruceZ when you say, "The formula is correct, but it is starting to look like it's an ill-conditioned calculation."

You mean,,, I'm not trying to contradict you here BruceZ,,, but the formula isn't/can't be correct, or there wouldn't be errors?
Or,,, are you trying to say,, mathematically the formula is correct,, but the Software,, IE Excel,, or different coding scripts interpret his mathematical formula slightly differently,,,a bit like making a cake? (:-))
Mathematically the formula is correct. But when you implement it on a computer, the computer has finite precision. That is, there are only so many bits that it can use to represent a number. Certain types of calculations are very prone to roundoff error which builds up as the calculation proceeds. This happens, for example, when you subtract very large numbers that are very close to each other. You can get zero when the result is not zero, or you can get whatever meaningless garbage is left over in the register. It's a big problem, and often a tricky problem to handle or even predict. Sometimes the best solution is to pick a different algorithm as is probably the case here since we have a much more robust one available.

I think the reason Excel produces different answers from VB is mainly because the VB code uses double precision. EDIT: Not true because Excel does too. They could also do things in a different order even though they appear to be exactly the same. I'm actually surprised that this is happening in VB with double precision. But the fact that I get different answers just by grouping terms slightly differently is a pretty sure sign that it's roundoff error.

Last edited by BruceZ; 11-06-2011 at 02:29 PM.
help:-)-Need to rework a spreadsheet if Poss Quote
11-05-2011 , 06:12 PM
OK, I fixed it. I ported my Perl script to VB. Just replace the functions currently called ProbRun and Beta with the following function:

Code:
Function ProbRun(n As Long, r As Long, p As Double)

' Probability of a r or more consecutive heads in n tosses
' of a coin having probability p of heads

    Dim prob(100)           As Double   'size of max r
    Dim c                   As Double
    Dim iter                As Long
    Dim last                As Long
    Dim i                   As Long
    Dim j                   As Long
    
    iter = n \ (r + 1)
    last = n - iter * (r + 1)

    c = (1 - p) * p ^ r

    prob(r) = p ^ r
    For j = 1 To iter
        prob(0) = prob(r) + (1 - prob(0)) * c
        For i = 1 To r
            prob(i) = prob(i - 1) + (1 - prob(i)) * c
        Next i
    Next j
    
    ProbRun = prob(last)
End Function

To replace it, go under Tools->Macro->Visual Basic Editor. Then replace everything from the line starting with "Function ProbRun" to the second "End Function" with the above function.

In case you ever want to add columns to compute more than 11 in a row, I set the size of the array "prob" to handle up to 100 with the statement "Dim prob(100)".

Last edited by BruceZ; 11-05-2011 at 07:03 PM.
help:-)-Need to rework a spreadsheet if Poss Quote
11-05-2011 , 06:21 PM
I think Excel only uses 15 significant figures so it's pretty quickly becomes useless for subtracting large but similar numbers.

I checked this by doing =10^15 in A1, =10^15-1 in B1, =A1-B1 in C1. It correctly gives 1. But if you change it to 10^16 and 10^16-1, it thinks the difference is 0.

Even under the assumption of 15 sig figs it gives some strange answers. For example A1 = 10^17, B1 = 10^17 - 1000, A1-B1 = 992?!? So perhaps it just goes crazy when the numbers get beyond 10^15
help:-)-Need to rework a spreadsheet if Poss Quote
11-06-2011 , 11:59 AM
Hello All,
Sorry for my late reply,,, I've just got in,,I've had to do some gardening for my mother God bless her,, what an enjoyable 3hrs & 14mins it was! :-)
(Photo link below; My handy work.
Warning: "Never buy a corner plot surrounded by trees!).
http://i.imgur.com/CYDtl.jpg

First of,,, Many thanks BruceZ.
I've done as you've said and managed to get the code in VB,,
It's working!!
I've also tried it entering #Trades up to 10,000,, and it seems to work fine with this large sample number.
Excellent BruceZ,, really really great.
I really appreciate this,, it was just to useful a sheet to give up on.
Many thanks indeed.

Just a couple of questions if I may.
1. I see Pyromantha mentions that excel seems to suffer from large calculations with powers over 15? (I'm not too sure if this is what he's saying, but I think it is,, & I'm not too sure how that would equate via a large number in cell B5) :-),,,so as an example,,,
Cell B5,, with regards to your formula BruceZ, & the table showing consecutive runs up to 11,, what would be IYO to be the max number that could be entered into cell B5?
Just as a test,, I just tried 1,000,000 and excel stalled only a few seconds,, but then the table did return results (It seems fine),,and I take it at 1,000,000 this is some really big number crunching thing going on,, but as to what the power would be? I take it by the sheer fact it sees to have worked this is under the power of 15 which Pyromantha mentioned? (Or am I way off the mark here,, and totally wrong in what I'm thinking Pyromantha is saying?) :-)

Not that in real life that this is a number (1,000,000) that would need to be entered in this spreadsheet,,,,,
I think as an absolute stupidly high number maximum for cell B5,, maybe 25,000 would never be breached.
(This I just formulated roughly/quickly in my head now by saying,,,
If a day trader (scalper) uses a certain trading strategy 100 times a day (Unlikely,, but possible),, and there were 240 trading days in 1 yr,, so,, I get 24,000,,,(100x240) he might want to ask,,
"If I use this same strategy,, what is the probability of me getting 9 losses in a row with a win rate of 70% over the course of a 1 yr period),,, & your formula actually returns a value of 28%,,, (But if his win rate rose 5% it would drop down to 7%),,, it's this kind of thing BruceZ I find interesting, & is useful I feel to know.

So to summarize the above (As I've made a short question slightly longer than it should be with my over elaborate example) :-)
What IYO is a max that your formula can handle within this spreadsheet BruceZ for cell B5?
(If this isn't an easy answer,, then is a 25,000 limit for cell B5 IYO well within its capabilities? (Seems to be).

1 other question. The run is set here to a max of 11,,, would the formula work fine if I insert a few more columns to make this go to a maximum run of 15?
Or,,, would this (Even with a max B5 input of say 25,000 be too much?),, Just an idea in my head BruceZ,, that's all,, to maybe increase the runs from 11 to 15.

Finally, maybe a question for SHG actually,, I just looked in the name manager and saw a name that was "ConZzz",,, just not sure what it is/does as it shows a value of (A lot of z's :-),,, and it says it refers to zzzz,,, etc etc)???
Just didn't know what it was/ what it does,, why so many zzz's that's all.

So, to Summarize;
Many thanks BruceZ,,,
I'm sure this will be of help to quite a few people and I'm really thankful to everybody here for getting it working.
Thanks also of course to SHG for his work on this as well.

It all started with a thought in my head and a question,, "What if?"
Funny where a 'Thought' can lead you BruceZ. :-)

Many thanks for all your time.
A very grateful.
Ghost :-)
help:-)-Need to rework a spreadsheet if Poss Quote
11-06-2011 , 12:15 PM
Quote:
Originally Posted by TheGhost007
Just a couple of questions if I may.
1. I see Pyromantha mentions that excel seems to suffer from large calculations with powers over 15? (I'm not too sure if this is what he's saying, but I think it is,, & I'm not too sure how that would equate via a large number in cell B5) :-),,,so as an example,,,
Cell B5,, with regards to your formula BruceZ, & the table showing consecutive runs up to 11,, what would be IYO to be the max number that could be entered into cell B5?
Just as a test,, I just tried 1,000,000 and excel stalled only a few seconds,, but then the table did return results (It seems fine),,and I take it at 1,000,000 this is some really big number crunching thing going on,, but as to what the power would be? I take it by the sheer fact it sees to have worked this is under the power of 15 which Pyromantha mentioned? (Or am I way off the mark here,, and totally wrong in what I'm thinking Pyromantha is saying?) :-)
The stuff that Pryromantha and I were talking about is not an issue with the new program. My algorithm doesn't subtract large numbers. You shouldn't have any issues with whatever numbers you enter in B5, other than the time it takes to run, up to the maximum value which is over 4.2 BILLION. That's limited only by the long integer format in 32 bit windows. If you have 64 bit windows, you might be able to go to over 1019, but of course a value that large would take forever to run.


Quote:
1 other question. The run is set here to a max of 11,,, would the formula work fine if I insert a few more columns to make this go to a maximum run of 15?
Or,,, would this (Even with a max B5 input of say 25,000 be too much?),, Just an idea in my head BruceZ,, that's all,, to maybe increase the runs from 11 to 15.
Yes, as I said, I set it up so that you could go up to 100 in a row with the statement "Dim prob(100)".

Last edited by BruceZ; 11-06-2011 at 02:27 PM.
help:-)-Need to rework a spreadsheet if Poss Quote
11-06-2011 , 01:34 PM
I modified my comments about the upper limits.
help:-)-Need to rework a spreadsheet if Poss Quote
11-06-2011 , 01:59 PM
Quote:
OK, I fixed it. I ported my Perl script to VB. Just replace the functions currently called ProbRun and Beta with the following function:

Code:
Function ProbRun(n As Long, r As Long, p As Double)

' Probability of a r or more consecutive heads in n tosses
' of a coin having probability p of heads

    Dim prob(100)           As Double   'size of max r
    Dim c                   As Double
    Dim iter                As Long
    Dim last                As Long
    Dim i                   As Long
    Dim j                   As Long
    
    iter = n \ (r + 1)
    last = n - iter * (r + 1)

    c = (1 - p) * p ^ r

    prob(r) = p ^ r
    For j = 1 To iter
        prob(0) = prob(r) + (1 - prob(0)) * c
        For i = 1 To r
            prob(i) = prob(i - 1) + (1 - prob(i)) * c
        Next i
    Next j
    
    ProbRun = prob(last)
End Function
Here's an interesting thing. I changed some variables from Long to Integer in an attempt to make it run faster, and it got SLOWER by about 12%. The ones I changed were r, i, and last. Perhaps the handling of Integer types has become antiquated.
help:-)-Need to rework a spreadsheet if Poss Quote
11-06-2011 , 02:18 PM
BruceZ,, Do you work for NASA?
:-)
help:-)-Need to rework a spreadsheet if Poss Quote
11-06-2011 , 02:25 PM
Quote:
Originally Posted by BruceZ
The calculation is done in VB, not Excel, so the stuff that Pryromantha and I were talking about is not an issue.
I should clarify this. With the old algorithm from the paper, both Excel and VB had roundoff problems because both use a double precision floating point word of 64 bits. The reason the new algorithm doesn't have this problem is because it doesn't generate large numbers or subtract large numbers, not because it is implemented in VB.

Last edited by BruceZ; 11-06-2011 at 02:34 PM.
help:-)-Need to rework a spreadsheet if Poss Quote
11-07-2011 , 07:28 AM
Hi BruceZ,, just a quick 1.
The paper (PDF I mentioned before;
http://arxiv.org/PS_cache/math/pdf/0511/0511652v1.pdf
It's a paper called, 'The Probability of a Run- By Mark B. Villarino.'

You said:
Code:
I'm familiar with that paper. The formula is correct, but it is starting to look
like it's an ill-conditioned calculation. The roundoff error is inherent to the calculation, not to Excel or VB.
My question is; Your formula BruceZ, is it based on this mathematical paper? Just wondered for reference. It's just that you say it's "Ill conditioned" so I was wondering there was an academic paper (Like buried deep within Google Scholar maybe) that you've derived your formula from.

Just wondered that was all. :-)
It is really a great sheet now,, I'm just reformatting now to make it stand out a bit. ;-)

Many thanks again BruceZ
TheGhost
help:-)-Need to rework a spreadsheet if Poss Quote
11-07-2011 , 09:27 AM
Actually BruceZ,, one other thing I've just come up against :-(,, I just don't know why,, it's regarding formatting,,
I'm 'Tarting' the sheet up a bit :-)


Funny,, the table (Not in screen shot) SHG's if I use the above custom formatting it seems to accept the custom formatting code fine,,,
(As a note); the only reason for type of formatting BruceZ was I was just thinking that I'd like to show 1 decimal place in both tables. But; it was pretty pointless showing a decimal place for 100% & 0%,, so someone on an excel forum kindly suggested I use the custom formatting of;
Code:
[=0]"0 %";[=1]"100 %";0.0%
Funny thing BruceZ,, it for some reason isn't working for your table.
I'm trying to think why?
My only thought is maybe your calculation code is highly accurate,, ie lots of decimal places,, and something that is showing 100%,, actually isn't,, like excel has rounded it off? (Just a layman's guess really BruceZ :-))

All that said,, in the screenshot,, it's funny how the lower table for 4 runs (at 5% Win Rate) shows 100%,,,,, yet for 3 consec runs with this custom formatting it isn't showing 100%???
You would have thought it would? Wouldn't you?

Just wanted to mention this as I don't know why it won't configure with the custom formatting suggested.

Any ideas BruceZ?
It's look good now,, almost there,,
Funny how you think that's it,, and life just throws up another little challenge to try you,, such fun :-0

Many thanks again BruceZ;
The Ghost
help:-)-Need to rework a spreadsheet if Poss Quote
11-07-2011 , 10:02 AM
Quote:
Originally Posted by TheGhost007
Hi BruceZ,, just a quick 1.
The paper (PDF I mentioned before;
http://arxiv.org/PS_cache/math/pdf/0511/0511652v1.pdf
It's a paper called, 'The Probability of a Run- By Mark B. Villarino.'

You said:
Code:
I'm familiar with that paper. The formula is correct, but it is starting to look
like it's an ill-conditioned calculation. The roundoff error is inherent to the calculation, not to Excel or VB.
My question is; Your formula BruceZ, is it based on this mathematical paper? Just wondered for reference. It's just that you say it's "Ill conditioned" so I was wondering there was an academic paper (Like buried deep within Google Scholar maybe) that you've derived your formula from.
No, I'm not using the method in that paper. The method that I use is very simple, and I just came to it by thinking about it. You can see an explanation here. That is for getting dealt AA 3 times in a row, but it's the same idea.
help:-)-Need to rework a spreadsheet if Poss Quote
11-07-2011 , 10:09 AM
I enjoyed this conversation.

OP: "Hey, where did your method come from? Did you use this formula over here?"

Bruce: "No, I used a different formula."

OP: "Where did your formula come from then?"

Bruce: "Thinking about it."
help:-)-Need to rework a spreadsheet if Poss Quote
11-07-2011 , 10:21 AM
Quote:
Originally Posted by TheGhost007
(As a note); the only reason for type of formatting BruceZ was I was just thinking that I'd like to show 1 decimal place in both tables. But; it was pretty pointless showing a decimal place for 100% & 0%,, so someone on an excel forum kindly suggested I use the custom formatting of;
Code:
[=0]"0 %";[=1]"100 %";0.0%
Funny thing BruceZ,, it for some reason isn't working for your table.
I'm trying to think why?
That custom format works fine for me. When I put 96 in B5, I see 100% for 4 in a row, and 100.0% for 3 in a row since that isn't exactly 100%. I don't see any that are 0%, only 0.0% because none are exactly 0.

Make sure that you have the columns set wide enough for your answer. Also, if you don't mind it always saying 100.0% and 0.0%, you don't need the custom format. Just select "Percentage", and set the number of decimal places to 1. It's never really exactly 100% anyway.
help:-)-Need to rework a spreadsheet if Poss Quote
11-07-2011 , 10:24 AM
I'm just googleing what 3AA is? :-)

Google came back with;
I searched;
"delt 3 AA in cards"

google came back with;
Delta Airlines Credit Cards!!!

:-)

Now Googling
Markov process
;-)

Last edited by TheGhost007; 11-07-2011 at 10:25 AM. Reason: just adding
help:-)-Need to rework a spreadsheet if Poss Quote

      
m