You are not signed in. Sign in, or Create an account.

BUGS FORUM: fun with math!

http://www.urlashare.com/forum/bugs/

Page 2 of 2 • Jump to page  1 2
#26 February 8, 2010 8:15 AM
cb123
joined: May 2009
OFFLINE
Posts: 117
calc.exe said:

***downloadhelper.net
cashinvested = 346 * 28 = 9688
totalvalue = 1910 * 28 = 53480

gpt = ((totalvalue - cashinvested) / cashinvested) * 100

gpt = ((53480 - 9688) / 9688) * 100

gpt = (43792 / 9688) * 100

gpt = 4.52023 * 100

gpt = 452.02

***thekingcenter.org
cashinvested= 8 * 183 = 1464
totalvalue = 46 * 183 = 8418

gpt = ((gpt + (((totalvalue - cashinvested) / cashinvested) * 100)) / 2)

gpt = ((452.02 + (((8418 - 1464) / 1464) * 100)) / 2)

gpt = ((452.02 + ((6954 / 1464) * 100)) / 2)

gpt = ((452.02 + (4.75 * 100)) / 2)

gpt = ((452.02 + 475.00) / 2)

gpt = (927.02 / 2)

gpt = 463.51

***martinlutherking.org
cashinvested= 5.5 * 183 = 1006.5
totalvalue = 49 * 183 = 8967

gpt = ((gpt + (((totalvalue - cashinvested) / cashinvested) * 100)) / 2)

gpt = ((463.51 + (((8967 - 1006.5) / 1006.5) * 100)) / 2)

gpt = ((463.51 + ((7960.5 / 1006.5) * 100)) / 2)

gpt = ((463.51 + (7.90909 * 100)) / 2)

gpt = ((463.51 + 790.90) / 2)

gpt = (1254.41 / 2)

gpt = 627.205



I'm so excited about this!!! Great work... Absolutely ready for production, But I think you can see there's quite a bit of math overhead here, and I don't like that one little bit, mostly because we can do better (and get better numbers to boot!! A real, full average!)

So, here's what I propose now that I've seen the calculation and have a better understanding of this whole system, let's chop this badboy down to do this in one loop: (Comments preceeded by ::X::)


::XX:: This is intended to "reset" the values of these variables if needed (you might be able ignore these next two lines.)
gpt=0
count=0

::X:: Start the loop to look at all values

startloop::
cashinvested= 5.5 * 183 = 1006.5
totalvalue = 49 * 183 = 8967
gpt = gpt + ((totalvalue - cashinvested) / cashinvested)
count= count + 1 ::X:: We're keeping this as a variable to later divide by, however, if you can get the total number of BUY/SELL paired transactions without needing this, you can also cut this out.
endloop:

::X:: Now we're out of the loop, next step is to turn GPT into a percentage [*100] and get the average out of the full GPT number [/count]

gpt=(gpt * 100)/count

-- And there it is- perfection in a smaller and lighter package.
 
 
#27 February 8, 2010 2:46 PM
NickSunshine
joined: March 2009
OFFLINE
Posts: 852
LMAO what? BONGHIT!
 
 
#28 February 8, 2010 7:46 PM
cb123
joined: May 2009
OFFLINE
Posts: 117
NickSunshine said:
LMAO what? BONGHIT!


BONGHIT!TWO THUMBS UP!

Holy sheet buhlz.. I have no idea what I was smoking earlier (hurrying to finish typing and get on with a meeting maybe??)-- Kinda funny though.. So, assuming you didn't fully understand my casually insane post from earlier....

No worries, everything is working. It's just another opportunity that I see to tighten up this code to produce even better results (mathematically and computationally) No need to over explain, we just get better results.

I came to this after admiring your new working code for a while and asking myself, "How could this be better?" as I do with every project I work on (you can imagine the hell I put my co-workers through, and how much the CEO likes my work HAHAHA ).

So, I figured out a simple way to reduce computational load, while improving the nature of the average calculation that is being done, basically there's just an overall better way to do this, while there is nothing wrong with the current setup. I just know from experience it's best to tighten up a project as much as possible before moving away from it.. Or something like that anyway.

