cb123 said:
Need to change formula (avg growth per transaction)
x=((((cash+portfolio)/10000)^(2/transactions))-1)*100
cb123 said:
I've been messing with that calculation for days now... You know what conclusion I've come to? The darn thing will simply never report the right number, no matter how I work it around... That's the bad news. The good news is that it's actually a much simpler problem than what I've been treating it as.
Granted the current calculation actually works, but it's reporting an overall % relative to the starting amount rather than a true average gain per trade, which isn't possible given the data we're trying to use..
No idea why this hadn't come to me earlier, sorry about being less than a stellar performer on this issue.
So the overall idea is this, we just need to add two variables for the value, which would be calculated on the sell transaction.
Essentially the pseudo-code (runs only on sell transaction) is this:
set user_trade_count_var = (count_var + 1)
set user_gain_total = (user_gain_total + this_gain_percent)
display user_avg_percent_gain = (user_gain_total / user_trade_count_var)
That will do it... And it does work, I've verified this to make sure I'm not wasting more of your time. Not too sure how this system is built, but I assume there is some ability to call this on the sell event, if not then it's of no use.
Cheers, and thanks!
-Cory
that data is calculated on the profile load, and not on the sell event.
ill see if i can find a way to fit it in, but wouldn't (total - 10000) / transactions at least give us an accurate average gain per transaction?
cb123 said:
Unfortunately no, it always favors a higher total. Because the calculation can tell you what the gain was over the entire run, but not per individual transactions.. That's what I had to figure out (and it took some thinking, talking, and more than a few sheets of paper

).. The idea is that you are looking at average gain balanced against the initial 10000, rather than the gain that is averaged from each transaction... Here's the simplified math--
So, if I have two transactions, starting with 10k -
1. gain 100% balance is now 20000
2. gain 100% balance is now 40000
----
Now we can see that the average gain is 100% here, however when we take [(total - 10000) / transactions] we get an average of 15000 gain per transaction, which averages to 150%, or 50% more than the real average, and this is an exponential increase, so it will increase non-geometrically (in other words, the more you make, the further from reality the calculation becomes...)
I tried to deal with this in my second attempt, turned out that even that method (while better) didn't address the overall conceptual issue, so after pounding my head against a wall for a while, I came to the conclusion that we just needed more data points and everything goes smooth..
****************8
Even if the data is calc'd at load (this is just fine I think..) can you (on a sell transaction) write to a persistent variable that will hold the needed data?
If so, then the calculation can just be done @ load, with the data.
Obviously, you are storing this data somewhere, because the ledger is already perfectly capable of showing the data from each transaction, we just need to act on that data rather than the data I was trying to shoehorn into this calculation..
So, like I said, this has spiraled into something more significant that I initially expected, so I can and will understand if this (a.) takes time, or (b.) never happens..
lol i think i smell toast.
im gonna read this over and over until i get it
lets think about it in a new way tho...
instead of thinking of it as happening 'at the sell', i should mention that i have records of every sell transaction, as well as its corresponding buy.
its all over my head tho, but its probably not impossible to get it working.
cb123 said:
Perfect. 
--
Let me think really carefully (I think this is now simple, which makes me think I'm missing something...) about this for a while, and I'll get back to you tomorrow with a working formula..
*if you want I can assist with the code, as you might have guessed, I'm pretty comfy with this stuff...
check your the values in the earnings column of your ledger view... they might be a key to all this.
ive got a hunch
cb123 said:
just for reference:
earnings=total sale value - cash invested
cash=cash invested
(earnings / cash) * 100 [values from ledger on a sell transactions] gives percent per transaction set.
now-- we have two options, one is to store a persistent value that is the result of this calculation, then refer to in on the next calculation, or we can just run this against every transaction made, but that is inefficient and could cause significant demand on the server, and potential delays (depending on your server config and how well the code handles calculations)
So, if you choose to set a persistent value, then let's call it avgpercent
if not, then just run this for each buy/sell set, and think of avgpercent as a display field.
note that I've included a int() function to make this easier on the eye.
I've been overly cautious on the use of () just to make SURE this is sequenced in a functional way..
Formulas:
____________________________
Simple:
avgpercent=int((avgpercent + (((earnings/cash) *100))) / 2)
Loop:
For x=1 to totaltrans
avgpercent=((avgpercent + (((earnings/cash) *100))) /2 )
next x
avgpercent=int(avgpercent)
_______________
Once again, I really think the better option is the simple approach, you would need to set a value in the DB table, or somehow persist that number, but the advantages are simplicity of calculation and much lower overhead...
Hope this clarifies everything well enough, if not let me know.
-Cory
Phew::

