The JSE and finance forum for South Africa

General Category => The Investor Challenge => Topic started by: Patrick on June 10, 2014, 03:07:52 pm

Title: Need some calculation help
Post by: Patrick 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!
Title: Re: Need some calculation help
Post by: gcr 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  :(
Title: Re: Need some calculation help
Post by: Feral Wolf 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.
Title: Re: Need some calculation help
Post by: CompTester on June 10, 2014, 09:35:53 pm
That was useful Mr Wolf. Could you check the figures now.
Title: Re: Need some calculation help
Post by: Feral Wolf on June 11, 2014, 05:33:40 pm
Awesome now it's spot on  :TU:
Title: Re: Need some calculation help
Post by: giggsie 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.
Title: Re: Need some calculation help
Post by: Nios on June 16, 2014, 09:54:07 pm
+1 for my omnmta account
Title: Re: Need some calculation help
Post by: Patrick on June 17, 2014, 09:48:44 am
Yep I see the issue, it's a profit/tax problem...
Title: Re: Need some calculation help
Post by: CompTester 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.
Title: Re: Need some calculation help
Post by: Patrick on June 18, 2014, 10:54:50 am
Still working in fixing peoples profit. It's a little harder than I thought :wall:
Title: Re: Need some calculation help
Post by: Patrick on June 18, 2014, 11:52:54 am
And we're back to normal. Fortunately I enjoy a challenge, that was one...  ???