Excel related R packages
////////////////////////////

loc<-"http://cran.us.r-project.org"
x<-available.packages(repos=loc)
df<-data.frame(x)
> grep("EXCEL",toupper(df$Package))
[1] 5237 5238 5239 5240

df[grep("EXCEL",toupper(df$Package)),1]
[1] "excel.link"     "exceldata"   "ExcelFunctionsR" "excelR"     

////////////////////////////

download.file() function 
////////////////////////////////////////////////

infile<-"http://datayyy.com/data_excel/ibmDaily.xlsx"
outfile<-"a.xlsx"


# test the difference between the following two lines. 

download.file(infile,outfile)

download.file(infile,outfile,mode="wb")

////////////////////////////////////////////////

read.xlsx
////////////////////////////

library(openxlsx)
infile<-"https://github.com/awalker89/openxlsx/raw/master/inst/readTest.xlsx"
df<-read.xlsx(infile)

typeof(df) # [1] "list"
class(x)   # [1] "data.frame"

> head(df)
   Var1 Var2 Var3 Var4  Var5         Var6 Var7
1  TRUE    1 1.00    a 42042 3209324 This   NA
2  TRUE   NA   NA    b 42041         <NA>   NA
3  TRUE    2 1.34    c 42040         <NA>   NA
4 FALSE    2   NA <NA>    NA         <NA>   NA
5 FALSE    3 1.56    e    NA         <NA>   NA
6 FALSE    1 1.70    f 42037         <NA>   NA

> dim(df)
[1] 10  7

////////////////////////////

Structure of read.xlsx() function
////////////////////////////

read.xlsx(
  xlsxFile,
  sheet,
  startRow = 1,
  colNames = TRUE,
  rowNames = FALSE,
  detectDates = FALSE,
  skipEmptyRows = TRUE,
  skipEmptyCols = TRUE,
  rows = NULL,
  cols = NULL,
  check.names = FALSE,
  sep.names = ".",
  namedRegion = NULL,
  na.strings = "NA",
  fillMergedCells = FALSE
)

////////////////////////////

Method #2 to calculate VaR (ranking)
///////////////////////////

Step 1: calculate returns

Step 2: sort all return from the lowest to highest

Step 3: n = # of returns

Step 4: VaR will be

           VaR = ret(k) *Position 

   k = as.integer(n *significanceLevel)
///////////////////////////

Formula to estimate Chi square 
///////////////////////////
Assume that we have three frequency columns

  #     ourFrequency  theoryFreq
  1      f1           t1
  2      f2           t2
  3      f3           t3

 ...      ...         ...

  n      fn           tn


  Step 1: estimate the squared percentage deviation 
           [(f1-t1)/t1]^2
  Step 2: chi square = summation of above 
          squared percentage deviation 
///////////////////////////