**We think therefore we R**, and kindly contributed to R-bloggers)

I came across this interesting research paper published in one of the most coveted journals, (*International Journal on Finance and Economics*)* *which has used the PCA on the macroeconomic variables. So relating it to my previous post and the question of investigating the factor affecting stock returns, what they do is that they take individual stocks and regresses it on the PCA of macroeconomic variables. At the first glance this would appear an inappropriate use of the tool, however the question that it intends to ask is also very different. There has been or infact still is this great battle between the Capital Asset Pricing (CAPM) school of thought and Arbitrage Pricing Theory (APT) school of thought. What the essential difference between these two schools is that the CAPM says that the returns to a stock are sensitive to only one factor, i.e the market rate of returns (single factor model) which captures the effect of all the various factors, however the APT guys scream that it depends on a number of factors and market rate of return would be just one of them. So in this battle to prove their point the APT folks take stock returns as a dependent variable and as independent variables they use the PCA of many macroeconomic variables. They do this essentially so that they can prove that there are more than one factors playing a significant part in the explaining the returns on a stock, they do not care whether the economic intuition is lost in the process on one-upmanship.

Well anything is fair in war, but I think this path taken by APT guys of proving their point is a fair point. The variables that are thrown into the PCA are chosen with an economic intuition in mind, so its not correct to say this entire methodology is flawed on the pretext that the PCA of these macroeconomic variables have no economics intuition. If one really digs into the intuition behind PCA as explained in this article one can visualize what the PCA of macroeconomics variables would be representing, the principal underlying components *that give rise to such a macroeconomic series (signals). *This is an unconventional way of doing an econometric study, as in this is more of a qualitative than a quantitative study. I cannot make sense of a statement that 1 unit increase in my first PCA results in “x” unit increase in returns, this is an absurd statement, but nevertheless the methodology of answering the underlying question is not absurd.

The methodology for calculating the PCA for macroeconomics is same as what was used in the previous post. We can have a number of macroeconomic variables, however, I have done this demonstration with only 2 variables change in Mumbai inter-bank offer rates (MIBOR) rates and change in INR/USD exchange rates.

#### Calculating the PCA of macroeconomic variables ####

# Reading the relevant files

mibor <- read.csv(“MIBOR.csv”, na.strings=”#N/A”)

exchange <- read.csv(“Exchange_rates.csv”, na.strings=”#N/A”)

# Making sure that there are no missing values in the data, the missing values are replaced by linear interpolation

mibor[, 2] <- approx(as.Date(mibor$Dates, ‘%d-%b-%y’), mibor[ ,2], as.Date(mibor$Dates, ‘%d-%b-%y’))$y # approx() returns the interpolated values in column ‘y’

exchange[, 2] <- approx(as.Date(exchange$Year,’%d-%b-%y’), exchange[ ,2], as.Date(exchange$Year, ‘%d-%b-%y’))$y # Similarly for exchange rates

# Now we will have to compute the change in MIBOR and exchange rates:

for(k in 2:nrow(mibor))

{

mibor$Change1[k] <- ((mibor$MIBOR[k] – mibor$MIBOR[k-1])/mibor$MIBOR[k-1])*100

}

for(j in 2:nrow(exchange))

{

exchange$Change[j] <- ((exchange$Exchange.rates[j] – exchange$Exchange.rates[j-1])/exchange$Exchange.rates[j-1])*100

}

# Creating matrix of the data

macro <- as.data.frame(rep(0, 2498))

macro$ex <- exchange$Change

macro$rate <- mibor$Change1

**Caveats and cautions:**

*not the best*idea to use PCA. One should use PCA only if one has many macroeconomic variables like M1, M3, CPI, IIP, WPI, etc and there is high correlation between them. I have done the above only for illustrative purposes (since I am not employing PCA on macro-variables in my project).

**Limitations in the above method:**

- In the above exercise I have just taken 2 variables merely for illustration, I would have to include more variables if I really intent to find evidences against the CAPM.
- Again the caveat of interpretation applies. Its difficult to interpret the PCA on macrovariables

**My take:**

**leave a comment**for the author, please follow the link and comment on their blog:

**We think therefore we R**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...