-
Notifications
You must be signed in to change notification settings - Fork 4
/
cit_functions_egypt.py
284 lines (243 loc) · 11.5 KB
/
cit_functions_egypt.py
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
"""
Functions that calculate personal income tax liability.
"""
# CODING-STYLE CHECKS:
# pycodestyle functions.py
# pylint --disable=locally-disabled functions.py
import math
import copy
import numpy as np
from taxcalc.decorators import iterate_jit
@iterate_jit(nopython=True)
def Net_accounting_profit(Revenues, Other_revenues, Expenses, Net_accounting_profit):
"""
Compute accounting profit from business
"""
Net_accounting_profit = Revenues + Other_revenues - Expenses
return Net_accounting_profit
@iterate_jit(nopython=True)
def Total_additions_to_GP(Donations_NGO, Donations_Others, Donations_Govt, Other_additions, Total_additions_to_GP):
"""
Compute accounting profit from business
"""
Total_additions_to_GP = Donations_NGO + Donations_Others + Donations_Govt + Other_additions
return Total_additions_to_GP
@iterate_jit(nopython=True)
def Total_taxable_profit(Net_accounting_profit, Total_additions_to_GP, Total_taxable_profit):
"""
Compute total taxable profits afer adding back non-allowable deductions.
"""
Total_taxable_profit = Net_accounting_profit + Total_additions_to_GP
return Total_taxable_profit
@iterate_jit(nopython=True)
def Op_WDV_depr(Op_WDV_Bld, Op_WDV_Intang, Op_WDV_Mach, Op_WDV_Others, Op_WDV_Comp):
"""
Return the opening WDV of each asset class.
"""
Op_WDV_Bld, Op_WDV_Intang, Op_WDV_Mach, Op_WDV_Others, Op_WDV_Comp = (Op_WDV_Bld,
Op_WDV_Intang, Op_WDV_Mach, Op_WDV_Others, Op_WDV_Comp)
return (Op_WDV_Bld, Op_WDV_Intang, Op_WDV_Mach, Op_WDV_Others, Op_WDV_Comp)
@iterate_jit(nopython=True)
def Tax_depr_Bld(Op_WDV_Bld, Add_Bld, Excl_Bld, rate_depr_bld, Tax_depr_Bld):
"""
Compute tax depreciation of building asset class.
"""
Tax_depr_Bld = max(rate_depr_bld*(Op_WDV_Bld + Add_Bld - Excl_Bld),0)
return Tax_depr_Bld
@iterate_jit(nopython=True)
def Tax_depr_Intang(Op_WDV_Intang, Add_Intang, Excl_Intang, rate_depr_intang, Tax_depr_Intang):
"""
Compute tax depreciation of intangibles asset class
"""
Tax_depr_Intang = max(rate_depr_intang*(Op_WDV_Intang + Add_Intang - Excl_Intang),0)
return Tax_depr_Intang
@iterate_jit(nopython=True)
def Tax_depr_Mach(Op_WDV_Mach, Add_Mach, Excl_Mach, rate_depr_mach, Tax_depr_Mach):
"""
Compute tax depreciation of Machinary asset class
"""
Tax_depr_Mach = max(rate_depr_mach*(Op_WDV_Mach + Add_Mach - Excl_Mach),0)
return Tax_depr_Mach
@iterate_jit(nopython=True)
def Tax_depr_Others(Op_WDV_Others, Add_Others, Excl_Others, rate_depr_others, Tax_depr_Others):
"""
Compute tax depreciation of Other asset class
"""
Tax_depr_Others = max(rate_depr_others*(Op_WDV_Others + Add_Others - Excl_Others),0)
return Tax_depr_Others
@iterate_jit(nopython=True)
def Tax_depr_Comp(Op_WDV_Comp, Add_Comp, Excl_Comp, rate_depr_comp, Tax_depr_Comp):
"""
Compute tax depreciation of Computer asset class
"""
Tax_depr_Comp = max(rate_depr_comp*(Op_WDV_Comp + Add_Comp - Excl_Comp),0)
return Tax_depr_Comp
@iterate_jit(nopython=True)
def Tax_depreciation(Tax_depr_Bld, Tax_depr_Intang, Tax_depr_Mach, Tax_depr_Others, Tax_depr_Comp, Tax_depr):
"""
Compute total depreciation of all asset classes.
"""
Tax_depr = Tax_depr_Bld + Tax_depr_Intang + Tax_depr_Mach + Tax_depr_Others + Tax_depr_Comp
return Tax_depr
@iterate_jit(nopython=True)
def Cl_WDV_depr(Op_WDV_Bld, Add_Bld, Excl_Bld, Tax_depr_Bld,
Op_WDV_Intang, Add_Intang, Excl_Intang, Tax_depr_Intang,
Op_WDV_Mach, Add_Mach, Excl_Mach, Tax_depr_Mach,
Op_WDV_Others, Add_Others, Excl_Others, Tax_depr_Others,
Op_WDV_Comp, Add_Comp, Excl_Comp, Tax_depr_Comp,
Cl_WDV_Bld, Cl_WDV_Intang, Cl_WDV_Mach, Cl_WDV_Others, Cl_WDV_Comp):
"""
Compute Closing WDV of each block of asset.
"""
Cl_WDV_Bld = max((Op_WDV_Bld + Add_Bld - Excl_Bld),0) - Tax_depr_Bld
Cl_WDV_Intang = max((Op_WDV_Intang + Add_Intang - Excl_Intang),0) - Tax_depr_Intang
Cl_WDV_Mach = max((Op_WDV_Mach + Add_Mach - Excl_Mach),0) - Tax_depr_Mach
Cl_WDV_Others = max((Op_WDV_Others + Add_Others - Excl_Others),0) - Tax_depr_Others
Cl_WDV_Comp= max((Op_WDV_Comp + Add_Comp - Excl_Comp),0) - Tax_depr_Comp
return (Cl_WDV_Bld, Cl_WDV_Intang, Cl_WDV_Mach, Cl_WDV_Others, Cl_WDV_Comp)
@iterate_jit(nopython=True)
def Total_deductions(Tax_depr, Other_deductions, Donations_Govt, Donations_Govt_rate, Total_deductions):
"""
Compute net taxable profits afer allowing deductions.
"""
Total_deductions = Tax_depr + Other_deductions + (Donations_Govt_rate*Donations_Govt)
return Total_deductions
@iterate_jit(nopython=True)
def Net_taxable_profit(Total_taxable_profit, Total_deductions, Net_taxable_profit):
"""
Compute net taxable profits afer allowing deductions.
"""
Net_taxable_profit = Total_taxable_profit - Total_deductions
return Net_taxable_profit
@iterate_jit(nopython=True)
def Donations_allowed(Donations_NGO, Donations_Others, Donations_NGO_rate, Net_taxable_profit, Donations_Others_rate, Donations_allowed):
"""
Compute net taxable profits afer allowing deductions.
"""
Donations_allowed = min(Donations_NGO, max(0, Donations_NGO_rate*Net_taxable_profit)) + Donations_Others_rate*Donations_Others
return Donations_allowed
@iterate_jit(nopython=True)
def Carried_forward_losses(Carried_forward_losses, CF_losses):
"""
Compute net taxable profits afer allowing deductions.
"""
CF_losses = Carried_forward_losses
return CF_losses
@iterate_jit(nopython=True)
def Tax_base_CF_losses(Net_taxable_profit, Donations_allowed, Loss_CFLimit, CF_losses,
Loss_lag1, Loss_lag2, Loss_lag3, Loss_lag4, Loss_lag5, Loss_lag6, Loss_lag7, Loss_lag8,
newloss1, newloss2, newloss3, newloss4, newloss5, newloss6, newloss7, newloss8, Used_loss_total, Tax_base):
"""
Compute net tax base afer allowing donations and losses.
"""
BF_loss = np.array([Loss_lag1, Loss_lag2, Loss_lag3, Loss_lag4, Loss_lag5, Loss_lag6, Loss_lag7, Loss_lag8])
Gross_Tax_base = min(Net_taxable_profit, max((Net_taxable_profit - Donations_allowed), 0))
if BF_loss.sum() == 0:
BF_loss[0] = CF_losses
N = int(Loss_CFLimit)
if N == 0:
(newloss1, newloss2, newloss3, newloss4, newloss5, newloss6, newloss7, newloss8) = np.zeros(8)
Used_loss_total = 0
Tax_base = Gross_Tax_base
else:
BF_loss = BF_loss[:N]
if Gross_Tax_base < 0:
CYL = abs(Gross_Tax_base)
Used_loss = np.zeros(N)
elif Gross_Tax_base >0:
CYL = 0
Cum_used_loss = 0
Used_loss = np.zeros(N)
for i in range(N, 0, -1):
GTI = Gross_Tax_base - Cum_used_loss
Used_loss[i-1] = min(BF_loss[i-1], GTI)
Cum_used_loss += Used_loss[i-1]
elif Gross_Tax_base == 0:
CYL=0
Used_loss = np.zeros(N)
New_loss = BF_loss - Used_loss
Tax_base = Gross_Tax_base - Used_loss.sum()
newloss1 = CYL
Used_loss_total = Used_loss.sum()
(newloss2, newloss3, newloss4, newloss5, newloss6, newloss7, newloss8) = np.append(New_loss[:-1], np.zeros(8-N))
return (Tax_base, newloss1, newloss2, newloss3, newloss4, newloss5, newloss6, newloss7, newloss8, Used_loss_total)
@iterate_jit(nopython=True)
def Net_tax_base(Tax_base, cit_rate_oil, Sector, Exemptions, Investment_incentive, Net_tax_base):
"""
Compute net tax base afer allowing donations and losses.
"""
if Sector == 2:
Net_tax_base = Tax_base/(1 - cit_rate_oil)
else:
Net_tax_base = Tax_base - Exemptions - Investment_incentive
return Net_tax_base
@iterate_jit(nopython=True)
def Net_tax_base_behavior(cit_rate_oil, cit_rate_hotels, cit_rate_banks,
cit_rate_oil_curr_law, cit_rate_hotels_curr_law,
cit_rate_banks_curr_law, cit_rate_genbus,
cit_rate_genbus_curr_law, elasticity_cit_taxable_income_threshold,
elasticity_cit_taxable_income_value, Net_tax_base,
Net_tax_base_behavior):
"""
Compute net taxable profits afer allowing deductions.
"""
NP = Net_tax_base
elasticity_taxable_income_threshold0 = elasticity_cit_taxable_income_threshold[0]
elasticity_taxable_income_threshold1 = elasticity_cit_taxable_income_threshold[1]
elasticity_taxable_income_threshold2 = elasticity_cit_taxable_income_threshold[2]
elasticity_taxable_income_value0=elasticity_cit_taxable_income_value[0]
elasticity_taxable_income_value1=elasticity_cit_taxable_income_value[1]
elasticity_taxable_income_value2=elasticity_cit_taxable_income_value[2]
if NP<=0:
elasticity=0
elif NP<elasticity_taxable_income_threshold0:
elasticity=elasticity_taxable_income_value0
elif NP<elasticity_taxable_income_threshold1:
elasticity=elasticity_taxable_income_value1
else:
elasticity=elasticity_taxable_income_value2
frac_change_net_of_cit_rate_oil = ((1-cit_rate_oil)-(1-cit_rate_oil_curr_law))/(1-cit_rate_oil_curr_law)
frac_change_Net_tax_base_oil = elasticity*(frac_change_net_of_cit_rate_oil)
frac_change_net_of_cit_rate_hotels = ((1-cit_rate_hotels)-(1-cit_rate_hotels_curr_law))/(1-cit_rate_hotels_curr_law)
frac_change_Net_tax_base_hotels = elasticity*(frac_change_net_of_cit_rate_hotels)
frac_change_net_of_cit_rate_banks = ((1-cit_rate_banks)-(1-cit_rate_banks_curr_law))/(1-cit_rate_banks_curr_law)
frac_change_Net_tax_base_banks = elasticity*(frac_change_net_of_cit_rate_banks)
frac_change_net_of_cit_rate_genbus = ((1-cit_rate_genbus)-(1-cit_rate_genbus_curr_law))/(1-cit_rate_genbus_curr_law)
frac_change_Net_tax_base_genbus = elasticity*(frac_change_net_of_cit_rate_genbus)
Net_tax_base_behavior = Net_tax_base*(1+frac_change_Net_tax_base_oil+frac_change_Net_tax_base_hotels+frac_change_Net_tax_base_banks+frac_change_Net_tax_base_genbus)
return Net_tax_base_behavior
@iterate_jit(nopython=True)
def Net_tax_base_Egyp_Pounds(Net_tax_base_behavior, Exchange_rate, Net_tax_base_Egyp_Pounds):
"""
Compute net tax base afer allowing donations and losses.
"""
Net_tax_base_Egyp_Pounds = Net_tax_base_behavior * Exchange_rate
return Net_tax_base_Egyp_Pounds
DEBUG = False
DEBUG_IDX = 0
@iterate_jit(nopython=True)
def mat_liability(mat_rate, Net_accounting_profit, mat):
"""
Compute net tax base afer allowing donations and losses.
"""
mat = Net_accounting_profit * mat_rate
return mat
@iterate_jit(nopython=True)
def cit_liability(cit_rate_oil, cit_rate_hotels, cit_rate_banks, cit_rate_genbus, Sector, Net_tax_base_Egyp_Pounds, mat, citax):
"""
Compute tax liability given the corporate rate
"""
# subtract TI_special_rates from TTI to get Aggregate_Income, which is
# the portion of TTI that is taxed at normal rates
taxinc = max(Net_tax_base_Egyp_Pounds, 0)
if Sector == 0:
citax = cit_rate_hotels * taxinc
elif Sector == 1:
citax = cit_rate_banks * taxinc
elif Sector == 2:
citax = cit_rate_oil * taxinc
elif Sector == 3:
citax = cit_rate_genbus * taxinc
if citax < mat:
citax = mat
return citax