library(QlikQonnections2016)
library(dplyr)
library(knitr)
library(sqldf)
library(MARSS)
library(ggplot2)
library(foreach)
library(doParallel)

Personal info:


The Norwegian Government Public Pension Fund (SPK)



The Premium Process for Retirement Pension at SPK



Three strategies for implementing Qlik and R for the Premium Process:


Strategi I: The non-integrated R and Qlik approach approach

# This script provides the datainput to Qlik for application #1
startp <- c(2007,1)
sluttp <- c(2016,2)
sluttpro <- c(2016,12)
#modelltype <- c(1)
variabler <- c(1,2)[1]
modelltype <- c(1,2)[1:2]  #[1:2]
customers <- seq(1,15)[1:15] #[1:15]

tidseriedatadf <- sqldf::read.csv.sql("data/PGlonnaggps.rda",sql = "SELECT * FROM PGlonnaggps") %>% dplyr::filter(avtalenr%in%customers)  %>% dplyr::select(observasjonsdato,avtalenr,aar,maaned,premiestatus,nobs,pensjonslonn,antallStillinger)

tidseriedata <- as.list(tidseriedatadf)
custforecast <- prognoseestimeringb(startp,sluttp,sluttpro,tidseriedata,modelltype,variabler)

colnames(custforecast) <- rep(c("customer","year","month","wagelevel (pension)","wageforcasting","wageforcastingvariance","model"),length(modelltype))

#Storing results
## from estimation
devtools::use_data(custforecast,overwrite = TRUE)
write.csv(custforecast, file = "data/custforecast.csv")

Qlik Sense application 1

alt text

Demo I will be shown here


Main comments:

$$\text{Combinations before}= 111200 = 1200 $$ $$\text{Combinations now} = 321200 = 7200 $$


Strategi II: The integrated R and Qlik approach (desktop)

alt text alt text alt text alt text

# This script provides the datainput to Qlik for application #2 (works only on Linux operating system)
## Settings
aaa <- 1                 # customer number
mmm <- 2                 # model number
startp <- c(2007,1)             
sluttp <- c(2016,2)             
sluttpro <- c(2016,12)          
## Finding data
tidseriedatadf <- sqldf::read.csv.sql("data/PGlonnaggps.rda",sql = "SELECT * FROM PGlonnaggps") %>% dplyr::filter(avtalenr==aaa)  %>% dplyr::select(observasjonsdato,avtalenr,aar,maaned,premiestatus,nobs,pensjonslonn,antallStillinger)

tidseriedata <- as.list(tidseriedatadf)
este <- enkeltavtestimeringb(tidseriedata,aaa,mmm,startp,sluttp,sluttpro)
estenkavtmodell <- cbind(este,mmm) 
colnames(estenkavtmodell) <- c("customer","year","month","wagelevel (pension)","wageforcasting","wageforcastingvariance","modelchoice")

estenkavtmodtable <- data.frame(estenkavtmodell) %>% left_join(premtable,by=c("customer"="avtale"))

## One customer estimation
esttableforec <- enkeltavtestimeringb(tidseriedata,aaa,mmm,startp,sluttp,sluttpro)
## One customer plot
estplot <- plotenkeltavtestimering(tidseriedata,aaa,mmm,startp,sluttp,sluttpro)
## One customer html-table
esttablepaym <- custtabpayhtml(tidseriedata,aaa,mmm,startp,sluttp,sluttpro)
estplotq <- plotenkeltavtestimering2(esttableforec,2)
esttabq <- custtabpayhtml2(esttableforec,2)

Qlik Sense application 2

alt text

Demo II will be shown here


Main comments:


Strategi III: The streamlined and integrated R and Qlik approach (server and the use of numascale)

alt text alt text alt text alt text

# This script provides the datainput to Qlik for application #3 (works only on Linux operating system)
startp <- c(2007,1)
sluttp <- c(2016,2)
sluttpro <- c(2016,12)
#modelltype <- c(1)
variabler <- c(1,2)[1]
modelltype <- c(1,2)[1:2]  #[1:2]
customers <-seq(1,15)[1:3]

tidseriedatadf <- sqldf::read.csv.sql("data/PGlonnaggps.rda",sql = "SELECT * FROM PGlonnaggps") %>% dplyr::filter(avtalenr%in%customers)  %>% dplyr::select(observasjonsdato,avtalenr,aar,maaned,premiestatus,nobs,pensjonslonn,antallStillinger)

## One customer estimation
tidseriedata <- as.list(tidseriedatadf)

custforecast <- prognoseestimering(startp,sluttp,sluttpro,tidseriedata,modelltype,variabler)
colnames(custforecast) <- rep(c("customer","year","month","wagelevel (pension)","wageforcasting","wageforcastingvariance","model"))

prempaytable <- data.frame(custforecast) %>% dplyr::filter(year==2016,month==12) %>% dplyr::select(customer,wageforcasting,model) %>%
  left_join(premtable,by=c("customer"="avtale"))

Qlik Sense application 3

Demo III will be shown here


Results from speedtesting:




Main comments:


Concluding remarks

alt text https://github.com/joernih/QlikQonnections2016Public

Appendix

<<<<<<< HEAD

MARSS model is written as follows

$$ x_{t} = B_{t}x_{t-1} + u_{t} + C_{t}c_{t} + w_{t} \text{ where } w_{t} \sim MVN(0,\textbf{Q}{t}) \ y{t} = Z_{t}x_{t} + a_{t} + D_{t}d_{t} + v_{t}, \text{ where } v_{t} \sim MVN(0,\textbf{R}{t}) \ x{1} \sim MVN(\pi,\Lambda) \text{ and } x_{0} \sim MVN(\pi,\Lambda) $$

Model 1: trend-growth model

$$ Y_t=T_{t}+C_{t}+v_{t} \ C_{t}=C_{t-1}+C_{t-2}+w_{3,t} $$

Model 2: trend-cycle model

$$ Y_t=T_{t}+C_{t}+v_{t} \ T_{t}=T_{t-1}+\beta_{t}+w_{1,t} \ \beta_{t}=\beta_{t-1}+w_{2,t} \ C_{t}=C_{t-1}+C_{t-2}+w_{3,t} $$





joernih/QlikQonnections2016Public documentation built on May 19, 2019, 3:01 p.m.