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

Add comparisons between the portfolio and benchmark including an orderbook sheet #1773

Merged
merged 32 commits into from
May 14, 2022

Conversation

JerBouma
Copy link
Contributor

@JerBouma JerBouma commented May 6, 2022

Description

This menu will be featuring a whole bunch of portfolio attribution commands. This allows you to understand how your portfolio performed via a variety of metrics comparing it to a benchmark to determine any alpha obtained. This is absolutely crucial to determine if active management has been beneficial.

Makes use of an orderbook sheet:
Screenshot 2022-05-06 at 18 08 10

Determine allocation differences between portfolio and benchmark (assets, sectors, countries and regions):

2022 May 13, 05:59 (🦋) /portfolio/ $ load Public_Equity_Orderbook.xlsx

Portfolio: Public_Equity_Orderbook.xlsx
Risk Free Rate: 0

2022 May 13, 06:00 (🦋) /portfolio/ $ bench Vanguard Total Stock Market ETF (VTI)

Benchmark: Vanguard Total Stock Market Index Fund (VTI)

2022 May 13, 06:00 (🦋) /portfolio/ $ alloc sectors
      Portfolio vs. Benchmark - Top 4 Sectors Allocation       
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ Sectors                ┃ Portfolio ┃ Benchmark ┃ Difference ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ Technology             │ 59.26%    │ 24.95%    │ 34.31%     │
├────────────────────────┼───────────┼───────────┼────────────┤
│ Communication Services │ 18.75%    │ 8.55%     │ 10.20%     │
├────────────────────────┼───────────┼───────────┼────────────┤
│ Consumer Cyclical      │ 15.62%    │ 11.55%    │ 4.07%      │
├────────────────────────┼───────────┼───────────┼────────────┤
│ Healthcare             │ 6.36%     │ 13.41%    │ -7.05%     │
└────────────────────────┴───────────┴───────────┴────────────┘

2022 May 13, 06:00 (🦋) /portfolio/ $ alloc assets
Portfolio vs. Benchmark - Top 10 Assets Allocation
┏━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ Symbol ┃ Portfolio ┃ Benchmark ┃ Difference ┃
┡━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ ASML   │ 24.41%    │ -         │ 24.41%     │
├────────┼───────────┼───────────┼────────────┤
│ AMZN   │ 22.21%    │ 3.33%     │ 18.88%     │
├────────┼───────────┼───────────┼────────────┤
│ GOOGL  │ 18.75%    │ 1.66%     │ 17.09%     │
├────────┼───────────┼───────────┼────────────┤
│ TSM    │ 9.38%     │ -         │ 9.38%      │
├────────┼───────────┼───────────┼────────────┤
│ DGX    │ 6.36%     │ -         │ 6.36%      │
├────────┼───────────┼───────────┼────────────┤
│ BABA   │ 5.47%     │ -         │ 5.47%      │
├────────┼───────────┼───────────┼────────────┤
│ APTV   │ 3.80%     │ -         │ 3.80%      │
├────────┼───────────┼───────────┼────────────┤
│ AAPL   │ 3.26%     │ 4.90%     │ -1.64%     │
├────────┼───────────┼───────────┼────────────┤
│ NKE    │ 3.25%     │ -         │ 3.25%      │
├────────┼───────────┼───────────┼────────────┤
│ YUM    │ 3.10%     │ -         │ 3.10%      │
└────────┴───────────┴───────────┴────────────┘

2022 May 13, 06:00 (🦋) /portfolio/ $ alloc countries
 Portfolio vs. Benchmark - Top 5 Countries Allocation 
