|
|
11-27-2006, 02:06 AM
|
#91
|
Registered User
Join Date: May 2002
Posts: 137
|
SJ,
Below are two functions. The first is the one I use, where you pass in the Mean and the Stdev and it calculates the result for you and returns it. I have added a cap at 2.5 standard deviations for the upside (you can set this at what you want). Even though rare, events further than that into the tail on the upside don't really make sense to me in the horseracing application. The second one is just another version that is the Random Number generator by itself (mean 0, stdev 1). Let me know if you have any problems.
Regards,
YM
''-----------------------------------------------
''Random function1
''-------------------------------------------------
Public Function rndNormal(mean, stdev)
'The Polar Method to create Random standardized normal
'Insure at least one loop
L = 0
Do
'Step 1: Generate random numbers, U1 and U2
Randomize
U1 = Rnd
U2 = Rnd
'Step 2: Calculate V1, V2, and S
v1 = 2 * U1 - 1
v2 = 2 * U2 - 1
S = (v1 ^ 2) + (v2 ^ 2)
'Step 3: If S=>1 get new values for U1 and U2
If S < 1 Then L = 1
Loop Until L = 1
'Step 4: Calculate normal- could create 2
Z = (((-2 * Log(S)) / S) ^ (1 / 2)) * v1
''cap upside
If z > 2.5 Then
z = 2.5
End If
rndNormal = (Z * Stdev) + mean
End Function
''-----------------------------------------------
''Random function2
''-------------------------------------------------
Function NormRand() As Double
' NormRand returns a randomly distributed drawing from a
' standard normal distribution i.e. one with:
' Average = 0 and Standard Deviation = 1.0
Dim fac As Double, rsq As Double, v1 As Double, v2 As Double
Static flag As Boolean, gset As Double
' Each pass through the calculation of the routine produces
' two normally-distributed deviates, so we only need to do
' the calculations every other call. So we set the flag
' variable (to true) if gset contains a spare NormRand value.
If flag Then
NormRand = gset
' Force calculation next time.
flag = False
Else
' Don't have anything saved so need to find a pair of values
' First generate a co-ordinate pair within the unit circle:
Do
v1 = 2 * Rnd - 1#
v2 = 2 * Rnd - 1#
rsq = v1 * v1 + v2 * v2
Loop Until rsq <= 1#
' Do the Math:
fac = Sqr(-2# * Log(rsq) / rsq)
' Return one of the values and save the other (gset) for next time:
NormRand = v2 * fac
gset = v1 * fac
flag = True
End If
End Function
|
|
|
11-27-2006, 02:21 AM
|
#92
|
Registered User
Join Date: Feb 2002
Posts: 10,861
|
By the way, I was at MNR Friday night.
Baird had a horse in one of the later races that went off at 16-1 and won -- it was number 4. I went to the paddock for every race. The 4 horse was coming off of a layoff and must have been bought by Baird in California -- I think this might have been it's first MNR start.
Anyway, I knew immediately it was a Baird horse when I saw it. He never grooms his horses. They always look scruffy. He keeps nearly 200 head so that accounts for the lack of grooming. The man is a racing machine.
His horse was really acting up in the paddock. He was either nervous coming off of a layoff, or really fit and ready to run or was on drugs. He looked scared to me. And the whites of his eyes also looked bloodshot. No other horse in the race was acting like him. And he was 20-1 morning line.
Anytime you can get 16-1 on a Baird horse you have to bet it. Did I bet it? No. I used it in the exotics. I should have had the exacta at least. I box/keyed some other horse on top of Baird's horse and the runner up, so I lost even though I had all the horses.
I did the same thing on that 40-1 shot. He looked great in the paddock, so I used him in the exotics, but didn't have him with the runner up.
I'm ahead lifetime at MNR, but lost Friday night. I had the winner in 4 of 6 races and still lost money. I played too many losing exotics and also had a favorite run out that I had a big show bet on.
Lots of fun though. MNR is my favorite track. Lots of value and a paddock handicapper has a big edge -- assuming he knows how to use the information!
|
|
|
12-04-2006, 02:30 AM
|
#93
|
Registered User
Join Date: Feb 2002
Posts: 10,861
|
Quote:
Originally Posted by yak merchant
SJ,
Below are two functions. The first is the one I use, where you pass in the Mean and the Stdev and it calculates the result for you and returns it.
|
Yak,
Sorry I have been slow getting back to you. Been very busy at work.
I haven't looked at my code for awhile, but your code looks more sophisticated than mine.
I'll try to incorporate your code into some software and then compare my old software output against your code's output and against my friend's known to be correct software output. Should be interesting.
The results of my old code approximate my friend's. But I had to use a fudge factor to make them work. Mine are probably close enough for horse racing, but it never hurts to do things better.
Thanks for so kindly posting your code. Very impressive.
John
|
|
|
12-04-2006, 03:19 AM
|
#94
|
Registered User
Join Date: Feb 2002
Posts: 10,861
|
Yak,
I incorporated your code into my software and compared your code, my old code and my friend's software's output.
Here are the results:
Data:
Means = 80, 81 and 82
SD = 5,5,5
YAK prob = .2688, .3719, .3996
SJ prob = .251, .325, .424
Friend prob = .252, .3279, .4199
This is very interesting. My friend is a world class statistician at a major university. He knows his math. He designed this for me with horse racing in mind and calibrated it to my various power ratings.
Unfortunately for me, he wrote it in C and I can't decipher it. I can call it from VB, so it is still useful.
However, I wanted something that would suit my needs even more, so I wrote a MC Sim that would approximate his output. I'm close -- within 2/1000 oftentimes and never so far away that it actually matters in horse racing.
Your code, which I also found a copy of on the net by the way, looks good, but seems to compress the extremes. I didn't limit the SD to 2.5. Mine allows for a little wider spread.
Which is better? Who the hell knows? All I can say is that they both look good. I could use either method. Having a one or two percent difference between methods does not seem like a big deal in a horse racing context.
Can anyone really develop a system that can distinguish between a 25% horse and a 27% horse? Maybe.
John
|
|
|
12-04-2006, 04:14 AM
|
#95
|
Registered User
Join Date: May 2002
Posts: 137
|
SJ,
I'm no statistician, I definitely found the code on the internet, I just did it along time ago, when things were alot harder to find. As far as the results, How many iterations did you run? I'd have to look at his code and a graph of the outputs, to even have a clue. Due to the 82 horse winning more than my code, his distribution definitely looks to be leptokurtic, or if not then skewed to the downside. This makes logical sense in a horseracing application, as a horse often runs 3 sigmas to the downside, but rarely runs 3 sigmas to the upside. But when you say mine compresses the extremes, I don't know what you mean by compress but from the data my code has fatter tails (80 mean horse won the most) which means the extreme happened more often.
While the differences are small they will make a difference in the very long run, but you'll just have to test the different predictions against historical results to see which performs better. Either way both are 1000 times better than just using a random number between -1 and 1. Good luck and I'd be interested in seeing his function if he doesn't mind.
YM
|
|
|
12-04-2006, 11:08 AM
|
#96
|
Registered User
Join Date: Feb 2002
Posts: 10,861
|
Quote:
Originally Posted by yak merchant
How many iterations did you run?
|
10,000 iterations. I forgot to put that in the specs.
Quote:
But when you say mine compresses the extremes, I don't know what you mean by compress but from the data my code has fatter tails (80 mean horse won the most) which means the extreme happened more often.
|
I just meant that your longshot has a higher prob of winning than mine. And your favorite has less of a chance of winning than mine. Your odds at the extremes are not as high or low as mine. But this is a small sample. I don't know what would happen in the long run or with more horses.
Quote:
Either way both are 1000 times better than just using a random number between -1 and 1
|
Definately.
Quote:
Good luck and I'd be interested in seeing his function if he doesn't mind.
YM
|
His code looks an awfully lot like yours!
#include <math.h>
/* generate random standard normal deviates */
double rnorm(double mu, double s) /* random normal */
{ double x,y,z,randm(void);
do
{ x=randm()*2.0-1.0;
y=randm()*2.0-1.0;
z=x*x+y*y;
}
while(z>=1.);
z=x*sqrt(-2.0*log(z)/z);
return(z*s+mu);
}
|
|
|
12-06-2006, 12:24 AM
|
#97
|
Registered User
Join Date: May 2002
Posts: 137
|
SJ,
Yeah same function as mine. Any differences in the long run would be due to 1 of 3 things. The way C and VB generate psuedo-random numbers Rndm() and Rnd() functions. I call the Randomize function every call to get the best psuedo number possible, I don't know how C handles this.
Or the fact he uses Void when calling Rndm(). I'm not 100% sure what this does, but I believe it excludes 1 and 0 from the allowable values it returns. Which I think VB does automatically.
Or three, some rounding differences in the math. I'm sure mine would be the one that is wrong as he declared all his variables as double and I didn't. Who knows what VB is doing with converting to Variant and back. You may want to declare all the variables in my code as Doubles before executing it, and see if that changes my output. Thanks for posting his code. Good luck with your project.
YM
|
|
|
12-06-2006, 01:03 AM
|
#98
|
Comfortably Numb
Join Date: Sep 2001
Location: Lexington, Ky
Posts: 6,174
|
Quote:
Originally Posted by yak merchant
Or the fact he uses Void when calling Rndm(). I'm not 100% sure what this does, but I believe it excludes 1 and 0 from the allowable values it returns. Which I think VB does automatically.
YM
|
The void is at the declaration point and tells the compiler that the function being declared accepts an argument of type "void" i.e. none - any call to the function randm with a real argument would be considered a syntax error. This does not affect the return values of the function that is called below as "randm()"
|
|
|
12-23-2006, 07:00 AM
|
#99
|
Registered User
Join Date: Dec 2006
Location: Scotland
Posts: 34
|
I know this thread is ancient history, but as a new member I would just like to say what a great read it is.
I have written my own MCS in Excel and they are a built in part of my handicapping software, if I had come across this thread sooner I could have saved myself a lot of time.
|
|
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|