Skip to content

Commit

Permalink
Merge pull request #64 from miraisolutions/develop
Browse files Browse the repository at this point in the history
1.0.1 release
  • Loading branch information
RolandASc authored Dec 28, 2018
2 parents 869a082 + 14993ca commit 2ac3096
Show file tree
Hide file tree
Showing 18 changed files with 69 additions and 65 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
Dockerfile
cloudbuild.yaml
man-roxygen
inst/application/data/taxdata
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: SmaRP
Title: SmaRP: Smart Retirement Planning
Version: 1.0.0
Version: 1.0.1
Authors@R: c(person("Gabriel", "Foix", role = c("aut", "cre"),
email = "[email protected]"),
person("Francesca", "Vitalini", role = c("aut"),
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# SmaRP 1.0.1

## Patch release

* Report spell check (#49)
* Documentation reviewed (#59)
* Fixed tooltip automatic disappearing (#54)

# SmaRP 1.0.0

## First versioned release of SmaRP
Expand Down
10 changes: 5 additions & 5 deletions R/TaxBenefit.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' * PLZGemeinden (includes Kirchensteuer)
#' * taxburden.list
#' * BundessteueTabelle
#' * BVGcontriburionratesPath, BVGcontriburionrates
#' * BVGcontributionratesPath, BVGcontributionrates
#' * MaxBVG, MinBVG
#' * KinderabzugKG
#' * NBU, maxNBU
Expand Down Expand Up @@ -77,9 +77,9 @@ getTaxAmount <- function(Income,
# Calc adjustIncomeKG
# 1. Age adjustment because of BVG contributions
# Tax burden based on the Pensionkassebeitrage from the examples (5%). Therefore, an adjustment factor is applied accordingly.
AjustBVGContri <- BVGcontriburionratesPath %>%
AjustBVGContri <- BVGcontributionratesPath %>%
filter(years == Age) %>%
transmute(AjustBVGContri = (0.05 - BVGcontriburionrates) * (min(Income, MaxBVG) - MinBVG))
transmute(AjustBVGContri = (0.05 - BVGcontributionrates) * (min(Income, MaxBVG) - MinBVG))

# 2. NChildren ajustment (only for VMK and DOPMK)
# Tax burden based on 2 kids. Therefore, an adjustment factor is applied accordingly.
Expand All @@ -104,11 +104,11 @@ getTaxAmount <- function(Income,
}

# Get Taxable Federal Income
TaxableIncomeFederal <- BVGcontriburionratesPath %>%
TaxableIncomeFederal <- BVGcontributionratesPath %>%
filter(years == Age) %>%
mutate(
DO = ifelse(Tarif == "DOPMK", DOV, 0),
BVG = DOfactor * (BVGcontriburionrates * (min(Income, MaxBVG) - MinBVG)),
BVG = DOfactor * (BVGcontributionrates * (min(Income, MaxBVG) - MinBVG)),
AHL = Income * AHL,
ALV = min(DOfactor * maxALV, Income * ALV),
NBU = min(DOfactor * maxNBU, Income * NBU),
Expand Down
11 changes: 11 additions & 0 deletions R/aaa.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
utils::globalVariables(
c("AHL", "ALV", "AgePath", "BVG", "BVGMindestzinssatz", "BVGcontributionrates",
"BVGcontributionratesPath", "BVGpurchase", "Beruf", "BerufsauslagenMax",
"BerufsauslagenMin", "BerufsauslagenTarif", "BundessteueTabelle", "DO", "DOV",
"DirectP3", "ExpectedSalaryPath", "Gemeindenummer", "Kids", "Kinder", "KinderabzugKG",
"Kirchensteuer", "MaxBVG", "MaxContrTax", "MinBVG", "NBU", "NetSalary",
"P3ContributionPath", "PLZ", "PLZGemeinden", "TaxBenefits", "TaxableIncome",
"TotalContr", "TotalP3", "TotalTax", "VM", "Verheiratet", "Versicherung",
"VersicherungsK", "VersicherungsL", "VersicherungsV", "calendar", "h4", "icon", "maxALV",
"maxNBU", "modalDialog", "removeModal", "showModal", "taxburden.list")
)
12 changes: 8 additions & 4 deletions R/core.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ getRetirementCalendar <- function(birthday, givenday = today("UTC"), RetirementA
#' @inheritParams buildt
#' @template salary
#' @template P2
#' @param CurrentP2 Value of the current assets in the Occupational Pension Fund.
#' @param rate Interests rate on annual basis. Constant interest rates are assumed.
#'
#' @return All contributions to the Pillar II in annual basis.
#'
Expand Down Expand Up @@ -143,23 +145,23 @@ buildContributionP2Path <- function(birthday,
RetirementAge) {

# build BVG rates from global input
BVGRatesPath <- BVGcontriburionratesPath %>%
BVGRatesPath <- BVGcontributionratesPath %>%
filter(years <= RetirementAge)

# calc contributions P2 Path
ContributionP2Path <- data.frame(calendar = getRetirementCalendar(birthday, givenday, RetirementAge = RetirementAge)) %>%
mutate(AgePath = sapply(calendar, calcAge, birthday = birthday) %>%
as.integer()) %>%
left_join(BVGRatesPath, by = c("AgePath" = "years")) %>%
mutate(BVGcontriburionrates = if_else(is.na(BVGcontriburionrates), 0, BVGcontriburionrates))
mutate(BVGcontributionrates = if_else(is.na(BVGcontributionrates), 0, BVGcontributionrates))

ncp <- nrow(ContributionP2Path)
isPurchase <- c(0, rep(1, ncp - 1))

ContributionP2Path %<>% within({
ExpectedSalaryPath <- calcExpectedSalaryPath(Salary, SalaryGrowthRate, ncp)
BVGpurchase <- calcBVGpurchase(TypePurchase, P2purchase, ncp)
BVGContributions <- if_else(is.na(BVGpurchase + (max(0, ExpectedSalaryPath - MinBVG) * BVGcontriburionrates)), 0, BVGpurchase + (max(0, ExpectedSalaryPath - MinBVG) * BVGcontriburionrates * isPurchase))
BVGContributions <- if_else(is.na(BVGpurchase + (max(0, ExpectedSalaryPath - MinBVG) * BVGcontributionrates)), 0, BVGpurchase + (max(0, ExpectedSalaryPath - MinBVG) * BVGcontributionrates * isPurchase))
BVGDirect <- BVGContributions + c(CurrentP2, rep(0, ncp - 1))
t <- buildt(birthday, givenday, RetirementAge = RetirementAge)
TotalP2 <- calcAnnuityAcumPath(BVGDirect, t, rate)
Expand All @@ -177,6 +179,7 @@ buildContributionP2Path <- function(birthday,
#' @description Calculate whether the salary will increase/decrease and by how much.
#'
#' @template salary
#' @param ncp Length contribution path to retirement.
#'
#' @return Expected salary path.
#' @examples
Expand Down Expand Up @@ -223,6 +226,7 @@ calcBVGpurchase <- function(TypePurchase, P2purchase, ncp) {
#' @inheritParams buildt
#' @inheritParams calcExpectedSalaryPath
#' @template P3
#' @param CurrentP3 Value of the current assets in the Private Pension Fund (Pillar 3).
#'
#' @return All contributions to the Pillar III in annual basis.
#' @examples
Expand Down Expand Up @@ -274,7 +278,7 @@ buildContributionP3path <- function(birthday,
#' @param t Vector of time intervals between contributions.
#' * Irregular time intervals are allowed.
#' * For frequency bellow annual, enter t as proportion of a year.
#' @template P2
#' @param rate Interests rate on annual basis. Constant interest rates are assumed.
#'
#' @return Vector of accumulated benefits given a set of contributions.
#' @examples
Expand Down
24 changes: 12 additions & 12 deletions inst/application/global.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ BVGMindestzinssatz <- 0.01
MaxContrTax <- 6768

# https://www.admin.ch/opc/de/classified-compilation/19820152/index.html
BVGcontriburionrates <- data.frame(
BVGcontributionrates <- data.frame(
lowerbound = c(18, 25, 35, 45, 55),
upperbound = c(24, 34, 44, 54, 70),
BVGcontriburionrates = c(0.00, 0.07, 0.10, 0.15, 0.18)
BVGcontributionrates = c(0.00, 0.07, 0.10, 0.15, 0.18)
)
# BVGcontriburionrates path
BVGcontriburionratesPath <- data.frame(
years = seq(BVGcontriburionrates$lowerbound[1], BVGcontriburionrates$upperbound[nrow(BVGcontriburionrates)]),
BVGcontriburionrates = rep(BVGcontriburionrates$BVGcontriburionrates,
times = BVGcontriburionrates$upperbound - BVGcontriburionrates$lowerbound + 1
# BVGcontributionrates path
BVGcontributionratesPath <- data.frame(
years = seq(BVGcontributionrates$lowerbound[1], BVGcontributionrates$upperbound[nrow(BVGcontributionrates)]),
BVGcontributionrates = rep(BVGcontributionrates$BVGcontributionrates,
times = BVGcontributionrates$upperbound - BVGcontributionrates$lowerbound + 1
)
)

Expand All @@ -42,13 +42,13 @@ Rate_group.list <- list(
)

church_tax.list <- list(
"Church Affilitation" = "A",
"No Church Affilitation" = "B"
"Yes" = "A",
"None" = "B"
)

Purchase.list <- list(
"Single Purchase" = "SingleP2",
"Annual Purchase" = "AnnualP2"
"Single" = "SingleP2",
"Annual" = "AnnualP2"
)

# PLZGemeinden <- readRDS("inst/application/data/PLZGemeinden.rds")
Expand All @@ -57,7 +57,7 @@ PLZGemeinden$PLZGDENAME <- with(PLZGemeinden, paste(PLZ, GDENAME))
kantons <- unique(PLZGemeinden$Kanton)

# BundessteueTabelle <- readRDS("inst/application/data/BundessteueTabelle.rds")
# taxburden.list <- readRDS("inst/application/data/taxburden.list.rds")
# taxburden_2016.list <- readRDS("inst/application/data/taxburden.list.rds")
BundessteueTabelle <- readRDS(system.file("application", "data", "BundessteueTabelle.rds", package = "SmaRP"))
taxburden.list <- readRDS(system.file("application", "data", "taxburden.list.rds", package = "SmaRP"))

Expand Down
6 changes: 3 additions & 3 deletions inst/application/report.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ It is implemented as an [R Shiny](https://shiny.rstudio.com/) pension calculator

```{r deduction_percentage, echo = FALSE}
Road2Retirement_to_print <- params$Road2Retirement %>%
select(calendar, ExpectedSalaryPath, BVGcontriburionrates, BVGContributions, BVGpurchase, DirectP2, ReturnP2, TotalP2, P3ContributionPath, P3purchase, DirectP3, ReturnP3, TotalP3, DirectTax, ReturnTax, TotalTax, Total) %>%
select(calendar, ExpectedSalaryPath, BVGcontributionrates, BVGContributions, BVGpurchase, DirectP2, ReturnP2, TotalP2, P3ContributionPath, P3purchase, DirectP3, ReturnP3, TotalP3, DirectTax, ReturnTax, TotalTax, Total) %>%
rename(P2ContributionPath = BVGContributions) %>%
rename(P2contriburionrates = BVGcontriburionrates) %>%
rename(P2contriburionrates = BVGcontributionrates) %>%
rename(P2purchase = BVGpurchase) %>%
mutate(Y = year(calendar)/5)%>%
filter(Y %in% unique(c(Y[1], Y[!Y%%1], Y[length(Y)])) )
Expand Down Expand Up @@ -305,7 +305,7 @@ Retirement age can be either explicitly provided as an input or inferred from th

# Bibliography

Der Bundesratdas Portal Der Schweizer RegierungP
Der Bundesratdas Portal Der Schweizer Regierung
Bundeskanzlei P - \url{https://www.admin.ch/opc/de/classified-compilation/19820152/index.html}

Der Bundesrat - \url{https://www.admin.ch/gov/de/start/dokumentation/medienmitteilungen.msg-id-62487.html}
Expand Down
18 changes: 9 additions & 9 deletions inst/application/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ fluidPage(
6,
checkboxInput(
"provideRetirementAge",
"Desired Retirement Age (optional)",
span("Desired Retirement Age (optional)") %>%
bs_embed_tooltip(title = IB$RetirementAgeOptional, placement = "right"),
FALSE
) %>%
bs_embed_tooltip(title = IB$RetirementAgeOptional, placement = "right")
)
),
column(
6,
Expand Down Expand Up @@ -129,12 +129,12 @@ fluidPage(
column(
6,
radioButtons("rate_group",
label = "Marital Status",
label = span("Marital Status") %>%
bs_embed_tooltip(title = IB$rate_group, placement = "right"),
inline = TRUE,
choices = Rate_group.list,
selected = "A"
) %>%
bs_embed_tooltip(title = IB$rate_group, placement = "right")
)
),
column(
6,
Expand Down Expand Up @@ -230,11 +230,11 @@ fluidPage(
column(
6,
radioButtons("TypePurchase",
label = br(), # empty placeholder for alignment
label = span("Purchase Type") %>%
bs_embed_tooltip(title = IB$TypePurchase, placement = "right"),
inline = TRUE,
choices = Purchase.list
) %>%
bs_embed_tooltip(title = IB$TypePurchase, placement = "right")
)
)
) # end fluidRow
) # end boxPlus
Expand Down
2 changes: 0 additions & 2 deletions man-roxygen/P2.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
#' @param CurrentP2 Value of the current assets in the Occupational Pension Fund.
#' @param P2purchase Annual voluntary contribution to the Occupational Pension Fund.
#' @param TypePurchase AnnualP2 if the purchase on the pillar II gets repeated every year until retirement.
#' @param rate Interests rate on annual basis. Constant interest rates are assumed.
1 change: 0 additions & 1 deletion man-roxygen/P3.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#' @param P3purchase Annual voluntary contribution to the Private Pension Fund (Pillar 3).
#' @param CurrentP3 Value of the current assets in the Private Pension Fund (Pillar 3).
#' @param returnP3 Annual expected return on the Private Pension Fund.
5 changes: 2 additions & 3 deletions man-roxygen/salary.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#' @param Salary Stipend
#' @param SalaryGrowthRate Rate at which the salary increases/decreases
#' @param ncp Length contribution path to retirement
#' @param Salary Stipend.
#' @param SalaryGrowthRate Rate at which the salary increases/decreases.
6 changes: 2 additions & 4 deletions man/buildContributionP2Path.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 2 additions & 10 deletions man/buildTaxBenefits.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions man/calcAnnuityAcumPath.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/calcBVGpurchase.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/calcExpectedSalaryPath.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/getTaxAmount.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2ac3096

Please sign in to comment.