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

[Bug] stocks/fa/balance --plot doesn't work after converting to K/M/B string notation #3873

Closed
JerBouma opened this issue Jan 5, 2023 · 3 comments · Fixed by #4142
Closed
Assignees
Labels
bug Fix bug

Comments

@JerBouma
Copy link
Contributor

JerBouma commented Jan 5, 2023

If this is the output:

2023 Jan 05, 05:17 (🦋) /stocks/fa/ $ cash --source FinancialModelingPrep

                                                                         MSFT Cash Flow
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃                                                ┃ 2018                ┃ 2019                ┃ 2020                ┃ 2021                ┃ 2022                ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ Reported currency                              │ USD                 │ USD                 │ USD                 │ USD                 │ USD                 │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Cik                                            │ 789.019 K           │ 789.019 K           │ 789.019 K           │ 789.019 K           │ 789.019 K           │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Filling date                                   │ 2018-08-03          │ 2019-08-01          │ 2020-07-30          │ 2021-07-29          │ 2022-07-28          │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Accepted date                                  │ 2018-08-03 11:03:33 │ 2019-08-01 16:09:55 │ 2020-07-30 20:44:46 │ 2021-07-29 16:21:55 │ 2022-07-28 16:06:19 │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Calendar year                                  │ 2.018 K             │ 2.019 K             │ 2.020 K             │ 2.021 K             │ 2.022 K             │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Period                                         │ FY                  │ FY                  │ FY                  │ FY                  │ FY                  │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Net income                                     │ 16.571 B            │ 39.240 B            │ 44.281 B            │ 61.271 B            │ 72.738 B            │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Depreciation and amortization                  │ 10.261 B            │ 11.682 B            │ 12.796 B            │ 11.686 B            │ 14.460 B            │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Deferred income tax                            │ 13.040 B            │ -3.534 B            │ -3.620 B            │ -150 M              │ -5.702 B            │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Stock based compensation                       │ 3.940 B             │ 4.652 B             │ 5.289 B             │ 6.118 B             │ 7.502 B             │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Change in working capital                      │ 2.284 B             │ 937 M               │ 2.148 B             │ -936 M              │ 446 M               │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Accounts receivables                           │ -3.862 B            │ -2.812 B            │ -2.577 B            │ -6.481 B            │ -6.834 B            │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Inventory                                      │ -465 M              │ 597 M               │ 168 M               │ -737 M              │ -1.123 B            │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Accounts payables                              │ 1.148 B             │ 232 M               │ 3.018 B             │ 2.798 B             │ 2.943 B             │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Other working capital                          │ 5.922 B             │ 4.462 B             │ 2.212 B             │ 2.324 B             │ 5.805 B             │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Other non cash items                           │ -2.212 B            │ -792 M              │ -219 M              │ -1.249 B            │ -409 M              │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Net cash provided by operating activities      │ 43.884 B            │ 52.185 B            │ 60.675 B            │ 76.740 B            │ 89.035 B            │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Investments in property plant and equipment    │ -11.632 B           │ -13.925 B           │ -15.441 B           │ -20.622 B           │ -23.886 B           │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Acquisitions net                               │ -888 M              │ -2.388 B            │ -2.521 B            │ -8.909 B            │ -22.038 B           │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Purchases of investments                       │ -137.380 B          │ -57.697 B           │ -77.190 B           │ -62.924 B           │ -26.456 B           │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Sales maturities of investments                │ 143.937 B           │ 58.237 B            │ 84.170 B            │ 65.800 B            │ 44.894 B            │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Other investing activites                      │ -98 M               │ 0                   │ -1.241 B            │ -922 M              │ -2.825 B            │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Net cash used for investing activites          │ -6.061 B            │ -15.773 B           │ -12.223 B           │ -27.577 B           │ -30.311 B           │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Debt repayment                                 │ -10.060 B           │ -4 B                │ -5.518 B            │ -3.750 B            │ -9.023 B            │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Common stock issued                            │ 1.002 B             │ 1.142 B             │ 1.343 B             │ 1.693 B             │ 1.841 B             │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Common stock repurchased                       │ -10.721 B           │ -19.543 B           │ -22.968 B           │ -27.385 B           │ -32.696 B           │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Dividends paid                                 │ -12.699 B           │ -13.811 B           │ -15.137 B           │ -16.521 B           │ -18.135 B           │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Other financing activites                      │ -1.112 B            │ -675 M              │ -3.751 B            │ -2.523 B            │ -863 M              │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Net cash used provided by financing activities │ -33.590 B           │ -36.887 B           │ -46.031 B           │ -48.486 B           │ -58.876 B           │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Effect of forex changes on cash                │ 50 M                │ -115 M              │ -201 M              │ -29 M               │ -141 M              │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Net change in cash                             │ 4.283 B             │ -590 M              │ 2.220 B             │ 648 M               │ -293 M              │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Cash at end of period                          │ 11.946 B            │ 11.356 B            │ 13.576 B            │ 14.224 B            │ 13.931 B            │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Cash at beginning of period                    │ 7.663 B             │ 11.946 B            │ 11.356 B            │ 13.576 B            │ 14.224 B            │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Operating cash flow                            │ 43.884 B            │ 52.185 B            │ 60.675 B            │ 76.740 B            │ 89.035 B            │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Capital expenditure                            │ -11.632 B           │ -13.925 B           │ -15.441 B           │ -20.622 B           │ -23.886 B           │
├────────────────────────────────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ Free cash flow                                 │ 32.252 B            │ 38.260 B            │ 45.234 B            │ 56.118 B            │ 65.149 B            │
└────────────────────────────────────────────────┴─────────────────────┴─────────────────────┴─────────────────────┴─────────────────────┴─────────────────────┘
                                                                                                 Final link
