Custom Ratios
Calculates all Custom Ratios based on the data provided.
Note that any of the following characters are considered as operators: +, -, *, /, **, %, //, <, >, ==, !=, >=, <=, (, ) using any of the above characters as part of the column naming will result into an error.
Custom Ratios in Python
collect_custom_ratios is part of the Ratios module of the open-source Finance Toolkit. Install it with:
pip install financetoolkit -U
Then call collect_custom_ratios as shown below.
from financetoolkit import Toolkit
custom_ratios = {
'WC / Net Income as %': '(Working Capital / Net Income) * 100',
'Large Revenues': 'Revenue > 1000000000',
'Quick Assets': 'Cash and Short Term Investments + Accounts Receivable',
'Cash Op Expenses':'Cost of Goods Sold + Selling, General and Administrative Expenses '
'- Depreciation and Amortization',
'Daily Cash Op Expenses': 'Cash Op Expenses / 365',
'Defensive Interval':'Quick Assets / Daily Cash Op Expenses'
}
companies = Toolkit(
tickers=["AAPL", "MSFT", "GOOGL", "AMZN"],
api_key="FINANCIAL_MODELING_PREP_KEY",
start_date="2022-10-01",
quarterly=True
)
custom_ratios = companies.ratios.collect_custom_ratios(
custom_ratios_dict=custom_ratios
)
custom_ratios.loc['AMZN']
Which returns:
| 2022Q4 | 2023Q1 | 2023Q2 | 2023Q3 | |
|---|---|---|---|---|
| WC / Net Income as % | 463.349 | 427.335 | 398.924 | 371.423 |
| Large Revenues | 1 | 1 | 1 | 1 |
| Quick Assets | 1.35341e+11 | 1.41847e+11 | 1.5995e+11 | 1.80898e+11 |
| Cash Op Expenses | 2.1056e+10 | 1.9972e+10 | 2.2854e+10 | 1.9042e+10 |
| Daily Cash Op Expenses | 5.76877e+07 | 5.47178e+07 | 6.26137e+07 | 5.21699e+07 |
| Defensive Interval | 2346.1 | 2592.34 | 2554.55 | 3467.48 |
Parameters
collect_custom_ratios accepts the following parameters:
- custom_ratios (dict): A dictionary containing the custom ratios to calculate.
- options (bool): Whether to return the available names to use in the custom ratios.
- rounding (int, optional): The number of decimals to round the results to. Defaults to 4.
- growth (bool, optional): Whether to calculate the growth of the ratios. Defaults to False.
- lag (int | str, optional): The lag to use for the growth calculation. Defaults to 1.
- standardize (bool, optional): Whether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False.
- trailing (int): Defines whether to select a trailing period. E.g. when selecting 4 with quarterly data, the TTM is calculated.