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

Fix portfolio metrics #2116

Merged
merged 18 commits into from
Jul 26, 2022

Conversation

northern-64bit
Copy link
Contributor

@northern-64bit northern-64bit commented Jul 20, 2022

Description

Fixing the portfolio metrics calculations and fixing the metrics after the refactor.

How has this been tested?

Running the commands in jupyter notebook and the terminal

Checklist:

Others

  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • My code passes all the checks pylint, flake8, black, ... To speed up development you should run pre-commit install.
  • New and existing unit tests pass locally with my changes. You can test this locally using pytest tests/....

@JerBouma JerBouma self-requested a review July 20, 2022 14:04
@JerBouma JerBouma added the feat S Small T-Shirt size Feature label Jul 21, 2022
@northern-64bit northern-64bit marked this pull request as ready for review July 25, 2022 08:50
Copy link
Contributor

@JerBouma JerBouma left a comment

Choose a reason for hiding this comment

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

The meaning of these results are confusing when you have no losing trades (e.g. a typical long-only portfolio). I'd suggest to notify the user that there is no losing trade (or gross loss) and that this calculations therefore will not be accurate. E.g. you can quite easily check if any return < 0.

2022 Jul 25, 05:59 (🦋) /portfolio/ $ metric profitfactor

Portfolio's profit factor
┏━━━━━┳━━━━━━━━━━━━━━━┓
┃     ┃ Profit Factor ┃
┡━━━━━╇━━━━━━━━━━━━━━━┩
│ mtd │ nan           │
├─────┼───────────────┤
│ qtd │ nan           │
├─────┼───────────────┤
│ ytd │ 0.064         │
├─────┼───────────────┤
│ 3m  │ inf           │
├─────┼───────────────┤
│ 6m  │ 0.064         │
├─────┼───────────────┤
│ 1y  │ 0.041         │
├─────┼───────────────┤
│ 3y  │ 0.167         │
├─────┼───────────────┤
│ 5y  │ 0.444         │
├─────┼───────────────┤
│ 10y │ 2.284         │
├─────┼───────────────┤
│ all │ 3.085         │
└─────┴───────────────┘

2022 Jul 25, 05:59 (🦋) /portfolio/ $ metric payoff

Portfolio's payoff ratio
┏━━━━━┳━━━━━━━━━━━━━━┓
┃     ┃ Payoff Ratio ┃
┡━━━━━╇━━━━━━━━━━━━━━┩
│ mtd │ 0.000        │
├─────┼──────────────┤
│ qtd │ 0.000        │
├─────┼──────────────┤
│ ytd │ 0.191        │
├─────┼──────────────┤
│ 3m  │ nan          │
├─────┼──────────────┤
│ 6m  │ 0.191        │
├─────┼──────────────┤
│ 1y  │ 0.162        │
├─────┼──────────────┤
│ 3y  │ 0.143        │
├─────┼──────────────┤
│ 5y  │ 0.311        │
├─────┼──────────────┤
│ 10y │ 0.731        │
├─────┼──────────────┤
│ all │ 0.796        │
└─────┴──────────────┘

Copy link
Contributor

@JerBouma JerBouma left a comment

Choose a reason for hiding this comment

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

The information ratio doesn't seem to work.

2022 Jul 25, 06:03 (🦋) /portfolio/ $ load Public_Equity_Orderbook.xlsx
 Preprocessing orderbook: ..........
      Loading price data: .
     Calculating returns: .


Portfolio: Public_Equity_Orderbook.xlsx
Risk Free Rate: 0

2022 Jul 25, 06:04 (🦋) /portfolio/ $ bench SPDR S&P 500 ETF Trust (SPY)

Benchmark: SPDR S&P 500 ETF Trust (SPY) (SPY)

2022 Jul 25, 06:04 (🦋) /portfolio/ $ metric information
Error: not enough values to unpack (expected 2, got 1)

Error: not enough values to unpack (expected 2, got 0)

2022 Jul 25, 06:04 (🦋) /portfolio/ $

@JerBouma
Copy link
Contributor

If you fix linting, I am happy to approve :)

Copy link
Contributor

@JerBouma JerBouma left a comment

Choose a reason for hiding this comment

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

Let's go!

@JerBouma JerBouma merged commit 9034055 into OpenBB-finance:main Jul 26, 2022
@northern-64bit northern-64bit deleted the portfolio_metrics_fix branch July 26, 2022 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat S Small T-Shirt size Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants