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

Showing portfolio portfolios after optimizing in po now works, cash comment removed from portfolio docs and Parameter file info added #4149

Merged
merged 16 commits into from
Feb 7, 2023

Conversation

JerBouma
Copy link
Contributor

@JerBouma JerBouma commented Feb 6, 2023

Description

This PR fixes:

Careful consideration and discussion has been done regarding not having cash (deposits and withdrawals) within the transactions data. This adds in complexity whereas the added benefit is not necessarily massive. E.g. a fund aims to have a cash position of zero anyways, moving funds between assets. Also note that the menu currently is a proof of concept and therefore has limitations regarding profits and levered positions. There is only so much we can work on ;)

Within the order book, cash is always taken out of the equation. The assumption is that you are able to fund any order you make and have exactly that portion of cash available leaving your net cash position always at 0. Therefore, any order you make always occurs the following way:

  • Deposit enough cash to the brokerage
  • Make your purchases
  • Withdraw any cash that is still left

You note the profit you received here. E.g. let’s say you sell for $2500 and you invested $2000. This means that your total invested amount reduces by $2000 and your total value by $2500. E.g. $5000 total invested and $7500 total value changes to $3000 total invested and $5000 total value. You’d have a +$500 profit that is taken out of the equation and stored separately. Again, assumption is that the $2000 goes back to your bank account. Whenever you make investments, you deduct this amount of the investment you do (if reachable). E.g. I invest $2000, then I add in $1500 to total invested and $2000 to total value ($1500 + 500 of the “profit”) and I set my reserves to 0.

Complexity arrises when you invest 500, 500 and 500 and then decide to sell 750. Do you use FIFO, LIFO, WACC. Should it feature a time component? Methods we will have in the future when we expand the functionality.

See how portfolio --> po now works.

(🦋) /portfolio/ $ load --example

Loading an example, please type `about` to learn how to create your own Portfolio Excel sheet.

Preprocessing transactions: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 14/14 [00:03<00:00,  4.31it/s]
        Loading price data: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:01<00:00,  1.33s/it]
       Calculating returns: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00,  3.28it/s]
         Loading benchmark: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 4/4 [00:01<00:00,  2.03it/s]

Portfolio: OpenBB Example Portfolio
Risk Free Rate: 0.00%
Benchmark: SPDR S&P 500 ETF Trust (SPY)

(🦋) /portfolio/ $ po