So, the optimized code looks like this (we've added the variable count, it might not be needed because you might be able to easily tell the thing how many transaction pairs exist without counting like this):

codesnippet said:

gpt=0
count=0

startloop::
gpt = gpt + ((totalvalue - cashinvested) / cashinvested)
count= count + 1
endloop:

gpt=(gpt * 100)/count


The first part of this code resets variables (you might not need to do this)

The second part is the optimized loop (one calculation, no need for logic, and fewer calculations)

The third part is a conversion to get an average out of the variable gpt ...

------

Easy enough right? And it will make your servers happy (and keep any real mathematicians that might stumble on this at least somewhat pleased that we arrived at a reasonably clean and nice final result, no worries though, I'm sure they will have laughed at us until they've cried long before this point in our conversation.. SMILE )
 
 
#29 February 8, 2010 10:32 PM
Spurtis55
joined: April 2009
OFFLINE
Posts: 204
sounds good hahahahhahah TWO THUMBS UP!

hey we need a wide eyed smily like whoa?
 
 
#30 February 10, 2010 2:11 AM
NickSunshine
joined: March 2009
OFFLINE
Posts: 852
Spurtis55 said:
hey we need a wide eyed smily like whoa?


HAH! YIKES! ROFL! POPCORN TIME! BRAVO!
 
 
#31 February 10, 2010 3:51 AM
NickSunshine
joined: March 2009
OFFLINE
Posts: 852
cb123 said:

Holy sheet buhlz.. I have no idea what I was smoking earlier (hurrying to finish typing and get on with a meeting maybe??)-- Kinda funny though.. So, assuming you didn't fully understand my casually insane post from earlier....


LOL actually, i got most of it... just wanted to give you a hard time HAH!

cb123 said:

No worries, everything is working. It's just another opportunity that I see to tighten up this code to produce even better results (mathematically and computationally) No need to over explain, we just get better results.

I came to this after admiring your new working code for a while and asking myself, "How could this be better?" as I do with every project I work on (you can imagine the hell I put my co-workers through, and how much the CEO likes my work HAHAHA ).

So, I figured out a simple way to reduce computational load, while improving the nature of the average calculation that is being done, basically there's just an overall better way to do this, while there is nothing wrong with the current setup. I just know from experience it's best to tighten up a project as much as possible before moving away from it.. Or something like that anyway.


well, load isnt much of an issue, as the contents of the fugly script are only meant to be ran once... at that point it will write the GPT to the database, and future updates will occur at the point of sale, not much overhead at all there.

cb123 said:

So, the optimized code looks like this (we've added the variable count, it might not be needed because you might be able to easily tell the thing how many transaction pairs exist without counting like this):

codesnippet said:

gpt=0
count=0

startloop::
gpt = gpt ((totalvalue - cashinvested) / cashinvested)
count= count 1
endloop:

gpt=(gpt * 100)/count


The first part of this code resets variables (you might not need to do this)

The second part is the optimized loop (one calculation, no need for logic, and fewer calculations)

The third part is a conversion to get an average out of the variable gpt ...

------


yep, if we were doing it all every time, that would be cleaner...

now would be a good time to mention that this number will never be 100% accurate if we divide by two...

that assumes that you only bought once... however, the math looks at the average price per share over all purchases (ie: more shares became available, so i bought em)

we can bend the math in fugly and divide by that number if that makes sense (total buy transactions +1) ?

same for the first sale? it should be divided by something right?

cb123 said:

Easy enough right? And it will make your servers happy (and keep any real mathematicians that might stumble on this at least somewhat pleased that we arrived at a reasonably clean and nice final result, no worries though, I'm sure they will have laughed at us until they've cried long before this point in our conversation.. SMILE )


ROFL! POPCORN TIME! ROFL!

we are damn close... just need to hammer out the little details THUMBSUP!
 
 
#32 February 19, 2010 2:15 PM
NickSunshine
joined: March 2009
OFFLINE
Posts: 852
bump.
 
 
#33 February 22, 2010 8:42 PM
NickSunshine
joined: March 2009
OFFLINE
Posts: 852
cb123 where are you!!!!
 
 
#34 February 24, 2010 10:09 PM
cb123
joined: May 2009
OFFLINE
Posts: 117
So busy
So sorry..

Will get to this very, very soon!!
 
 
#35 February 24, 2010 11:04 PM
NickSunshine
joined: March 2009
OFFLINE
Posts: 852
LOL take your time!

i was just worried that you had given up or couldnt find page 2 SMILE
 
 
#36 February 26, 2010 2:58 AM
NickSunshine
joined: March 2009
OFFLINE
Posts: 852
updated fugly.php with 'the new math' -

all calculations:

fugly.php said:
GPT = ((GPT + (((TOTAL VALUE - CASH INVESTED) / CASH INVESTED) * 100)) / (PURCHASES + 1))

 
 
Page 2 of 2 • Jump to page  1 2
YOU ARE NOT LOGGED IN.
 

POST A NEW MESSAGE

45
USERS ONLINE
Who's Online: 45 guests.


Privacy Policy  • Site Statistics  • @urlashare