Note
Click here to download the full example code or to run this example in your browser via Binder
Manipulating Statements¶
Note: The formatting of the statements is off in the web view. Download the Jupyter notebook for the full experience.
First import the necessary classes and pandas.
import os
os.chdir('..')
from finstmt import FinancialStatements, IncomeStatements, BalanceSheets
import pandas as pd
Load Financial Statements¶
root_folder = os.path.sep.join(['..', 'tests', 'sources', 'stockrow', 'CAT'])
inc_path = os.path.join(root_folder, 'annual_income.csv')
bs_path = os.path.join(root_folder, 'annual_bs.csv')
inc_df = pd.read_csv(inc_path, index_col=0)
bs_df = pd.read_csv(bs_path, index_col=0)
bs = BalanceSheets.from_df(bs_df)
inc = IncomeStatements.from_df(inc_df)
stmts = FinancialStatements(inc, bs)
INFO: Was not able to extract data from the following names: {'Other Liabilities', 'Net Debt', 'Other Assets', 'Investments'}
/home/runner/work/py-finstmt/py-finstmt/finstmt/findata/period_data.py:116: UserWarning: Previously had ebit extracted from "Operating Income". Replacing with value from "EBIT"
warnings.warn(
/home/runner/work/py-finstmt/py-finstmt/finstmt/findata/period_data.py:116: UserWarning: Previously had ebit extracted from "Operating Income". Replacing with value from "EBIT"
warnings.warn(
/home/runner/work/py-finstmt/py-finstmt/finstmt/findata/period_data.py:116: UserWarning: Previously had ebit extracted from "Operating Income". Replacing with value from "EBIT"
warnings.warn(
/home/runner/work/py-finstmt/py-finstmt/finstmt/findata/period_data.py:116: UserWarning: Previously had ebit extracted from "Operating Income". Replacing with value from "EBIT"
warnings.warn(
/home/runner/work/py-finstmt/py-finstmt/finstmt/findata/period_data.py:116: UserWarning: Previously had ebit extracted from "Operating Income". Replacing with value from "EBIT"
warnings.warn(
/home/runner/work/py-finstmt/py-finstmt/finstmt/findata/period_data.py:116: UserWarning: Previously had ebit extracted from "Operating Income". Replacing with value from "EBIT"
warnings.warn(
/home/runner/work/py-finstmt/py-finstmt/finstmt/findata/period_data.py:116: UserWarning: Previously had ebit extracted from "Operating Income". Replacing with value from "EBIT"
warnings.warn(
/home/runner/work/py-finstmt/py-finstmt/finstmt/findata/period_data.py:116: UserWarning: Previously had ebit extracted from "Operating Income". Replacing with value from "EBIT"
warnings.warn(
/home/runner/work/py-finstmt/py-finstmt/finstmt/findata/period_data.py:116: UserWarning: Previously had ebit extracted from "Operating Income". Replacing with value from "EBIT"
warnings.warn(
/home/runner/work/py-finstmt/py-finstmt/finstmt/findata/period_data.py:116: UserWarning: Previously had ebit extracted from "Operating Income". Replacing with value from "EBIT"
warnings.warn(
INFO: Was not able to extract data from the following names: {'EPS Diluted', 'Profit Margin', 'EBITDA', 'Net Income Com', 'Net Income - Discontinued ops', 'EBITDA Margin', 'Shares (weighted)', 'EBIT Margin', 'Shares (weighted, diluted)', 'Net Profit Margin', 'Revenue Growth', 'Shares (basic)', 'Consolidated Income', 'EPS', 'Gross Profit', 'Gross Margin', 'Preferred Dividends', 'Net Income - Non-Controlling int', 'Dividend per Share', 'Free Cash Flow margin', 'Earnings Before Tax Margin'}
View Statements¶
stmts
Select Statement Periods¶
Statements periods can be selected by indexing the statements object with them.
stmts['12-31-2018'] # one period
Now select multiple periods. Notice how the date format doesn’t matter.
stmts[['12/31/2015', '12-31-2018']]
Statement Math¶
All of the math operators are valid on statements. If the operation is with a number, it will apply to each item. If the operation is with another statement, for any overlapping time periods, it will apply the operation on the two items, while for non-overlapping time periods it will combine the statements.
Adjust Units¶
It is easy to adjust units by multiplying or dividing the statements.
stmts / 1000000 # in millions
Math with Overlapping Statements¶
If the time periods overlap, math will be done with each pair of items. This can be useful for aggregating statements from subsidiaries, segments, etc.:
stmts + stmts
Combine Non-Overlapping Statements¶
If the statements have different time periods, adding them will put both sets of periods in a single statement.
stmts['12/31/2018'] + stmts['12/31/2014']
This can be very useful in the case where you have done a forecast and need to calculate something which requires data from the last historical period, such as FCF.
stmts.config.update_all(['forecast_config', 'method'], 'trend')
fcst = stmts.forecast(periods=2)
(stmts[stmts.dates[-1]] + fcst).fcf.dropna()
INFO: Forecasting Income Statement
0%| | 0/16 [00:00<?, ?it/s]/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:72: FutureWarning: Argument `closed` is deprecated in favor of `inclusive`.
return pd.date_range(
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:39: FutureWarning: The default dtype for empty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning.
return pd.Series()
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:72: FutureWarning: Argument `closed` is deprecated in favor of `inclusive`.
return pd.date_range(
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:39: FutureWarning: The default dtype for empty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning.
return pd.Series()
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:72: FutureWarning: Argument `closed` is deprecated in favor of `inclusive`.
return pd.date_range(
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:39: FutureWarning: The default dtype for empty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning.
return pd.Series()
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:72: FutureWarning: Argument `closed` is deprecated in favor of `inclusive`.
return pd.date_range(
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:39: FutureWarning: The default dtype for empty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning.
return pd.Series()
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:72: FutureWarning: Argument `closed` is deprecated in favor of `inclusive`.
return pd.date_range(
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:39: FutureWarning: The default dtype for empty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning.
return pd.Series()
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:72: FutureWarning: Argument `closed` is deprecated in favor of `inclusive`.
return pd.date_range(
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:39: FutureWarning: The default dtype for empty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning.
return pd.Series()
100%|##########| 16/16 [00:00<00:00, 427.08it/s]
INFO: Forecasting Balance Sheet
0%| | 0/38 [00:00<?, ?it/s]/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:72: FutureWarning: Argument `closed` is deprecated in favor of `inclusive`.
return pd.date_range(
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:39: FutureWarning: The default dtype for empty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning.
return pd.Series()
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:72: FutureWarning: Argument `closed` is deprecated in favor of `inclusive`.
return pd.date_range(
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:39: FutureWarning: The default dtype for empty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning.
return pd.Series()
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:72: FutureWarning: Argument `closed` is deprecated in favor of `inclusive`.
return pd.date_range(
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:39: FutureWarning: The default dtype for empty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning.
return pd.Series()
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:72: FutureWarning: Argument `closed` is deprecated in favor of `inclusive`.
return pd.date_range(
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:39: FutureWarning: The default dtype for empty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning.
return pd.Series()
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:72: FutureWarning: Argument `closed` is deprecated in favor of `inclusive`.
return pd.date_range(
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:39: FutureWarning: The default dtype for empty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning.
return pd.Series()
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:72: FutureWarning: Argument `closed` is deprecated in favor of `inclusive`.
return pd.date_range(
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:39: FutureWarning: The default dtype for empty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning.
return pd.Series()
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:72: FutureWarning: Argument `closed` is deprecated in favor of `inclusive`.
return pd.date_range(
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:39: FutureWarning: The default dtype for empty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning.
return pd.Series()
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:72: FutureWarning: Argument `closed` is deprecated in favor of `inclusive`.
return pd.date_range(
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:39: FutureWarning: The default dtype for empty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning.
return pd.Series()
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:72: FutureWarning: Argument `closed` is deprecated in favor of `inclusive`.
return pd.date_range(
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:39: FutureWarning: The default dtype for empty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning.
return pd.Series()
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:72: FutureWarning: Argument `closed` is deprecated in favor of `inclusive`.
return pd.date_range(
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:39: FutureWarning: The default dtype for empty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning.
return pd.Series()
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:72: FutureWarning: Argument `closed` is deprecated in favor of `inclusive`.
return pd.date_range(
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:39: FutureWarning: The default dtype for empty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning.
return pd.Series()
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:72: FutureWarning: Argument `closed` is deprecated in favor of `inclusive`.
return pd.date_range(
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:39: FutureWarning: The default dtype for empty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning.
return pd.Series()
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:72: FutureWarning: Argument `closed` is deprecated in favor of `inclusive`.
return pd.date_range(
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:39: FutureWarning: The default dtype for empty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning.
return pd.Series()
100%|##########| 38/38 [00:00<00:00, 506.88it/s]
INFO: Balancing balance sheet
INFO: Balanced in 0.1s
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:72: FutureWarning: Argument `closed` is deprecated in favor of `inclusive`.
return pd.date_range(
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:39: FutureWarning: The default dtype for empty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning.
return pd.Series()
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:72: FutureWarning: Argument `closed` is deprecated in favor of `inclusive`.
return pd.date_range(
/home/runner/work/py-finstmt/py-finstmt/finstmt/forecast/models/base.py:39: FutureWarning: The default dtype for empty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning.
return pd.Series()
2019-12-31 -1.394863e+09
2020-12-31 -3.646065e+07
dtype: float64
Total running time of the script: ( 1 minutes 11.598 seconds)