What if the end date is not there. You need to sort according to your latest one.
“latest one” in the sense ?
Yes, I was not considering the end date being not present.
Now am sorting it only with “annualizedReturns” in descending order as mentioned in the task.
And do I need to limit the digits after decimal places , n round off values?
Sort according to annualizedReturn only.
Make sure to check for value type mismatch when doing arithmetic with the difference in days/years.
for finding the number of days I’ve used ChronoUnit.DAYS (that returns result in “long”) , and I’m casting it to “double” and then using it. I hope am doing that properly (?)
The value in the figure has 6 digits after decimal point (for annualizedReturn), is there any problem with that?
The 6 point precision is not effecting the result IMO.
Think about the different ways you can calculate the no. of years. Remember, precision is important here.
The problem occurs when you try skipping a step since it’s mathematically same. For example, if one is calculating years by dividing days by 365, try not to do it as 365 / days and instead stick to days / 365 and inverting it later. I am not saying that may be the case here, but I have often seen this bug which I believe is due to the fact that even with a large precision, there might be some difference when doing both calculations and it might affect the final result.
As for final result, it is not affected by 6 digits of precision.
As @shoryajain spilled the beans , just find the number of days and do day/365 where required .
He was doing it using Days anyway, so seemed like an apt example
All I could say to others who are stuck here
yes, even I was feeling it would take me a year/365.0/366 more days to pass the test !!!
Thanks @shoryajain i was stucked from last 4 days in same problem, but this one worked like a charm!
You guys are appreciating it so much, maybe they should make an FAQ out of it
I have tried this but still, assessment is failing. By inverting means I have calculated res=days / 365 and then did Math.pow(res,-1) right?
I also tried doing 1/res.
But still getting failure…
What may be going wrong?
Hey, @this_is_PM, have you solved this problem?
Because I also have a problem in what to return in totalReturns value
Is your problem solved because I am stuck due to this from past 2,3 days.
Nope. Just tried it few more times.
Have you solve the problem?I am having same issue.
How did you resolved the issue. I am still stucked. Please help
My issue was resolved by making correction in the logic I used for calculating annualized return.
there was a loss of precision in the logic I used earlier. Same thing might be happening in your case too(if itz the same test case, that got failed for you)…reconsider the way you are calculating that…concentrate on how you are calculating number of years.
My assessment is failing for oldTrades one. I calculated the days using chronoUnit days and years = days / 365; Should I consider Leap year condition ?
I sticked to the above formula…
used two different cases: one less than a year other greater than/equal to a year
and “directly substituting years” with what you have mentioned in the same formula solved it. (I used .0 and took care of data types)
follow this thread to know more about my approach
others have used different approaches and were successful too…but this is what I used.
And answer by @shoryajain explains everything and is enough to crack this…so am not going with more explanation on the same