mainCalculateReturnsOldTrades() and mainCalculateReturnsVaryingDateRanges() are failing. Any hints for these internal cases?

The time period for annualized returns needs to be calculated accurately.

There are two cases 1)less than year 2)more than year. right? Is there any other?

Think in terms of how you are calculating it. Which formula/method you are using.

Read this article any then implement you calculations.

tried this too still failing 1 test case mainCalculateReturnsOldTrades().

multiple git pushes but still stuck on this for 2 days.

Any advice please.

@shoryajain @shubhamkumar27 @gouravsardana

other people are also stuck on this.

There might be the issue with number of years you calculated or the data type of variables you are using in your formula. Checkout various ways by which you can calculate no. of days, months and years between a given time period, checkout the values and data type which they return. You will surely get the solution.

calculating the number of days using java Chronounits class.

then using formula mentioned in below article 365/numDays and explicitly making it a double while division itself like so ((double)365/numdays).

Is this okay ? @shubhamkumar27

are you handling any special case of inputs instead of the calculation part ??

Check the data type Chronounits is returning. and cast it accordingly to calculate no. of years.

Debug your code using debugger for mainCalculateReturnsOldTrade() this is the method which test your function for data returned as a response from API between start date and end date. Here as per TODO’s you have to take latest stock close value and calculate annualized return and sort it in descending order. Are you doing this?

chronounits is returning a long and am later casting it to a double.

Try keeping everything to a single typecasted value, preferably double. Even the constants. Make sure all results are stored in that too. Then use debugger to see if your code us failing anywhere.

I did the same… still the same result

As @shoryajain and others mentioned, most probable problems are:

- Silly mistake in the formula
- Wrong calculation of years

for problem 1, double check the formula provided in this link and carefully debug your code:

https://www.fool.com/knowledge-center/how-to-calculate-annualized-holding-period-return.aspx

for problem 2, try looking online for how to get years between two dates. This link might help:

https://stackoverflow.com/questions/7906301/how-can-i-find-the-number-of-years-between-two-dates

I hope it helps

Sorry, but I am still getting the same error

Read the TODO once more carefully. You are probably missing 1 point or so.

It’s been so long ,could you help me with this as I am not able to get where is the problem…I have read the TODOs carefully but I am not able to solve these two failures.