Unable to pass mainCalculateAnnualReturn() test

I am unable to pass this test case. I have done the following steps:

  1. found the purchase value using tiingo and purchaseDate and stored it in a ArrayList.
  2. Found the endDate price of each stock and stored it in a second array, if the price is not available for endDate then the date just before the endDate for which the price is available has been used.
  3. Applied the formula on the values obtained from each of the array.
  4. Stored it in a third array and finally sorted the list in decreasing order.

I have been facing this issue since the last two days. Please help.


It might be the case your formula for calculating annualized return is wrong.
Refer to this -

If the issue was with the formula, then I wouldn’t have been able to pass the rest of the tests, but I am able to pass them. Actually I tried to print the purchase date of each stock and I am getting the same date, I don’t understand why.


Put multiple breakpoint, run the debugger and see what went wrong with the purchase date. Go through each and every step :slight_smile:

I have tried debugging it but I still get assertion error for wrong values, I checked the data returned by the api with respect to the dates.

I hope you didn’t forget to sort them. I guess it was a part of the TODO to sort them as well. Please check once.

@utkarsh Please refer to the following FAQ

If there is any variation in expected vs actual , it means that there is something wrong in your logic or you have not implemented all the TODO’s properly.

  • Check for the formula.
  • Check if the values you are fetching are right or not.
  • Check if you are calculating the number of years properly.

Try to run the individual test case and observe the report to know what’s going wrong with your code.

The thing is I am getting correct answer for rest of the cases, so it is not a issue with formula or the way I am calculating the number of years. To check if the values being fetched were correct, I printed the dates for which the data is available before the endDate and purchaseDate, and it shows the given purchaseDate and endDate and as well as the values fetched. Can you take a look at my workspace to check for potential issues that I might have misssed.

I solved the issue, I am able to pass all the test but now in assessment I get “qmoney:compileTestJava” error.

@utkarsh Please make sure that you have not modified any of the test files.

Closing this topic as there is no response since last 12 hours. Please feel free to create a new topic and post this question as a reference link in the description of the new topic.