Wednesday, March 28, 2012

Insurance Blog Superceded for Statistical/Econometric Computing!

There now exists the Statistical Computing Blog for everyone who comes here for statistics, econometrics ...etc.

For everyone else, this blog will continue with the theme of discussing insurance, life insurance for example.

Enjoy!

Friday, March 23, 2012

The Julia Language

The purpose of this post is to mention the Julia Language. It is a new language for technical computing. Its main strength is that it runs faster than R, MATLAB...etc. The code is compiled Just-In-Time. In the backend, amongst other things, it has LAPACK and ARPACK.

So check out http://julialang.org/

Wednesday, March 21, 2012

R Programming Syntax Reference To Get You Started Quickly So You Can Start Implementing Your Insurance Models, Probably Life Insurance

EDIT:This article has been re-written and updated in my analytics blog: R Programming Syntax Quickstart

If you have ANY programming experience in other languages, this guide will get you started in R very quickly and then you can start implementing your favourite insurance models. A special mention goes out to my friend who is currently working on a health insurance project.

Logic Operators

a == ba equals b
a != ba is not equal to b
a > ba is greater than b
a < ba is less than b
a >= ba is greater than OR equal to b
a <= ba is less than OR equal to b
(condition 1) & (condition 2)(condition 1) AND (condition 2)
(condition 1) | (condition 2)(condition 1) OR (condition 2)


Also, try the following to understand "&&" and "||":

> a<-c(1:10) > b<-a > c<-b > c[1:4]<-.5 > (a == b) && (a > c)
[1] TRUE
> (a == b) & (a > c)
[1] TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE
> (a == b) | (a > c)
[1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
> (a == b) || (a > c)
[1] TRUE


IF statements

The general example:

if( condition ) {

} else if( other condition ){

} else {

}


The specific example:

a<-55
if( a <= 54.9 ) {
   print("a is less than or equal to 54.9")
} else if( a == 55 ){
   print("a equals 55")
} else {
   print("a is greater than 54.9 and not 55")
}



For Loops

The general example:

for(variable in vector) {

}



Specific examples:

#example 1
for(i in 1:10) {
   print(i)
}

#example 2
index.vector<-c(4,3,7,5)
numberz<-runif(10)
print(numberz)

for(i in index.vector) {
   print(numberz[i])
}

#example 3
for(i in 1:10) {
   if(i == 3) {
      next
   } else if(i == 7) {
      break
   }
   print(i)
}

#example 4
mat<-matrix(0,3,4)
print(mat)

for(i in 1:3) {
   for(j in 1:4) {
      mat[i,j]<-rnorm(1)
   }
}



While Loops

General Example:

while(condition) {

}

Note that you must something write something within the while that will update at least one of the variables in the condition. Otherwise, you could have a perpetual loop.

Specific Example:

i<- -1
while( i < 10) {

    print(i)
    i<-i+1 
}

Repeat Loop

In a repeat loop, you not only explicitly update variables, you must also explicitly test the condition.
Specific Example:

i<- -1
repeat{
   print(i)
   i<-i+1
   if( i == 10) {
      break
   }
}


Functions

For example, you could have a function that evaluates an insurance contract pricing equation. A function could return the amount of excess that must be paid on an insurance claim. A function can call other functions.

General Example:

function_name<-function(parameters) {


   return(return_variable)
}


Specific Example:

calcQuadratic<-function(a, b, c, x) {
   y<-a*x*x+b*x+c
   return(y)
}

calcQuadratic(2,3,5,.07)

my.var<-calcQuadratic(3.32,7.6,5.999,3.2)
print(my.var)



Easy as purchasing life insurance without asking any questions that strain the mind of the sale person, right!? :-P Just not as pointless.