Thursday, 15 August 2013

php - Calculate Net Worth from Transaction data -



php - Calculate Net Worth from Transaction data -

i have list of transactions of stock purchases. trying calculate net worth. table defined:

id | date | symbol | shares | cost | close ------------------------------------------------- 1 | 2010-06-01 | t | 100 | 24.35 | 24.15 2 | 2010-07-01 | rso | 10 | 6.25 | 6.40 ......

goes 2010-today. calculate value multiply shares * close = value. works day. have script gives me closing value @ day.

$history = getclose($symbol, $daterange)

returns multidimensional array symbol contains dates below

$history['symbol']['20100601'] = $price $history['symbol']['20100701'] = $price

i know has simple have pieces puzzle cant figure out how set together. have sql statement gives me of holdings on given day.

select symbol, sum(shares) shares, sum(shares * close) value transactions (action<> 5) , date <='2010-06-01' grouping symbol having (sum(shares) > 0);

but gives me value days purchases made. goal set in chart showing growth(or decline) on time

id have more code literally cant wrap mind around how it. not makes difference, using codeigniter framework website

you're missing piece of puzzle. unless perpetually buying , never selling you'll need way indicate actual holdings on every day sum. means knowing changes - both buys , sells.

two ways (that come mind):

update holdings table reflect ownership everyday stock owned. can sum on total value track sells somehow. you'll know periods sum on , can loop on date-delta each , sum.

since 3rd query titled transactions , includes sort of action column must have info somewhere. need date ranges , sum on values each.

php mysql codeigniter

No comments:

Post a Comment