Skip to content

Commit

Permalink
Minor updates'
Browse files Browse the repository at this point in the history
  • Loading branch information
JerBouma committed Sep 21, 2024
1 parent e961ebb commit 9887f59
Show file tree
Hide file tree
Showing 13 changed files with 2,049 additions and 1,879 deletions.
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.6.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
Expand All @@ -10,16 +10,16 @@ repos:
- id: check-merge-conflict
- id: detect-private-key
- repo: https://github.com/psf/black
rev: 23.1.0
rev: 24.8.0
hooks:
- id: black
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.1.1"
rev: "v0.6.7"
hooks:
- id: ruff
entry: ruff --ignore PLR0915,S301
entry: ruff check --ignore PLR0915,S301
- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
rev: v2.3.0
hooks:
- id: codespell
entry: codespell
Expand Down
15 changes: 7 additions & 8 deletions financetoolkit/historical_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Historical Module"""

__docformat__ = "google"

import contextlib
Expand Down Expand Up @@ -836,15 +837,13 @@ def convert_daily_to_other_period(

if "Cumulative Return" in period_historical_data:
if start:
start = pd.Period(start).asfreq(period_str)

if start < period_historical_data.index[0]:
start = period_historical_data.index[0]
start = max(
pd.Period(start).asfreq(period_str), period_historical_data.index[0]
)
if end:
end = pd.Period(end).asfreq(period_str)

if end > period_historical_data.index[-1]:
end = period_historical_data.index[-1]
end = min(
pd.Period(end).asfreq(period_str), period_historical_data.index[-1]
)

adjusted_return = period_historical_data.loc[start:end, "Return"].copy()
adjusted_return.iloc[0] = 0
Expand Down
163 changes: 84 additions & 79 deletions financetoolkit/ratios/ratios_controller.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Ratios Module"""

__docformat__ = "google"


