Skip to content

Commit

Permalink
Merge pull request #135 from miraisolutions/develop
Browse files Browse the repository at this point in the history
1.2.0 release
  • Loading branch information
nfarabullini authored Jun 13, 2019
2 parents 75b6fc9 + fa73f99 commit a4e3e4c
Show file tree
Hide file tree
Showing 29 changed files with 319 additions and 241 deletions.
13 changes: 7 additions & 6 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
^Meta$
^data$
^doc$
^man-roxygen$
^Meta$

^.*\.Rproj$
^\.Rproj\.user$

Dockerfile
cloudbuild.yaml
man-roxygen
inst/application/data/taxdata
^Dockerfile$
^cloudbuild\.yaml$
^inst/application/data/taxdata$
5 changes: 4 additions & 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.1.1
Version: 1.2.0
Authors@R: c(person("Gabriel", "Foix", role = c("aut", "cre"),
email = "[email protected]"),
person("Francesca", "Vitalini", role = c("aut"),
Expand All @@ -14,6 +14,9 @@ Authors@R: c(person("Gabriel", "Foix", role = c("aut", "cre"),
Description: Shiny App to calculate total pension fund.
Depends: R (>= 3.5.0)
License: GPL-3
URL: https://mirai-solutions.ch,
https://github.com/miraisolutions/SmaRP#readme
BugReports: https://github.com/miraisolutions/SmaRP/issues
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export(makeTable)
export(need_not_zero)
export(printCurrency)
export(returnPLZKanton)
export(update_neg)
export(withModalSpinner)
import(dplyr)
importFrom(dplyr,'%>%')
Expand Down
21 changes: 21 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
# SmaRP 1.2.0

### Changes

* The naming of pension funds was reviewed and aligned, and now reflects the official terminology (#103).
* The 3rd Pillar annual contribution in the app is now initialized with a non-zero value (#129).
* Negative input values are now re-set to zero, and maximum allowed values were consolidated (#129).
* `launch_application()` exposes the `launch.browser` argument of `shiny::runApp()` (#108).
* Minor updates to package vignettes (#101).

### Fixes

* Missing page title in the app (#118).
* Missing automatic cleanup of data created via configure (#119).
* App header background image re-centering upon page resize (#123).

### Maintenance

* Included `URL` and `BugReports` in DESCRIPTION file (#125).
* Updated `install_github()` README instructions due to un-supported `build_vignettes` argument (#120).

# SmaRP 1.1.1

### Fixes
Expand Down
6 changes: 3 additions & 3 deletions R/TaxBenefit.R
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ lookupTaxAmount <- function(Income, Tabelle, CivilStatus) {
#'
#' @import dplyr
#'
#' @return data.frame tax benefit path.
#' @return data.frame tax benefits path.
#' @examples
#' \dontrun{buildTaxBenefits(
#' birthday,
Expand Down Expand Up @@ -236,7 +236,7 @@ buildTaxBenefits <- function(birthday,
#'
#' @rdname calcTaxBenefitSwiss
#'
#' @description Calculates the tax benefit as a difference of the taxes paid with and without retirement contributions.
#' @description Calculates the tax benefits as a difference of the taxes paid with and without retirement contributions.
#' Calls 'getTaxAmount()', therefore, it assumes objects in the global environment.
#' @seealso [getTaxAmount()]
#' @seealso swisstax
Expand All @@ -245,7 +245,7 @@ buildTaxBenefits <- function(birthday,
#' @param TaxableIncome Vector of annual taxable income until retirement.
#' @inheritParams getTaxAmount
#'
#' @return Single tax benefit (tax relief) of one contribution.
#' @return Single tax benefits (tax relief) of one contribution.
#' @examples
#' \dontrun{
#' calcTaxBenefitSwiss(ExpectedSalaryPath = seq(90000, 100000, 1000),
Expand Down
33 changes: 26 additions & 7 deletions R/core.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ getRetirementCalendar <- function(birthday, givenday = today("UTC"), RetirementA
#'
#' @rdname buildContributionP2Path
#'
#' @description Gather all the required information to project the annual contributions to the occupational pension fund.
#' @description Gather all the required information to project the annual contributions to the occupational fund.
#'
#' @inheritParams buildt
#' @template salary
#' @template P2
#' @param CurrentP2 Value of the current assets in the Occupational Pension Fund.
#' @param CurrentP2 Value of the current assets in the Occupational Fund.
#' @param rate Interests rate on annual basis. Constant interest rates are assumed.
#'
#' @return All contributions to the Pillar II in annual basis.
#' @return All contributions to the 2nd Pillar on an annual basis.
#'
#' @examples
#' \dontrun{
Expand Down Expand Up @@ -197,7 +197,7 @@ calcExpectedSalaryPath <- function(Salary, SalaryGrowthRate, ncp) {
#'
#' @rdname calcBVGpurchase
#'
#' @description Calculate the path of purchases to the Pilar II (Occupational pension fund, BVG).
#' @description Calculate the path of purchases to the 2nd Pillar (Occupational fund, BVG).
#'
#' @inheritParams calcExpectedSalaryPath
#' @inheritParams buildContributionP2Path
Expand All @@ -220,15 +220,15 @@ calcBVGpurchase <- function(TypePurchase, P2purchase, ncp) {
#'
#' @rdname buildContributionP3path
#'
#' @description Build the contribution path for a standard pension fund, called Pillar III in Switzerland.
#' @description Build the contribution path for a standard pension fund, called 3rd Pillar in Switzerland.
#' Based on 'calcAnnuityAcumPath()'.
#'
#' @inheritParams buildt
#' @inheritParams calcExpectedSalaryPath
#' @template P3
#' @param CurrentP3 Value of the current assets in the Private Pension Fund (Pillar 3).
#' @param CurrentP3 Value of the current assets in the Private Fund (3rd Pillar).
#'
#' @return All contributions to the Pillar III in annual basis.
#' @return All contributions to the 3rd Pillar on an annual basis.
#' @examples
#' \dontrun{
#' buildContributionP3path(
Expand Down Expand Up @@ -434,6 +434,25 @@ need_not_zero <- function(input, inputname) {
}
}

#' @title update_neg
#'
#' @rdname update_neg
#'
#' @description Automatically updates numericInput to zero if input is negative.
#'
#' @param inputId Field name.
#' @param session Current session.
#'
#' @return Zero value.
#' @export
update_neg <- function(inputId, session) {
val <- 0
input <- session$input[[inputId]]
if (!is.na(input) && input < val) {
shiny::updateNumericInput(session, toString(inputId), value = val)
}
}


# Format Percentage ----

Expand Down
10 changes: 5 additions & 5 deletions R/launch_application.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#' @title launch_application
#'
#'
#' @rdname launch_application
#'
#' @description Launch the SmaRP Shiny wep app.
#'
#' @param ... Additional arguments passed on to [runApp()]. Note that
#' argument `launch.browser` is always passed as `TRUE`.
#' @inheritParams shiny::runApp
#' @param ... Additional arguments passed on to [runApp()].
#'
#' @return Side-effecting function. Launches the SmaRP app.
#'
Expand All @@ -15,10 +15,10 @@
#' }
#' @importFrom shiny runApp
#' @export
launch_application <- function(...) {
launch_application <- function(launch.browser = interactive(), ...) {
runApp(
appDir = system.file("application", package = "SmaRP"),
launch.browser = TRUE,
launch.browser = launch.browser,
...
)
}
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<!--# The Swiss social security system, considered as one of the most robust, is based on a three-pillar regime.
# The first Pillar, common to most developed countries, is a state-run pay-as-you-earn system with minimum benefits.
# The voluntary contribution (Pillar III) is a privately-run, tax-deductible insurance fund.
# At the heart of the Swiss system is the so-called Pillar II, a compulsory, tax-deductible company occupational pension insurance fund.
# Voluntary additional Pillar II buy-ins are regulated but allow for benefits improvement at retirement age while reducing the tax burden during the working career.
# The voluntary contribution (3rd Pillar) is a privately-run, tax-deductible insurance fund.
# At the heart of the Swiss system is the so-called Second Pillar, a compulsory, tax-deductible company occupational pension insurance fund.
# Voluntary additional second Pillar buy-ins are regulated but allow for benefits improvement at retirement age while reducing the tax burden during the working career.
# The complexity is further increased by a municipality-dependent taxation.
# Altogether this calls for an early-stage conscious approach towards retirement planning.
# However, it is not straight-forward to assess effects of elements such as early retirement, moving to a different canton or applying a different voluntary pension schema.
Expand Down Expand Up @@ -32,8 +32,9 @@ containers](https://www.docker.com/resources/what-container)) and can be
accessed at https://mirai-solutions.ch/apps/smarp/.

The (development version of) **SmaRP** can also be served locally by installing the package from GitHub
<!-- argument build_vignettes not available anymore (r-lib/remotes#353), build_opts = "" for a full installation including vignettes -->
``` r
devtools::install_github("miraisolutions/SmaRP", build_vignettes = TRUE)
devtools::install_github("miraisolutions/SmaRP", build_opts = "")
```
and running
``` r
Expand All @@ -43,11 +44,11 @@ SmaRP::launch_application()

## Details and key features

The evolution of the total retirement fund over time is computed by projecting the value of the occupational pension fund (Pillar II), the private pension fund (Pillar III) and the tax relief, thus deriving their contributions at the desired retirement age.
The evolution of the total retirement fund over time is computed by projecting the value of the occupational fund (2nd Pillar), the private fund (3rd Pillar) and the tax relief, thus deriving their contributions at the desired retirement age.

*Contributions to Pillar II* are calculated from the salary and any additional voluntary purchases.
*Contributions to the second Pillar* are calculated from the salary and any additional voluntary purchases.

*Contributions to Pillar III* are fully voluntary and repeated every year until retirement.
*Contributions to the third Pillar* are fully voluntary and repeated every year until retirement.

*Tax savings* are built as an additional fund where tax relieves from a certain year are used as contributions for the next. Tax relieves are calculated using an approximation of the given gross salary and other factors including: residence, civil status, number on kids, etc.

Expand All @@ -64,8 +65,8 @@ The evolution of the total retirement fund over time is computed by projecting t
- Constant interest rates are assumed throughout the working life.
- Inflation is not taken into account, although it can be proxied using the salary growth rate input.
- The retirement plan is valid for employees only, i.e. persons whose main income is a salary. Self-employed people do not belong to this category.
- The publicly managed pay-as-you-go system (Pillar I) is not considered.
- All generated tax benefits are 100% reinvested as an additional fund, interpreting the same return as the private pension fund.
- The publicly managed pay-as-you-go system (1st Pillar) is not considered.
- All generated tax benefits are 100% reinvested as an additional fund, interpreting the same return as the private fund.
- In case of married couples with double income, the combined amount of all variables should be entered and a 50% income distribution is assumed.


Expand Down Expand Up @@ -97,6 +98,6 @@ Legal parameters in **SmaRP** are defined in [SmaRP/inst/application/global.R](h

While **SmaRP** was developed under the utmost care and diligence, Mirai Solutions does not guarantee for its accuracy and correctness. In addition, **SmaRP** is based on assumptions and projections (explained in a section above and in the PDF report) and as such computed figures should be understood as general references and do not hold any legal value.

Besides standard unit tests at the functional level, results from the **SmaRP** web app have been checked against other online free sources for Pillar II and III and tax calculators.
Besides standard unit tests at the functional level, results from the **SmaRP** web app have been checked against other online free sources for second, third Pillars and tax calculators.

To keep testing and improving **SmaRP**, we encourage users to get back to us! Your feedback is always highly appreciated. You can use the issue tracker on GitHub to suggest enhancements or report problems, and reach out via email at [email protected] for any questions and comments.
27 changes: 24 additions & 3 deletions inst/application/global.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ library(SmaRP)
`%>%` <- magrittr::`%>%`

# Global variables
# Gender-based retirement age
MRetirementAge <- 65
FRetirementAge <- 64

# https://www.admin.ch/opc/de/classified-compilation/19820152/index.html#a8
MinBVG <- 24885 # Min Koordinierter Lohn (MinBVG = MaxAHV * (7 / 8))
Expand Down Expand Up @@ -105,3 +102,27 @@ BerufsauslagenMax <- 4000
BerufsauslagenMin <- 2000
NBU <- 0.0084
maxNBU <- 1065

# List of initial, max and min values
value <- list (
birthday = "1980-12-30",
gender = "M",
min_retirement = 55,
max_retirement = 70,
retirement_female = 64,
retirement_male = 65,
plz = with(PLZGemeinden, PLZGDENAME[match(8001, PLZ)]),
rate = "A",
min_children = 0,
max_children = 9,
church = "A",
salary = 100000,
max_salary = 1e+08,
growth_rate = 0.5,
p2 = 100000,
min_p2_interest = 100 * BVGMindestzinssatz,
p2_voluntary = 0,
p3 = 50000,
p3_annual = 5000,
p3_return = 100 * BVGMindestzinssatz
)
Loading

0 comments on commit a4e3e4c

Please sign in to comment.