Problem with calculateAnnualizedReturn

the formulae given to find totalReturn is (sell_value - buy_value) / buy_value so for the values provided by testcalculateAnnualizedReturn the result should be 0.1 but in test cases it fails because it is mentioned that correct result is 0.0001 is there something i am missing due to which i am getting a wrong answer

Hey, @shubhamjadon that 0.0001 is precision not answer. Answer is 0.0322. for annualized return.

but my testcase is failing any idea why that might be happening. Also my function is returning 0.0322 for annualized return

1 Like

yes you are calculating total return but using that total return you have to calculate annualized return

Annualised_return = ((1 + Total_return) ^ (1/no. of years)) – 1
OR
Annualised_return = ((1 + Total_return) ^ (365/no. of days)) – 1

use these formulas and calculate annualize return

Thanks man, got it one last thing though do we have to consider precision in our answer

No, you don’t need to bother about it just use double.

NOTE

double is a 64 bit IEEE 754 double precision Floating Point Number 
(1 bit for the sign, 11 bits for the exponent, and 52* bits for the value), 
i.e. double has 15 decimal digits of precision.

they are checking only 4 digit precision and when you use double it will give you 15 digit precision after decimal

1 Like