├── .travis.yml
├── FinancialFormulas.png
├── LICENSE
├── README.md
├── build.xml
├── lib
├── README.md
├── hamcrest-all-1.3.jar
└── junit-4.12.jar
├── main
├── cplusplus
│ └── srbrettle
│ │ └── financialformulas
│ │ ├── FinancialFormulas.cpp
│ │ └── FinancialFormulas.h
├── csharp
│ └── srbrettle
│ │ └── FinancialFormulas
│ │ └── FinancialFormulas.cs
├── java
│ └── srbrettle
│ │ └── financialformulas
│ │ └── FinancialFormulas.java
└── python
│ └── srbrettle
│ └── financialformulas
│ └── FinancialFormulas.py
└── test
├── csharp
└── srbrettle
│ └── FinancialFormulas
│ └── UnitTest.FinancialFormulas.cs
└── java
└── srbrettle
└── financialformulas
└── FinancialFormulasTest.java
/.travis.yml:
--------------------------------------------------------------------------------
1 | matrix:
2 | include:
3 | - language: python
4 | python:
5 | - "2.6"
6 | - "2.7"
7 | - "3.3"
8 | - "3.4"
9 | - "3.5"
10 | - "3.5-dev" # 3.5 development branch
11 | - "3.6"
12 | - "3.6-dev" # 3.6 development branch
13 | - "3.7-dev" # 3.7 development branch
14 | before_script:
15 | - cd main/python/srbrettle/financialformulas/
16 | script:
17 | - python FinancialFormulas.py
18 |
19 | - language: java
20 | jdk: oraclejdk8
21 |
22 | script: ant main
23 | script: ant test
24 |
--------------------------------------------------------------------------------
/FinancialFormulas.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srbrettle/Financial-Formulas/2bf89605d84d246d4a2b0d87ada305918652893e/FinancialFormulas.png
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Scott Brettle
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Financial-Formulas [](https://travis-ci.org/srbrettle/Financial-Formulas) [](https://github.com/srbrettle/Financial-Formulas/issues)
2 |
3 | A collection of methods for solving Finance/Accounting equations, implemented in C#, Java, Python and C++.
4 |
5 | ## See in Action
6 |
7 | [Finance Calculator - Android Application](https://play.google.com/store/apps/details?id=barwick.financecalculator)
8 |
9 | ## Getting Started - Java
10 |
11 | 1. Download and import [this](/main/java/) library into your project:
12 | ```java
13 | import srbrettle.financialformulas.FinancialFormulas;
14 | ```
15 | 2. Use the library methods:
16 | ```java
17 | double result = FinancialFormulas.CalcPriceSalesRatio(500,200);
18 | ```
19 |
20 | ## Getting Started - C# [Deprecated - New GitHub Repo](https://github.com/srbrettle/Financial-Formulas-Library-.NET-Core/tree/master)
21 |
22 | ### Using NuGet [](https://www.nuget.org/packages/FinancialFormulas/1.0.2)
23 |
24 | 1. Within your project, install FinancialFormulas NuGet package (via "Manage Packages for Solution" or running the following in "Packet Manager Console".
25 | ```PowerShell
26 | Install-Package FinancialFormulas -Version 1.0.2
27 | ```
28 | 2. Reference the Namespace:
29 | ```c#
30 | using srbrettle.FinancialFormulas;
31 | ```
32 | 3. Use the static library methods:
33 | ```c#
34 | double result = FinancialFormulas.CalcPriceSalesRatio(500,200);
35 | ```
36 |
37 | ### Manually
38 |
39 | 1. Download and import [this](/main/csharp/) library into your project.
40 | 2. Reference the Namespace:
41 | ```c#
42 | using srbrettle.FinancialFormulas;
43 | ```
44 | 3. Use the static library methods:
45 | ```c#
46 | double result = FinancialFormulas.CalcPriceSalesRatio(500,200);
47 | ```
48 |
49 | ## Getting Started - Python
50 |
51 | Note that the mothod and variable names have been changed to meet PEP 8 guidelines.
52 |
53 | 1. Download and import [this](/main/python/) library into your project:
54 | ```python
55 | import srbrettle.financialformulas.FinancialFormulas as calc
56 | ```
57 | 2. Use the library methods:
58 | ```python
59 | assets = calc.calc_price_sales_ratio(500, 200)
60 | ```
61 |
62 | ## Getting Started - C++
63 |
64 | 1. Download the [source code](/main/cplusplus/).
65 | 2. Follow the instructions in [Walkthrough: Creating and Using a Static Library (C++)](https://docs.microsoft.com/en-gb/cpp/windows/walkthrough-creating-and-using-a-static-library-cpp)
66 |
67 | ## License
68 |
69 | This project is licensed under the MIT License - see the [LICENSE](/LICENSE) file for details.
70 |
71 | ## Formulas / Equations included
72 |
73 | * Asset Turnover
74 | * Assets
75 | * Average Collection Period
76 | * Book Value
77 | * Cash Conversion Cycle
78 | * Cash Ratio
79 | * Current Ratio
80 | * Debt Equity Ratio
81 | * Debt Ratio
82 | * Debt Service Coverage Ratio
83 | * Declining Balance
84 | * Dividend Cover
85 | * Dividend Yield
86 | * Dividends Per Share
87 | * Earnings Per Share
88 | * EBIT
89 | * EBITDA
90 | * Efficiency Ratio
91 | * Equity
92 | * Gross Profit
93 | * Gross Profit Margin
94 | * Inventory Conversion Period
95 | * Inventory Conversion Ratio
96 | * Inventory Turnover
97 | * Long-Term Debt Equity Ratio
98 | * Liabilities
99 | * Net Profit
100 | * Operating Cash Flow Ratio
101 | * Operating Margin
102 | * Operating Profit
103 | * Payables Conversion Period
104 | * Payout Ratio
105 | * PEG Ratio
106 | * Price Sales Ratio
107 | * Profit Margin
108 | * Quick Ratio
109 | * Receivables Conversion Period
110 | * Receivables Turnover Ratio
111 | * Return On Assets
112 | * Return On Capital
113 | * Return On Equity
114 | * Return On Investment
115 | * Return On Net Assets
116 | * Risk Adjusted Return On Capital
117 | * Sales Revenue
118 | * Straight Line Method
119 | * Units Of Production
120 |
--------------------------------------------------------------------------------
/build.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/lib/README.md:
--------------------------------------------------------------------------------
1 | JUnit and Hamcrest jar files included only for testing as part of CI, it is not required to use the library.
2 |
--------------------------------------------------------------------------------
/lib/hamcrest-all-1.3.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srbrettle/Financial-Formulas/2bf89605d84d246d4a2b0d87ada305918652893e/lib/hamcrest-all-1.3.jar
--------------------------------------------------------------------------------
/lib/junit-4.12.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srbrettle/Financial-Formulas/2bf89605d84d246d4a2b0d87ada305918652893e/lib/junit-4.12.jar
--------------------------------------------------------------------------------
/main/cplusplus/srbrettle/financialformulas/FinancialFormulas.cpp:
--------------------------------------------------------------------------------
1 | // FinancialFormulas.cpp
2 | // compile with: cl /c /EHsc FinancialFormulas.cpp
3 | // post-build command: lib FinancialFormulas.obj
4 |
5 | #include "FinancialFormulas.h"
6 |
7 | #include
8 |
9 | using namespace std;
10 |
11 | namespace FinancialFormulas
12 | {
13 |
14 | /*
15 | * -----------------------------------------------------------------------------
16 | * | Formulas - Activity |
17 | * -----------------------------------------------------------------------------
18 | */
19 |
20 | /// Calculates Asset Turnover from Net Sales and Total Assets
21 | double CalcAssetTurnover(double netSales, double totalAssets)
22 | {
23 | return netSales / totalAssets;
24 | }
25 |
26 | /// Calculates Average Collection Period from Accounts Receivable and Annual Credit Sales
27 | double CalcAverageCollectionPeriod(double accountsReceivable, double annualCreditSales)
28 | {
29 | return accountsReceivable / (annualCreditSales / 365);
30 | }
31 |
32 | /// Calcualtes Cash Conversion Cycle from Inventory Conversion Period, Receivables Conversion Period and Payables Conversion Period
33 | double CalcCashConversionCycle(double inventoryConversionPeriod, double receivablesConversionPeriod, double payablesConversionPeriod)
34 | {
35 | return (inventoryConversionPeriod
36 | + receivablesConversionPeriod - payablesConversionPeriod);
37 | }
38 |
39 | /// Calculates Inventory Conversion Period from Inventory Turnover Ratio
40 | double CalcInventoryConversionPeriod(double inventoryTurnoverRatio)
41 | {
42 | return 365 / inventoryTurnoverRatio;
43 | }
44 |
45 | /// Calculates Inventory Conversion Ratio from Sales and Cost Of Goods Sold
46 | double CalcInventoryConversionRatio(double sales, double costOfGoodsSold)
47 | {
48 | return (sales * 0.5) / costOfGoodsSold;
49 | }
50 |
51 | /// Calculates Inventory Turnover from Sales and Average Inventory
52 | double CalcInventoryTurnover(double sales, double averageInventory)
53 | {
54 | return sales / averageInventory;
55 | }
56 |
57 | /// Calculates Payables Conversion Period from Accounts Payable and Purchases
58 | double CalcPayablesConversionPeriod(double accountsPayable, double purchases)
59 | {
60 | return (accountsPayable / purchases) * 365;
61 | }
62 |
63 | /// Calculates Receivables Conversion Period from Receivables and Net Sales
64 | double CalcReceivablesConversionPeriod(double receivables, double netSales)
65 | {
66 | return (receivables / netSales) * 365;
67 | }
68 |
69 | /// Calculates Receivables Turnover Ratio from Net Credit Sales and Average Net Receivables
70 | double CalcReceivablesTurnoverRatio(double netCreditSales, double averageNetReceivables)
71 | {
72 | return netCreditSales / averageNetReceivables;
73 | }
74 |
75 | /*
76 | * -----------------------------------------------------------------------------
77 | * | Formulas - Basic |
78 | * -----------------------------------------------------------------------------
79 | */
80 |
81 | /// Calculates Assets from Liabilities and Equity
82 | double CalcAssets(double liabilities, double equity)
83 | {
84 | return liabilities + equity;
85 | }
86 |
87 | /// Calculates Earnings Before Interest and Taxes (EBIT) from Revenue and Operating Expenses
88 | double CalcEbit(double revenue, double operatingExpenses)
89 | {
90 | return revenue - operatingExpenses;
91 | }
92 |
93 | /// Calculates Equity from Assets and Liabilities
94 | double CalcEquity(double assets, double liabilities)
95 | {
96 | return assets - liabilities;
97 | }
98 |
99 | /// Calculates Gross Profit from Revenue and Cost Of Goods Sold (COGS)
100 | double CalcGrossProfit(double revenue, double costOfGoodsSold)
101 | {
102 | return revenue - costOfGoodsSold;
103 | }
104 |
105 | /// Calculates Liabilities from Assets and Equity
106 | double CalcLiabilities(double assets, double equity)
107 | {
108 | return assets - equity;
109 | }
110 |
111 | /// Calculates Net Profit from Gross Profit, Operating Expenses, Taxes and Interest
112 | double CalcNetProfit(double grossProfit, double operatingExpenses, double taxes, double interest)
113 | {
114 | return grossProfit - operatingExpenses - taxes - interest;
115 | }
116 |
117 | /// Calculates Operation Profit from Gross Profit and Operating Expenses
118 | double CalcOperatingProfit(double grossProfit, double operatingExpenses)
119 | {
120 | return grossProfit - operatingExpenses;
121 | }
122 |
123 | /// Calculates Sales Revenue from Gross Sales and Sales of Returns and Allowances
124 | double CalcSalesRevenue(double grossSales, double salesOfReturnsAndAllowances)
125 | {
126 | return grossSales - salesOfReturnsAndAllowances;
127 | }
128 |
129 | /*
130 | * -----------------------------------------------------------------------------
131 | * | Formulas - Debt |
132 | * -----------------------------------------------------------------------------
133 | */
134 |
135 | /// Calculates Debt to Equity Ratio from Total Liabilities and Shareholder Equity
136 | double CalcDebtEquityRatio(double totalLiabilities, double shareholderEquity)
137 | {
138 | return totalLiabilities / shareholderEquity;
139 | }
140 |
141 | /// Calculates Debt Ratio Total Liabilities and Total Assets
142 | double CalcDebtRatio(double totalLiabilities, double totalAssets)
143 | {
144 | return totalLiabilities / totalAssets;
145 | }
146 |
147 | /// Calculates Debt-Service Coverage Ratio Net Operating Income and Total Debt Service
148 | double CalcDebtServiceCoverageRatio(double netOperatingIncome, double totalDebtService)
149 | {
150 | return netOperatingIncome / totalDebtService;
151 | }
152 |
153 | /// Calculates Long-Term Debt to Equity Ratio from Long-Term Liabilities and Equity
154 | double CalcLongTermDebtEquityRatio(double longTermLiabilities, double equity)
155 | {
156 | return longTermLiabilities / equity;
157 | }
158 |
159 | /*
160 | * -----------------------------------------------------------------------------
161 | * | Formulas - Depreciation |
162 | * -----------------------------------------------------------------------------
163 | */
164 |
165 | /// Calculates Book Value from Acquisition Cost and Depreciation
166 | double CalcBookValue(double acquisitionCost, double depreciation)
167 | {
168 | return acquisitionCost - depreciation;
169 | }
170 |
171 | /// Calculates Decling Balance from Depreciation Rate and Book Value at Beginning of Year
172 | double CalcDecliningBalance(double depreciationRate, double bookValueAtBeginningOfYear)
173 | {
174 | return depreciationRate * bookValueAtBeginningOfYear;
175 | }
176 |
177 | /// Calculates Units Of Production from Cost of Asset, Residual Value, Estimated Total Production and Actual Production
178 | double CalcUnitsOfProduction(double costOfAsset, double residualValue, double estimatedTotalProduction, double actualProduction)
179 | {
180 | return ((costOfAsset - residualValue) / estimatedTotalProduction) * actualProduction;
181 | }
182 |
183 | /// Calculates Straight Line Method from Cost of Fixed Asset, Residual Value and Useful Life of Asset
184 | double CalcStraightLineMethod(double costOfFixedAsset, double residualValue, double usefulLifeOfAsset)
185 | {
186 | return (costOfFixedAsset - residualValue) / usefulLifeOfAsset;
187 | }
188 |
189 | /*
190 | * -----------------------------------------------------------------------------
191 | * | Formulas - Liquidity |
192 | * -----------------------------------------------------------------------------
193 | */
194 |
195 | /// Calculates Cash Ration from Cash, Marketable Securities and Current Liabilities
196 | double CalcCashRatio(double cash, double marketableSecurities, double currentLiabilities)
197 | {
198 | return (cash + marketableSecurities) / currentLiabilities;
199 | }
200 |
201 | /// Calculates Current Ratio from Current Assets and Current Liabilties
202 | double CalcCurrentRatio(double currentAssets, double currentLiabilities)
203 | {
204 | return currentAssets / currentLiabilities;
205 | }
206 |
207 | /// Calculates Operating Cash Flow Ratio from Operating Cash Flow and Total Debts
208 | double CalcOperatingCashFlowRatio(double operatingCashFlow, double totalDebts)
209 | {
210 | return operatingCashFlow / totalDebts;
211 | }
212 |
213 | /// Calculates Quick Ratio from Current Assets, Inventories and Current Liabilities
214 | double CalcQuickRatio(double currentAssets, double inventories, double currentLiabilities)
215 | {
216 | return (currentAssets - inventories) / currentLiabilities;
217 | }
218 |
219 | /*
220 | * -----------------------------------------------------------------------------
221 | * | Formulas - Market |
222 | * -----------------------------------------------------------------------------
223 | */
224 |
225 | /// Calculates Dividend Cover from Earnings Per Share and Dividends Per Share
226 | double CalcDividendCover(double earningsPerShare, double dividendsPerShare)
227 | {
228 | return earningsPerShare / dividendsPerShare;
229 | }
230 |
231 | /// Calculates Dividends Per Share (DPS) from Dividends Paid and Number Of Shares
232 | double CalcDividendsPerShare(double dividendsPaid, double numberOfShares)
233 | {
234 | return dividendsPaid / numberOfShares;
235 | }
236 |
237 | /// Calculates Dividend Yield from Annual Dividend Per Share and Price Per Share
238 | double CalcDividendYield(double annualDividendPerShare, double pricePerShare)
239 | {
240 | return annualDividendPerShare / pricePerShare;
241 | }
242 |
243 | /// Calculates Earnings Per Share from Net Earnings and Number of Shares
244 | double CalcEarningsPerShare(double netEarnings, double numberOfShares)
245 | {
246 | return netEarnings / numberOfShares;
247 | }
248 |
249 | /// Calculates Payout Ratio from Dividends and Earnings
250 | double CalcPayoutRatio(double dividends, double earnings)
251 | {
252 | return dividends / earnings;
253 | }
254 |
255 | /// Calculates Price/Earnings to Growth (PEG) Ratio from Price Per Earnings and Annual EPS Growth
256 | double CalcPegRatio(double pricePerEarnings, double annualEpsGrowth)
257 | {
258 | return pricePerEarnings / annualEpsGrowth;
259 | }
260 |
261 | /// Calculates Price to Sales Ratio from Price Per Share and Revenue Per Share
262 | double CalcPriceSalesRatio(double pricePerShare, double revenuePerShare)
263 | {
264 | return pricePerShare / revenuePerShare;
265 | }
266 |
267 | /*
268 | * -----------------------------------------------------------------------------
269 | * | Formulas - Profitability |
270 | * -----------------------------------------------------------------------------
271 | */
272 |
273 | /// Calculates Efficiency Ratio from Non-Interest Expense and Revenue
274 | double CalcEfficiencyRatio(double nonInterestExpense, double revenue)
275 | {
276 | return nonInterestExpense / revenue;
277 | }
278 |
279 | /// Calculates Gross Profit Margin from Gross Profit and Revenue
280 | double CalcGrossProfitMargin(double grossProfit, double revenue)
281 | {
282 | return grossProfit / revenue;
283 | }
284 |
285 | /// Calculates Operating Margin from Operating Income and Revenue
286 | double CalcOperatingMargin(double operatingIncome, double revenue)
287 | {
288 | return operatingIncome / revenue;
289 | }
290 |
291 | /// Calculates Profit Margin from Net Profit and Revenue
292 | double CalcProfitMargin(double netProfit, double revenue)
293 | {
294 | return netProfit / revenue;
295 | }
296 |
297 | /// Calculates Return On Assets (ROA) from Net Income and Total Assets
298 | double CalcReturnOnAssets(double netIncome, double totalAssets)
299 | {
300 | return netIncome / totalAssets;
301 | }
302 |
303 | /// Calculates Return On Capital (ROC) from EBIT, Tax Rate and Invested Capital
304 | double CalcReturnOnCapital(double ebit, double taxRate, double investedCapital)
305 | {
306 | return ebit * (1 - taxRate) / investedCapital;
307 | }
308 |
309 | /// Calculates Return on Equity (ROE) from Net Income and Average Shareholder Equity
310 | double CalcReturnOnEquity(double netIncome, double averageShareholderEquity)
311 | {
312 | return netIncome / averageShareholderEquity;
313 | }
314 |
315 | /// Calculates Return On Net Assets (RONA) from Net Income, Fixed Assets and Working Capital
316 | double CalcReturnOnNetAssets(double netIncome, double fixedAssets, double workingCapital)
317 | {
318 | return netIncome / (fixedAssets + workingCapital);
319 | }
320 |
321 | /// Calculates Risk-Adjusted Return On Capital (RAROC) from Expected Return and Economic Capital
322 | double CalcRiskAdjustedReturnOnCapital(double expectedReturn, double economicCapital)
323 | {
324 | return expectedReturn / economicCapital;
325 | }
326 |
327 | /// Calculates Return on Investment (ROI) from Gain and Cost
328 | double CalcReturnOnInvestment(double gain, double cost)
329 | {
330 | return (gain - cost) / cost;
331 | }
332 |
333 | /// Calculates Earnings Before Interest, Taxes, Depreciation and Amortization (EBITDA) from EBIT, Depreciation and Amortization
334 | double CalcEbitda(double ebit, double depreciation, double amortization)
335 | {
336 | return ebit + depreciation + amortization;
337 | }
338 | }
339 |
--------------------------------------------------------------------------------
/main/cplusplus/srbrettle/financialformulas/FinancialFormulas.h:
--------------------------------------------------------------------------------
1 | // FinancialFormulas.h
2 |
3 | #pragma once
4 |
5 | namespace FinancialFormulas
6 | {
7 | class FinancialFormulas
8 | {
9 | public:
10 | /*
11 | * -----------------------------------------------------------------------------
12 | * | Formulas - Activity |
13 | * -----------------------------------------------------------------------------
14 | */
15 |
16 | // Calculates Asset Turnover from Net Sales and Total Assets
17 | static double CalcAssetTurnover(static double netSales, static double totalAssets);
18 |
19 | // Calculates Average Collection Period from Accounts Receivable and Annual Credit Sales
20 | static double CalcAverageCollectionPeriod(static double accountsReceivable, static double annualCreditSales);
21 |
22 | // Calcualtes Cash Conversion Cycle from Inventory Conversion Period, Receivables Conversion Period and Payables Conversion Period
23 | static double CalcCashConversionCycle(static double inventoryConversionPeriod, static double receivablesConversionPeriod, static double payablesConversionPeriod);
24 |
25 | // Calculates Inventory Conversion Period from Inventory Turnover Ratio
26 | static double CalcInventoryConversionPeriod(static double inventoryTurnoverRatio);
27 |
28 | // Calculates Inventory Conversion Ratio from Sales and Cost Of Goods Sold
29 | static double CalcInventoryConversionRatio(static double sales, static double costOfGoodsSold);
30 |
31 | // Calculates Inventory Turnover from Sales and Average Inventory
32 | static double CalcInventoryTurnover(static double sales, static double averageInventory);
33 |
34 | // Calculates Payables Conversion Period from Accounts Payable and Purchases
35 | static double CalcPayablesConversionPeriod(static double accountsPayable, static double purchases);
36 |
37 | // Calculates Receivables Conversion Period from Receivables and Net Sales
38 | static double CalcReceivablesConversionPeriod(static double receivables, static double netSales);
39 |
40 | // Calculates Receivables Turnover Ratio from Net Credit Sales and Average Net Receivables
41 | static double CalcReceivablesTurnoverRatio(static double netCreditSales, static double averageNetReceivables);
42 |
43 | /*
44 | * -----------------------------------------------------------------------------
45 | * | Formulas - Basic |
46 | * -----------------------------------------------------------------------------
47 | */
48 |
49 | // Calculates Assets from Liabilities and Equity
50 | static double CalcAssets(static double liabilities, static double equity);
51 |
52 | // Calculates Earnings Before Interest and Taxes (EBIT) from Revenue and Operating Expenses
53 | static double CalcEbit(static double revenue, static double operatingExpenses);
54 |
55 | // Calculates Equity from Assets and Liabilities
56 | static double CalcEquity(static double assets, static double liabilities);
57 |
58 | // Calculates Gross Profit from Revenue and Cost Of Goods Sold (COGS);
59 | static double CalcGrossProfit(static double revenue, static double costOfGoodsSold);
60 |
61 | // Calculates Liabilities from Assets and Equity
62 | static double CalcLiabilities(static double assets, static double equity);
63 |
64 | // Calculates Net Profit from Gross Profit, Operating Expenses, Taxes and Interest
65 | static double CalcNetProfit(static double grossProfit, static double operatingExpenses, static double taxes, static double interest);
66 |
67 | // Calculates Operation Profit from Gross Profit and Operating Expenses
68 | static double CalcOperatingProfit(static double grossProfit, static double operatingExpenses);
69 |
70 | // Calculates Sales Revenue from Gross Sales and Sales of Returns and Allowances
71 | static double CalcSalesRevenue(static double grossSales, static double salesOfReturnsAndAllowances);
72 |
73 | /*
74 | * -----------------------------------------------------------------------------
75 | * | Formulas - Debt |
76 | * -----------------------------------------------------------------------------
77 | */
78 |
79 | // Calculates Debt to Equity Ratio from Total Liabilities and Shareholder Equity
80 | static double CalcDebtEquityRatio(static double totalLiabilities, static double shareholderEquity);
81 |
82 | // Calculates Debt Ratio Total Liabilities and Total Assets
83 | static double CalcDebtRatio(static double totalLiabilities, static double totalAssets);
84 |
85 | // Calculates Debt-Service Coverage Ratio Net Operating Income and Total Debt Service
86 | static double CalcDebtServiceCoverageRatio(static double netOperatingIncome, static double totalDebtService);
87 |
88 | // Calculates Long-Term Debt to Equity Ratio from Long-Term Liabilities and Equity
89 | static double CalcLongTermDebtEquityRatio(static double longTermLiabilities, static double equity);
90 |
91 | /*
92 | * -----------------------------------------------------------------------------
93 | * | Formulas - Depreciation |
94 | * -----------------------------------------------------------------------------
95 | */
96 |
97 | // Calculates Book Value from Acquisition Cost and Depreciation
98 | static double CalcBookValue(static double acquisitionCost, static double depreciation);
99 |
100 | // Calculates Decling Balance from Depreciation Rate and Book Value at Beginning of Year
101 | static double CalcDecliningBalance(static double depreciationRate, static double bookValueAtBeginningOfYear);
102 |
103 | // Calculates Units Of Production from Cost of Asset, Residual Value, Estimated Total Production and Actual Production
104 | static double CalcUnitsOfProduction(static double costOfAsset, static double residualValue, static double estimatedTotalProduction, static double actualProduction);
105 |
106 | // Calculates Straight Line Method from Cost of Fixed Asset, Residual Value and Useful Life of Asset
107 | static double CalcStraightLineMethod(static double costOfFixedAsset, static double residualValue, static double usefulLifeOfAsset);
108 |
109 | /*
110 | * -----------------------------------------------------------------------------
111 | * | Formulas - Liquidity |
112 | * -----------------------------------------------------------------------------
113 | */
114 |
115 | // Calculates Cash Ration from Cash, Marketable Securities and Current Liabilities
116 | static double CalcCashRatio(static double cash, static double marketableSecurities, static double currentLiabilities);
117 |
118 | // Calculates Current Ratio from Current Assets and Current Liabilties
119 | static double CalcCurrentRatio(static double currentAssets, static double currentLiabilities);
120 |
121 | // Calculates Operating Cash Flow Ratio from Operating Cash Flow and Total Debts
122 | static double CalcOperatingCashFlowRatio(static double operatingCashFlow, static double totalDebts);
123 |
124 | // Calculates Quick Ratio from Current Assets, Inventories and Current Liabilities
125 | static double CalcQuickRatio(static double currentAssets, static double inventories, static double currentLiabilities);
126 |
127 | /*
128 | * -----------------------------------------------------------------------------
129 | * | Formulas - Market |
130 | * -----------------------------------------------------------------------------
131 | */
132 |
133 | // Calculates Dividend Cover from Earnings Per Share and Dividends Per Share
134 | static double CalcDividendCover(static double earningsPerShare, static double dividendsPerShare);
135 |
136 | // Calculates Dividends Per Share (DPS) from Dividends Paid and Number Of Shares
137 | static double CalcDividendsPerShare(static double dividendsPaid, static double numberOfShares);
138 |
139 | // Calculates Dividend Yield from Annual Dividend Per Share and Price Per Share
140 | static double CalcDividendYield(static double annualDividendPerShare, static double pricePerShare);
141 |
142 | // Calculates Earnings Per Share from Net Earnings and Number of Shares
143 | static double CalcEarningsPerShare(static double netEarnings, static double numberOfShares);
144 |
145 | // Calculates Payout Ratio from Dividends and Earnings
146 | static double CalcPayoutRatio(static double dividends, static double earnings);
147 |
148 | // Calculates Price/Earnings to Growth (PEG) Ratio from Price Per Earnings and Annual EPS Growth
149 | static double CalcPegRatio(static double pricePerEarnings, static double annualEpsGrowth);
150 |
151 | // Calculates Price to Sales Ratio from Price Per Share and Revenue Per Share
152 | static double CalcPriceSalesRatio(static double pricePerShare, static double revenuePerShare);
153 |
154 | /*
155 | * -----------------------------------------------------------------------------
156 | * | Formulas - Profitability |
157 | * -----------------------------------------------------------------------------
158 | */
159 |
160 | // Calculates Efficiency Ratio from Non-Interest Expense and Revenue
161 | static double CalcEfficiencyRatio(static double nonInterestExpense, static double revenue);
162 |
163 | // Calculates Gross Profit Margin from Gross Profit and Revenue
164 | static double CalcGrossProfitMargin(static double grossProfit, static double revenue);
165 |
166 | // Calculates Operating Margin from Operating Income and Revenue
167 | static double CalcOperatingMargin(static double operatingIncome, static double revenue);
168 |
169 | // Calculates Profit Margin from Net Profit and Revenue
170 | static double CalcProfitMargin(static double netProfit, static double revenue);
171 |
172 | // Calculates Return On Assets (ROA) from Net Income and Total Assets
173 | static double CalcReturnOnAssets(static double netIncome, static double totalAssets);
174 |
175 | // Calculates Return On Capital (ROC) from EBIT, Tax Rate and Invested Capital
176 | static double CalcReturnOnCapital(static double ebit, static double taxRate, static double investedCapital);
177 |
178 | // Calculates Return on Equity (ROE) from Net Income and Average Shareholder Equity
179 | static double CalcReturnOnEquity(static double netIncome, static double averageShareholderEquity);
180 |
181 | // Calculates Return On Net Assets (RONA) from Net Income, Fixed Assets and Working Capital
182 | static double CalcReturnOnNetAssets(static double netIncome, static double fixedAssets, static double workingCapital);
183 |
184 | // Calculates Risk-Adjusted Return On Capital (RAROC) from Expected Return and Economic Capital
185 | static double CalcRiskAdjustedReturnOnCapital(static double expectedReturn, static double economicCapital);
186 |
187 | // Calculates Return on Investment (ROI) from Gain and Cost
188 | static double CalcReturnOnInvestment(static double gain, static double cost);
189 |
190 | // Calculates Earnings Before Interest, Taxes, Depreciation and Amortization (EBITDA) from EBIT, Depreciation and Amortization
191 | static double CalcEbitda(static double ebit, static double depreciation, static double amortization);
192 | };
193 | }
194 |
--------------------------------------------------------------------------------
/main/csharp/srbrettle/FinancialFormulas/FinancialFormulas.cs:
--------------------------------------------------------------------------------
1 | namespace srbrettle.FinancialFormulas
2 | {
3 | ///
4 | /// A collection of methods for solving Finance/Accounting equations.
5 | ///
6 | public static class FinancialFormulas
7 | {
8 | /*
9 | * -----------------------------------------------------------------------------
10 | * | Formulas - Activity |
11 | * -----------------------------------------------------------------------------
12 | */
13 |
14 | ///
15 | /// Calculates Asset Turnover from Net Sales and Total Assets
16 | ///
17 | /// Net Sales
18 | /// Total Assets
19 | ///
20 | public static double CalcAssetTurnover(double netSales, double totalAssets)
21 | {
22 | return netSales / totalAssets;
23 | }
24 |
25 | ///
26 | /// Calculates Average Collection Period from Accounts Receivable and Annual Credit Sales
27 | ///
28 | /// Accounts Receivable
29 | /// Annual Credit Sales
30 | ///
31 | public static double CalcAverageCollectionPeriod(double accountsReceivable, double annualCreditSales)
32 | {
33 | return accountsReceivable / (annualCreditSales / 365);
34 | }
35 |
36 | ///
37 | /// Calcualtes Cash Conversion Cycle from Inventory Conversion Period, Receivables Conversion Period and Payables Conversion Period
38 | ///
39 | /// Inventory Conversion Period
40 | /// Receivables Conversion Period
41 | /// Payables Conversion Period
42 | ///
43 | public static double CalcCashConversionCycle(double inventoryConversionPeriod, double receivablesConversionPeriod, double payablesConversionPeriod)
44 | {
45 | return (inventoryConversionPeriod
46 | + receivablesConversionPeriod - payablesConversionPeriod);
47 | }
48 |
49 | ///
50 | /// Calculates Inventory Conversion Period from Inventory Turnover Ratio
51 | ///
52 | /// Inventory Turnover Ratio
53 | ///
54 | public static double CalcInventoryConversionPeriod(double inventoryTurnoverRatio)
55 | {
56 | return 365 / inventoryTurnoverRatio;
57 | }
58 |
59 | ///
60 | /// Calculates Inventory Conversion Ratio from Sales and Cost Of Goods Sold
61 | ///
62 | /// Sales
63 | /// Cost Of Goods Sold
64 | ///
65 | public static double CalcInventoryConversionRatio(double sales, double costOfGoodsSold)
66 | {
67 | return (sales * 0.5) / costOfGoodsSold;
68 | }
69 |
70 | ///
71 | /// Calculates Inventory Turnover from Sales and Average Inventory
72 | ///
73 | /// Sales
74 | /// Average Inventory
75 | ///
76 | public static double CalcInventoryTurnover(double sales, double averageInventory)
77 | {
78 | return sales / averageInventory;
79 | }
80 |
81 | ///
82 | /// Calculates Payables Conversion Period from Accounts Payable and Purchases
83 | ///
84 | /// Accounts Payable
85 | /// Purchases
86 | ///
87 | public static double CalcPayablesConversionPeriod(double accountsPayable, double purchases)
88 | {
89 | return (accountsPayable / purchases) * 365;
90 | }
91 |
92 | ///
93 | /// Calculates Receivables Conversion Period from Receivables and Net Sales
94 | ///
95 | /// Receivables
96 | /// Net Sales
97 | ///
98 | public static double CalcReceivablesConversionPeriod(double receivables, double netSales)
99 | {
100 | return (receivables / netSales) * 365;
101 | }
102 |
103 | ///
104 | /// Calculates Receivables Turnover Ratio from Net Credit Sales and Average Net Receivables
105 | ///
106 | /// Net Credit Sales
107 | /// Average Net Receivables
108 | ///
109 | public static double CalcReceivablesTurnoverRatio(double netCreditSales, double averageNetReceivables)
110 | {
111 | return netCreditSales / averageNetReceivables;
112 | }
113 |
114 | /*
115 | * -----------------------------------------------------------------------------
116 | * | Formulas - Basic |
117 | * -----------------------------------------------------------------------------
118 | */
119 |
120 | ///
121 | /// Calculates Assets from Liabilities and Equity
122 | ///
123 | /// Liabilities
124 | /// Equity
125 | ///
126 | public static double CalcAssets(double liabilities, double equity)
127 | {
128 | return liabilities + equity;
129 | }
130 |
131 | ///
132 | /// Calculates Earnings Before Interest and Taxes (EBIT) from Revenue and Operating Expenses
133 | ///
134 | /// Revenue
135 | /// Operating Expenses
136 | ///
137 | public static double CalcEbit(double revenue, double operatingExpenses)
138 | {
139 | return revenue - operatingExpenses;
140 | }
141 |
142 | ///
143 | /// Calculates Equity from Assets and Liabilities
144 | ///
145 | /// Assets
146 | /// Liabilities
147 | ///
148 | public static double CalcEquity(double assets, double liabilities)
149 | {
150 | return assets - liabilities;
151 | }
152 |
153 | ///
154 | /// Calculates Gross Profit from Revenue and Cost Of Goods Sold (COGS)
155 | ///
156 | /// Revenue
157 | /// Cost Of Goods Sold
158 | ///
159 | public static double CalcGrossProfit(double revenue, double costOfGoodsSold)
160 | {
161 | return revenue - costOfGoodsSold;
162 | }
163 |
164 | ///
165 | /// Calculates Liabilities from Assets and Equity
166 | ///
167 | /// Assets
168 | /// Equity
169 | ///
170 | public static double CalcLiabilities(double assets, double equity)
171 | {
172 | return assets - equity;
173 | }
174 |
175 | ///
176 | /// Calculates Net Profit from Gross Profit, Operating Expenses, Taxes and Interest
177 | ///
178 | /// Gross Profit
179 | /// Operating Expenses
180 | /// Taxes
181 | /// Interest
182 | ///
183 | public static double CalcNetProfit(double grossProfit, double operatingExpenses, double taxes, double interest)
184 | {
185 | return grossProfit - operatingExpenses - taxes - interest;
186 | }
187 |
188 | ///
189 | /// Calculates Operation Profit from Gross Profit and Operating Expenses
190 | ///
191 | /// Gross Profit
192 | /// Operating Expenses
193 | ///
194 | public static double CalcOperatingProfit(double grossProfit, double operatingExpenses)
195 | {
196 | return grossProfit - operatingExpenses;
197 | }
198 |
199 | ///
200 | /// Calculates Sales Revenue from Gross Sales and Sales of Returns and Allowances
201 | ///
202 | /// Gross Sales
203 | /// Sales of Returns and Allowances
204 | ///
205 | public static double CalcSalesRevenue(double grossSales, double salesOfReturnsAndAllowances)
206 | {
207 | return grossSales - salesOfReturnsAndAllowances;
208 | }
209 |
210 | /*
211 | * -----------------------------------------------------------------------------
212 | * | Formulas - Debt |
213 | * -----------------------------------------------------------------------------
214 | */
215 |
216 | ///
217 | /// Calculates Debt to Equity Ratio from Total Liabilities and Shareholder Equity
218 | ///
219 | /// Total Liabilities
220 | /// Shareholder Equity
221 | ///
222 | public static double CalcDebtEquityRatio(double totalLiabilities, double shareholderEquity)
223 | {
224 | return totalLiabilities / shareholderEquity;
225 | }
226 |
227 | ///
228 | /// Calculates Debt Ratio Total Liabilities and Total Assets
229 | ///
230 | /// Total Liabilities
231 | /// Total Assets
232 | ///
233 | public static double CalcDebtRatio(double totalLiabilities, double totalAssets)
234 | {
235 | return totalLiabilities / totalAssets;
236 | }
237 |
238 | ///
239 | /// Calculates Debt-Service Coverage Ratio Net Operating Income and Total Debt Service
240 | ///
241 | /// Net Operating Income
242 | /// Total Debt Service
243 | ///
244 | public static double CalcDebtServiceCoverageRatio(double netOperatingIncome, double totalDebtService)
245 | {
246 | return netOperatingIncome / totalDebtService;
247 | }
248 |
249 | ///
250 | /// Calculates Long-Term Debt to Equity Ratio from Long-Term Liabilities and Equity
251 | ///
252 | /// Long-Term Liabilities
253 | /// Equity
254 | ///
255 | public static double CalcLongTermDebtEquityRatio(double longTermLiabilities, double equity)
256 | {
257 | return longTermLiabilities / equity;
258 | }
259 |
260 | /*
261 | * -----------------------------------------------------------------------------
262 | * | Formulas - Depreciation |
263 | * -----------------------------------------------------------------------------
264 | */
265 |
266 | ///
267 | /// Calculates Book Value from Acquisition Cost and Depreciation
268 | ///
269 | /// Acquisition Cost
270 | /// Depreciation
271 | ///
272 | public static double CalcBookValue(double acquisitionCost, double depreciation)
273 | {
274 | return acquisitionCost - depreciation;
275 | }
276 |
277 | ///
278 | /// Calculates Decling Balance from Depreciation Rate and Book Value at Beginning of Year
279 | ///
280 | /// Depreciation Rate
281 | /// Book Value at Beginning of Year
282 | ///
283 | public static double CalcDecliningBalance(double depreciationRate, double bookValueAtBeginningOfYear)
284 | {
285 | return depreciationRate * bookValueAtBeginningOfYear;
286 | }
287 |
288 | ///
289 | /// Calculates Units Of Production from Cost of Asset, Residual Value, Estimated Total Production and Actual Production
290 | ///
291 | /// Cost of Asset
292 | /// Residual Value
293 | /// Estimated Total Production
294 | /// Actual Production
295 | ///
296 | public static double CalcUnitsOfProduction(double costOfAsset, double residualValue, double estimatedTotalProduction, double actualProduction)
297 | {
298 | return ((costOfAsset - residualValue) / estimatedTotalProduction) * actualProduction;
299 | }
300 |
301 | ///
302 | /// Calculates Straight Line Method from Cost of Fixed Asset, Residual Value and Useful Life of Asset
303 | ///
304 | /// Cost of Fixed Asset
305 | /// Residual Value
306 | /// Useful Life of Asset
307 | ///
308 | public static double CalcStraightLineMethod(double costOfFixedAsset, double residualValue, double usefulLifeOfAsset)
309 | {
310 | return (costOfFixedAsset - residualValue) / usefulLifeOfAsset;
311 | }
312 |
313 | /*
314 | * -----------------------------------------------------------------------------
315 | * | Formulas - Liquidity |
316 | * -----------------------------------------------------------------------------
317 | */
318 |
319 | ///
320 | /// Calculates Cash Ration from Cash, Marketable Securities and Current Liabilities
321 | ///
322 | /// Cash
323 | /// Marketable Securities
324 | /// Current Liabilities
325 | ///
326 | public static double CalcCashRatio(double cash, double marketableSecurities, double currentLiabilities)
327 | {
328 | return (cash + marketableSecurities) / currentLiabilities;
329 | }
330 |
331 | ///
332 | /// Calculates Current Ratio from Current Assets and Current Liabilties
333 | ///
334 | /// Current Assets
335 | /// Current Liabilities
336 | ///
337 | public static double CalcCurrentRatio(double currentAssets, double currentLiabilities)
338 | {
339 | return currentAssets / currentLiabilities;
340 | }
341 |
342 | ///
343 | /// Calculates Operating Cash Flow Ratio from Operating Cash Flow and Total Debts
344 | ///
345 | /// Operating Cash Flow
346 | /// Total Debts
347 | ///
348 | public static double CalcOperatingCashFlowRatio(double operatingCashFlow, double totalDebts)
349 | {
350 | return operatingCashFlow / totalDebts;
351 | }
352 |
353 | ///
354 | /// Calculates Quick Ratio from Current Assets, Inventories and Current Liabilities
355 | ///
356 | /// Current Assets
357 | /// Inventories
358 | /// Current Liabilities
359 | ///
360 | public static double CalcQuickRatio(double currentAssets, double inventories, double currentLiabilities)
361 | {
362 | return (currentAssets - inventories) / currentLiabilities;
363 | }
364 |
365 |
366 | /*
367 | * -----------------------------------------------------------------------------
368 | * | Formulas - Market |
369 | * -----------------------------------------------------------------------------
370 | */
371 |
372 | ///
373 | /// Calculates Dividend Cover from Earnings Per Share and Dividends Per Share
374 | ///
375 | /// Earnings Per Share
376 | /// Devidends Per Share
377 | ///
378 | public static double CalcDividendCover(double earningsPerShare, double dividendsPerShare)
379 | {
380 | return earningsPerShare / dividendsPerShare;
381 | }
382 |
383 | ///
384 | /// Calculates Dividends Per Share (DPS) from Dividends Paid and Number Of Shares
385 | ///
386 | /// Dividends Paid
387 | /// Number of Shares
388 | ///
389 | public static double CalcDividendsPerShare(double dividendsPaid, double numberOfShares)
390 | {
391 | return dividendsPaid / numberOfShares;
392 | }
393 |
394 | ///
395 | /// Calculates Dividend Yield from Annual Dividend Per Share and Price Per Share
396 | ///
397 | /// Annual Dividend Per Share
398 | /// Price Per Share
399 | ///
400 | public static double CalcDividendYield(double annualDividendPerShare, double pricePerShare)
401 | {
402 | return annualDividendPerShare / pricePerShare;
403 | }
404 |
405 | ///
406 | /// Calculates Earnings Per Share from Net Earnings and Number of Shares
407 | ///
408 | /// Net Earnings
409 | /// Number of Shares
410 | ///
411 | public static double CalcEarningsPerShare(double netEarnings, double numberOfShares)
412 | {
413 | return netEarnings / numberOfShares;
414 | }
415 |
416 | ///
417 | /// Calculates Payout Ratio from Dividends and Earnings
418 | ///
419 | /// Dividends
420 | /// Earnings
421 | ///
422 | public static double CalcPayoutRatio(double dividends, double earnings)
423 | {
424 | return dividends / earnings;
425 | }
426 |
427 | ///
428 | /// Calculates Price/Earnings to Growth (PEG) Ratio from Price Per Earnings and Annual EPS Growth
429 | ///
430 | /// Price Per Earnings
431 | /// Annual EPS Growth
432 | ///
433 | public static double CalcPegRatio(double pricePerEarnings, double annualEpsGrowth)
434 | {
435 | return pricePerEarnings / annualEpsGrowth;
436 | }
437 |
438 | ///
439 | /// Calculates Price to Sales Ratio from Price Per Share and Revenue Per Share
440 | ///
441 | /// Price Per Share
442 | /// Revenue Per Share
443 | ///
444 | public static double CalcPriceSalesRatio(double pricePerShare, double revenuePerShare)
445 | {
446 | return pricePerShare / revenuePerShare;
447 | }
448 |
449 | /*
450 | * -----------------------------------------------------------------------------
451 | * | Formulas - Profitability |
452 | * -----------------------------------------------------------------------------
453 | */
454 |
455 | ///
456 | /// Calculates Efficiency Ratio from Non-Interest Expense and Revenue
457 | ///
458 | /// Non-Interest Expense
459 | /// Revenue
460 | ///
461 | public static double CalcEfficiencyRatio(double nonInterestExpense, double revenue)
462 | {
463 | return nonInterestExpense / revenue;
464 | }
465 |
466 | ///
467 | /// Calculates Gross Profit Margin from Gross Profit and Revenue
468 | ///
469 | /// Gross Profit
470 | /// Revenue
471 | ///
472 | public static double CalcGrossProfitMargin(double grossProfit, double revenue)
473 | {
474 | return grossProfit / revenue;
475 | }
476 |
477 | ///
478 | /// Calculates Operating Margin from Operating Income and Revenue
479 | ///
480 | /// Operating Income
481 | /// Revenue
482 | ///
483 | public static double CalcOperatingMargin(double operatingIncome, double revenue)
484 | {
485 | return operatingIncome / revenue;
486 | }
487 |
488 | ///
489 | /// Calculates Profit Margin from Net Profit and Revenue
490 | ///
491 | /// Net Profit
492 | /// Revenue
493 | ///
494 | public static double CalcProfitMargin(double netProfit, double revenue)
495 | {
496 | return netProfit / revenue;
497 | }
498 |
499 | ///
500 | /// Calculates Return On Assets (ROA) from Net Income and Total Assets
501 | ///
502 | /// Net Income
503 | /// Total Assets
504 | ///
505 | public static double CalcReturnOnAssets(double netIncome, double totalAssets)
506 | {
507 | return netIncome / totalAssets;
508 | }
509 |
510 | ///
511 | /// Calculates Return On Capital (ROC) from EBIT, Tax Rate and Invested Capital
512 | ///
513 | /// Earnings Before Interest and Taxes
514 | /// Tax Rate
515 | /// Invested Capital
516 | ///
517 | public static double CalcReturnOnCapital(double ebit, double taxRate, double investedCapital)
518 | {
519 | return ebit * (1 - taxRate) / investedCapital;
520 | }
521 |
522 | ///
523 | /// Calculates Return on Equity (ROE) from Net Income and Average Shareholder Equity
524 | ///
525 | /// Net Income
526 | /// Average Shareholder Equity
527 | ///
528 | public static double CalcReturnOnEquity(double netIncome, double averageShareholderEquity)
529 | {
530 | return netIncome / averageShareholderEquity;
531 | }
532 |
533 | ///
534 | /// Calculates Return On Net Assets (RONA) from Net Income, Fixed Assets and Working Capital
535 | ///
536 | /// Net Income
537 | /// Fixed Assets
538 | /// Working Capital
539 | ///
540 | public static double CalcReturnOnNetAssets(double netIncome, double fixedAssets, double workingCapital)
541 | {
542 | return netIncome / (fixedAssets + workingCapital);
543 | }
544 |
545 | ///
546 | /// Calculates Risk-Adjusted Return On Capital (RAROC) from Expected Return and Economic Capital
547 | ///
548 | /// Expected Return
549 | /// Economic Capital
550 | ///
551 | public static double CalcRiskAdjustedReturnOnCapital(double expectedReturn, double economicCapital)
552 | {
553 | return expectedReturn / economicCapital;
554 | }
555 |
556 | ///
557 | /// Calculates Return on Investment (ROI) from Gain and Cost
558 | ///
559 | /// Gain
560 | /// Cost
561 | ///
562 | public static double CalcReturnOnInvestment(double gain, double cost)
563 | {
564 | return (gain - cost) / cost;
565 | }
566 |
567 | ///
568 | /// Calculates Earnings Before Interest, Taxes, Depreciation and Amortization (EBITDA) from EBIT, Depreciation and Amortization
569 | ///
570 | /// Earnings Before Interest and Taxes
571 | /// Depreciation
572 | /// Amortization
573 | ///
574 | public static double CalcEbitda(double ebit, double depreciation, double amortization)
575 | {
576 | return ebit + depreciation + amortization;
577 | }
578 | }
579 | }
580 |
--------------------------------------------------------------------------------
/main/java/srbrettle/financialformulas/FinancialFormulas.java:
--------------------------------------------------------------------------------
1 | package srbrettle.financialformulas;
2 |
3 | /**
4 | * A collection of methods for solving Finance/Accounting equations.
5 | *
6 | * @author Scott Brettle
7 | */
8 | public class FinancialFormulas
9 | {
10 | /*
11 | * -----------------------------------------------------------------------------
12 | * | Formulas - Activity |
13 | * -----------------------------------------------------------------------------
14 | */
15 |
16 | /**
17 | * Calculates Asset Turnover from Net Sales and Total Assets.
18 | * @param netSales Net Sales
19 | * @param totalAssets Total Assets
20 | * @return
21 | */
22 | public static double CalcAssetTurnover(double netSales, double totalAssets)
23 | {
24 | return netSales / totalAssets;
25 | }
26 |
27 | /**
28 | * Calculates Average Collection Period from Accounts Receivable and Annual Credit Sales.
29 | * @param accountsReceivable Accounts Receivable
30 | * @param annualCreditSales Annual Credit Sales
31 | * @return
32 | */
33 | public static double CalcAverageCollectionPeriod(double accountsReceivable, double annualCreditSales)
34 | {
35 | return accountsReceivable / (annualCreditSales / 365);
36 | }
37 |
38 | /**
39 | * Calcualtes Cash Conversion Cycle from Inventory Conversion Period, Receivables Conversion Period and Payables Conversion Period.
40 | * @param inventoryConversionPeriod Inventory Conversion Period
41 | * @param receivablesConversionPeriod Receivables Conversion Period
42 | * @param payablesConversionPeriod Payables Conversion Period
43 | * @return
44 | */
45 | public static double CalcCashConversionCycle(double inventoryConversionPeriod, double receivablesConversionPeriod, double payablesConversionPeriod)
46 | {
47 | return (inventoryConversionPeriod
48 | + receivablesConversionPeriod - payablesConversionPeriod);
49 | }
50 |
51 | /**
52 | * Calculates Inventory Conversion Period from Inventory Turnover Ratio.
53 | * @param inventoryTurnoverRatio Inventory Turnover Ratio
54 | * @return
55 | */
56 | public static double CalcInventoryConversionPeriod(double inventoryTurnoverRatio)
57 | {
58 | return 365 / inventoryTurnoverRatio;
59 | }
60 |
61 | /**
62 | * Calculates Inventory Conversion Ratio from Sales and Cost Of Goods Sold.
63 | * @param sales Sales
64 | * @param costOfGoodsSold Cost Of Goods Sold
65 | * @return
66 | */
67 | public static double CalcInventoryConversionRatio(double sales, double costOfGoodsSold)
68 | {
69 | return (sales * 0.5) / costOfGoodsSold;
70 | }
71 |
72 | /**
73 | * Calculates Inventory Turnover from Sales and Average Inventory.
74 | * @param sales Sales
75 | * @param averageInventory Average Inventory
76 | * @return
77 | */
78 | public static double CalcInventoryTurnover(double sales, double averageInventory)
79 | {
80 | return sales / averageInventory;
81 | }
82 |
83 | /**
84 | * Calculates Payables Conversion Period from Accounts Payable and Purchases.
85 | * @param accountsPayable Accounts Payable
86 | * @param purchases Purchases
87 | * @return
88 | */
89 | public static double CalcPayablesConversionPeriod(double accountsPayable, double purchases)
90 | {
91 | return (accountsPayable / purchases) * 365;
92 | }
93 |
94 | /**
95 | * Calculates Receivables Conversion Period from Receivables and Net Sales.
96 | * @param receivables Receivables
97 | * @param netSales Net Sales
98 | * @return
99 | */
100 | public static double CalcReceivablesConversionPeriod(double receivables, double netSales)
101 | {
102 | return (receivables / netSales) * 365;
103 | }
104 |
105 | /**
106 | * Calculates Receivables Turnover Ratio from Net Credit Sales and Average Net Receivables.
107 | * @param netCreditSales Net Credit Sales
108 | * @param averageNetReceivables Average Net Receivables
109 | * @return
110 | */
111 | public static double CalcReceivablesTurnoverRatio(double netCreditSales, double averageNetReceivables)
112 | {
113 | return netCreditSales / averageNetReceivables;
114 | }
115 |
116 | /*
117 | * -----------------------------------------------------------------------------
118 | * | Formulas - Basic |
119 | * -----------------------------------------------------------------------------
120 | */
121 |
122 | /**
123 | * Calculates Assets from Liabilities and Equity.
124 | * @param liabilities Liabilities
125 | * @param equity Equity
126 | * @return
127 | */
128 | public static double CalcAssets(double liabilities, double equity)
129 | {
130 | return liabilities + equity;
131 | }
132 |
133 | /**
134 | * Calculates Earnings Before Interest and Taxes (EBIT) from Revenue and Operating Expenses.
135 | * @param revenue Revenue
136 | * @param operatingExpenses Operating Expenses
137 | * @return
138 | */
139 | public static double CalcEbit(double revenue, double operatingExpenses)
140 | {
141 | return revenue - operatingExpenses;
142 | }
143 |
144 | /**
145 | * Calculates Equity from Assets and Liabilities.
146 | * @param assets Assets
147 | * @param liabilities Liabilities
148 | * @return
149 | */
150 | public static double CalcEquity(double assets, double liabilities)
151 | {
152 | return assets - liabilities;
153 | }
154 |
155 | /**
156 | * Calculates Gross Profit from Revenue and Cost Of Goods Sold (COGS).
157 | * @param revenue Revenue
158 | * @param costOfGoodsSold Cost Of Goods Sold
159 | * @return
160 | */
161 | public static double CalcGrossProfit(double revenue, double costOfGoodsSold)
162 | {
163 | return revenue - costOfGoodsSold;
164 | }
165 |
166 | /**
167 | * Calculates Liabilities from Assets and Equity.
168 | * @param assets Assets
169 | * @param equity Equity
170 | * @return
171 | */
172 | public static double CalcLiabilities(double assets, double equity)
173 | {
174 | return assets - equity;
175 | }
176 |
177 | /**
178 | * Calculates Net Profit from Gross Profit, Operating Expenses, Taxes and Interest.
179 | * @param grossProfit Gross Profit
180 | * @param operatingExpenses Operating Expenses
181 | * @param taxes Taxes
182 | * @param interest Interest
183 | * @return
184 | */
185 | public static double CalcNetProfit(double grossProfit, double operatingExpenses, double taxes, double interest)
186 | {
187 | return grossProfit - operatingExpenses - taxes - interest;
188 | }
189 |
190 | /**
191 | * Calculates Operation Profit from Gross Profit and Operating Expenses.
192 | * @param grossProfit Gross Profit
193 | * @param operatingExpenses Operating Expenses
194 | * @return
195 | */
196 | public static double CalcOperatingProfit(double grossProfit, double operatingExpenses)
197 | {
198 | return grossProfit - operatingExpenses;
199 | }
200 |
201 | /**
202 | * Calculates Sales Revenue from Gross Sales and Sales of Returns and Allowances.
203 | * @param grossSales Gross Sales
204 | * @param salesOfReturnsAndAllowances Sales of Returns and Allowances
205 | * @return
206 | */
207 | public static double CalcSalesRevenue(double grossSales, double salesOfReturnsAndAllowances)
208 | {
209 | return grossSales - salesOfReturnsAndAllowances;
210 | }
211 |
212 | /*
213 | * -----------------------------------------------------------------------------
214 | * | Formulas - Debt |
215 | * -----------------------------------------------------------------------------
216 | */
217 |
218 | /**
219 | * Calculates Debt to Equity Ratio from Total Liabilities and Shareholder Equity.
220 | * @param totalLiabilities Total Liabilities
221 | * @param shareholderEquity Shareholder Equity
222 | * @return
223 | */
224 | public static double CalcDebtEquityRatio(double totalLiabilities, double shareholderEquity)
225 | {
226 | return totalLiabilities / shareholderEquity;
227 | }
228 |
229 | /**
230 | * Calculates Debt Ratio Total Liabilities and Total Assets.
231 | * @param totalLiabilities Total Liabilities
232 | * @param totalAssets Total Assets
233 | * @return
234 | */
235 | public static double CalcDebtRatio(double totalLiabilities, double totalAssets)
236 | {
237 | return totalLiabilities / totalAssets;
238 | }
239 |
240 | /**
241 | * Calculates Debt-Service Coverage Ratio Net Operating Income and Total Debt Service.
242 | * @param netOperatingIncome Net Operating Income
243 | * @param totalDebtService Total Debt Service
244 | * @return
245 | */
246 | public static double CalcDebtServiceCoverageRatio(double netOperatingIncome, double totalDebtService)
247 | {
248 | return netOperatingIncome / totalDebtService;
249 | }
250 |
251 | /**
252 | * Calculates Long-Term Debt to Equity Ratio from Long-Term Liabilities and Equity.
253 | * @param longTermLiabilities Long-Term Liabilities
254 | * @param equity Equity
255 | * @return
256 | */
257 | public static double CalcLongTermDebtEquityRatio(double longTermLiabilities, double equity)
258 | {
259 | return longTermLiabilities / equity;
260 | }
261 |
262 | /*
263 | * -----------------------------------------------------------------------------
264 | * | Formulas - Depreciation |
265 | * -----------------------------------------------------------------------------
266 | */
267 |
268 | /**
269 | * Calculates Book Value from Acquisition Cost and Depreciation.
270 | * @param acquisitionCost Acquisition Cost
271 | * @param depreciation Depreciation
272 | * @return
273 | */
274 | public static double CalcBookValue(double acquisitionCost, double depreciation)
275 | {
276 | return acquisitionCost - depreciation;
277 | }
278 |
279 | /**
280 | * Calculates Decling Balance from Depreciation Rate and Book Value at Beginning of Year.
281 | * @param depreciationRate Depreciation Rate
282 | * @param bookValueAtBeginningOfYear Book Value at Beginning of Year
283 | * @return
284 | */
285 | public static double CalcDecliningBalance(double depreciationRate, double bookValueAtBeginningOfYear)
286 | {
287 | return depreciationRate * bookValueAtBeginningOfYear;
288 | }
289 |
290 | /**
291 | * Calculates Units Of Production from Cost of Asset, Residual Value, Estimated Total Production and Actual Production.
292 | * @param costOfAsset Cost of Asset
293 | * @param residualValue Residual Value
294 | * @param estimatedTotalProduction Estimated Total Production
295 | * @param actualProduction Actual Production
296 | * @return
297 | */
298 | public static double CalcUnitsOfProduction(double costOfAsset, double residualValue, double estimatedTotalProduction, double actualProduction)
299 | {
300 | return ((costOfAsset - residualValue) / estimatedTotalProduction) * actualProduction;
301 | }
302 |
303 | /**
304 | * Calculates Straight Line Method from Cost of Fixed Asset, Residual Value and Useful Life of Asset.
305 | * @param costOfFixedAsset Cost of Fixed Asset
306 | * @param residualValue Residual Value
307 | * @param usefulLifeOfAsset Useful Life of Asset
308 | * @return
309 | */
310 | public static double CalcStraightLineMethod(double costOfFixedAsset, double residualValue, double usefulLifeOfAsset)
311 | {
312 | return (costOfFixedAsset - residualValue) / usefulLifeOfAsset;
313 | }
314 |
315 | /*
316 | * -----------------------------------------------------------------------------
317 | * | Formulas - Liquidity |
318 | * -----------------------------------------------------------------------------
319 | */
320 |
321 | /**
322 | * Calculates Cash Ration from Cash, Marketable Securities and Current Liabilities.
323 | * @param cash Cash
324 | * @param marketableSecurities Marketable Securities
325 | * @param currentLiabilities Current Liabilities
326 | * @return
327 | */
328 | public static double CalcCashRatio(double cash, double marketableSecurities, double currentLiabilities)
329 | {
330 | return (cash + marketableSecurities) / currentLiabilities;
331 | }
332 |
333 | /**
334 | * Calculates Current Ratio from Current Assets and Current Liabilties.
335 | * @param currentAssets Current Assets
336 | * @param currentLiabilities Current Liabilities
337 | * @return
338 | */
339 | public static double CalcCurrentRatio(double currentAssets, double currentLiabilities)
340 | {
341 | return currentAssets / currentLiabilities;
342 | }
343 |
344 | /**
345 | * Calculates Operating Cash Flow Ratio from Operating Cash Flow and Total Debts.
346 | * @param operatingCashFlow Operating Cash Flow
347 | * @param totalDebts Total Debts
348 | * @return
349 | */
350 | public static double CalcOperatingCashFlowRatio(double operatingCashFlow, double totalDebts)
351 | {
352 | return operatingCashFlow / totalDebts;
353 | }
354 |
355 | /**
356 | * Calculates Quick Ratio from Current Assets, Inventories and Current Liabilities.
357 | * @param currentAssets Current Assets
358 | * @param inventories Inventories
359 | * @param currentLiabilities Current Liabilities
360 | * @return
361 | */
362 | public static double CalcQuickRatio(double currentAssets, double inventories, double currentLiabilities)
363 | {
364 | return (currentAssets - inventories) / currentLiabilities;
365 | }
366 |
367 |
368 | /*
369 | * -----------------------------------------------------------------------------
370 | * | Formulas - Market |
371 | * -----------------------------------------------------------------------------
372 | */
373 |
374 | /**
375 | * Calculates Dividend Cover from Earnings Per Share and Dividends Per Share.
376 | * @param earningsPerShare Earnings Per Share
377 | * @param dividendsPerShare Devidends Per Share
378 | * @return
379 | */
380 | public static double CalcDividendCover(double earningsPerShare, double dividendsPerShare)
381 | {
382 | return earningsPerShare / dividendsPerShare;
383 | }
384 |
385 | /**
386 | * Calculates Dividends Per Share (DPS) from Dividends Paid and Number Of Shares.
387 | * @param dividendsPaid Dividends Paid
388 | * @param numberOfShares Number of Shares
389 | * @return
390 | */
391 | public static double CalcDividendsPerShare(double dividendsPaid, double numberOfShares)
392 | {
393 | return dividendsPaid / numberOfShares;
394 | }
395 |
396 | /**
397 | * Calculates Dividend Yield from Annual Dividend Per Share and Price Per Share.
398 | * @param annualDividendPerShare Annual Dividend Per Share
399 | * @param pricePerShare Price Per Share
400 | * @return
401 | */
402 | public static double CalcDividendYield(double annualDividendPerShare, double pricePerShare)
403 | {
404 | return annualDividendPerShare / pricePerShare;
405 | }
406 |
407 | /**
408 | * Calculates Earnings Per Share from Net Earnings and Number of Shares.
409 | * @param netEarnings Net Earnings
410 | * @param numberOfShares Number of Shares
411 | * @return
412 | */
413 | public static double CalcEarningsPerShare(double netEarnings, double numberOfShares)
414 | {
415 | return netEarnings / numberOfShares;
416 | }
417 |
418 | /**
419 | * Calculates Payout Ratio from Dividends and Earnings.
420 | * @param dividends Dividends
421 | * @param earnings Earnings
422 | * @return
423 | */
424 | public static double CalcPayoutRatio(double dividends, double earnings)
425 | {
426 | return dividends / earnings;
427 | }
428 |
429 | /**
430 | * Calculates Price/Earnings to Growth (PEG) Ratio from Price Per Earnings and Annual EPS Growth.
431 | * @param pricePerEarnings Price Per Earnings
432 | * @param annualEpsGrowth Annual EPS Growth
433 | * @return
434 | */
435 | public static double CalcPegRatio(double pricePerEarnings, double annualEpsGrowth)
436 | {
437 | return pricePerEarnings / annualEpsGrowth;
438 | }
439 |
440 | /**
441 | * Calculates Price to Sales Ratio from Price Per Share and Revenue Per Share.
442 | * @param pricePerShare Price Per Share
443 | * @param revenuePerShare Revenue Per Share
444 | * @return
445 | */
446 | public static double CalcPriceSalesRatio(double pricePerShare, double revenuePerShare)
447 | {
448 | return pricePerShare / revenuePerShare;
449 | }
450 |
451 | /*
452 | * -----------------------------------------------------------------------------
453 | * | Formulas - Profitability |
454 | * -----------------------------------------------------------------------------
455 | */
456 |
457 | /**
458 | * Calculates Efficiency Ratio from Non-Interest Expense and Revenue.
459 | * @param nonInterestExpense Non-Interest Expense
460 | * @param revenue Revenue
461 | * @return
462 | */
463 | public static double CalcEfficiencyRatio(double nonInterestExpense, double revenue)
464 | {
465 | return nonInterestExpense / revenue;
466 | }
467 |
468 | /**
469 | * Calculates Gross Profit Margin from Gross Profit and Revenue.
470 | * @param grossProfit Gross Profit
471 | * @param revenue Revenue
472 | * @return
473 | */
474 | public static double CalcGrossProfitMargin(double grossProfit, double revenue)
475 | {
476 | return grossProfit / revenue;
477 | }
478 |
479 | /**
480 | * Calculates Operating Margin from Operating Income and Revenue.
481 | * @param operatingIncome Operating Income
482 | * @param revenue Revenue
483 | * @return
484 | */
485 | public static double CalcOperatingMargin(double operatingIncome, double revenue)
486 | {
487 | return operatingIncome / revenue;
488 | }
489 |
490 | /**
491 | * Calculates Profit Margin from Net Profit and Revenue.
492 | * @param netProfit Net Profit
493 | * @param revenue Revenue
494 | * @return
495 | */
496 | public static double CalcProfitMargin(double netProfit, double revenue)
497 | {
498 | return netProfit / revenue;
499 | }
500 |
501 | /**
502 | * Calculates Return On Assets (ROA) from Net Income and Total Assets.
503 | * @param netIncome Net Income
504 | * @param totalAssets Total Assets
505 | * @return
506 | */
507 | public static double CalcReturnOnAssets(double netIncome, double totalAssets)
508 | {
509 | return netIncome / totalAssets;
510 | }
511 |
512 | /**
513 | * Calculates Return On Capital (ROC) from EBIT, Tax Rate and Invested Capital.
514 | * @param ebit Earnings Before Interest and Taxes
515 | * @param taxRate Tax Rate
516 | * @param investedCapital Invested Capital
517 | * @return
518 | */
519 | public static double CalcReturnOnCapital(double ebit, double taxRate, double investedCapital)
520 | {
521 | return ebit * (1 - taxRate) / investedCapital;
522 | }
523 |
524 | /**
525 | * Calculates Return on Equity (ROE) from Net Income and Average Shareholder Equity.
526 | * @param netIncome Net Income
527 | * @param averageShareholderEquity Average Shareholder Equity
528 | * @return
529 | */
530 | public static double CalcReturnOnEquity(double netIncome, double averageShareholderEquity)
531 | {
532 | return netIncome / averageShareholderEquity;
533 | }
534 |
535 | /**
536 | * Calculates Return On Net Assets (RONA) from Net Income, Fixed Assets and Working Capital.
537 | * @param netIncome Net Income
538 | * @param fixedAssets Fixed Assets
539 | * @param workingCapital Working Capital
540 | * @return
541 | */
542 | public static double CalcReturnOnNetAssets(double netIncome, double fixedAssets, double workingCapital)
543 | {
544 | return netIncome / (fixedAssets + workingCapital);
545 | }
546 |
547 | /**
548 | * Calculates Risk-Adjusted Return On Capital (RAROC) from Expected Return and Economic Capital.
549 | * @param expectedReturn Expected Return
550 | * @param economicCapital Economic Capital
551 | * @return
552 | */
553 | public static double CalcRiskAdjustedReturnOnCapital(double expectedReturn, double economicCapital)
554 | {
555 | return expectedReturn / economicCapital;
556 | }
557 |
558 | /**
559 | * Calculates Return on Investment (ROI) from Gain and Cost.
560 | * @param gain Gain
561 | * @param cost Cost
562 | * @return
563 | */
564 | public static double CalcReturnOnInvestment(double gain, double cost)
565 | {
566 | return (gain - cost) / cost;
567 | }
568 |
569 | /**
570 | * Calculates Earnings Before Interest, Taxes, Depreciation and Amortization (EBITDA) from EBIT, Depreciation and Amortization.
571 | * @param ebit Earnings Before Interest and Taxes
572 | * @param depreciation Depreciation
573 | * @param amortization Amortization
574 | * @return
575 | */
576 | public static double CalcEbitda(double ebit, double depreciation, double amortization)
577 | {
578 | return ebit + depreciation + amortization;
579 | }
580 | }
581 |
--------------------------------------------------------------------------------
/main/python/srbrettle/financialformulas/FinancialFormulas.py:
--------------------------------------------------------------------------------
1 | """ activity """
2 |
3 |
4 | def calc_asset_turnover(net_sales, total_assets):
5 | return net_sales / total_assets
6 |
7 |
8 | def calc_average_collection_period(accounts_receivable, annual_credit_sales):
9 | return accounts_receivable / (annual_credit_sales / 365)
10 |
11 |
12 | def calc_cash_conversion_cycle(
13 | inventory_conversion_period,
14 | receivables_conversion_period,
15 | payables_conversion_period):
16 | return (inventory_conversion_period
17 | + receivables_conversion_period - payables_conversion_period)
18 |
19 |
20 | def calc_inventory_conversion_period(inventory_turnover_ratio):
21 | return 365 / inventory_turnover_ratio
22 |
23 |
24 | def calc_inventory_conversion_ratio(sales, cost_of_goods_sold):
25 | return (sales * 0.5) / cost_of_goods_sold
26 |
27 |
28 | def calc_inventory_turnover(sales, average_inventory):
29 | return sales / average_inventory
30 |
31 |
32 | def calc_payables_conversion_period(accounts_payable, purchases):
33 | return (accounts_payable / purchases) * 365
34 |
35 |
36 | def calc_receivables_conversion_period(receivables, net_sales):
37 | return (receivables / net_sales) * 365
38 |
39 |
40 | def calc_receivables_turnover_ratio(net_credit_sales, average_net_receivables):
41 | return net_credit_sales / average_net_receivables
42 |
43 |
44 | """ basic """
45 |
46 |
47 | def calc_assets(liabilities, equity):
48 | return liabilities + equity
49 |
50 |
51 | def calc_ebit(revenue, operating_expenses):
52 | return revenue - operating_expenses
53 |
54 |
55 | def calc_equity(assets, liabilities):
56 | return assets - liabilities
57 |
58 |
59 | def calc_gross_profit(revenue, cost_of_goods_sold):
60 | return revenue - cost_of_goods_sold
61 |
62 |
63 | def calc_liabilities(assets, equity):
64 | return assets - equity
65 |
66 |
67 | def calc_net_profit(gross_profit, operating_expenses, taxes, interest):
68 | return gross_profit - operating_expenses - taxes - interest
69 |
70 |
71 | def calc_operating_profit(gross_profit, operating_expenses):
72 | return gross_profit - operating_expenses
73 |
74 |
75 | def calc_sales_revenue(gross_sales, sales_of_returns_and_allowances):
76 | return gross_sales - sales_of_returns_and_allowances
77 |
78 |
79 | """ debt """
80 |
81 |
82 | def calc_debt_equity_ratio(total_liabilities, shareholder_equity):
83 | return total_liabilities / shareholder_equity
84 |
85 |
86 | def calc_debt_ratio(total_liabilities, total_assets):
87 | return total_liabilities / total_assets
88 |
89 |
90 | def calc_debt_service_coverage_ratio(net_operating_income, total_debt_service):
91 | return net_operating_income / total_debt_service
92 |
93 |
94 | def calc_long_term_debt_equity_ratio(long_term_liabilities, equity):
95 | return long_term_liabilities / equity
96 |
97 |
98 | """ depreciation """
99 |
100 |
101 | def calc_book_value(acquisition_cost, depreciation):
102 | return acquisition_cost - depreciation
103 |
104 |
105 | def calc_declining_balance(depreciation_rate, book_value_at_beginning_of_year):
106 | return depreciation_rate * book_value_at_beginning_of_year
107 |
108 |
109 | def calc_units_of_production(
110 | cost_of_asset,
111 | residual_value,
112 | estimated_total_production,
113 | actual_production):
114 | return ((cost_of_asset - residual_value) /
115 | estimated_total_production) * actual_production
116 |
117 |
118 | def calc_straight_line_method(
119 | cost_of_fixed_asset,
120 | residual_value,
121 | useful_life_of_asset):
122 | return (cost_of_fixed_asset - residual_value) / useful_life_of_asset
123 |
124 |
125 | """ liquidity """
126 |
127 |
128 | def calc_cash_ratio(cash, marketable_securities, current_liabilities):
129 | return (cash + marketable_securities) / current_liabilities
130 |
131 |
132 | def calc_current_ratio(current_assets, current_liabilities):
133 | return current_assets / current_liabilities
134 |
135 |
136 | def calc_operating_cash_flow_ratio(operating_cash_flow, total_debts):
137 | return operating_cash_flow / total_debts
138 |
139 |
140 | def calc_quick_ratio(current_assets, inventories, current_liabilities):
141 | return (current_assets - inventories) / current_liabilities
142 |
143 |
144 | """ market """
145 |
146 |
147 | def calc_dividend_cover(earnings_per_share, dividends_per_share):
148 | return earnings_per_share / dividends_per_share
149 |
150 |
151 | def calc_dividends_per_share(dividends_paid, number_of_shares):
152 | return dividends_paid / number_of_shares
153 |
154 |
155 | def calc_dividend_yield(annual_dividend_per_share, price_per_share):
156 | return annual_dividend_per_share / price_per_share
157 |
158 |
159 | def calc_earnings_per_share(net_earnings, number_of_shares):
160 | return net_earnings / number_of_shares
161 |
162 |
163 | def calc_payout_ratio(dividends, earnings):
164 | return dividends / earnings
165 |
166 |
167 | def calc_peg_ratio(price_per_earnings, annual_eps_growth):
168 | return price_per_earnings / annual_eps_growth
169 |
170 |
171 | def calc_price_sales_ratio(price_per_share, revenue_per_share):
172 | return price_per_share / revenue_per_share
173 |
174 |
175 | """ profitability """
176 |
177 |
178 | def calc_efficiency_ratio(non_interest_expense, revenue):
179 | return non_interest_expense / revenue
180 |
181 |
182 | def calc_gross_profit_margin(gross_profit, revenue):
183 | return gross_profit / revenue
184 |
185 |
186 | def calc_operating_margin(operating_income, revenue):
187 | return operating_income / revenue
188 |
189 |
190 | def calc_profit_margin(net_profit, revenue):
191 | return net_profit / revenue
192 |
193 |
194 | def calc_return_on_assets(net_income, total_assets):
195 | return net_income / total_assets
196 |
197 |
198 | def calc_return_on_capital(ebit, tax_rate, invested_capital):
199 | return ebit * (1 - tax_rate) / invested_capital
200 |
201 |
202 | def calc_return_on_equity(net_income, average_shareholder_equity):
203 | return net_income / average_shareholder_equity
204 |
205 |
206 | def calc_return_on_net_assets(net_income, fixed_assets, working_capital):
207 | return net_income / (fixed_assets + working_capital)
208 |
209 |
210 | def calc_risk_adjusted_return_on_capital(expected_return, economic_capital):
211 | return expected_return / economic_capital
212 |
213 |
214 | def calc_return_on_investment(gain, cost):
215 | return (gain - cost) / cost
216 |
217 |
218 | def calc_ebitda(ebit, depreciation, amortization):
219 | return ebit + depreciation + amortization
220 |
--------------------------------------------------------------------------------
/test/csharp/srbrettle/FinancialFormulas/UnitTest.FinancialFormulas.cs:
--------------------------------------------------------------------------------
1 | using srbrettle.FinancialFormulas;
2 | using Xunit;
3 |
4 | namespace UnitTest_FinancialFormulas
5 | {
6 | public class UnitTest_FinancialFormulas
7 | {
8 | [Fact]
9 | public void AssetTurnover_ValidInput_ReturnsCorrect()
10 | {
11 | double result = FinancialFormulas.CalcAssetTurnover(500, 200);
12 | Assert.Equal(2.5, result);
13 | }
14 |
15 | [Fact]
16 | public void AverageCollectionPeriod_ValidInput_ReturnsCorrect()
17 | {
18 | double result = FinancialFormulas.CalcAverageCollectionPeriod(500, 200);
19 | Assert.Equal(912.5, result);
20 | }
21 |
22 | [Fact]
23 | public void CashConversionCycle_ValidInput_ReturnsCorrect()
24 | {
25 | double result = FinancialFormulas.CalcCashConversionCycle(500, 200, 100);
26 | Assert.Equal(600.0, result);
27 | }
28 |
29 | [Fact]
30 | public void InventoryConversionPeriod_ValidInput_ReturnsCorrect()
31 | {
32 | double result = FinancialFormulas.CalcInventoryConversionPeriod(365);
33 | Assert.Equal(1.0, result);
34 | }
35 |
36 | [Fact]
37 | public void InventoryConversionRatio_ValidInput_ReturnsCorrect()
38 | {
39 | double result = FinancialFormulas.CalcInventoryConversionRatio(500, 200);
40 | Assert.Equal(1.25, result);
41 | }
42 |
43 | [Fact]
44 | public void InventoryTurnover_ValidInput_ReturnsCorrect()
45 | {
46 | double result = FinancialFormulas.CalcInventoryTurnover(500, 200);
47 | Assert.Equal(2.5, result);
48 | }
49 |
50 | [Fact]
51 | public void PayablesConversionPeriod_ValidInput_ReturnsCorrect()
52 | {
53 | double result = FinancialFormulas.CalcPayablesConversionPeriod(500, 200);
54 | Assert.Equal(912.5, result);
55 | }
56 |
57 | [Fact]
58 | public void ReceivablesConversionPeriod_ValidInput_ReturnsCorrect()
59 | {
60 | double result = FinancialFormulas.CalcReceivablesConversionPeriod(500, 200);
61 | Assert.Equal(912.5, result);
62 | }
63 |
64 | [Fact]
65 | public void ReceivablesTurnoverRatio_ValidInput_ReturnsCorrect()
66 | {
67 | double result = FinancialFormulas.CalcReceivablesTurnoverRatio(500, 200);
68 | Assert.Equal(2.5, result);
69 | }
70 |
71 | [Fact]
72 | public void Assets_ValidInput_ReturnsCorrect()
73 | {
74 | double result = FinancialFormulas.CalcAssets(300, 200);
75 | Assert.Equal(500.0, result);
76 | }
77 |
78 | [Fact]
79 | public void Ebit_ValidInput_ReturnsCorrect()
80 | {
81 | double result = FinancialFormulas.CalcEbit(500, 200);
82 | Assert.Equal(300.0, result);
83 | }
84 |
85 | [Fact]
86 | public void Equity_ValidInput_ReturnsCorrect()
87 | {
88 | double result = FinancialFormulas.CalcEquity(300, 200);
89 | Assert.Equal(100.0, result);
90 | }
91 |
92 | [Fact]
93 | public void GrossProfit_ValidInput_ReturnsCorrect()
94 | {
95 | double result = FinancialFormulas.CalcGrossProfit(500, 200);
96 | Assert.Equal(300.0, result);
97 | }
98 |
99 | [Fact]
100 | public void Liabilities_ValidInput_ReturnsCorrect()
101 | {
102 | double result = FinancialFormulas.CalcLiabilities(500, 200);
103 | Assert.Equal(300.0, result);
104 | }
105 |
106 | [Fact]
107 | public void NetProfit_ValidInput_ReturnsCorrect()
108 | {
109 | double result = FinancialFormulas.CalcNetProfit(500, 200, 100, 100);
110 | Assert.Equal(100.0, result);
111 | }
112 |
113 | [Fact]
114 | public void OperatingProfit_ValidInput_ReturnsCorrect()
115 | {
116 | double result = FinancialFormulas.CalcOperatingProfit(500, 200);
117 | Assert.Equal(300.0, result);
118 | }
119 |
120 | [Fact]
121 | public void SalesRevenue_ValidInput_ReturnsCorrect()
122 | {
123 | double result = FinancialFormulas.CalcSalesRevenue(500, 200);
124 | Assert.Equal(300.0, result);
125 | }
126 |
127 | [Fact]
128 | public void DebtEquityRatio_ValidInput_ReturnsCorrect()
129 | {
130 | double result = FinancialFormulas.CalcDebtEquityRatio(500, 200);
131 | Assert.Equal(2.5, result);
132 | }
133 |
134 | [Fact]
135 | public void DebtRatio_ValidInput_ReturnsCorrect()
136 | {
137 | double result = FinancialFormulas.CalcDebtRatio(500, 200);
138 | Assert.Equal(2.5, result);
139 | }
140 |
141 | [Fact]
142 | public void DebtServiceCoverageRatio_ValidInput_ReturnsCorrect()
143 | {
144 | double result = FinancialFormulas.CalcDebtServiceCoverageRatio(500, 200);
145 | Assert.Equal(2.5, result);
146 | }
147 |
148 | [Fact]
149 | public void LongTermDebtEquityRatio_ValidInput_ReturnsCorrect()
150 | {
151 | double result = FinancialFormulas.CalcLongTermDebtEquityRatio(500, 200);
152 | Assert.Equal(2.5, result);
153 | }
154 |
155 | [Fact]
156 | public void BookValue_ValidInput_ReturnsCorrect()
157 | {
158 | double result = FinancialFormulas.CalcBookValue(500, 200);
159 | Assert.Equal(300.0, result);
160 | }
161 |
162 | [Fact]
163 | public void DecliningBalance_ValidInput_ReturnsCorrect()
164 | {
165 | double result = FinancialFormulas.CalcDecliningBalance(0.5, 200);
166 | Assert.Equal(100.0, result);
167 | }
168 |
169 | [Fact]
170 | public void UnitsOfProduction_ValidInput_ReturnsCorrect()
171 | {
172 | double result = FinancialFormulas.CalcUnitsOfProduction(500, 200, 100, 150);
173 | Assert.Equal(450.0, result);
174 | }
175 |
176 | [Fact]
177 | public void StraightLineMethod_ValidInput_ReturnsCorrect()
178 | {
179 | double result = FinancialFormulas.CalcStraightLineMethod(500, 200, 10);
180 | Assert.Equal(30.0, result);
181 | }
182 |
183 | [Fact]
184 | public void CashRatio_ValidInput_ReturnsCorrect()
185 | {
186 | double result = FinancialFormulas.CalcCashRatio(500, 200, 100);
187 | Assert.Equal(7.0, result);
188 | }
189 |
190 | [Fact]
191 | public void CurrentRatio_ValidInput_ReturnsCorrect()
192 | {
193 | double result = FinancialFormulas.CalcCurrentRatio(500, 200);
194 | Assert.Equal(2.5, result);
195 | }
196 |
197 | [Fact]
198 | public void OperatingCashFlowRatio_ValidInput_ReturnsCorrect()
199 | {
200 | double result = FinancialFormulas.CalcOperatingCashFlowRatio(500, 200);
201 | Assert.Equal(2.5, result);
202 | }
203 |
204 | [Fact]
205 | public void QuickRatio_ValidInput_ReturnsCorrect()
206 | {
207 | double result = FinancialFormulas.CalcQuickRatio(500, 200, 100);
208 | Assert.Equal(3.0, result);
209 | }
210 |
211 | [Fact]
212 | public void DividendCover_ValidInput_ReturnsCorrect()
213 | {
214 | double result = FinancialFormulas.CalcDividendCover(500, 200);
215 | Assert.Equal(2.5, result);
216 | }
217 |
218 | [Fact]
219 | public void DividendsPerShare_ValidInput_ReturnsCorrect()
220 | {
221 | double result = FinancialFormulas.CalcDividendsPerShare(500, 200);
222 | Assert.Equal(2.5, result);
223 | }
224 |
225 | [Fact]
226 | public void DividendYield_ValidInput_ReturnsCorrect()
227 | {
228 | double result = FinancialFormulas.CalcDividendYield(5, 200);
229 | Assert.Equal(0.025, result);
230 | }
231 |
232 | [Fact]
233 | public void EarningsPerShare_ValidInput_ReturnsCorrect()
234 | {
235 | double result = FinancialFormulas.CalcEarningsPerShare(500, 200);
236 | Assert.Equal(2.5, result);
237 | }
238 |
239 | [Fact]
240 | public void PayoutRatio_ValidInput_ReturnsCorrect()
241 | {
242 | double result = FinancialFormulas.CalcPayoutRatio(500, 10000);
243 | Assert.Equal(0.05, result);
244 | }
245 |
246 | [Fact]
247 | public void PegRatio_ValidInput_ReturnsCorrect()
248 | {
249 | double result = FinancialFormulas.CalcPegRatio(500, 200);
250 | Assert.Equal(2.5, result);
251 | }
252 |
253 | [Fact]
254 | public void PriceSalesRatio_ValidInput_ReturnsCorrect()
255 | {
256 | double result = FinancialFormulas.CalcPriceSalesRatio(500, 200);
257 | Assert.Equal(2.5, result);
258 | }
259 |
260 | [Fact]
261 | public void EfficiencyRatio_ValidInput_ReturnsCorrect()
262 | {
263 | double result = FinancialFormulas.CalcEfficiencyRatio(500, 200);
264 | Assert.Equal(2.5, result);
265 | }
266 |
267 | [Fact]
268 | public void GrossProfitMargin_ValidInput_ReturnsCorrect()
269 | {
270 | double result = FinancialFormulas.CalcGrossProfitMargin(500, 200);
271 | Assert.Equal(2.5, result);
272 | }
273 |
274 | [Fact]
275 | public void OperatingMargin_ValidInput_ReturnsCorrect()
276 | {
277 | double result = FinancialFormulas.CalcOperatingMargin(500, 200);
278 | Assert.Equal(2.5, result);
279 | }
280 |
281 | [Fact]
282 | public void ProfitMargin_ValidInput_ReturnsCorrect()
283 | {
284 | double result = FinancialFormulas.CalcProfitMargin(500, 200);
285 | Assert.Equal(2.5, result);
286 | }
287 |
288 | [Fact]
289 | public void ReturnOnAssets_ValidInput_ReturnsCorrect()
290 | {
291 | double result = FinancialFormulas.CalcReturnOnAssets(500, 200);
292 | Assert.Equal(2.50, result);
293 | }
294 |
295 | [Fact]
296 | public void ReturnOnCapital_ValidInput_ReturnsCorrect()
297 | {
298 | double result = FinancialFormulas.CalcReturnOnCapital(500, 0.2, 100);
299 | Assert.Equal(4.0, result);
300 | }
301 |
302 | [Fact]
303 | public void ReturnOnEquity_ValidInput_ReturnsCorrect()
304 | {
305 | double result = FinancialFormulas.CalcReturnOnEquity(500, 200);
306 | Assert.Equal(2.5, result);
307 | }
308 |
309 | [Fact]
310 | public void ReturnOnNetAssets_ValidInput_ReturnsCorrect()
311 | {
312 | double result = FinancialFormulas.CalcReturnOnNetAssets(500, 200, 50);
313 | Assert.Equal(2.0, result);
314 | }
315 |
316 | [Fact]
317 | public void RiskAdjustedReturnOnCapital_ValidInput_ReturnsCorrect()
318 | {
319 | double result = FinancialFormulas.CalcRiskAdjustedReturnOnCapital(500, 200);
320 | Assert.Equal(2.5, result);
321 | }
322 |
323 | [Fact]
324 | public void ReturnOnInvestment_ValidInput_ReturnsCorrect()
325 | {
326 | double result = FinancialFormulas.CalcReturnOnInvestment(500, 200);
327 | Assert.Equal(1.5, result);
328 | }
329 |
330 | [Fact]
331 | public void Ebitda_ValidInput_ReturnsCorrect()
332 | {
333 | double result = FinancialFormulas.CalcEbitda(500, 200, 100);
334 | Assert.Equal(800.0, result);
335 | }
336 | }
337 | }
338 |
--------------------------------------------------------------------------------
/test/java/srbrettle/financialformulas/FinancialFormulasTest.java:
--------------------------------------------------------------------------------
1 | package srbrettle.financialformulas;
2 |
3 | import junit.framework.Assert;
4 | import org.junit.Test;
5 |
6 | public class FinancialFormulasTest {
7 |
8 | @Test
9 | public void AssetTurnover_ValidInput_ReturnsCorrect() {
10 | double result = FinancialFormulas.CalcAssetTurnover(500,200);
11 | Assert.assertEquals(2.5,result);
12 | }
13 |
14 | @Test
15 | public void AverageCollectionPeriod_ValidInput_ReturnsCorrect() {
16 | double result = FinancialFormulas.CalcAverageCollectionPeriod(500,200);
17 | Assert.assertEquals(912.5,result);
18 | }
19 |
20 | @Test
21 | public void CashConversionCycle_ValidInput_ReturnsCorrect() {
22 | double result = FinancialFormulas.CalcCashConversionCycle(500,200,100);
23 | Assert.assertEquals(600.0,result);
24 | }
25 |
26 | @Test
27 | public void InventoryConversionPeriod_ValidInput_ReturnsCorrect() {
28 | double result = FinancialFormulas.CalcInventoryConversionPeriod(365);
29 | Assert.assertEquals(1.0,result);
30 | }
31 |
32 | @Test
33 | public void InventoryConversionRatio_ValidInput_ReturnsCorrect() {
34 | double result = FinancialFormulas.CalcInventoryConversionRatio(500,200);
35 | Assert.assertEquals(1.25,result);
36 | }
37 |
38 | @Test
39 | public void InventoryTurnover_ValidInput_ReturnsCorrect() {
40 | double result = FinancialFormulas.CalcInventoryTurnover(500,200);
41 | Assert.assertEquals(2.5,result);
42 | }
43 |
44 | @Test
45 | public void PayablesConversionPeriod_ValidInput_ReturnsCorrect() {
46 | double result = FinancialFormulas.CalcPayablesConversionPeriod(500,200);
47 | Assert.assertEquals(912.5,result);
48 | }
49 |
50 | @Test
51 | public void ReceivablesConversionPeriod_ValidInput_ReturnsCorrect() {
52 | double result = FinancialFormulas.CalcReceivablesConversionPeriod(500,200);
53 | Assert.assertEquals(912.5,result);
54 | }
55 |
56 | @Test
57 | public void ReceivablesTurnoverRatio_ValidInput_ReturnsCorrect() {
58 | double result = FinancialFormulas.CalcReceivablesTurnoverRatio(500,200);
59 | Assert.assertEquals(2.5,result);
60 | }
61 |
62 | @Test
63 | public void Assets_ValidInput_ReturnsCorrect() {
64 | double result = FinancialFormulas.CalcAssets(300,200);
65 | Assert.assertEquals(500.0,result);
66 | }
67 |
68 | @Test
69 | public void Ebit_ValidInput_ReturnsCorrect() {
70 | double result = FinancialFormulas.CalcEbit(500,200);
71 | Assert.assertEquals(300.0,result);
72 | }
73 |
74 | @Test
75 | public void Equity_ValidInput_ReturnsCorrect() {
76 | double result = FinancialFormulas.CalcEquity(300,200);
77 | Assert.assertEquals(100.0,result);
78 | }
79 |
80 | @Test
81 | public void GrossProfit_ValidInput_ReturnsCorrect() {
82 | double result = FinancialFormulas.CalcGrossProfit(500,200);
83 | Assert.assertEquals(300.0,result);
84 | }
85 |
86 | @Test
87 | public void Liabilities_ValidInput_ReturnsCorrect() {
88 | double result = FinancialFormulas.CalcLiabilities(500,200);
89 | Assert.assertEquals(300.0,result);
90 | }
91 |
92 | @Test
93 | public void NetProfit_ValidInput_ReturnsCorrect() {
94 | double result = FinancialFormulas.CalcNetProfit(500,200,100,100);
95 | Assert.assertEquals(100.0,result);
96 | }
97 |
98 | @Test
99 | public void OperatingProfit_ValidInput_ReturnsCorrect() {
100 | double result = FinancialFormulas.CalcOperatingProfit(500,200);
101 | Assert.assertEquals(300.0,result);
102 | }
103 |
104 | @Test
105 | public void SalesRevenue_ValidInput_ReturnsCorrect() {
106 | double result = FinancialFormulas.CalcSalesRevenue(500,200);
107 | Assert.assertEquals(300.0,result);
108 | }
109 |
110 | @Test
111 | public void DebtEquityRatio_ValidInput_ReturnsCorrect() {
112 | double result = FinancialFormulas.CalcDebtEquityRatio(500,200);
113 | Assert.assertEquals(2.5,result);
114 | }
115 |
116 | @Test
117 | public void DebtRatio_ValidInput_ReturnsCorrect() {
118 | double result = FinancialFormulas.CalcDebtRatio(500,200);
119 | Assert.assertEquals(2.5,result);
120 | }
121 |
122 | @Test
123 | public void DebtServiceCoverageRatio_ValidInput_ReturnsCorrect() {
124 | double result = FinancialFormulas.CalcDebtServiceCoverageRatio(500,200);
125 | Assert.assertEquals(2.5,result);
126 | }
127 |
128 | @Test
129 | public void LongTermDebtEquityRatio_ValidInput_ReturnsCorrect() {
130 | double result = FinancialFormulas.CalcLongTermDebtEquityRatio(500,200);
131 | Assert.assertEquals(2.5,result);
132 | }
133 |
134 | @Test
135 | public void BookValue_ValidInput_ReturnsCorrect() {
136 | double result = FinancialFormulas.CalcBookValue(500,200);
137 | Assert.assertEquals(300.0,result);
138 | }
139 |
140 | @Test
141 | public void DecliningBalance_ValidInput_ReturnsCorrect() {
142 | double result = FinancialFormulas.CalcDecliningBalance(0.5,200);
143 | Assert.assertEquals(100.0,result);
144 | }
145 |
146 | @Test
147 | public void UnitsOfProduction_ValidInput_ReturnsCorrect() {
148 | double result = FinancialFormulas.CalcUnitsOfProduction(500,200,100,150);
149 | Assert.assertEquals(450.0,result);
150 | }
151 |
152 | @Test
153 | public void StraightLineMethod_ValidInput_ReturnsCorrect() {
154 | double result = FinancialFormulas.CalcStraightLineMethod(500,200, 10);
155 | Assert.assertEquals(30.0,result);
156 | }
157 |
158 | @Test
159 | public void CashRatio_ValidInput_ReturnsCorrect() {
160 | double result = FinancialFormulas.CalcCashRatio(500,200, 100);
161 | Assert.assertEquals(7.0,result);
162 | }
163 |
164 | @Test
165 | public void CurrentRatio_ValidInput_ReturnsCorrect() {
166 | double result = FinancialFormulas.CalcCurrentRatio(500,200);
167 | Assert.assertEquals(2.5,result);
168 | }
169 |
170 | @Test
171 | public void OperatingCashFlowRatio_ValidInput_ReturnsCorrect() {
172 | double result = FinancialFormulas.CalcOperatingCashFlowRatio(500,200);
173 | Assert.assertEquals(2.5,result);
174 | }
175 |
176 | @Test
177 | public void QuickRatio_ValidInput_ReturnsCorrect() {
178 | double result = FinancialFormulas.CalcQuickRatio(500,200,100);
179 | Assert.assertEquals(3.0,result);
180 | }
181 |
182 | @Test
183 | public void DividendCover_ValidInput_ReturnsCorrect() {
184 | double result = FinancialFormulas.CalcDividendCover(500,200);
185 | Assert.assertEquals(2.5,result);
186 | }
187 |
188 | @Test
189 | public void DividendsPerShare_ValidInput_ReturnsCorrect() {
190 | double result = FinancialFormulas.CalcDividendsPerShare(500,200);
191 | Assert.assertEquals(2.5,result);
192 | }
193 |
194 | @Test
195 | public void DividendYield_ValidInput_ReturnsCorrect() {
196 | double result = FinancialFormulas.CalcDividendYield(5,200);
197 | Assert.assertEquals(0.025,result);
198 | }
199 |
200 | @Test
201 | public void EarningsPerShare_ValidInput_ReturnsCorrect() {
202 | double result = FinancialFormulas.CalcEarningsPerShare(500,200);
203 | Assert.assertEquals(2.5,result);
204 | }
205 |
206 | @Test
207 | public void PayoutRatio_ValidInput_ReturnsCorrect() {
208 | double result = FinancialFormulas.CalcPayoutRatio(500,10000);
209 | Assert.assertEquals(0.05,result);
210 | }
211 |
212 | @Test
213 | public void PegRatio_ValidInput_ReturnsCorrect() {
214 | double result = FinancialFormulas.CalcPegRatio(500,200);
215 | Assert.assertEquals(2.5,result);
216 | }
217 |
218 | @Test
219 | public void PriceSalesRatio_ValidInput_ReturnsCorrect() {
220 | double result = FinancialFormulas.CalcPriceSalesRatio(500,200);
221 | Assert.assertEquals(2.5,result);
222 | }
223 |
224 | @Test
225 | public void EfficiencyRatio_ValidInput_ReturnsCorrect() {
226 | double result = FinancialFormulas.CalcEfficiencyRatio(500,200);
227 | Assert.assertEquals(2.5,result);
228 | }
229 |
230 | @Test
231 | public void GrossProfitMargin_ValidInput_ReturnsCorrect() {
232 | double result = FinancialFormulas.CalcGrossProfitMargin(500,200);
233 | Assert.assertEquals(2.5,result);
234 | }
235 |
236 | @Test
237 | public void OperatingMargin_ValidInput_ReturnsCorrect() {
238 | double result = FinancialFormulas.CalcOperatingMargin(500,200);
239 | Assert.assertEquals(2.5,result);
240 | }
241 |
242 | @Test
243 | public void ProfitMargin_ValidInput_ReturnsCorrect() {
244 | double result = FinancialFormulas.CalcProfitMargin(500,200);
245 | Assert.assertEquals(2.5,result);
246 | }
247 |
248 | @Test
249 | public void ReturnOnAssets_ValidInput_ReturnsCorrect() {
250 | double result = FinancialFormulas.CalcReturnOnAssets(500,200);
251 | Assert.assertEquals(2.50,result);
252 | }
253 |
254 | @Test
255 | public void ReturnOnCapital_ValidInput_ReturnsCorrect() {
256 | double result = FinancialFormulas.CalcReturnOnCapital(500,0.2, 100);
257 | Assert.assertEquals(4.0,result);
258 | }
259 |
260 | @Test
261 | public void ReturnOnEquity_ValidInput_ReturnsCorrect() {
262 | double result = FinancialFormulas.CalcReturnOnEquity(500,200);
263 | Assert.assertEquals(2.5,result);
264 | }
265 |
266 | @Test
267 | public void ReturnOnNetAssets_ValidInput_ReturnsCorrect() {
268 | double result = FinancialFormulas.CalcReturnOnNetAssets(500,200,50);
269 | Assert.assertEquals(2.0,result);
270 | }
271 |
272 | @Test
273 | public void RiskAdjustedReturnOnCapital_ValidInput_ReturnsCorrect() {
274 | double result = FinancialFormulas.CalcRiskAdjustedReturnOnCapital(500,200);
275 | Assert.assertEquals(2.5,result);
276 | }
277 |
278 | @Test
279 | public void ReturnOnInvestment_ValidInput_ReturnsCorrect() {
280 | double result = FinancialFormulas.CalcReturnOnInvestment(500,200);
281 | Assert.assertEquals(1.5,result);
282 | }
283 |
284 | @Test
285 | public void Ebitda_ValidInput_ReturnsCorrect() {
286 | double result = FinancialFormulas.CalcEbitda(500,200,100);
287 | Assert.assertEquals(800.0,result);
288 | }
289 |
290 | }
291 |
--------------------------------------------------------------------------------