┏━━━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ Countries     ┃ Portfolio ┃ Benchmark ┃ Difference ┃
┡━━━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ United States │ 57.48%    │ 99.17%    │ -41.69%    │
├───────────────┼───────────┼───────────┼────────────┤
│ Netherlands   │ 24.41%    │ -         │ 24.41%     │
├───────────────┼───────────┼───────────┼────────────┤
│ Taiwan        │ 9.38%     │ 1.00e-04  │ 9.37%      │
├───────────────┼───────────┼───────────┼────────────┤
│ China         │ 5.47%     │ -         │ 5.47%      │
├───────────────┼───────────┼───────────┼────────────┤
│ Germany       │ 3.25%     │ -         │ 3.25%      │
└───────────────┴───────────┴───────────┴────────────┘

2022 May 13, 06:00 (🦋) /portfolio/ $ alloc regions
  Portfolio vs. Benchmark - Top 3 Regions Allocation  
┏━━━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ Regions       ┃ Portfolio ┃ Benchmark ┃ Difference ┃
┡━━━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ North America │ 57.48%    │ 99.25%    │ -41.77%    │
├───────────────┼───────────┼───────────┼────────────┤
│ Europe        │ 27.66%    │ 0.64%     │ 27.02%     │
├───────────────┼───────────┼───────────┼────────────┤
│ Asia          │ 14.86%    │ 7.00e-04  │ 14.79%     │
└───────────────┴───────────┴───────────┴────────────┘

2022 May 13, 06:00 (🦋) /portfolio/ $ perf
            Portfolio vs. Benchmark - Totals             
┏━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃                  ┃ Portfolio ┃ Benchmark ┃ Difference ┃
┡━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ Total Investment │ 61331.99  │ 61331.99  │ -          │
├──────────────────┼───────────┼───────────┼────────────┤
│ Total Value      │ 96283.10  │ 82028.23  │ 14254.87   │
├──────────────────┼───────────┼───────────┼────────────┤
│ Total % Return   │ 56.99%    │ 33.74%    │ 23.24%     │
├──────────────────┼───────────┼───────────┼────────────┤
│ Total Abs Return │ 34951.11  │ 20696.24  │ 14254.87   │
└──────────────────┴───────────┴───────────┴────────────┘

2022 May 13, 06:00 (🦋) /portfolio/ $ perf -t
            Portfolio vs. Benchmark - Totals             
┏━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃                  ┃ Portfolio ┃ Benchmark ┃ Difference ┃
┡━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ Total Investment │ 61331.99  │ 61331.99  │ -          │
├──────────────────┼───────────┼───────────┼────────────┤
│ Total Value      │ 96283.10  │ 82028.23  │ 14254.87   │
├──────────────────┼───────────┼───────────┼────────────┤
│ Total % Return   │ 56.99%    │ 33.74%    │ 23.24%     │
├──────────────────┼───────────┼───────────┼────────────┤
│ Total Abs Return │ 34951.11  │ 20696.24  │ 14254.87   │
└──────────────────┴───────────┴───────────┴────────────┘

                                  Portfolio vs. Benchmark - Individual Trades                                  
