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 new functionality to measure country performance #4514

Merged
merged 22 commits into from
Mar 20, 2023

Conversation

JerBouma
Copy link
Contributor

@JerBouma JerBouma commented Mar 17, 2023

Description

This adds new functionality to measure country performance, this includes:

  • economy/country: Country Performance
  • economy/gdp: Show annual nominal Gross Domestic Product (GDP)
  • economy/qgdp: Show quarterly real Gross Domestic Product (GDP)
  • economy/fgdp: Show forecasts of nominal and real Gross Domestic Product (GDP)
  • economy/debt: Show government debt-to-GDP ratio
  • economy/cpi: obtain the (harmonized) Consumer Price Index (CPI)
  • economy/ccpi: obtain components of the CPI including Food, Energy and Total
  • economy/balance: Show Government defict or surplus in capital income and expenditures
  • economy/revenue: Show Government revenue based on tax income
  • economy/spending: Show Government spending as indicator of size of government
  • economy/trust: Show Government trust based on surveys regarding confidence in the government

This makes it possible to look into cases like https://en.wikipedia.org/wiki/Greek_government-debt_crisis and https://economictimes.indiatimes.com/news/international/business/japans-debt-mountain-how-is-it-sustainable/articleshow/76298563.cms?from=mdr.

image

A good example is to look into the high Debt-to-GDP ratio that Greece has compared to the average OECD countries hinting at the large pressure of foreign debt.

image

I can also show how little my country cared about military compared to the United States 😛

image

How has this been tested?

Made new tests for oecd_model.py and also added them to the test_economy_controller.py.

  • 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.
  • [ x ] Make sure affected commands still run in terminal
  • [ x ] Ensure the SDK still works
  • [ x ] Check any related reports. Economy report not affected.

Checklist:

Others

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

@reviewpad reviewpad bot added the feat XL Extra Large feature label Mar 17, 2023
@codecov
Copy link

codecov bot commented Mar 17, 2023

Codecov Report

❗ No coverage uploaded for pull request base (develop@cceeb3e). Click here to learn what that means.
Patch has no changes to coverable lines.

❗ Current head 512b1ef differs from pull request most recent head 135c59f. Consider uploading reports for the commit 135c59f to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #4514   +/-   ##
==========================================
  Coverage           ?   54.69%           
==========================================
  Files              ?      586           
  Lines              ?    53233           
  Branches           ?        0           
==========================================
  Hits               ?    29115           
  Misses             ?    24118           
  Partials           ?        0           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@minhhoang1023
Copy link
Contributor

@JerBouma is there any free source that provides Country equity risk premium? This is one of the requirements in the Analyst requirements. I found that FMP has it but it's under paid tier now, so would be good to make it available to everyone.

@jmaslek
Copy link
Collaborator

jmaslek commented Mar 17, 2023

i broke it:

2023 Mar 17, 14:08 (🦋) /economy/ $ gdp -c united_states,china

Error: 'china'

Error: 'list' object has no attribute 'columns'

didnt realize that wasnt a choice, but found an edge case :P

@jmaslek
Copy link
Collaborator

jmaslek commented Mar 17, 2023

│     gdp                Show annual nominal Gross Domestic Product (GDP)                               [OECD]    │
│     qgdp               Show quarterly real Gross Domestic Product (GDP)      

this should be one function with a -q flag like in stocks/fa

@jmaslek
Copy link
Collaborator

jmaslek commented Mar 17, 2023

Screenshot 2023-03-17 at 2 15 12 PM

This seems kind of confusing. If its forecasting, we should probably indicate with some shading somewhere? Or is it the historical forecast?

@jmaslek
Copy link
Collaborator

jmaslek commented Mar 17, 2023

debt default timestampe not in correct form:

  -s START_DATE, --start START_DATE
                        Start date of data, in YYYY-MM-DD format (default: 1993-03-17 14:16:41.123661)
  -e END_DATE, --end END_DATE

@jmaslek
Copy link
Collaborator

jmaslek commented Mar 17, 2023

cpi seems misleading since you give the numbers in terms of YoY, but the chart is titled as CPI:

Screenshot 2023-03-17 at 2 19 11 PM

@jmaslek
Copy link
Collaborator

jmaslek commented Mar 17, 2023

ccpi takes forever, anything we can add a timer for?

@deeleeramone
Copy link
Contributor

It would be ideal to have the functionality available to other time-series data in the economy menu.

Screenshot 2023-03-17 at 1 57 26 PM

@JerBouma
Copy link
Contributor Author

JerBouma commented Mar 17, 2023

│     gdp                Show annual nominal Gross Domestic Product (GDP)                               [OECD]    │
│     qgdp               Show quarterly real Gross Domestic Product (GDP)      

