.explain2stepApproach<-function(){ " Objective: explain the so-called 2-step approach to convert APR to effective rate (APR) input : none Example :>.explainHedging() Note 1: the output is not shown here. Note 2: after the above command, just hit the Enter-key several times Note 3: If you don't get it first time, run it again. ";.explain2stepApproach_()} .oneLine<-function(){ cat("* ------------------------------------------------------------- *\n") } .hitEnter<-function(){ cat("Enter!") x<-readline() } .explain2stepApproach_<-function(){ .oneLine();.oneLine() cat("* Explain the 2-step to convert interest rate *"); .hitEnter(); .oneLine() cat("* Step 1: which effective rate is given? *"); .hitEnter() cat("* enter your APR and frequency, such as 0.1 2 *\n") x<-scan() APR<-x[1] m1<-x[2] cat("* Your inputs: APR=",APR,"m=",m1," *\n") if(m1==1){ word<-'annually' freq<-'annual' }else if(m1==2){ word<-'semi-annually' freq<-'semi-annual' }else if(m1==4){ word<-'quarterly' freq<-'quarterly' }else if(m1==12){ word<-'monthly' freq<-'monthly' }else{ stop("Compouding frequency is not correct\n") } cat('* Since compounded',word,',the effectiv ',freq, "*\n") cat("* rate is given and its value is ", APR/m1,"\n"); .oneLine() cat("* Step 2: from one effective rate to another effective rate *"); .hitEnter() cat("* enter 2nd compouding frequency, such as 1,2,4,12,356 *\n") m2<-scan() R<-(1+APR/m1)^(m1/m2)-1 cat("* your effective rate is ", R," *\n") .oneLine();.oneLine() }