┏━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ Date       ┃ Name  ┃ Portfolio Value ┃ % Portfolio Return ┃ Benchmark Value ┃ % Benchmark Return ┃ Alpha    ┃
┡━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━┩
│ 2010-05-03 │ CASH  │ 0.00e+00        │ 0.00e+00           │ 0.00e+00        │ 0.00e+00           │ 0.00e+00 │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2010-05-03 │ GOOGL │ 4513.76         │ 750.69%            │ 2104.60         │ 296.64%            │ 454.05%  │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2010-07-06 │ AMZN  │ 10693.05        │ 1843.13%           │ 2566.01         │ 366.29%            │ 1476.84% │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2011-08-06 │ AAPL  │ 427.68          │ 1030.53%           │ 157.67          │ 316.78%            │ 713.75%  │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2011-12-12 │ APTV  │ 457.45          │ 407.71%            │ 336.94          │ 273.96%            │ 133.76%  │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2012-02-03 │ ASML  │ 3656.52         │ 782.81%            │ 1409.35         │ 240.27%            │ 542.54%  │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2012-05-04 │ NKE   │ 323.70          │ 286.05%            │ 280.86          │ 234.96%            │ 51.09%   │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2012-08-04 │ TSM   │ 4384.50         │ 515.80%            │ 2344.17         │ 229.24%            │ 286.56%  │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2012-10-12 │ DGX   │ 816.54          │ 114.69%            │ 1214.07         │ 219.21%            │ -104.52% │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2013-02-03 │ YUM   │ 442.04          │ 140.34%            │ 551.36          │ 199.78%            │ -59.44%  │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2013-03-04 │ GOOGL │ 2256.88         │ 449.45%            │ 1206.35         │ 193.69%            │ 255.76%  │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2013-08-08 │ AMZN  │ 2138.61         │ 623.14%            │ 770.32          │ 160.47%            │ 462.67%  │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2013-10-09 │ AAPL  │ 712.80          │ 720.25%            │ 230.15          │ 164.85%            │ 555.41%  │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2014-02-03 │ APTV  │ 457.45          │ 84.72%             │ 619.65          │ 150.21%            │ -65.50%  │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2014-02-05 │ ASML  │ 1567.08         │ 513.39%            │ 635.39          │ 148.70%            │ 364.68%  │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2014-12-08 │ NKE   │ 1079.00         │ 120.84%            │ 1030.68         │ 110.95%            │ 9.89%    │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2015-02-02 │ BABA  │ 2432.70         │ -10.03%            │ 5778.87         │ 113.72%            │ -123.75% │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2015-03-08 │ TSM   │ 1753.80         │ 273.94%            │ 968.91          │ 106.59%            │ 167.35%  │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2015-12-05 │ DGX   │ 2857.89         │ 97.72%             │ 2980.71         │ 106.22%            │ -8.50%   │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2016-02-06 │ YUM   │ 221.02          │ 127.90%            │ 225.93          │ 132.97%            │ -5.07%   │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2016-09-07 │ GOOGL │ 4513.76         │ 179.32%            │ 3103.03         │ 92.02%             │ 87.30%   │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2017-01-10 │ AMZN  │ 4277.22         │ 168.70%            │ 2916.33         │ 83.21%             │ 85.49%   │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2017-05-10 │ AAPL  │ 1425.60         │ 272.03%            │ 662.08          │ 72.78%             │ 199.25%  │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2017-12-08 │ APTV  │ 914.90          │ 7.36%              │ 1319.18         │ 54.80%             │ -47.44%  │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2018-07-05 │ ASML  │ 2611.80         │ 166.52%            │ 1442.95         │ 47.25%             │ 119.28%  │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2018-09-03 │ NKE   │ 323.70          │ 35.55%             │ 332.25          │ 39.13%             │ -3.58%   │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2019-05-04 │ BABA  │ 405.45          │ -56.92%            │ 1286.22         │ 36.66%             │ -93.58%  │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2019-09-09 │ TSM   │ 263.07          │ 99.98%             │ 177.19          │ 34.70%             │ 65.28%   │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2019-12-10 │ DGX   │ 1088.72         │ 29.68%             │ 1070.16         │ 27.47%             │ 2.21%    │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2020-02-03 │ YUM   │ 1105.10         │ 3.85%              │ 1305.62         │ 22.70%             │ -18.84%  │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2020-03-08 │ GOOGL │ 6770.64         │ 85.63%             │ 5330.19         │ 46.14%             │ 39.49%   │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2020-06-09 │ AMZN  │ 4277.22         │ -17.77%            │ 6442.98         │ 23.86%             │ -41.64%  │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2020-12-12 │ AAPL  │ 570.24          │ 17.06%             │ 512.88          │ 5.29%              │ 11.78%   │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2021-01-07 │ APTV  │ 1829.80         │ -36.82%            │ 2904.34         │ 0.29%              │ -37.10%  │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2021-05-06 │ ASML  │ 15670.80        │ -18.93%            │ 17662.89        │ -8.63%             │ -10.31%  │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2021-12-28 │ NKE   │ 1402.70         │ -35.16%            │ 1751.31         │ -19.05%            │ -16.11%  │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2022-02-02 │ BABA  │ 2432.70         │ -34.01%            │ 3145.10         │ -14.68%            │ -19.33%  │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2022-03-04 │ TSM   │ 2630.70         │ -16.53%            │ 2838.16         │ -9.95%             │ -6.58%   │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2022-04-12 │ DGX   │ 1360.90         │ -0.86%             │ 1218.06         │ -11.27%            │ 10.41%   │
├────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2022-05-02 │ YUM   │ 1215.61         │ -4.54%             │ 1195.29         │ -6.13%             │ 1.60%    │
└────────────┴───────┴─────────────────┴────────────────────┴─────────────────┴────────────────────┴──────────┘

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 requested a review from jmaslek May 6, 2022 16:05
@JerBouma
Copy link
Contributor Author

