-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory
512 lines (512 loc) · 19.4 KB
/
.Rhistory
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
#calculate additional income taxable payable for high income earners (div293), generally payable from finances, not SUPER
income.gross.div293 <<- income.gross*(1+super.rate.employer)
total.income.div293 <<- income.gross*(1+super.rate.employer) + super.cont.vol
if(total.income.div293 > tmp$cap_div293){
tax_payable_div293 <<- min(total.income.div293 - tmp$cap_div293, super.contributions.total)*tmp$rate_div293
} else {
tax_payable_div293 <<- 0
}
# return(tax_payable_div293)
# calculate tax refund resulting from voluntary post-tax super contributions
#blabla - super.cont.vol
super.deduction.cap <<- max(concessional.cap - super.contributions.employer, 0)
super.deduction <<- min(super.deduction.cap, super.cont.vol)
income.gross.super.deduction <<- income.gross - super.deduction
}
super_total_contributions(income.gross, super_rate_data
, tax_marginal_rate)
max(10, min(super.contributions.concessional*tmp$listo_rate, tmp$listo_cap_refund))
## calculate baseline tax payable on superannuation contributions and your net super contribution, includes listo
if(income.gross <= tmp$listo_cap_income) {
super.listo.refund <<- max
} else {
super.listo.refund <<- 0
}
if(income.gross <= tmp$listo_cap_income) {
super.listo.refund <<- max(10, min(super.contributions.concessional*tmp$listo_rate, tmp$listo_cap_refund))
} else {
super.listo.refund <<- 0
}
super.contrubtions.tax <<- super.contributions.concessional*tmp$rate +
super.contributions.excess*tax_marginal_rate -
max(10, min(super.contributions.concessional*tmp$listo_rate, tmp$listo_cap_refund))
super.contrubtions.net <<- super.contributions.total - super.contrubtions.tax
if(income.gross <= tmp$listo_cap_income) {
super.listo.refund <<- max(10, min(super.contributions.concessional*tmp$listo_rate, tmp$listo_cap_refund))
} else {
super.listo.refund <<- 0
}
super.contrubtions.tax <<- super.contributions.concessional*tmp$rate +
super.contributions.excess*tax_marginal_rate -
super.listo.refund
super.contrubtions.net <<- super.contributions.total - super.contrubtions.tax
super.listo.refund
super.contrubtions.net
super_total_contributions(income.gross, super_rate_data
, tax_marginal_rate)
tax_threshold_data %>%
filter(year == yr
, residency == resident_status
, threshold < income.gross) %>%
pull(rate) %>%
max()
################################################################################ income taxes #######
super_rate_data <- read_excel(here("taxes.xlsx")
, sheet = "super_contributions"
, skip = 0) %>%
select(c(1:14)) %>%
na.omit()
super_total_contributions <- function(income.gross ##compulsory
, super_rate_data ## dataframe
, tax_threshold_data # to calculate marginal tax rate
, yr = year(Sys.Date())
, super.rate.employer = NULL
, super.cont.vol = NULL
, super.cont.last5 = NULL
, super.balance = NULL
, resident_status = "resident"
) {
## find marginal tax rate
tax_marginal_rate <<- tax_threshold_data %>%
filter(year == yr
, residency == resident_status
, threshold < income.gross) %>%
pull(rate) %>%
max()
### filter super rate data
tmp <- super_rate_data %>%
filter(year == yr)
##### pass remaining optional arguments
if (is.null(super.rate.employer)) {super.rate.employer <- tmp$super_guarantee}
if (is.null(super.cont.vol)) {super.cont.vol <- tmp$default_vol_cont}
## assumes contribution for last 5y at current employer rate using 80% of current gross income
if (is.null(super.cont.last5)) {super.cont.last5 <- income.gross*super.rate.employer*5*0.8}
if (is.null(super.balance)) {super.balance <- tmp$default_super_balance}
super.guarantee <<- tmp$super_guarantee
#calculate gross super contributions and reportable super contributions and income for hecs and mls purposes
super.contributions.employer <<- income.gross*super.rate.employer
super.contributions.total <<- super.contributions.employer + super.cont.vol
super.contributions.rep <<- min(super.contributions.employer - income.gross*super.guarantee + super.cont.vol, tmp$cap_annual)
income.hecs.mls <<- income.gross + super.contributions.rep
income.gross.incl.super <<- income.gross*(1+super.rate.employer)
#return(super.contributions.total)
#return(super.contributions.rep)
#return(income.hecs.mls)
#return(income.gross.incl.super)
# calculate concessional and non-concessional super contributions
super.concessional.carry.limit <<- super_rate_data %>%
filter(year < yr, year >= yr-5) %>%
summarise(sum(cap_annual)) %>%
pull()
concessional.cap <<- tmp$cap_annual + max(0, super.concessional.carry.limit - super.cont.last5)
super.contributions.concessional <<- min(super.contributions.total, concessional.cap)
super.contributions.excess <<- max(0, super.contributions.total - concessional.cap)
## calculate tax payable on superannuation contributions and your net super contribution, includes listo
if(income.gross <= tmp$listo_cap_income) {
super.listo.refund <<- max(10, min(super.contributions.concessional*tmp$listo_rate, tmp$listo_cap_refund))
} else {
super.listo.refund <<- 0
}
super.contrubtions.tax <<- super.contributions.concessional*tmp$rate +
super.contributions.excess*tax_marginal_rate -
super.listo.refund
super.contrubtions.net <<- super.contributions.total - super.contrubtions.tax
#return(super.contrubtions.tax)
return(super.contrubtions.net)
#calculate additional income taxable payable for high income earners (div293), generally payable from finances, not SUPER
income.gross.div293 <<- income.gross*(1+super.rate.employer)
total.income.div293 <<- income.gross*(1+super.rate.employer) + super.cont.vol
if(total.income.div293 > tmp$cap_div293){
tax_payable_div293 <<- min(total.income.div293 - tmp$cap_div293, super.contributions.total)*tmp$rate_div293
} else {
tax_payable_div293 <<- 0
}
# return(tax_payable_div293)
# calculate tax refund resulting from voluntary post-tax super contributions
#blabla - super.cont.vol
super.deduction.cap <<- max(concessional.cap - super.contributions.employer, 0)
super.deduction <<- min(super.deduction.cap, super.cont.vol)
income.gross.super.deduction <<- income.gross - super.deduction
}
income.gross.super.deduction
super.deduction.cap
super.deduction
runApp()
runApp()
runApp()
shiny::runApp()
runApp()
runApp()
runApp()
shiny::runApp()
runApp()
runApp()
shiny::runApp()
runApp()
######################################################################################## medicare levy surcharge #######
mls_threshold_data <- read_excel(here("taxes.xlsx")
, sheet = "medicare_levy_surcharge"
, skip = 0) %>%
select(c(1:4)) %>%
mutate_if(is.character, as.logical) %>%
mutate_all(as.numeric)
mls_threshold_data
runApp()
runApp()
runApp()
runApp()
as.logical(TRUE)
as.numeric(as.logical(TRUE))
runApp()
runApp()
######################################################################################## medicare levy surcharge #######
mls_threshold_data <- read_excel(here("taxes.xlsx")
, sheet = "medicare_levy_surcharge"
, skip = 0) %>%
select(c(1:4)) %>%
mutate_if(is.character, as.logical) %>%
mutate_all(as.numeric)
mls_threshold_data
runApp()
runApp()
runApp()
runApp()
income_taxable
######################################################################################## medicare levy surcharge #######
mls_threshold_data <- read_excel(here("taxes.xlsx")
, sheet = "medicare_levy_surcharge"
, skip = 0) %>%
select(c(1:4)) %>%
mutate_if(is.character, as.logical) %>%
mutate_all(as.numeric)
medicare.levy.surcharge <- function(income_hecs_mls
, mls_threshold_data
, yr = year(Sys.Date()) # optional
, x_single = 1 # optional, defaults to single
, private_health = 0 # optional, defaults to no private health
, x_income_partner_annual = 0 # optional, defaults to 0
) {
if (private_health ==0){
rate <- mls_threshold_data %>%
filter(year == yr
, single == x_single # error hERE for some reason
, threshold <= income_hecs_mls) %>%
select(rate) %>%
max()
mls_payable <<- (income_hecs_mls+x_income_partner_annual)*rate
} else {
mls_payable <<- 0
}
return(mls_payable)
}
medicare.levy.surcharge(211200, mls_threshold_data)
income_max <- 200000
custom_step <- 1000 # You can adjust this to your desired step size
income_min <- custom_step
income_taxable <- seq(income_min, income_max, by = custom_step)
x_income_personal_fortnightly <- income_taxable/365.25*14
no_steps <- length(income_taxable)
net_investment_loss <- 0
rep_fringe_benefits <- 0
rep_super_contributions <- 0
yr <- year(Sys.Date())
resdent_status <- "resident"
medicare.levy.surcharge(211200, mls_threshold_data)
income_hecs_mls
income_taxable
medicare.levy.surcharge(income_taxable, mls_threshold_data)
sapply(income_taxable, medicare.levy.surcharge, mls_threshold_data)
sapply(income_taxable, medicare.levy.surcharge, mls_threshold_data, yr, 1, 0, 0)
sapply(income_taxable, medicare.levy.surcharge, mls_threshold_data, yr, 1, 0, 10000)
sapply(income_taxable, medicare.levy.surcharge, mls_threshold_data, yr, 1, 0, 100000)
medicare.levy.surcharge <- function(income_hecs_mls
, mls_threshold_data
, yr = year(Sys.Date()) # optional
, x_single = 1 # optional, defaults to single
, private_health = 0 # optional, defaults to no private health
, x_income_partner_annual = 0 # optional, defaults to 0
) {
if (private_health ==0){
rate <- mls_threshold_data %>%
filter(year == yr
, single == x_single # error hERE for some reason
, threshold <= income_hecs_mls+x_income_partner_annual) %>%
select(rate) %>%
max()
mls_payable <<- (income_hecs_mls+x_income_partner_annual)*rate
} else {
mls_payable <<- 0
}
return(mls_payable)
}
sapply(income_taxable, medicare.levy.surcharge, mls_threshold_data, yr, 1, 0, 100000)
runApp()
runApp()
private_health
runApp()
mls_payable <<- (income_hecs_mls+x_income_partner_annual)*rate
runApp()
runApp()
runApp()
################################################################################ superannuation #######
super_rate_data <- read_excel(here("taxes.xlsx")
, sheet = "super_contributions"
, skip = 0) %>%
select(c(1:14)) %>%
na.omit()
super_rate_data
tax_threshold_data
######################################################################################## hecs #######
hecs_threshold_data <- read_excel(here("taxes.xlsx")
, sheet = "hecs"
, skip = 0) %>%
select(c(1:3)) %>%
mutate(residency_dummy = 0
, residency_dummy = ifelse(residency_dummy=="foreign_resident", 1, residency_dummy)
, residency_dummy = ifelse(residency_dummy=="working_holiday", 2, residency_dummy))
hecs_threshold_data
######################################################################################## hecs #######
hecs_threshold_data <- read_excel(here("taxes.xlsx")
, sheet = "hecs"
, skip = 0) %>%
select(c(1:3)) %>%
mutate(residency_dummy = 0
, residency_dummy = ifelse(residency=="foreign_resident", 1, residency_dummy)
, residency_dummy = ifelse(residency=="working_holiday", 2, residency_dummy))
read_excel(here("taxes.xlsx")
, sheet = "hecs"
, skip = 0) %>%
select(c(1:3))
read_excel(here("taxes.xlsx")
, sheet = "income_tax"
, skip = 0) %>%
select(c(1:6)) %>%
mutate(residency_dummy = 0
, residency_dummy = ifelse(residency=="foreign_resident", 1, residency_dummy)
, residency_dummy = ifelse(residency=="working_holiday", 2, residency_dummy))
runApp()
runApp()
runApp()
runApp()
super_rate_data %>%
filter(year == yr)
tmp$super_guarantee
### filter super rate data
tmp <- super_rate_data %>%
filter(year == yr)
tmp$super_guarantee
## find marginal tax rate
tax_marginal_rate <<- tax_threshold_data %>%
filter(year == yr
, residency_dummy == resident_status
, threshold < income_gross) %>%
pull(rate) %>%
max()
super.total.contributions <- function(income_gross ##compulsory
, super_rate_data ## dataframe
, tax_threshold_data # to calculate marginal tax rate
, yr = year(Sys.Date())
, super_rate_employer = NULL
, super_cont_vol = NULL
, super_cont_last5 = NULL
, super_balance = NULL
, resident_status = 0 ## = resident
) {
## find marginal tax rate
tax_marginal_rate <<- tax_threshold_data %>%
filter(year == yr
, residency_dummy == resident_status
, threshold < income_gross) %>%
pull(rate) %>%
max()
### filter super rate data
tmp <- super_rate_data %>%
filter(year == yr)
##### pass remaining optional arguments
if (is.null(super_rate_employer)) {super_rate_employer <- tmp$super_guarantee}
if (is.null(super_cont_vol)) {super_cont_vol <- tmp$default_vol_cont}
## assumes contribution for last 5y at current employer rate using 80% of current gross income
if (is.null(super_cont_last5)) {super_cont_last5 <- income_gross*super_rate_employer*5*0.8}
if (is.null(super_balance)) {super_balance <- tmp$default_super_balance}
super_guarantee <<- tmp$super_guarantee
#calculate gross super contributions and reportable super contributions and income for hecs and mls purposes
super_contributions_employer <<- income_gross*super_rate_employer
super_contributions_total <<- super_contributions_employer + super_cont_vol
super_contributions_rep <<- min(super_contributions_employer - income_gross*super_guarantee + super_cont_vol, tmp$cap_annual)
income_hecs_mls <<- income_gross + super_contributions_rep
income_gross_incl_super <<- income_gross*(1+super_rate_employer)
#return(super_contributions_total)
#return(super_contributions_rep)
#return(income_hecs_mls)
#return(income_gross_incl_super)
# calculate concessional and non-concessional super contributions
super_concessional_carry_limit <<- super_rate_data %>%
filter(year < yr, year >= yr-5) %>%
summarise(sum(cap_annual)) %>%
pull()
concessional_cap <<- tmp$cap_annual + max(0, super_concessional_carry_limit - super_cont_last5)
super_contributions_concessional <<- min(super_contributions_total, concessional_cap)
super_contributions_excess <<- max(0, super_contributions_total - concessional_cap)
## calculate tax payable on superannuation contributions and your net super contribution, includes listo
if(income_gross <= tmp$listo_cap_income) {
super_listo_refund <<- max(10, min(super_contributions_concessional*tmp$listo_rate, tmp$listo_cap_refund))
} else {
super_listo_refund <<- 0
}
super_contrubtions_tax <<- super_contributions_concessional*tmp$rate +
super_contributions_excess*tax_marginal_rate -
super_listo_refund
super_contrubtions_net <<- super_contributions_total - super_contrubtions_tax
#return(super_contrubtions_tax)
return(super_contrubtions_net)
#calculate additional income taxable payable for high income earners (div293), generally payable from finances, not SUPER
income_gross_div293 <<- income_gross*(1+super_rate_employer)
total_income_div293 <<- income_gross*(1+super_rate_employer) + super_cont_vol
if(total_income_div293 > tmp$cap_div293){
tax_payable_div293 <<- min(total_income_div293 - tmp$cap_div293, super_contributions_total)*tmp$rate_div293
} else {
tax_payable_div293 <<- 0
}
# return(tax_payable_div293)
# calculate tax refund resulting from voluntary post-tax super contributions
#blabla - super_cont_vol
super_deduction_cap <<- max(concessional_cap - super_contributions_employer, 0)
super_deduction <<- min(super_deduction_cap, super_cont_vol)
income_gross_super_deduction <<- income_gross - super_deduction
}
taxable_income
income_max <- 200000
custom_step <- 1000 # You can adjust this to your desired step size
income_min <- custom_step
income_taxable <- seq(income_min, income_max, by = custom_step)
################################################################################ variables ####
income_gross =income_taxable #from shiny app
## find marginal tax rate
tax_marginal_rate <<- tax_threshold_data %>%
filter(year == yr
, residency_dummy == resident_status
, threshold < income_gross) %>%
pull(rate) %>%
max()
resident_status = 0
## find marginal tax rate
tax_marginal_rate <<- tax_threshold_data %>%
filter(year == yr
, residency_dummy == resident_status
, threshold < income_gross) %>%
pull(rate) %>%
max()
income_gross <- 112000
yr <- year(Sys.Date())
resident_status <- 0
## find marginal tax rate
tax_marginal_rate <<- tax_threshold_data %>%
filter(year == yr
, residency_dummy == resident_status
, threshold < income_gross) %>%
pull(rate) %>%
max()
tax_marginal_rate
### filter super rate data
tmp <- super_rate_data %>%
filter(year == yr)
##### pass remaining optional arguments
if (is.null(super_rate_employer)) {super_rate_employer <- tmp$super_guarantee}
super_rate_employer = NULL
super_cont_vol = NULL
super_cont_last5 = NULL
super_balance = NULL
##### pass remaining optional arguments
if (is.null(super_rate_employer)) {super_rate_employer <- tmp$super_guarantee}
if (is.null(super_cont_vol)) {super_cont_vol <- tmp$default_vol_cont}
## assumes contribution for last 5y at current employer rate using 80% of current gross income
if (is.null(super_cont_last5)) {super_cont_last5 <- income_gross*super_rate_employer*5*0.8}
if (is.null(super_balance)) {super_balance <- tmp$default_super_balance}
super_guarantee <<- tmp$super_guarantee
super_guarantee
income_gross
super_rate_employer
#calculate gross super contributions and reportable super contributions and income for hecs and mls purposes
super_contributions_employer <<- income_gross*super_rate_employer
super_contributions_total <<- super_contributions_employer + super_cont_vol
super_contributions_rep <<- min(super_contributions_employer - income_gross*super_guarantee + super_cont_vol, tmp$cap_annual)
income_hecs_mls <<- income_gross + super_contributions_rep
income_gross_incl_super <<- income_gross*(1+super_rate_employer)
# calculate concessional and non-concessional super contributions
super_concessional_carry_limit <<- super_rate_data %>%
filter(year < yr, year >= yr-5) %>%
summarise(sum(cap_annual)) %>%
pull()
concessional_cap <<- tmp$cap_annual + max(0, super_concessional_carry_limit - super_cont_last5)
super_contributions_concessional <<- min(super_contributions_total, concessional_cap)
super_contributions_excess <<- max(0, super_contributions_total - concessional_cap)
if(income_gross <= tmp$listo_cap_income) {
super_listo_refund <<- max(10, min(super_contributions_concessional*tmp$listo_rate, tmp$listo_cap_refund))
} else {
super_listo_refund <<- 0
}
super_contrubtions_tax <<- super_contributions_concessional*tmp$rate +
super_contributions_excess*tax_marginal_rate -
super_listo_refund
super_contrubtions_net <<- super_contributions_total - super_contrubtions_tax
super_contrubtions_net
runApp()
super_contributions_total
super_contrubtions_tax
super_contributions_employer
## find marginal tax rate
tax_marginal_rate <<- tax_threshold_data %>%
filter(year == yr
, residency_dummy == resident_status
, threshold < income_gross) %>%
pull(rate) %>%
max()
### filter super rate data
tmp <- super_rate_data %>%
filter(year == yr)
##### pass remaining optional arguments
if (is.null(super_rate_employer)) {super_rate_employer <- tmp$super_guarantee}
if (is.null(super_cont_vol)) {super_cont_vol <- tmp$default_vol_cont}
## assumes contribution for last 5y at current employer rate using 80% of current gross income
if (is.null(super_cont_last5)) {super_cont_last5 <- income_gross*super_rate_employer*5*0.8}
if (is.null(super_balance)) {super_balance <- tmp$default_super_balance}
super_guarantee <<- tmp$super_guarantee
income_gross
super_rate_employer
super_contributions_employer
super_contributions_employer
income_gross
super_rate_employer
super_cont_vol
super_contributions_employer
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
library(here)
[A caption that is just the right length.](here::here("example.png"))
library(here)
![A caption that is just the right length.](here::here("example.png"))
# library(here)
# ![A caption that is just the right length.](here::here("example.png"))
library(here)
![Alt Text](here::here("example.png"))
# library(here)
# ![A caption that is just the right length.](here::here("example.png"))
library(here)
![Alt Text](here::here("example.png"))
# library(here)
# ![A caption that is just the right length.](here::here("example.png"))
library(here)
library(knitr)
knitr::include_graphics(here("example.png"))
#![Alt Text](here("example.png"))
runApp()