Expand Down Expand Up @@ -473,33 +474,33 @@ def collect_efficiency_ratios(

efficiency_ratios: dict = {}

efficiency_ratios[
"Days of Inventory Outstanding"
] = self.get_days_of_inventory_outstanding(days=days, trailing=trailing)
efficiency_ratios[
"Days of Sales Outstanding"
] = self.get_days_of_sales_outstanding(days=days, trailing=trailing)
efficiency_ratios["Days of Inventory Outstanding"] = (
self.get_days_of_inventory_outstanding(days=days, trailing=trailing)
)
efficiency_ratios["Days of Sales Outstanding"] = (
self.get_days_of_sales_outstanding(days=days, trailing=trailing)
)
efficiency_ratios["Operating Cycle"] = self.get_operating_cycle(
trailing=trailing
)
efficiency_ratios[
"Days of Accounts Payable Outstanding"
] = self.get_days_of_accounts_payable_outstanding(days=days, trailing=trailing)
efficiency_ratios["Days of Accounts Payable Outstanding"] = (
self.get_days_of_accounts_payable_outstanding(days=days, trailing=trailing)
)
efficiency_ratios["Cash Conversion Cycle"] = self.get_cash_conversion_cycle(
days=days, trailing=trailing
)
efficiency_ratios[
"Cash Conversion Efficiency"
] = self.get_cash_conversion_efficiency(trailing=trailing)
efficiency_ratios["Cash Conversion Efficiency"] = (
self.get_cash_conversion_efficiency(trailing=trailing)
)
efficiency_ratios["Receivables Turnover"] = self.get_receivables_turnover(
trailing=trailing
)
efficiency_ratios[
"Inventory Turnover Ratio"
] = self.get_inventory_turnover_ratio()
efficiency_ratios[
"Accounts Payable Turnover Ratio"
] = self.get_accounts_payables_turnover_ratio()
efficiency_ratios["Inventory Turnover Ratio"] = (
self.get_inventory_turnover_ratio()
)
efficiency_ratios["Accounts Payable Turnover Ratio"] = (
self.get_accounts_payables_turnover_ratio()
)
efficiency_ratios["SGA-to-Revenue Ratio"] = self.get_sga_to_revenue_ratio(
trailing=trailing
)
Expand Down Expand Up @@ -1745,15 +1746,15 @@ def collect_liquidity_ratios(
liquidity_ratios["Working Capital"] = self.get_working_capital(
trailing=trailing
)
liquidity_ratios[
"Operating Cash Flow Ratio"
] = self.get_operating_cash_flow_ratio(trailing=trailing)
liquidity_ratios[
"Operating Cash Flow to Sales Ratio"
] = self.get_operating_cash_flow_sales_ratio(trailing=trailing)
liquidity_ratios[
"Short Term Coverage Ratio"
] = self.get_short_term_coverage_ratio(trailing=trailing)
liquidity_ratios["Operating Cash Flow Ratio"] = (
self.get_operating_cash_flow_ratio(trailing=trailing)
)
liquidity_ratios["Operating Cash Flow to Sales Ratio"] = (
self.get_operating_cash_flow_sales_ratio(trailing=trailing)
)
liquidity_ratios["Short Term Coverage Ratio"] = (
self.get_short_term_coverage_ratio(trailing=trailing)
)

self._liquidity_ratios = (
pd.concat(liquidity_ratios)
Expand Down Expand Up @@ -2361,12 +2362,12 @@ def collect_profitability_ratios(
profitability_ratios["Net Profit Margin"] = self.get_net_profit_margin(
trailing=trailing
)
profitability_ratios[
"Interest Coverage Ratio"
] = self.get_interest_coverage_ratio(trailing=trailing)
profitability_ratios[
"Income Before Tax Profit Margin"
] = self.get_income_before_tax_profit_margin(trailing=trailing)
profitability_ratios["Interest Coverage Ratio"] = (
self.get_interest_coverage_ratio(trailing=trailing)
)
profitability_ratios["Income Before Tax Profit Margin"] = (
self.get_income_before_tax_profit_margin(trailing=trailing)
)
profitability_ratios["Effective Tax Rate"] = self.get_effective_tax_rate(
trailing=trailing
)
Expand All @@ -2376,24 +2377,24 @@ def collect_profitability_ratios(
profitability_ratios["Return on Equity"] = self.get_return_on_equity(
trailing=trailing
)
profitability_ratios[
"Return on Invested Capital"
] = self.get_return_on_invested_capital(trailing=trailing)
profitability_ratios[
"Return on Capital Employed"
] = self.get_return_on_capital_employed(trailing=trailing)
profitability_ratios[
"Return on Tangible Assets"
] = self.get_return_on_tangible_assets(trailing=trailing)
profitability_ratios["Return on Invested Capital"] = (
self.get_return_on_invested_capital(trailing=trailing)
)
profitability_ratios["Return on Capital Employed"] = (
self.get_return_on_capital_employed(trailing=trailing)
)
profitability_ratios["Return on Tangible Assets"] = (
self.get_return_on_tangible_assets(trailing=trailing)
)
profitability_ratios["Income Quality Ratio"] = self.get_income_quality_ratio(
trailing=trailing
)
profitability_ratios["Net Income per EBT"] = self.get_net_income_per_ebt(
trailing=trailing
)
profitability_ratios[
"Free Cash Flow to Operating Cash Flow Ratio"
] = self.get_free_cash_flow_operating_cash_flow_ratio()
profitability_ratios["Free Cash Flow to Operating Cash Flow Ratio"] = (
self.get_free_cash_flow_operating_cash_flow_ratio()
)
profitability_ratios["EBT to EBIT Ratio"] = self.get_EBT_to_EBIT(
trailing=trailing
)
Expand Down Expand Up @@ -3085,12 +3086,14 @@ def get_return_on_invested_capital(
.T.rolling(trailing)
.sum()
.T,
self._cash_flow_statement.loc[:, "Dividends Paid", :]
.T.rolling(trailing)
.sum()
.T
if dividend_adjusted
else 0,
(
self._cash_flow_statement.loc[:, "Dividends Paid", :]
.T.rolling(trailing)
.sum()
.T
if dividend_adjusted
else 0
),
self._balance_sheet_statement.loc[:, "Total Equity", :]
.shift(axis=1)
.T.rolling(trailing)
Expand All @@ -3115,9 +3118,11 @@ def get_return_on_invested_capital(
return_on_invested_capital = (
profitability_model.get_return_on_invested_capital(
self._income_statement.loc[:, "Net Income", :],
self._cash_flow_statement.loc[:, "Dividends Paid", :]
if dividend_adjusted
else 0,
(
self._cash_flow_statement.loc[:, "Dividends Paid", :]
if dividend_adjusted
else 0
),
self._balance_sheet_statement.loc[:, "Total Equity", :].shift(
axis=1
),
Expand Down Expand Up @@ -3846,9 +3851,9 @@ def collect_solvency_ratios(
solvency_ratios["Debt-to-Equity Ratio"] = self.get_debt_to_equity_ratio(
trailing=trailing
)
solvency_ratios[
"Debt Service Coverage Ratio"
] = self.get_debt_service_coverage_ratio(trailing=trailing)
solvency_ratios["Debt Service Coverage Ratio"] = (
self.get_debt_service_coverage_ratio(trailing=trailing)
)
solvency_ratios["Equity Multiplier"] = self.get_equity_multiplier(
trailing=trailing
)
Expand All @@ -3864,9 +3869,9 @@ def collect_solvency_ratios(
solvency_ratios["CAPEX Coverage Ratio"] = self.get_capex_coverage_ratio(
trailing=trailing
)
solvency_ratios[
"Dividend CAPEX Coverage Ratio"
] = self.get_capex_dividend_coverage_ratio(trailing=trailing)
solvency_ratios["Dividend CAPEX Coverage Ratio"] = (
self.get_capex_dividend_coverage_ratio(trailing=trailing)
)

self._solvency_ratios = (
pd.concat(solvency_ratios)
Expand Down Expand Up @@ -4352,7 +4357,7 @@ def get_free_cash_flow_yield(
if trailing:
market_cap = valuation_model.get_market_cap(
share_prices.T.rolling(trailing).sum().T,
average_shares.T.rolling(trailing).sum().T,
average_shares,
)

free_cash_flow_yield = solvency_model.get_free_cash_flow_yield(
Expand Down Expand Up @@ -4731,10 +4736,10 @@ def collect_valuation_ratios(
valuation_ratios["Price-to-Earnings"] = self.get_price_earnings_ratio(
include_dividends=include_dividends, diluted=diluted, trailing=trailing
)
valuation_ratios[
"Price-to-Earnings-Growth"
] = self.get_price_to_earnings_growth_ratio(
include_dividends=include_dividends, diluted=diluted, trailing=trailing
valuation_ratios["Price-to-Earnings-Growth"] = (
self.get_price_to_earnings_growth_ratio(
include_dividends=include_dividends, diluted=diluted, trailing=trailing
)
)
valuation_ratios["Book Value per Share"] = self.get_book_value_per_share(
diluted=diluted, trailing=trailing
Expand Down Expand Up @@ -4771,9 +4776,9 @@ def collect_valuation_ratios(
valuation_ratios["Price-to-Cash-Flow"] = self.get_price_to_cash_flow_ratio(
diluted=diluted, trailing=trailing
)
valuation_ratios[
"Price-to-Free-Cash-Flow"
] = self.get_price_to_free_cash_flow_ratio(diluted=diluted, trailing=trailing)
valuation_ratios["Price-to-Free-Cash-Flow"] = (
self.get_price_to_free_cash_flow_ratio(diluted=diluted, trailing=trailing)
)
valuation_ratios["Market Cap"] = self.get_market_cap(
diluted=diluted, trailing=trailing
)
Expand All @@ -4789,9 +4794,9 @@ def collect_valuation_ratios(
valuation_ratios["EV-to-EBITDA"] = self.get_ev_to_ebitda_ratio(
diluted=diluted, trailing=trailing
)
valuation_ratios[
"EV-to-Operating-Cash-Flow"
] = self.get_ev_to_operating_cashflow_ratio(diluted=diluted, trailing=trailing)
valuation_ratios["EV-to-Operating-Cash-Flow"] = (
self.get_ev_to_operating_cashflow_ratio(diluted=diluted, trailing=trailing)
)
valuation_ratios["Tangible Asset Value"] = self.get_tangible_asset_value(
trailing=trailing
)
Expand Down Expand Up @@ -4910,7 +4915,7 @@ def get_earnings_per_share(
.sum()
.T,
dividends,
average_shares, # Shares of current period
average_shares,
)
else:
dividends = (
Expand Down Expand Up @@ -4991,7 +4996,7 @@ def get_revenue_per_share(
if trailing:
revenue_per_share = valuation_model.get_revenue_per_share(
self._income_statement.loc[:, "Revenue", :].T.rolling(trailing).sum().T,
average_shares, # Shares of current period, alternatively average_shares.T.rolling(trailing).mean().T
average_shares,
)
else:
revenue_per_share = valuation_model.get_revenue_per_share(
Expand Down Expand Up @@ -5219,7 +5224,7 @@ def get_book_value_per_share(
.T.rolling(trailing)
.sum()
.T,
average_shares.T.rolling(trailing).sum().T,
average_shares,
)
else:
book_value_per_share = valuation_model.get_book_value_per_share(
Expand Down Expand Up @@ -5373,7 +5378,7 @@ def get_interest_debt_per_share(
.T.rolling(trailing)
.sum()
.T,
average_shares, # Shares of current period, alternatively average_shares.T.rolling(trailing).mean().T
average_shares,
)
else:
interest_debt_per_share = valuation_model.get_interest_debt_per_share(
Expand Down Expand Up @@ -5451,7 +5456,7 @@ def get_capex_per_share(
.T.rolling(trailing)
.sum()
.T,
average_shares, # Shares of current period, alternatively average_shares.T.rolling(trailing).mean().T
average_shares,
)
else:
capex_per_share = valuation_model.get_capex_per_share(
Expand Down Expand Up @@ -5598,7 +5603,7 @@ def get_weighted_dividend_yield(
.T.rolling(trailing)
.sum()
.T,
average_shares, # Shares of current period, alternatively average_shares.T.rolling(trailing).mean().T
average_shares,
share_prices,
)
else:
Expand Down Expand Up @@ -5837,8 +5842,8 @@ def get_market_cap(

if trailing:
market_cap = valuation_model.get_market_cap(
share_prices,
average_shares, # Shares of current period, alternatively average_shares.T.rolling(trailing).mean().T
share_prices,
average_shares,
)
else:
market_cap = valuation_model.get_market_cap(share_prices, average_shares)
Expand Down
Loading

0 comments on commit 9887f59

Please sign in to comment.