Purpose
Use Concordance and Discordance to check for any meaning correlation between NIFTY , Gold and Liquid

> start.date <- "2003-01-01"
> end.date <- "2009-08-28"
> library(corpcor)
> library(mnormt)
> library(fields)
> library(fPortfolio)
> library(fPortfolioBacktest)
> library(PerformanceAnalytics)
> library(xts)
> annualized.returns <- function(x) {
+     n <- length(x)
+     (x[n] - x[1])/x[1]
+ }
> nifty.data <- read.csv("C:/Cauldron/Benchmark/PMS/Product/MF/nifty_mar_12.csv",
+     stringsAsFactors = FALSE, header = T)
> nifty.data$trade.date <- as.Date(nifty.data$Date, format = "%d-%m-%Y")
> gold.data <- read.csv("C:/Cauldron/Benchmark/PMS/Product/MF/gold_mar_10.csv",
+     stringsAsFactors = FALSE, header = T)
> gold.data$trade.date <- as.Date(gold.data$Date, format = "%d-%m-%Y")
> liquid.data <- read.csv("C:/Cauldron/Benchmark/PMS/Product/MF/liquid_april_22.csv",
+     stringsAsFactors = FALSE, header = T)
> liquid.data$trade.date <- as.Date(liquid.data$Date, format = "%d-%m-%Y")
> nifty.data$nifty.100 <- as.numeric(nifty.data$nifty.100)
> gold.data$gold <- as.numeric(gold.data$gold)
> liquid.data$liquid <- as.numeric(liquid.data$liquid)
> nifty.ts <- as.timeSeries(nifty.data$nifty.100, timeDate(nifty.data$trade.date))
> rownames(nifty.ts) <- nifty.data$trade.date
> colnames(nifty.ts) <- "nifty.100"
> gold.ts <- as.timeSeries(gold.data$gold, timeDate(gold.data$trade.date))
> rownames(gold.ts) <- gold.data$trade.date
> colnames(gold.ts) <- "gold"
> liquid.ts <- as.timeSeries(liquid.data$liquid, timeDate(liquid.data$trade.date))
> rownames(liquid.ts) <- liquid.data$trade.date
> colnames(liquid.ts) <- "liquid"
> rawdata <- merge(nifty.ts, gold.ts)
> rawdata <- na.locf(rawdata)
> workdata <- window(rawdata, start = start.date, end = end.date)
> dates <- as.Date(rownames(workdata))
> workdata.xts <- xts(workdata[, 1:2], dates)
> workdata.ret.roll.y <- cbind(rollapply(workdata.xts[, 1], width = 252, annualized.returns,
+     align = "right"), rollapply(workdata.xts[, 2], width = 252, annualized.returns,
+     align = "right"))
> colnames(workdata.ret.roll.y) <- c("Nifty100Ret", "GoldRet")
> workdata.ret.master <- workdata.ret.roll.y
> workdata.ret.master <- as.timeSeries(coredata(workdata.ret.master), timeDate(as.Date(index(workdata.ret.master))))
> dates.liquid <- as.Date(rownames(liquid.ts))
> liquiddata.xts <- xts(liquid.ts[, 1], dates.liquid)
> liquiddata.ret.roll.y <- rollapply(liquiddata.xts[, 1], width = 300, annualized.returns,
+     align = "right")
> colnames(liquiddata.ret.roll.y) <- c("Liquid")
> liqworkdata.ret.master <- liquiddata.ret.roll.y
> liqworkdata.ret.master <- as.timeSeries(coredata(liqworkdata.ret.master), timeDate(as.Date(index(liqworkdata.ret.master))))
> all.master <- merge(workdata.ret.master, liqworkdata.ret.master)
> all.master <- window(all.master, start = start.date, end = end.date)
> all.master <- all.master[(!is.na(all.master[, 1])), ]
> all.master <- all.master[(!is.na(all.master[, 2])), ]
> all.master <- all.master[(!is.na(all.master[, 3])), ]
> plot(all.master[, 1], ylim = c(-0.6, 1.2), col = "blue", ylab = "Return", lwd = 1.5)
> par(new = T)
> plot(all.master[, 2], ylim = c(-0.6, 1.2), col = "sienna", ylab = "", lwd = 1.5)
> par(new = T)
> plot(all.master[, 3], ylim = c(-0.6, 1.2), col = "green", ylab = "", lwd = 1.5)
> legend("topright", legend = c("NIFTY 100", "Gold", "Liquid"), fill = c("blue",
+     "sienna", "green"))

ConcordDiscord-001.jpg

Plain simple correlation

> cor(all.master)
            Nifty100Ret GoldRet  Liquid
Nifty100Ret      1.0000 -0.1321 -0.4214
GoldRet         -0.1321  1.0000  0.2406
Liquid          -0.4214  0.2406  1.0000

Test of Independence using Kendall’s metric

> n <- dim(all.master)[1]
> sqrt(9 * n/4) * abs(cor(coredata(all.master), method = "kendall"))
            Nifty100Ret GoldRet Liquid
Nifty100Ret       57.00   5.980 11.287
GoldRet            5.98  57.000  6.955
Liquid            11.29   6.955 57.000

All pairs are dependent as each value is greater than 1.96
Test of Independence using Spearman metric

> n <- dim(all.master)[1]
> sqrt(n) * abs(cor(coredata(all.master), method = "spearman"))
            Nifty100Ret GoldRet Liquid
Nifty100Ret      38.000   6.213 10.741
GoldRet           6.213  38.000  8.687
Liquid           10.741   8.687 38.000

All pairs are dependent as each value is greater than 1.96