this should be one function with a -q flag like in stocks/fa

Issue is that a good bunch of countries don't have quarterly so then you need some smart functionality too.

And more importantly, one is real other is nominal. I think I should just call it rdgp instead.

@JerBouma
Copy link
Contributor Author

ccpi takes forever, anything we can add a timer for?

Most likely the date range is too big, will look into it.

@JerBouma
Copy link
Contributor Author

cpi seems misleading since you give the numbers in terms of YoY, but the chart is titled as CPI:

Screenshot 2023-03-17 at 2 19 11 PM

CPI is actually by default known as YoY so this is normal actually. Just Google CPI and look at the charts.

@JerBouma
Copy link
Contributor Author

Screenshot 2023-03-17 at 2 15 12 PM

This seems kind of confusing. If its forecasting, we should probably indicate with some shading somewhere? Or is it the historical forecast?

Fixed, it also doesn't plot this box if you change the date to be before a future date.

image

@JerBouma
Copy link
Contributor Author

JerBouma commented Mar 19, 2023

@jmaslek

Fixed everything you mentioned:

  • Instead of mention annual and quarterly gdp, I mention nominal and real GDP. Since they have different country lists, my suggestion is to keep them seperate. Also becomes they are two quite different things.
  • Fixed all date formats.
  • Reduced CCPI range, it was set to 30 years with monthly data which meant long loading. This is now 5 years with monthly data.
  • I didn't change CPI since YoY is actually how CPI is represented. When people say the "CPI is 10%" they mean "10% compared to previous year". The term Consumer Price Index just doesn't refer to an index with a specific base .
  • Fixed forecasting GDP to present the actual forecast.
  • If you now enter a country that has no data (as not in the list) the _model will tell you.

EDIT: also saw that I could make things more efficient so the query now already reflects units, measurements etc. Now all should be pretty quick.

@JerBouma
Copy link
Contributor Author

JerBouma commented Mar 19, 2023

@minhhoang1023

Actually, yes? See: https://www.oecd.org/trade/topics/export-credits/arrangement-and-sector-understandings/financing-terms-and-conditions/country-risk-classification/

Can you check if this seems to be what you might need? Then, we do need to find a way to read this PDF and get the table out but I am confident in the Engineers to make that work.

Note:

The country risk classifications are meant to reflect country risk. Under the Participants’ system, country risk encompasses transfer and convertibility risk (i.e. the risk a government imposes capital or exchange controls that prevent an entity from converting local currency into foreign currency and/or transferring funds to creditors located outside the country) and cases of force majeure (e.g. war, expropriation, revolution, civil disturbance, floods, earthquakes).

The country risk classifications are not sovereign risk classifications and therefore should not be compared with the sovereign risk classifications of private credit rating agencies (CRAs). Conceptually, they are more similar to the “country ceilings” that are produced by some of the major CRAs. Please note that no historical risk classifications exist prior to the establishment of the rules in 1997.

@JerBouma
Copy link
Contributor Author

I don't know why it does this, made a new env too. Can you fix tests for me? Just needs a rewrite @jmaslek

