I have done the following things:
- throw error if end date is before start date
- do not pass end date, if it is not provided in the arguments, to the API and use the latest date as the end date.
- sort the annualizedReturns in decreasing order.
- buy price is the open price on the purchaseDate and sell price is the close price on the endDate.
Still the mainCalculateReturnsOldTrades test case in assessment is failing. It would be helpful if someone can point out where I might have made the mistake. Or otherwise I will just have to rewrite it again.