Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introducing the R-squared coefficient and Treynor Ratio for a financial portfolio #134

Merged
merged 29 commits into from
Sep 3, 2023

Conversation

PietropaoloFrisoni
Copy link
Collaborator

@PietropaoloFrisoni PietropaoloFrisoni commented Aug 17, 2023

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.

@PietropaoloFrisoni PietropaoloFrisoni marked this pull request as draft August 17, 2023 15:19
@PietropaoloFrisoni PietropaoloFrisoni changed the title First commit: adding a feature for computing the R-squared parameter … Introducing the R-squared coefficient and Treynor Ratio for a financial portfolio Aug 22, 2023
@PietropaoloFrisoni PietropaoloFrisoni marked this pull request as ready for review August 24, 2023 05:29
finquant/portfolio.py Outdated Show resolved Hide resolved
Copy link
Owner

@fmilthaler fmilthaler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :)

Co-authored-by: Frank Milthaler <fmilthaler@users.noreply.github.com>
Co-authored-by: Frank Milthaler <fmilthaler@users.noreply.github.com>
@PietropaoloFrisoni
Copy link
Collaborator Author

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).

@PietropaoloFrisoni PietropaoloFrisoni merged commit 55112a9 into master Sep 3, 2023
3 checks passed
@PietropaoloFrisoni PietropaoloFrisoni deleted the feature/R-squared branch September 3, 2023 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants