Closed PietropaoloFrisoni closed 10 months ago
Very good implementation. Only the two tiny suggestions I mentioned, and can I ask you to add unit tests for finquant.quants.treynor_ratio please. The other one does not require any since you are using a function from scikit-learn, so we can assume it is thoroughly tested. Other than that, this PR is clean and nicely done. Thank you for this addition :)
My pleasure! I forgot the unit tests for the Treynor Ratio, but I just added them. As you guessed, I used a function from scikit-learn
to compute the R-squared coefficient precisely because it was deeply tested, although it could have easily been implemented with NumPy
. Curiously, the scikit-learn
R-squared function can also assume negative values, which some sources don't consider possible for such a parameter (in the case of scikit-learn
, this is a deliberate choice, as explained here: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.r2_score.html).
The R-squared coefficient measures how closely the portfolio's returns track the benchmark market index's returns. On the other hand, the Treynor Ratio is a metric used to evaluate an investment portfolio's risk-adjusted returns.
They have been incorporated in the same PR to simplify the merging, and because such parameters both refer to the market index.