╭───────────────────────────────────────────────────────────────────────────── Portfolio - Portfolio Optimization ──────────────────────────────────────────────────────────────────────────────╮
│                                                                                                                                                                                               │
│     load               load tickers and categories from .xlsx or .csv file (use load --example for an example)                                                                                │
│                                                                                                                                                                                               │
│ Portfolio loaded:                                                                                                                                                                             │
│                                                                                                                                                                                               │
│ Tickers: AAPL, AMZN, APTV, ASML, BABA, DGX, GOOGL, NKE, TSM, YUM                                                                                                                              │
│ Categories: ASSET_CLASS, SECTOR, INDUSTRY, COUNTRY, CURRENCY                                                                                                                                  │
│                                                                                                                                                                                               │
│     file               file that contains portfolio risk parameters                                                                                                                           │
│ >   params             specify and show portfolio risk parameters                                                                                                                             │
│                                                                                                                                                                                               │
│ Parameter file:                                                                                                                                                                               │
│                                                                                                                                                                                               │
│ Mean Risk Optimization:                                                                                                                                                                       │
│     maxsharpe          maximal Sharpe ratio portfolio (a.k.a the tangency portfolio)                                                                                                          │
│     minrisk            minimum risk portfolio                                                                                                                                                 │
│     maxutil            maximal risk averse utility function, given some risk aversion parameter                                                                                               │
│     maxret             maximal return portfolio                                                                                                                                               │
│     maxdiv             maximum diversification portfolio                                                                                                                                      │
│     maxdecorr          maximum decorrelation portfolio                                                                                                                                        │
│     blacklitterman     black litterman portfolio                                                                                                                                              │
│     ef                 show the efficient frontier                                                                                                                                            │
│                                                                                                                                                                                               │
│ Risk Parity Optimization:                                                                                                                                                                     │
│     riskparity         risk parity portfolio using risk budgeting approach                                                                                                                    │
│     relriskparity      relaxed risk parity using least squares approach                                                                                                                       │
│                                                                                                                                                                                               │
│ Hierarchical Clustering Models:                                                                                                                                                               │
│     hrp                hierarchical risk parity                                                                                                                                               │
│     herc               hierarchical equal risk contribution                                                                                                                                   │
│     nco                nested clustering optimization                                                                                                                                         │
│                                                                                                                                                                                               │
│ Other Optimization Techniques:                                                                                                                                                                │
│     equal              equally weighted                                                                                                                                                       │
│     mktcap             weighted according to market cap (property marketCap)                                                                                                                  │
│     dividend           weighted according to dividend yield (property dividendYield)                                                                                                          │
│     property           weight according to selected info property                                                                                                                             │
│                                                                                                                                                                                               │
│ Optimized portfolio:                                                                                                                                                                          │
│                                                                                                                                                                                               │
│     rpf                remove portfolios from the list of saved portfolios                                                                                                                    │
│     show               show selected portfolios and categories from the list of saved portfolios                                                                                              │
│     plot               plot selected charts from the list of saved portfolios                                                                                                                 │
│                                                                                                                                                                                               │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── OpenBB Terminal v2.3.1 (https://openbb.co) ─╯
(🦋) /portfolio/po/ $ riskparity

Optimization can take time. Please be patient...

[3 Years] Risk parity portfolio based on risk budgeting approach
using volatility as risk measure

      Weights       
┏━━━━━━━┳━━━━━━━━━━┓
┃       ┃ Value    ┃
┡━━━━━━━╇━━━━━━━━━━┩
│ AAPL  │   9.47 % │
├───────┼──────────┤
│ AMZN  │   9.79 % │
├───────┼──────────┤
│ APTV  │   6.80 % │
├───────┼──────────┤
│ ASML  │   7.23 % │
├───────┼──────────┤
│ BABA  │   9.03 % │
├───────┼──────────┤
│ DGX   │  15.74 % │
├───────┼──────────┤
│ GOOGL │   9.81 % │
├───────┼──────────┤
│ NKE   │   9.75 % │
├───────┼──────────┤
│ TSM   │   9.47 % │
├───────┼──────────┤
│ YUM   │  12.91 % │
└───────┴──────────┘

Annual (by 252) expected return: 16.83%
Annual (by √252) volatility: 27.95%
Sharpe ratio: 0.4629

(🦋) /portfolio/po/ $ show --portfolios RP_0

Current Portfolios: RP_0

Current Categories: ASSET_CLASS, CURRENT_INVESTED_AMOUNT, INDUSTRY, SECTOR, CURRENCY, COUNTRY

Portfolio: RP_0

      Weights       
┏━━━━━━━┳━━━━━━━━━━┓
┃       ┃ Value    ┃
┡━━━━━━━╇━━━━━━━━━━┩
│ AAPL  │   9.47 % │
├───────┼──────────┤
│ AMZN  │   9.79 % │
├───────┼──────────┤
│ APTV  │   6.80 % │
├───────┼──────────┤
│ ASML  │   7.23 % │
├───────┼──────────┤
│ BABA  │   9.03 % │
├───────┼──────────┤
│ DGX   │  15.74 % │
├───────┼──────────┤
│ GOOGL │   9.81 % │
├───────┼──────────┤
│ NKE   │   9.75 % │
├───────┼──────────┤
│ TSM   │   9.47 % │
├───────┼──────────┤
│ YUM   │  12.91 % │
└───────┴──────────┘

                           Category - Asset_Class                           
┏━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┓
┃     ┃ Asset_Class ┃ Current_Invested_Amount ┃ Current_Weights ┃ Value    ┃
┡━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━┩
│ USD │ STOCK       │                48,694 $ │        100.00 % │ 100.00 % │
├─────┼─────────────┼─────────────────────────┼─────────────────┼──────────┤
│ USD │ TOTAL USD   │                48,694 $ │        100.00 % │ 100.00 % │
└─────┴─────────────┴─────────────────────────┴─────────────────┴──────────┘

                                   Category - Sector                                   
┏━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┓
┃     ┃ Sector                 ┃ Current_Invested_Amount ┃ Current_Weights ┃ Value    ┃
┡━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━┩
│ USD │ Communication Services │                   425 $ │          0.87 % │   9.81 % │
├─────┼────────────────────────┼─────────────────────────┼─────────────────┼──────────┤
│ USD │ Consumer Cyclical      │                17,119 $ │         35.16 % │  38.49 % │
├─────┼────────────────────────┼─────────────────────────┼─────────────────┼──────────┤
│ USD │ Healthcare             │                 4,081 $ │          8.38 % │  15.74 % │
├─────┼────────────────────────┼─────────────────────────┼─────────────────┼──────────┤
│ USD │ Technology             │                27,069 $ │         55.59 % │  35.96 % │
├─────┼────────────────────────┼─────────────────────────┼─────────────────┼──────────┤
│ USD │ TOTAL USD              │                48,694 $ │        100.00 % │ 100.00 % │
└─────┴────────────────────────┴─────────────────────────┴─────────────────┴──────────┘

                                        Category - Industry                                         
┏━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┓
┃     ┃ Industry                            ┃ Current_Invested_Amount ┃ Current_Weights ┃ Value    ┃
┡━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━┩
│ USD │ Auto Parts                          │                 4,104 $ │          8.43 % │   6.80 % │
├─────┼─────────────────────────────────────┼─────────────────────────┼─────────────────┼──────────┤
│ USD │ Consumer Electronics                │                 1,011 $ │          2.08 % │   9.47 % │
├─────┼─────────────────────────────────────┼─────────────────────────┼─────────────────┼──────────┤
│ USD │ Diagnostics & Research              │                 4,081 $ │          8.38 % │  15.74 % │
├─────┼─────────────────────────────────────┼─────────────────────────┼─────────────────┼──────────┤
│ USD │ Footwear & Accessories              │                 2,999 $ │          6.16 % │   9.75 % │
├─────┼─────────────────────────────────────┼─────────────────────────┼─────────────────┼──────────┤
│ USD │ Internet Content & Information      │                   425 $ │          0.87 % │   9.81 % │
├─────┼─────────────────────────────────────┼─────────────────────────┼─────────────────┼──────────┤
│ USD │ Internet Retail                     │                 7,920 $ │         16.27 % │  18.82 % │
├─────┼─────────────────────────────────────┼─────────────────────────┼─────────────────┼──────────┤
│ USD │ Restaurants                         │                 2,682 $ │          5.51 % │  12.91 % │
├─────┼─────────────────────────────────────┼─────────────────────────┼─────────────────┼──────────┤
│ USD │ Semiconductor Equipment & Materials │                20,995 $ │         43.12 % │   7.23 % │
├─────┼─────────────────────────────────────┼─────────────────────────┼─────────────────┼──────────┤
│ USD │ Semiconductors                      │                 4,476 $ │          9.19 % │   9.47 % │
├─────┼─────────────────────────────────────┼─────────────────────────┼─────────────────┼──────────┤
│ USD │ TOTAL USD                           │                48,694 $ │        100.00 % │ 100.00 % │
└─────┴─────────────────────────────────────┴─────────────────────────┴─────────────────┴──────────┘

                              Category - Country                              
┏━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┓
┃     ┃ Country       ┃ Current_Invested_Amount ┃ Current_Weights ┃ Value    ┃
┡━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━┩
│ USD │ China         │                 7,333 $ │         15.06 % │   9.03 % │
├─────┼───────────────┼─────────────────────────┼─────────────────┼──────────┤
│ USD │ Germany       │                 2,999 $ │          6.16 % │   9.75 % │
├─────┼───────────────┼─────────────────────────┼─────────────────┼──────────┤
│ USD │ Netherlands   │                20,995 $ │         43.12 % │   7.23 % │
├─────┼───────────────┼─────────────────────────┼─────────────────┼──────────┤
│ USD │ Taiwan        │                 4,476 $ │          9.19 % │   9.47 % │
├─────┼───────────────┼─────────────────────────┼─────────────────┼──────────┤
│ USD │ United States │                12,891 $ │         26.47 % │  64.52 % │
├─────┼───────────────┼─────────────────────────┼─────────────────┼──────────┤
│ USD │ TOTAL USD     │                48,694 $ │        100.00 % │ 100.00 % │
└─────┴───────────────┴─────────────────────────┴─────────────────┴──────────┘

                        Category - Currency                         
┏━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ Currency  ┃ Current_Invested_Amount ┃ Current_Weights ┃ Value    ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━┩
│ USD       │                48,694 $ │        100.00 % │ 100.00 % │
├───────────┼─────────────────────────┼─────────────────┼──────────┤
│ TOTAL USD │                48,694 $ │        100.00 % │ 100.00 % │
└───────────┴─────────────────────────┴─────────────────┴──────────┘

How has this been tested?

  • Please describe the tests that you ran to verify your changes.
  • Provide instructions so we can reproduce.
  • Please also list any relevant details for your test configuration.
  • Make sure affected commands still run in terminal
  • Ensure the SDK still works
  • Check any related reports

Checklist:

Others

  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.

@JerBouma JerBouma changed the title Portfolio to Po now works well and removed cash Portfolio to Po now works well and removed cash from Portfolio Feb 6, 2023
@JerBouma JerBouma changed the title Portfolio to Po now works well and removed cash from Portfolio Portfolio to Po now works well and removed cash from Portfolio Introduction doc Feb 6, 2023
@reviewpad reviewpad bot added the feat XS Extra small feature label Feb 6, 2023
@JerBouma JerBouma changed the title Portfolio to Po now works well and removed cash from Portfolio Introduction doc Showing portfolio portfolios after optimizing in po now works, cash comment removed from portfolio docs and Parameter file info added Feb 6, 2023
@JerBouma JerBouma linked an issue Feb 6, 2023 that may be closed by this pull request
@reviewpad reviewpad bot added feat M Medium T-Shirt size feature and removed feat XS Extra small feature labels Feb 6, 2023
@reviewpad reviewpad bot added feat XS Extra small feature and removed feat M Medium T-Shirt size feature labels Feb 6, 2023
@jmaslek jmaslek merged commit 1e1f19e into develop Feb 7, 2023
@jmaslek jmaslek deleted the feature/remove-cash branch February 7, 2023 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat XS Extra small feature
Projects
None yet
4 participants