-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulator.py
More file actions
319 lines (254 loc) · 14.4 KB
/
Copy pathsimulator.py
File metadata and controls
319 lines (254 loc) · 14.4 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
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
import tkinter as tk
from tkinter import ttk, messagebox
import locale
# Attempt to set locale for Indian Rupee formatting formatting if supported
try:
locale.setlocale(locale.LC_ALL, 'en_IN')
except:
try:
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
except:
locale.setlocale(locale.LC_ALL, '')
def format_currency(amount):
try:
return locale.currency(amount, grouping=True)
except:
return f"₹ {amount:,.2f}"
class FinancialSimulatorApp:
def __init__(self, root):
self.root = root
self.root.title("Advanced Financial Simulator (20-Year Projections)")
self.root.geometry("1400x800")
# Styles
style = ttk.Style()
style.theme_use('clam')
style.configure("Treeview", rowheight=25, font=('Arial', 10))
style.configure("Treeview.Heading", font=('Arial', 10, 'bold'))
style.configure("Header.TLabel", font=('Arial', 12, 'bold'))
# Variables
self.vars = {}
# Layouts
self.main_pw = ttk.PanedWindow(self.root, orient=tk.HORIZONTAL)
self.main_pw.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
self.left_frame = ttk.Frame(self.main_pw, width=450)
self.right_frame = ttk.Frame(self.main_pw)
self.main_pw.add(self.left_frame, weight=1)
self.main_pw.add(self.right_frame, weight=3)
self.setup_inputs_panel(self.left_frame)
self.setup_outputs_panel(self.right_frame)
def setup_inputs_panel(self, parent):
top_frame = ttk.Frame(parent)
top_frame.pack(fill=tk.X, pady=(0, 10))
btn_frame = ttk.Frame(top_frame)
btn_frame.pack(fill=tk.X, pady=5)
simulate_btn = ttk.Button(btn_frame, text="RUN SIMULATION", command=self.run_simulation)
simulate_btn.pack(fill=tk.X, ipady=10)
gen_lf = ttk.LabelFrame(parent, text="General Parameters")
gen_lf.pack(fill=tk.X, pady=5)
self.add_entry(gen_lf, "years", "Years (Tenure)", 20, 0)
self.add_entry(gen_lf, "tax_rate", "Effective Tax Rate (e.g. 0.312)", 0.312, 1)
self.add_entry(gen_lf, "business_income", "Business Income (₹ p.a.)", 6000000, 2)
# Notebook for case specific inputs
self.inputs_nb = ttk.Notebook(parent)
self.inputs_nb.pack(fill=tk.BOTH, expand=True)
# Case A Inputs
case_a_frame = ttk.Frame(self.inputs_nb)
self.inputs_nb.add(case_a_frame, text="Case A")
self.add_entry(case_a_frame, "a_cash", "Start Re-investable Cash (₹)", 35500000, 0)
self.add_entry(case_a_frame, "a_prop", "Start Non-Reinvest Prop (₹)", 40000000, 1)
self.add_entry(case_a_frame, "a_renov", "Renovation Deduction (₹)", 2500000, 2)
self.add_entry(case_a_frame, "a_stamp_base", "Stamp Duty Base Value (₹)", 13000000, 3)
self.add_entry(case_a_frame, "a_stamp_pct", "Stamp Duty % (e.g. 0.07)", 0.07, 4)
self.add_entry(case_a_frame, "a_returns", "Corpus Returns %", 0.07, 5)
self.add_entry(case_a_frame, "a_maint", "Maintenance Exp p.a. (₹)", 120000, 6)
self.add_entry(case_a_frame, "a_ptax", "Property Tax p.a. (₹)", 60000, 7)
self.add_entry(case_a_frame, "a_depr_base", "Comm. Prop Depr Base (₹)", 17500000, 8)
self.add_entry(case_a_frame, "a_comm_pct", "Comm. Prop % (e.g. 0.35)", 0.35, 9)
self.add_entry(case_a_frame, "a_depr_rate", "Depreciation Rate WDV %", 0.10, 10)
self.add_entry(case_a_frame, "a_prop_appr", "Property Appr Rate % p.a.", 0.01, 11)
# Case B Inputs
case_b_frame = ttk.Frame(self.inputs_nb)
self.inputs_nb.add(case_b_frame, text="Case B")
self.add_entry(case_b_frame, "b_cash_base", "Base Cash Corps (₹)", 65000000, 0)
self.add_entry(case_b_frame, "b_prop_sold", "Property Sold Added (₹)", 20000000, 1)
self.add_entry(case_b_frame, "b_office_bought", "A Comm. Office Bought (₹)", 35000000, 2)
self.add_entry(case_b_frame, "b_parallel_cash", "Parallel Cash (₹)", 7000000, 3)
self.add_entry(case_b_frame, "b_returns", "Corpus Returns %", 0.07, 4)
self.add_entry(case_b_frame, "b_house_rent", "House Rent Exp Year 1 (₹)", 1500000, 5)
self.add_entry(case_b_frame, "b_rent_esc", "Rent Escalation % p.a.", 0.05, 6)
self.add_entry(case_b_frame, "b_office_maint", "Office Maint p.a. (₹)", 300000, 7)
self.add_entry(case_b_frame, "b_depr_base", "Comm. Prop Depr Base (₹)", 23000000, 8)
self.add_entry(case_b_frame, "b_depr_rate", "Depreciation Rate WDV %", 0.10, 9)
self.add_entry(case_b_frame, "b_prop_appr_base", "Comm. Prop Appr Base (₹)", 35000000, 10)
self.add_entry(case_b_frame, "b_prop_appr", "Property Appr Rate % p.a.", 0.05, 11)
# Case C Inputs
case_c_frame = ttk.Frame(self.inputs_nb)
self.inputs_nb.add(case_c_frame, text="Case C")
self.add_entry(case_c_frame, "c_cash_base", "Base Cash Corps (₹)", 65000000, 0)
self.add_entry(case_c_frame, "c_prop_sold", "Property Sold Added (₹)", 20000000, 1)
self.add_entry(case_c_frame, "c_parallel_cash", "Parallel Cash (₹)", 12000000, 2)
self.add_entry(case_c_frame, "c_returns", "Corpus Returns %", 0.07, 3)
self.add_entry(case_c_frame, "c_comm_rent", "Office Rent Exp Year 1 (₹)", 2400000, 4)
self.add_entry(case_c_frame, "c_house_rent", "House Rent Exp Year 1 (₹)", 1500000, 5)
self.add_entry(case_c_frame, "c_rent_esc", "Rent Escalation % p.a.", 0.05, 6)
def add_entry(self, parent, var_name, label_text, default_val, row):
ttk.Label(parent, text=label_text).grid(row=row, column=0, padx=5, pady=3, sticky=tk.W)
var = tk.StringVar(value=str(default_val))
self.vars[var_name] = var
ttk.Entry(parent, textvariable=var, width=15).grid(row=row, column=1, padx=5, pady=3, sticky=tk.E)
def setup_outputs_panel(self, parent):
self.outputs_nb = ttk.Notebook(parent)
self.outputs_nb.pack(fill=tk.BOTH, expand=True)
self.tree_a, self.lbl_nw_a = self.create_result_tab(self.outputs_nb, "Case A Output")
self.tree_b, self.lbl_nw_b = self.create_result_tab(self.outputs_nb, "Case B Output")
self.tree_c, self.lbl_nw_c = self.create_result_tab(self.outputs_nb, "Case C Output")
def create_result_tab(self, parent_nb, title):
frame = ttk.Frame(parent_nb)
parent_nb.add(frame, text=title)
top_frame = ttk.Frame(frame)
top_frame.pack(fill=tk.X, pady=10)
lbl_nw = ttk.Label(top_frame, text="Ending Net Worth: -", style="Header.TLabel")
lbl_nw.pack()
cols = ("Year", "Start Cash", "Biz Inc", "Grp Returns", "Total Exp", "Tax Deductibles", "Income Tax", "Profit After Tax", "End Cash", "Paral. Non-Reinv")
tree = ttk.Treeview(frame, columns=cols, show='headings')
for p in cols:
tree.heading(p, text=p)
tree.column(p, width=100, anchor=tk.E)
tree.column("Year", width=50, anchor=tk.CENTER)
vsb = ttk.Scrollbar(frame, orient="vertical", command=tree.yview)
hsb = ttk.Scrollbar(frame, orient="horizontal", command=tree.xview)
tree.configure(yscrollcommand=vsb.set, xscrollcommand=hsb.set)
tree.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
vsb.pack(side=tk.RIGHT, fill=tk.Y)
hsb.pack(side=tk.BOTTOM, fill=tk.X)
return tree, lbl_nw
def get_val(self, key, is_int=False):
try:
val = float(self.vars[key].get())
return int(val) if is_int else val
except ValueError:
return 0
def run_simulation(self):
try:
self.sim_case_a()
self.sim_case_b()
self.sim_case_c()
messagebox.showinfo("Success", "Simulation Completed Successfully!")
except Exception as e:
messagebox.showerror("Error", f"Simulation failed: {str(e)}")
def clear_tree(self, tree):
for item in tree.get_children():
tree.delete(item)
def sim_case_a(self):
self.clear_tree(self.tree_a)
years = self.get_val("years", True)
tax_rate = self.get_val("tax_rate")
biz_inc = self.get_val("business_income")
cash = self.get_val("a_cash")
prop = self.get_val("a_prop")
renov = self.get_val("a_renov")
stamp_duty = self.get_val("a_stamp_base") * self.get_val("a_stamp_pct")
returns_rate = self.get_val("a_returns")
maint = self.get_val("a_maint")
ptax = self.get_val("a_ptax")
wdv = self.get_val("a_depr_base") * self.get_val("a_comm_pct")
depr_rate = self.get_val("a_depr_rate")
prop_appr_rate = self.get_val("a_prop_appr")
# Initial year zero deduction
cash = cash - renov - stamp_duty
for y in range(1, years + 1):
start_cash = cash
returns = cash * returns_rate
total_exp = maint + ptax
# Tax deductibles: Expenses + Depreciation
depr = wdv * depr_rate
tax_deductibles = (total_exp * self.get_val("a_comm_pct")) + depr
wdv -= depr
gross_income = returns + biz_inc
taxable_income = max(0, gross_income - tax_deductibles)
income_tax = taxable_income * tax_rate
# Profit after tax. Total net cash flow for the year:
profit_after_tax = gross_income - total_exp - income_tax
cash += profit_after_tax
# Non re-investable property appreciation
prop = prop * (1 + prop_appr_rate)
row = (y, format_currency(start_cash), format_currency(biz_inc), format_currency(returns),
format_currency(total_exp), format_currency(tax_deductibles), format_currency(income_tax),
format_currency(profit_after_tax), format_currency(cash), format_currency(prop))
self.tree_a.insert('', tk.END, values=row)
total_nw = cash + prop
self.lbl_nw_a.config(text=f"Ending Net Worth (Year {years}): {format_currency(total_nw)}")
def sim_case_b(self):
self.clear_tree(self.tree_b)
years = self.get_val("years", True)
tax_rate = self.get_val("tax_rate")
biz_inc = self.get_val("business_income")
# 6.5 Cr starting base + 2 Cr property sold = 8.5 Cr total.
# Then minus 3.5 Cr office bought = 5.0 Cr.
# Minus 0.7 Cr completely parallel separated.
cash = self.get_val("b_cash_base") + self.get_val("b_prop_sold") - self.get_val("b_office_bought") - self.get_val("b_parallel_cash")
returns_rate = self.get_val("b_returns")
house_rent = self.get_val("b_house_rent")
rent_esc = self.get_val("b_rent_esc")
maint = self.get_val("b_office_maint")
wdv = self.get_val("b_depr_base")
depr_rate = self.get_val("b_depr_rate")
prop_val = self.get_val("b_prop_appr_base")
prop_appr_rate = self.get_val("b_prop_appr")
parallel_cash = self.get_val("b_parallel_cash")
for y in range(1, years + 1):
start_cash = cash
returns = cash * returns_rate
total_exp = house_rent + maint
# Tax deductibles: Maint + Commercial Depreciation
depr = wdv * depr_rate
tax_deductibles = maint + depr # House rent is non-deductible for self-use
wdv -= depr
gross_income = returns + biz_inc
taxable_income = max(0, gross_income - tax_deductibles)
income_tax = taxable_income * tax_rate
profit_after_tax = gross_income - total_exp - income_tax
cash += profit_after_tax
prop_val = prop_val * (1 + prop_appr_rate)
house_rent = house_rent * (1 + rent_esc)
paral = prop_val + parallel_cash
row = (y, format_currency(start_cash), format_currency(biz_inc), format_currency(returns),
format_currency(total_exp), format_currency(tax_deductibles), format_currency(income_tax),
format_currency(profit_after_tax), format_currency(cash), format_currency(paral))
self.tree_b.insert('', tk.END, values=row)
total_nw = cash + prop_val + parallel_cash
self.lbl_nw_b.config(text=f"Ending Net Worth (Year {years}): {format_currency(total_nw)}")
def sim_case_c(self):
self.clear_tree(self.tree_c)
years = self.get_val("years", True)
tax_rate = self.get_val("tax_rate")
biz_inc = self.get_val("business_income")
cash = self.get_val("c_cash_base") + self.get_val("c_prop_sold") - self.get_val("c_parallel_cash")
parallel_cash = self.get_val("c_parallel_cash")
returns_rate = self.get_val("c_returns")
comm_rent = self.get_val("c_comm_rent")
house_rent = self.get_val("c_house_rent")
rent_esc = self.get_val("c_rent_esc")
for y in range(1, years + 1):
start_cash = cash
returns = cash * returns_rate
total_exp = comm_rent + house_rent
# Tax deductibles: Commercial Rent Let's say yes. House Rent no.
tax_deductibles = comm_rent
gross_income = returns + biz_inc
taxable_income = max(0, gross_income - tax_deductibles)
income_tax = taxable_income * tax_rate
profit_after_tax = gross_income - total_exp - income_tax
cash += profit_after_tax
comm_rent = comm_rent * (1 + rent_esc)
house_rent = house_rent * (1 + rent_esc)
row = (y, format_currency(start_cash), format_currency(biz_inc), format_currency(returns),
format_currency(total_exp), format_currency(tax_deductibles), format_currency(income_tax),
format_currency(profit_after_tax), format_currency(cash), format_currency(parallel_cash))
self.tree_c.insert('', tk.END, values=row)
total_nw = cash + parallel_cash
self.lbl_nw_c.config(text=f"Ending Net Worth (Year {years}): {format_currency(total_nw)}")
if __name__ == "__main__":
root = tk.Tk()
app = FinancialSimulatorApp(root)
root.mainloop()