JerBouma commented May 6, 2022

@jmaslek Initial set-up of the Portfolio menu but have a look if you like. Still a lot to do though.

@JerBouma JerBouma added the feat XL Extra Large feature label May 6, 2022
@JerBouma JerBouma self-assigned this May 6, 2022
@JerBouma JerBouma added feat M Medium T-Shirt size feature and removed feat XL Extra Large feature labels May 12, 2022
@JerBouma JerBouma marked this pull request as ready for review May 12, 2022 15:51
@JerBouma JerBouma changed the title Portfolio Attribution Menu Add comparisons between the portfolio and benchmark including an orderbook sheet May 12, 2022
@JerBouma
Copy link
Contributor Author

JerBouma commented May 12, 2022

@jmaslek @DidierRLopes

I kind of want to merge this PR before it gets too big. Especially since I have little time to work on it. Think I made some decent progress others can build on top of. So if one of you can review it that would be great.

@jmaslek
Copy link
Collaborator

jmaslek commented May 12, 2022

looking through images:

spelling:

2022 May 12, 06:23 (🦋) /portfolio/ $ alloc countries
alloLess than the limit 10 are shown because the portfolio only has 5 countries.

The zeros show as 0.00e+00 and my personal pet peeve of the date times showing with the times :P 2010-05-03 00:00:00

Copy link
Collaborator

@jmaslek jmaslek left a comment

Choose a reason for hiding this comment

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

couple small comments on printing but the rest looks good to me for now

@jmaslek
Copy link
Collaborator

jmaslek commented May 12, 2022

You also goofed the main terminal menu:

│ >   econometrics                                                                                                                                                          │
│                                                                                                                                                                           │
│ >   portfolio      

Copy link
Collaborator

@jmaslek jmaslek left a comment

Choose a reason for hiding this comment

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

2022 May 12, 14:43 (🦋) /portfolio/ $ load Public_Equity_Orderbook.xlsx

Portfolio: Public_Equity_Orderbook.xlsx
Risk Free Rate: 0

2022 May 12, 14:43 (🦋) /portfolio/ $ rolling
Error: 'Portfolio' object has no attribute 'benchmark_returns'

@JerBouma
Copy link
Contributor Author

looking through images:

spelling:

2022 May 12, 06:23 (🦋) /portfolio/ $ alloc countries
alloLess than the limit 10 are shown because the portfolio only has 5 countries.

The zeros show as 0.00e+00 and my personal pet peeve of the date times showing with the times :P 2010-05-03 00:00:00

So this is just me typing too quickly and thus the next command I am typing also showing. Will fix date format.

@JerBouma JerBouma requested a review from jmaslek May 13, 2022 08:49
@JerBouma
Copy link
Contributor Author

JerBouma commented May 13, 2022

@jmaslek Should all be fixed now and made some tables look a bit nicer.

@DidierRLopes DidierRLopes merged commit 7e37ed0 into OpenBB-finance:main May 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat M Medium T-Shirt size feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants