A financial modeling library for elixir. Contains functions that can be used as building blocks for complex financial modeling.
The package can be installed by adding financial
to your list of dependencies in mix.exs
:
def deps do
[
{:financials, "~> 0.1.0"}
]
end
All arguments must be decimals with the exception of "strictly integer type" arguments such as days
which may be either decimal, float or int. If you are unsure just use decimals.
Requests return a 2-tuple with the standard :ok
or :error
status.
All results within :ok
tuples are Decimals, and are string error-messages in :error
tuples.
# Use Decimals
total_liabilities = D.new("100500700.45")
total_equity = D.from_float(30050070.77)
# Successful response
{:ok, result} = Financials.debt_to_equity(total_liabilities, total_equity)
# Unsuccessful response due to argument type
{:error, "Arguments must be decimals"} = Financials.debt_to_equity(123.23, "23.45")
# Unsuccessful response due to argument value
{:error, "total_equity can't equal zero (Divide by zero error)"} = Financials.debt_to_equity(total_liabilities, 0)
- For more info check the
Decimal
hex docs here.
The context specifies the maximum precision of the result of calculations and the rounding algorithm if the result has a higher precision than the specified maximum. It also holds the list of set of trap enablers and the currently set flags.
The context is stored in the process dictionary, this means that you don't have to pass the context around explicitly and the flags will be updated automatically.
The context is accessed with Decimal.Context.get/0
and set with
Decimal.Context.set/1
. It can also be temporarily set with
Decimal.Context.with/2
.
iex> D.Context.get()
%Decimal.Context{flags: [:rounded, :inexact], precision: 9, rounding: :half_up,
traps: [:invalid_operation, :division_by_zero]}
iex> D.Context.set(%D.Context{D.Context.get() | traps: []})
:ok
iex> D.Context.get()
%Decimal.Context{flags: [:rounded, :inexact], precision: 9, rounding: :half_up,
traps: []}
The precision is used to limit the amount of decimal digits in the coefficient:
iex> D.Context.set(%D.Context{D.Context.get() | precision: 9})
:ok
iex> D.div(100, 3)
#Decimal<33.3333333>
iex> D.Context.set(%D.Context{D.Context.get() | precision: 2})
:ok
iex> D.div(100, 3)
#Decimal<33>
The rounding algorithm specifies how the result of an operation shall be rounded when it get be represented with the current precision:
iex> D.Context.set(%D.Context{D.Context.get() | rounding: :half_up})
:ok
iex> D.div(31, 2)
#Decimal<16>
iex> D.Context.set(%D.Context{D.Context.get() | rounding: :floor})
:ok
iex> D.div(31, 2)
#Decimal<15>
net_income(total_revenues, total_expenses)
earnings(net_income, preferred_dividends)
retained_earnings(beginning_period_retained_earnings, net_income, cash_dividends, stock_dividends)
ocf(operating_income, depreciation, taxes, change_in_working_capital)
ror(net_income, sales_revenue)
ros(operating_profit, net_sales)
cogs(beginning_inventory, purchases, ending_inventory)
ebit(revenue, cogs, operating_expenses)
ebita(revenue, cogs, operating_expenses, amortization)
ebitda(net_income, interest_expense, taxes, depreciation, amortization)
receivable_turnover_ratio(net_credit_sales, average_accounts_receivable)
accumulated_depreciation_to_fixed_assets(accumulated_depreciation, total_fixed_assets)
asset_coverage(total_assets, intangible_assets, current_liabilities, short_term_debt, total_debt)
asset_turnover(net_sales, average_total_sales)
average_inventory_period(days, inventory_turnover)
average_payment_period(average_accounts_payable, total_credit_purchases, days)
break_even_analysis(fixed_costs, sales_price_per_unit, variable_cost_per_unit)
capitalization_ratio(total_debt, shareholders_equity)
cash_conversion_cycle(days_inventory_outstanding, days_sales_outstanding, days_payables_outstanding)
cash_flow_coverage(operating_cash_flows, total_debt)
cash_ratio(cash, cash_equivalents, total_current_liabilities)
cagr(beginning_investment_value, ending_investment_value, years)
contribution_margin(net_sales, variable_costs)
current_ratio(current_assets, current_liabilities)
dpo(accounts_payable, cost_of_sales, days)
days_sales_in_inventory(ending_inventory, cogs)
days_sales_outstanding(accounts_receivable, net_credit_sales)
debt_ratio(total_liabilities, total_assets)
dscr(operating_income, total_debt_service_costs)
debt_to_asset(total_debt, total_assets)
debt_to_capital(total_debt, shareholders_equity)
debt_to_equity(total_liabilities, total_equity)
dti(total_monthly_debt_payments, gross_monthly_income)
dir(defensive_assets, daily_operational_expenses)
eps_basic(earnings, shares_outstanding)
eps_diluted(earnings, shares_outstanding, diluted_shares)
eps_pro_forma(acquirers_net_income, targets_net_income, incremental_adjustments, shares_outstanding, diluted_shares)
eps_book_value(total_equity, preferred_equity, shares_outstanding)
eps_retained(retained_earnings, shares_outstanding)
eps_cash(operating_cash_flow, shares_outstanding)
pe_ratio(price, earnings_per_share)
peg_ratio(price_to_earnings, earnings_growth)
dividend_payout(net_dividends, net_income)
dividend_yield(cash_dividends_per_share, market_value_per_share)
du_pont_analysis(profit_margin, total_asset_turnover, financial_leverage)
ev(market_capitalization, debt, current_cash)
equity_multiplier(total_assets, total_stockholders_equity)
equity_ratio(total_equity, total_assets)
expense_ratio(operating_expenses, average_value_of_fund_assets)
fixed_asset_turnover_ratio(net_sales, fixed_assets, accumulated_depreciation)
fixed_charge_coverage_ratio(ebit, fixed_charges_before_taxes, interest)
fcf(operating_cash_flow, capital_expenditures)
goodwill_to_assets(goodwill, assets)
gross_margin_ratio(gross_margin, net_sales)
gross_profit(total_sales, cogs)
interest_coverage_ratio(ebit, interest_expense)
inventory_turnover_ratio(cogs, average_inventory)
ltv(mortgage_amount, appraised_value_of_property)
long_term_debt_to_total_asset_ratio(long_term_debt, total_assets)
margin_of_safety(actual_sales, break_even_point)
margin_of_safety_ratio(actual_sales, break_even_point)
margin_of_revenue(change_in_total_revenues, change_in_quantity_sold)
Open an issue or create a fork and submit a pull request.