-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathratios.py
More file actions
115 lines (77 loc) · 3.94 KB
/
ratios.py
File metadata and controls
115 lines (77 loc) · 3.94 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# -*- coding: utf-8 -*-
"""
Copyright [2020] [Sinisa Seslak (seslaks@gmail.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
---
Ratios file for CredPy package (https://github.com/seslak/CredPy)
@author: Sinisa Seslak
"""
# Ratios
def getratio(dataset, ratio, c, days=365):
"""
These are liquidity ratios.
Currently available: current, quick, cashr, nwc, cashta, salestor, dayssales, costsales, ctr
If you plan to commit, please follow this structure.
"""
if ratio == "current": # Current ratio
return dataset['tsta']/dataset['tso']
if ratio == "quick": # Quick/Acid ratio
return (dataset['tsta']-dataset['inventory'])/dataset['tso']
if ratio == "cashr": # Cash ratio
return dataset['cash']/(dataset['tso']+dataset['ltloansyear']+dataset['otherstobl']+dataset['ltloans']+dataset['otherltobl'])
if ratio == "nwc": # Net-working capital
return dataset['tsta']-dataset['tso']
if ratio == "cashta": # Cash to assets ratio
return dataset['cash']/dataset['ta']
if ratio == "salestor": # Sales to receivables (or turnover ratio)
return dataset['revenues']/dataset['receivables']
if ratio == "dayssales": # Days sales outstanding
return dataset['receivables']/dataset['revenues']*days
if ratio == "costsales": # Cost of sales
return (dataset['cogs']+dataset['gna']+dataset['salaries'])/dataset['receivables']
if ratio == "ctr": # Cash turnover
return dataset['revenues']/dataset['cash']
"""
These are leverage ratios.
Currently available: debtequ, debt, fatonw, ebitint, earnings, equityr
If you plan to commit, please follow this structure.
"""
if ratio == "debtequ": # Debt to equity ratio
return dataset['tli']/dataset['paidincap']
if ratio == "debt": # Debt ratio
return dataset['tli']/dataset['ta']
if ratio == "fatonw": # Fixed-assets to net-worth
from errors import error
error("fatonw")
return (dataset['equipment']+dataset['buildings']+dataset['land']-dataset['amortization']*2)/(dataset['equipment']+dataset['buildings']+dataset['land']-dataset['tli'])
if ratio == "ebitint": # Interest coverage
return dataset['ebit']/dataset['interest']
if ratio == "earnings": # Retained earnings ratio compared to equity
return dataset['retainedear']/dataset['equity']
if ratio == "equityr": # Equity ratio
return dataset['equity']/dataset['ta']
"""
These are efficiency ratios.
Currently available: invtr, invhp, invta, acctr, acccp, dpo
If you plan to commit, please follow this structure.
"""
if ratio == "invtr": # Inventory turnover
return dataset['revenues']/dataset['inventory']
if ratio == "invhp": # Inventory holding period
return days/dataset['revenues']/dataset['inventory']
if ratio == "invta": # Inventory to assets ratio
return days/dataset['inventory']/dataset['ta']
if ratio == "acctr": # Accounts receivable turnover
return dataset['revenues']/dataset['receivables']
if ratio == "acccp": # Accounts receivable collection period
return days/dataset['revenues']/dataset['receivables']
if ratio == "dpo": # Days payable outstanding
return dataset['payables']/dataset['cogs']*days