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

Portfolio optimization bug fixes #3675

Merged
merged 48 commits into from
Dec 2, 2022
Merged

Portfolio optimization bug fixes #3675

merged 48 commits into from
Dec 2, 2022

Conversation

montezdesousa
Copy link
Contributor

@montezdesousa montezdesousa commented Dec 1, 2022

Description

How has this been tested?

Terminal:
Run the portfolio optimization scripts in openbb_terminal/miscellaneous/scripts/portfolio
Try portfolio/po/params commands load and save

SDK:

from openbb_terminal.sdk import openbb

d = {
            "SECTOR": {
                "AAPL": "INFORMATION TECHNOLOGY",
                "MSFT": "INFORMATION TECHNOLOGY",
                "AMZN": "CONSUMER DISCRETIONARY",
            },
            "CURRENCY": {
                "AAPL": "USD",
                "MSFT": "USD",
                "AMZN": "USD",
            },
            "CURRENT_INVESTED_AMOUNT": {
                "AAPL": "100000.0",
                "MSFT": "200000.0",
                "AMZN": "300000.0",
            },
        }

p = openbb.portfolio.po.load(symbols_categories=d)
openbb.portfolio.po.maxsharpe(portfolio_engine=p)
openbb.portfolio.po.minrisk(portfolio_engine=p)
openbb.portfolio.po.maxutil(portfolio_engine=p)
openbb.portfolio.po.maxret(portfolio_engine=p)
openbb.portfolio.po.maxdiv(portfolio_engine=p)
openbb.portfolio.po.maxdecorr(portfolio_engine=p)
openbb.portfolio.po.blacklitterman(portfolio_engine=p)
openbb.portfolio.po.ef(portfolio_engine=p)
openbb.portfolio.po.ef_chart(portfolio_engine=p)
openbb.portfolio.po.riskparity(portfolio_engine=p)
openbb.portfolio.po.relriskparity(portfolio_engine=p)
openbb.portfolio.po.hrp(portfolio_engine=p)
openbb.portfolio.po.herc(portfolio_engine=p)
openbb.portfolio.po.nco(portfolio_engine=p)
openbb.portfolio.po.equal(portfolio_engine=p)
openbb.portfolio.po.mktcap(portfolio_engine=p)
openbb.portfolio.po.dividend(portfolio_engine=p)
openbb.portfolio.po.property(portfolio_engine=p, prop="forwardPE")
openbb.portfolio.po.plot(p, category="SECTOR", chart_type="pie")
openbb.portfolio.po.plot(p, category="SECTOR", chart_type="hist")
openbb.portfolio.po.plot(p, category="SECTOR", chart_type="dd")
openbb.portfolio.po.plot(p, category="SECTOR", chart_type="rc")
openbb.portfolio.po.plot(p, category="SECTOR", chart_type="heat")
openbb.portfolio.po.plot(p, category="CURRENCY", chart_type="heat")

@montezdesousa
Copy link
Contributor Author

@deeleeramone can you test this to see if the bugs you found are fixed pls?

@montezdesousa montezdesousa marked this pull request as ready for review December 1, 2022 19:01
@montezdesousa montezdesousa added the do not merge Label to prevent pull request merge label Dec 1, 2022
@montezdesousa montezdesousa removed the do not merge Label to prevent pull request merge label Dec 1, 2022
@deeleeramone
Copy link
Contributor

Will take a look at this shortly, thanks!

@deeleeramone
Copy link
Contributor

Amazing, @montezdesousa!! We're cooking with gas now! The ability to modify parameters in the terminal makes a much smoother user-experience, and now because you don't have leave the terminal, fine adjustments can be incorporated into routines!

Haven't yet tested with the SDK layer, but in the Terminal it is not crashing anymore and the argparse bug is gone. Error handling is also much more graceful.

I ran into a few minor things. First, a typo here in the output print, MaxUtil is returning a $ instead of %.

Screenshot 2022-12-01 at 6 24 18 PM

Secondly, I can't seem to make the window large enough to be able to have the title and axes labels on screen with plot --heat. In the image below, my screen is maxed out and I'm not able to get a usable image from it.

Screenshot 2022-12-01 at 7 05 28 PM

Zooming out doesn't help either.

Screenshot 2022-12-01 at 7 11 11 PM

If the syntax is incorrect, or using it wrong, plot --heat will print a big screen of nested dictionaries belonging to the portfolio file.

Screenshot 2022-12-01 at 6 39 36 PM

Thirdly, /po/params load does not see the OpenBBUserData folder.

Then a few comments, and I realize these fall outside of the scope of this PR; so, do with them as you will.

If I am remembering correctly, there was a previous effort to clean up all arguments, terminal-wide, so that - are assigned to only single letters; and arguments which can't reasonably be abbreviated as one letter should convert to being only -- with the full argument name. I'm pretty sure there was a specific reason for this, argparse-related, but it was a little while back.

Screenshot 2022-12-01 at 6 41 54 PM

Using the S&P 500 example, optimizing will show lots of 0.00 % allocations, but intuitively I know they are not actually zeros. There are +/- 0 % allocations, and you are unable to distinguish what this means. The user is also not able to verify if rounded numbers are being used for downstream calculations, which would create compounding errors. 0 is a much different outcome than 0.004.

Screenshot 2022-12-01 at 6 32 31 PM