INTERNALERROR>   File "/Users/jeroenbouma/miniconda3/envs/obb2/lib/python3.10/site-packages/pluggy/_result.py", line 9, in _raise_wrapfail
INTERNALERROR>     raise RuntimeError(
INTERNALERROR> RuntimeError: wrap_controller at 'pytest_runtest_makereport' /Users/jeroenbouma/miniconda3/envs/obb2/lib/python3.10/site-packages/dash/testing/plugin.py:106 did not yield

=============================================================================== no tests ran in 0.05s ===============================================================================
(obb2) jeroenbouma@Jeroens-MacBook-Pro OpenBBTerminal % 

@jmaslek
Copy link
Collaborator

jmaslek commented Mar 20, 2023

rgdp -u IDX -c united_states
Screenshot 2023-03-20 at 8 50 25 AM

Also for the gdp numbers, lets default to dollars instead of percent change to match what one would find with a google search or a fred search:
Screenshot 2023-03-20 at 8 52 12 AM

@jmaslek
Copy link
Collaborator

jmaslek commented Mar 20, 2023

None of these functionalities have been added to the economy integration test scripts (under miscellaneous)

@jmaslek
Copy link
Collaborator

jmaslek commented Mar 20, 2023

Under fgdp, you have:

  -u {Q,A}, --units {Q,A}
                        Use either Q (quarterly) or A (annually) for units (default: Q)

Lets use the same standard we use in /fa/ and just make this a -q flag.

@JerBouma
Copy link
Contributor Author

rgdp -u IDX -c united_states Screenshot 2023-03-20 at 8 50 25 AM

Also for the gdp numbers, lets default to dollars instead of percent change to match what one would find with a google search or a fred search: Screenshot 2023-03-20 at 8 52 12 AM

Fixed this and Real GDP of OECD doesn't have absolute numbers unfortunately. Can add in FRED as additional source but in the end, this does allow for proper comparison between countries and if you want macro gives RGDP absolute numbers (just a bit limited). I am bit conflicted if it's worth the time now to build that in properly, I don't need it for my case.

Also fixed quarterly flag for fgdp and added commands to integration tests. Also, are integration tests still used? The file contained a lot of old functionality which is why I didn't update it at first.

@jmaslek
Copy link
Collaborator

jmaslek commented Mar 20, 2023

Looks like the sdk trail map is missing too. Looks like you edited economy_sdk_model.py, but if you look at the top:

# ######### THIS FILE IS AUTO GENERATED - ANY CHANGES WILL BE VOID ######### #

That file gets generated from the trail map.

@JerBouma
Copy link
Contributor Author

Looks like the sdk trail map is missing too. Looks like you edited economy_sdk_model.py, but if you look at the top:

# ######### THIS FILE IS AUTO GENERATED - ANY CHANGES WILL BE VOID ######### #

That file gets generated from the trail map.

So do I still need to update the csv? I thought that wasnt te way to go anymore.

@jmaslek
Copy link
Collaborator

jmaslek commented Mar 20, 2023

Looks like the sdk trail map is missing too. Looks like you edited economy_sdk_model.py, but if you look at the top:

# ######### THIS FILE IS AUTO GENERATED - ANY CHANGES WILL BE VOID ######### #

That file gets generated from the trail map.

So do I still need to update the csv? I thought that wasnt te way to go anymore.

yup:
https://github.com/OpenBB-finance/OpenBBTerminal/blob/develop/CONTRIBUTING.md#add-sdk-endpoint

@JerBouma
Copy link
Contributor Author

Looks like the sdk trail map is missing too. Looks like you edited economy_sdk_model.py, but if you look at the top:

# ######### THIS FILE IS AUTO GENERATED - ANY CHANGES WILL BE VOID ######### #

That file gets generated from the trail map.

So do I still need to update the csv? I thought that wasnt te way to go anymore.

yup: https://github.com/OpenBB-finance/OpenBBTerminal/blob/develop/CONTRIBUTING.md#add-sdk-endpoint

Fixed, actually ran into unrelated issues when running that script so fixed that too. Apparently not everyone runs that script on every change ;)

@jmaslek jmaslek enabled auto-merge March 20, 2023 15:09
@jmaslek jmaslek added this pull request to the merge queue Mar 20, 2023
@jmaslek jmaslek removed this pull request from the merge queue due to a manual request Mar 20, 2023
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.

anything on the website need to be changed?

jmaslek added a commit that referenced this pull request Mar 20, 2023
* Add in new country parameters

* Add in tests corresponding to the new commands

* Update SDK and some more robustness

* Update tests

* Update tests

* Revenue and spending didnt work, then saw spending has many more options

* Small bug

* Update tests and overall improvements

* Forgot to add ccpi

* Make more efficient

* Update tests

* Fix IDX issue within real gdp

* Add quarterly flag to fgdp

* Add integration tests

* Update tests

* Fix SDK and related bugs and fix CPI for SDK

* Zzzz tests

---------

Co-authored-by: James Maslek <[email protected]>
@JerBouma
Copy link
Contributor Author

anything on the website need to be changed?

Added new menu image but that's it, examples are sound.

@jmaslek
Copy link
Collaborator

jmaslek commented Mar 20, 2023

anything on the website need to be changed?

Added new menu image but that's it, examples are sound.

thank you sir

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.

noice

@jmaslek jmaslek added this pull request to the merge queue Mar 20, 2023
@jmaslek jmaslek merged commit 6b4f0ad into develop Mar 20, 2023
@jmaslek jmaslek deleted the feature/country-performance branch March 20, 2023 15:32
jmaslek added a commit that referenced this pull request Apr 13, 2023
* Add in new country parameters

* Add in tests corresponding to the new commands

* Update SDK and some more robustness

* Update tests

* Update tests

* Revenue and spending didnt work, then saw spending has many more options

* Small bug

* Update tests and overall improvements

* Forgot to add ccpi

* Make more efficient

* Update tests

* Fix IDX issue within real gdp

* Add quarterly flag to fgdp

* Add integration tests

* Update tests

* Fix SDK and related bugs and fix CPI for SDK

* Zzzz tests

---------

Co-authored-by: James Maslek <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat XL Extra Large feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants