Floating point error in an expression for evaluating investments
I am using the following formula for calculating the percentage an
investment has given at the current moment:
% = Power ( Current value / Initial value , 360 / days total )
I maintain a file wher each record holds the individual data of each
investment. Therefore, the above formula translates into the following
Delphi expression:
StckTblPercent.Value:= (StckTblCurrent.Value/StckTblInitial.Value ,
360/StckTblDays.Value )
This seems to work OK but in one case: if the initial value gets negative, I
get an error "invalid floating point operation". The initial value can get
negative, since it represent the cumulative net amount of possibly numerous
purchases and sales of the specific investment item.
Given that, I have two questions :
- why do I get the floating point error
- am I using the wrong way for evaluating an investment ? What I wish is
simply understand whether I am gaining (?!) or loosing, and how much, having
spent $100 3 years ago, 200 more one year ago and perhaps cashed $50 or
something like that
Here is an example:
01.01.1999 Purchase IBM stocks 90 x $100 $9,000.00
05.01.1999 Purchase IBM stocks 10 x $100 $1,000.00
01.01.2000 Sale IBM stocks 50 x $120 $ 6,000.00
01.01.2000 Dividends $ 100.00
Current portfolio situation:
IBM stocks 50 current quotation $90 current value $
4,500.00
Total costs $ 10,000 Total earnings $ 6,100 Net costs $ 3,900