I personally see no benefit to limiting the number of decimal places displayed, especially when the value is < 1. Displaying 1,000,000 is the same number of characters as 0.0000001. If the number is > 1, then a reasonable number of decimals might be 2 - 6, with less decimals as the number grows - i.e., 10, 100, 1000, 100000. For example, stocks and options are quoted on exchange on a sub-penny level; many crypto assets have a ridiculous number of zeros before the first integer.

Lastly, there must be a way to export the weightings of optimized portfolios for use in the main portfolio menu and elsewhere, or for recall. In the other direction, categories are already known by the main portfolio engine after a transactions file has been loaded. These two menus need to work together instead of independently.

@montezdesousa
Copy link
Contributor Author

Amazing, @montezdesousa!! We're cooking with gas now! The ability to modify parameters in the terminal makes a much smoother user-experience, and now because you don't have leave the terminal, fine adjustments can be incorporated into routines!

Haven't yet tested with the SDK layer, but in the Terminal it is not crashing anymore and the argparse bug is gone. Error handling is also much more graceful.

I ran into a few minor things. First, a typo here in the output print, MaxUtil is returning a $ instead of %.

Screenshot 2022-12-01 at 6 24 18 PM

Secondly, I can't seem to make the window large enough to be able to have the title and axes labels on screen with plot --heat. In the image below, my screen is maxed out and I'm not able to get a usable image from it.

Screenshot 2022-12-01 at 7 05 28 PM

Zooming out doesn't help either.

Screenshot 2022-12-01 at 7 11 11 PM

If the syntax is incorrect, or using it wrong, plot --heat will print a big screen of nested dictionaries belonging to the portfolio file.

Screenshot 2022-12-01 at 6 39 36 PM

Thirdly, /po/params load does not see the OpenBBUserData folder.

Then a few comments, and I realize these fall outside of the scope of this PR; so, do with them as you will.

If I am remembering correctly, there was a previous effort to clean up all arguments, terminal-wide, so that - are assigned to only single letters; and arguments which can't reasonably be abbreviated as one letter should convert to being only -- with the full argument name. I'm pretty sure there was a specific reason for this, argparse-related, but it was a little while back.

Screenshot 2022-12-01 at 6 41 54 PM

Using the S&P 500 example, optimizing will show lots of 0.00 % allocations, but intuitively I know they are not actually zeros. There are +/- 0 % allocations, and you are unable to distinguish what this means. The user is also not able to verify if rounded numbers are being used for downstream calculations, which would create compounding errors. 0 is a much different outcome than 0.004.

Screenshot 2022-12-01 at 6 32 31 PM

I personally see no benefit to limiting the number of decimal places displayed, especially when the value is < 1. Displaying 1,000,000 is the same number of characters as 0.0000001. If the number is > 1, then a reasonable number of decimals might be 2 - 6, with less decimals as the number grows - i.e., 10, 100, 1000, 100000. For example, stocks and options are quoted on exchange on a sub-penny level; many crypto assets have a ridiculous number of zeros before the first integer.

Lastly, there must be a way to export the weightings of optimized portfolios for use in the main portfolio menu and elsewhere, or for recall. In the other direction, categories are already known by the main portfolio engine after a transactions file has been loaded. These two menus need to work together instead of independently.

Thanks for your feedback! Taking a look

@montezdesousa
Copy link
Contributor Author

montezdesousa commented Dec 2, 2022

Can you describe the steps to reproduce this pls?

Edit: No need. Oddly, we are assuming that the values are in $ terms if the weights don't add up to 100% (with slight tolerance). I increase the tolerance to avoid this too often, but the logic itself does not make much sense to me. Are you aware of optimization methods in the menu that deal with actual $ instead of %?

If not, I'd include this issue in the decimals display issue I quoted below so that we address it later.

image

@montezdesousa
Copy link
Contributor Author

montezdesousa commented Dec 2, 2022

Regarding these points below, can you open specific issues so they don't get lost here in the comments? Already opened the arguments with more than one letter when '-' #3687

Quote:
Using the S&P 500 example, optimizing will show lots of 0.00 % allocations, but intuitively I know they are not actually zeros. There are +/- 0 % allocations, and you are unable to distinguish what this means. The user is also not able to verify if rounded numbers are being used for downstream calculations, which would create compounding errors. 0 is a much different outcome than 0.004.

Screenshot 2022-12-01 at 6 32 31 PM

I personally see no benefit to limiting the number of decimal places displayed, especially when the value is < 1. Displaying 1,000,000 is the same number of characters as 0.0000001. If the number is > 1, then a reasonable number of decimals might be 2 - 6, with less decimals as the number grows - i.e., 10, 100, 1000, 100000. For example, stocks and options are quoted on exchange on a sub-penny level; many crypto assets have a ridiculous number of zeros before the first integer.

Lastly, there must be a way to export the weightings of optimized portfolios for use in the main portfolio menu and elsewhere, or for recall. In the other direction, categories are already known by the main portfolio engine after a transactions file has been loaded. These two menus need to work together instead of independently.

@montezdesousa
Copy link
Contributor Author

montezdesousa commented Dec 2, 2022

Can you open a separate issue about this plot window thing? In my end it works fine when I maximize the window, not sure what's happening there tbh

image

@montezdesousa montezdesousa requested a review from jmaslek December 2, 2022 14:01
@deeleeramone
Copy link
Contributor

I don't think there are any models returning $ amounts. Will add to the decimal issue.

@montezdesousa montezdesousa merged commit faca7ab into main Dec 2, 2022
@montezdesousa montezdesousa deleted the po_toolkit branch December 2, 2022 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants