mainCalculateAnnualReturn test fails every time

Been stuck with this issue for more than a day.

I am getting assertion error: expecting 0.81 but getting 0.77

The answer what I am getting is off by 0.02-0.04 for all 3 stock.

The result is sorted, I am probably using the correct formula as rest 11 cases are passing. One doubt I have is probably my date is not correct or I am fetching wrong values. The difference between the dates I am getting is 344 days.

If someone can help me it will be pretty amazing of you. Thanks.

I guess it’s a calcuation error.
Recheck the formula once again

I took the values and calculated on pen and paper I am getting 0.77 only.

The function you wrote is returning 0.81

the function is also returning 0.77 but the test case wants 0.814

I guess whatever your logic is make sure that you are dealing all your calculations in float values.
Like the division should also be in float value not in integer

Firstly make sure you are fetching the right data, if yes then check for the formula you are using to calculate.
Hint: Firstly try to find the difference between dates by calculating the number of days between them and try to convert that result into years.
For the assertion error , please refer to this.

Error: Assertion Error Exception

1 Like

sell=271.46 (close on given date)
buy=157.92 (close on purchase date)

can you recheck my calculation.

I have converted everything to double and then checking it. Probably am fetching the wrong data.

buy_price = open_price on purchase_date and sell_value = close_price on end_date

1 Like

ooh GOD. THANK YOU very much.
I am actually crying here.
You are the best. Thank you so very much.