Author Topic: Need some calculation help  (Read 6723 times)

Patrick

  • Administrator
  • Hero Member
  • *****
  • Posts: 2550
  • Karma: +47/-2
    • View Profile
Need some calculation help
« on: June 10, 2014, 03:07:52 pm »
So clearly there's a problem in the way I'm currently calculating the price per share. Here's a couple of examples:
http://www.shareforum.co.za/competition/com_holdings_public.php?user_id=1897&year=current
and
http://www.shareforum.co.za/competition/com_holdings_public.php?user_id=6&year=current

In this case both competitors had shares they'd previously bought and sold, but now the current price per share is wrong. How would I calculate the price per share using the information under the transaction history. My brain just isn't clicking in right now!

gcr

  • Hero Member
  • *****
  • Posts: 1008
  • Karma: +28/-1
    • View Profile
Re: Need some calculation help
« Reply #1 on: June 10, 2014, 04:46:50 pm »
Can't see what the problem is - on which counters specific are you referring to. To my mind if you apply brokerage (charges) on each leg of the transaction and buy/sell at your 15 minute delay prices then you shouldn't have a problem with your history files  :(
Not everything that counts, can be counted, and, not everything that can be counted counts - Albert Einstein

Feral Wolf

  • I've just arrived
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Need some calculation help
« Reply #2 on: June 10, 2014, 05:38:44 pm »
Whenever the quantity of a share reaches 0 (zero), the avg_cost variable for that specific share should be zeroed,
(avg_cost = 0.0;) so that when ALL shares are sold (qty = 0) and more are bought later, the avg_cost of the shares sold a month ago doesn't affect the average cost displayed of the new shares you are buying.

Each transaction of a specific share should contribute its weight to the avg cost, so if 50 are bought at R1 then 100 bought at R2 and 40 sold at R3: (the avg cost is R1*(50/150) + R2*(100/150) = R1.67)
Now when the 40 shares are sold, the total qty of shares are reduced, but the avg cost should remain unchanged because selling price doesn't affect the buying price, so now we have 110 shares bought at R1.67 each, and when we buy again, say 90 at R2.50, then avg cost = (R1.67*(110/200) + R2.5*(90/200)) = R2.04.
The transaction fees and tax on share profit can be calculated seperately as I beleive you are allready doing.

CompTester

  • I've just arrived
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Need some calculation help
« Reply #3 on: June 10, 2014, 09:35:53 pm »
That was useful Mr Wolf. Could you check the figures now.

Feral Wolf

  • I've just arrived
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Need some calculation help
« Reply #4 on: June 11, 2014, 05:33:40 pm »
Awesome now it's spot on  :TU:

giggsie

  • I've just arrived
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: Need some calculation help
« Reply #5 on: June 13, 2014, 03:58:49 pm »
That was the exact issue i had earlier on in the competition when i re bought MIX when the crashed to a lower price after i sold off my initial loss.
I now have a new problem. Just sold MIX off at a profit and dropped 200 positions on the leader board. It shows my net profit on sale of shares and when i add up all the values on my portfolio i come to +-660K but the leader board registers me as 595K. It is the same result when viewing from an external source. (ie. not logged in)

I think there might still be a calculation gremlin hiding somewhere in the works :(

I hope you can find what is causing the issue.

Nios

  • Full Member
  • ***
  • Posts: 124
  • Karma: +3/-1
    • View Profile
Re: Need some calculation help
« Reply #6 on: June 16, 2014, 09:54:07 pm »
+1 for my omnmta account

Patrick

  • Administrator
  • Hero Member
  • *****
  • Posts: 2550
  • Karma: +47/-2
    • View Profile
Re: Need some calculation help
« Reply #7 on: June 17, 2014, 09:48:44 am »
Yep I see the issue, it's a profit/tax problem...

CompTester

  • I've just arrived
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Need some calculation help
« Reply #8 on: June 17, 2014, 03:51:22 pm »
Ok the system is fixed, but correcting the errors is going to take a little longer. Hopefully I'll have everything back to normal tomorrow.

Patrick

  • Administrator
  • Hero Member
  • *****
  • Posts: 2550
  • Karma: +47/-2
    • View Profile
Re: Need some calculation help
« Reply #9 on: June 18, 2014, 10:54:50 am »
Still working in fixing peoples profit. It's a little harder than I thought :wall:

Patrick

  • Administrator
  • Hero Member
  • *****
  • Posts: 2550
  • Karma: +47/-2
    • View Profile
Re: Need some calculation help
« Reply #10 on: June 18, 2014, 11:52:54 am »
And we're back to normal. Fortunately I enjoy a challenge, that was one...  ???