Fiscal Date Ending
2018                https://www.sec.gov/Archives/edgar/data/789019/000156459018019062/msft-10k_20180630.htm
2019                https://www.sec.gov/Archives/edgar/data/789019/000156459019027952/msft-10k_20190630.htm
2020                https://www.sec.gov/Archives/edgar/data/789019/000156459020034944/msft-10k_20200630.htm
2021                https://www.sec.gov/Archives/edgar/data/789019/000156459021039151/msft-10k_20210630.htm
2022                https://www.sec.gov/Archives/edgar/data/789019/000156459022026876/msft-10k_20220630.htm

                                                                                                                Link
Fiscal Date Ending
2018                https://www.sec.gov/Archives/edgar/data/789019/000156459018019062/0001564590-18-019062-index.htm
2019                https://www.sec.gov/Archives/edgar/data/789019/000156459019027952/0001564590-19-027952-index.htm
2020                https://www.sec.gov/Archives/edgar/data/789019/000156459020034944/0001564590-20-034944-index.htm
2021                https://www.sec.gov/Archives/edgar/data/789019/000156459021039151/0001564590-21-039151-index.htm
2022                https://www.sec.gov/Archives/edgar/data/789019/000156459022026876/0001564590-22-026876-index.htm

You can not use any of the plotting arguments as it would complain about not being able to convert a string:

2023 Jan 05, 05:17 (🦋) /stocks/fa/ $ cash --source FinancialModelingPrep --plot net_income

Error: could not convert string to float: 'USD'

Furthermore, the options that --plot provides often do not match when you use a different source than Yahoo Finance.

@github-actions github-actions bot added the bug Fix bug label Jan 5, 2023
@jmaslek
Copy link
Collaborator

jmaslek commented Jan 5, 2023

do you mean when the table contains Ms and Bs?

Furthermore, the options that --plot provides often do not match when you use a different source than Yahoo Finance.

This is a limitation of prompt toolkit. We cannot dynamically change the auto complete options based on the previous output (without massively slowing down), so we defaulted to picking yf options as default

@JerBouma
Copy link
Contributor Author

JerBouma commented Jan 5, 2023

@jmaslek

Yeah it tries to plot strings which is most likely due to the Ms and the Bs. For the auto complete, I think it can help we have some generic naming in that case. Right now, many will also fail since they do not match properly. Let the ones that are available at least map to something for each data source.

@jmaslek jmaslek changed the title [Bug] stocks/fa/balance --plot doesn't work if the source contains Ms and Bs [Bug] stocks/fa/balance --plot doesn't work after converting to K/M/B string notation Jan 5, 2023
@northern-64bit
Copy link
Contributor

northern-64bit commented Jan 14, 2023

Yeah it tries to plot strings which is most likely due to the Ms and the Bs.

This is not the case. The data output depends if one should plot or not, see following from the code base:

    df_fa = df_fa.iloc[:, 0:limit]
    df_fa_c = clean_metrics_df(df_fa, num=limit)

    return df_fa_c if not plot else df_fa

df_fa_c is the "clean" data frame and df_fa is the one for plotting.

Note that we default to the options of the chosen default data source.

@northern-64bit northern-64bit self-assigned this Jan 14, 2023
jmaslek added a commit that referenced this issue Feb 20, 2023
* Fix plotting error

I choose to fix it by removing the denomination transform, since it doesn't affect the result (even when fixed).

* Add generic naming to financial statements, except for EODHD source

* Fix linting

* Fix linting

* Fix bugs

* Fix linting

* Handle invalid plot options for sources

* Fix linting

* Fix linting

* Some tests

* more tests

---------

Co-authored-by: James Maslek <jmaslek11@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fix bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants