Macro Analysis
Introduction
A global macro strategy is a hedge fund that bases its holdings - such as long and short positions in various equity, fixed income, currency, commodities and futures markets - primarily on the overall economic and political views of various countries or their macroeconomic principles
Analysis I
This project aims to analyze 5 different countries namely US, UK, Canada, Australia and Germany on some core macro parameters like equity markets, Unemployment and benchmark 30 year rate. The idea is to perform a couple of stragegies to shock the macro parameters and determine the strength of the equity markets during the course.
library(reshape2)
library(ggplot2)
library(formattable)
stockmarket <- read.csv(file="https://raw.githubusercontent.com/mkunissery/Data621/master/Finals/stock.csv", header=TRUE, sep=",")
unemp <- read.csv(file="https://raw.githubusercontent.com/mkunissery/Data621/master/Finals/unemp.csv", header=TRUE, sep=",")
benchmark <- read.csv(file="https://raw.githubusercontent.com/mkunissery/Data621/master/Finals/benchmark.csv", header=TRUE, sep=",")
formattable(head(stockmarket))| date | us | germany | uk | australia | canada |
|---|---|---|---|---|---|
| 2019-05-21 | 2864.36 | 12143.5 | 7328.92 | 16426.5 | 6500.14 |
| 2019-05-20 | 2840.23 | 12041.3 | 7310.88 | 16401.8 | 6476.10 |
| 2019-05-17 | 2859.53 | 12238.9 | 7348.62 | 16401.8 | 6365.30 |
| 2019-05-16 | 2876.32 | 12310.4 | 7353.51 | 16443.9 | 6327.84 |
| 2019-05-15 | 2850.96 | 12099.6 | 7296.95 | 16318.1 | 6284.20 |
| 2019-05-14 | 2834.41 | 11991.6 | 7241.60 | 16284.5 | 6239.91 |
formattable(head(unemp))| date | us | germany | uk | australia | canada |
|---|---|---|---|---|---|
| 2019-03-31 | 3.87 | 3.2 | 3.87 | 5.00 | 5.80 |
| 2019-03-30 | 3.80 | 3.1 | 4.03 | 5.03 | 5.63 |
| 2019-03-29 | 3.80 | 3.1 | 4.03 | 5.03 | 5.63 |
| 2019-03-28 | 3.80 | 3.1 | 4.03 | 5.03 | 5.63 |
| 2019-03-27 | 3.80 | 3.1 | 4.03 | 5.03 | 5.63 |
| 2019-03-26 | 3.80 | 3.1 | 4.03 | 5.03 | 5.63 |
formattable(head(benchmark))| date | us | germany | uk | canada | australia |
|---|---|---|---|---|---|
| 2019-05-21 | 2.841 | 0.590 | 1.633 | 1.969 | 2.315 |
| 2019-05-17 | 2.824 | 0.537 | 1.593 | 1.922 | 2.321 |
| 2019-05-16 | 2.839 | 0.537 | 1.613 | 1.914 | 2.317 |
| 2019-05-15 | 2.823 | 0.531 | 1.613 | 1.898 | 2.360 |
| 2019-05-14 | 2.852 | 0.565 | 1.637 | 1.920 | 2.365 |
| 2019-05-13 | 2.837 | 0.576 | 1.651 | 1.898 | 2.375 |
Time Series Charts
3 Time Series chart below present the historical data of the equity markets, unemployment history and 30 year benchmark rate
Performance of Stock Market in the last 12 years
unemployment of different countries in the last 12 years
30 year benchmark of different countries in the last 12 years
sample Check for linearity
Before applying linear regression models, we will need to make sure that a linear regression exists between the dependent variable and the independent variable/s.
A quick way to check for linearity is by using scatter plots.
For our example, we’ll check that a linear relationship exists between:
The Stock Market (dependent variable) and the Unemployment (independent variable); and The Stock Market (dependent variable) and the 30 Year Bond rate (independent variable)
Multiple Linear Regression (MLR)
MLR is done for the five countries and the coefficient of regression and the intercept is captured and used to predict outcomes .
library(plyr)
library(reshape2)
lmcoeff <- function(country)
{
Stock_Index_Price =do.call("cbind", stockmarket[country])[1:1000]
benchmark_rate = do.call("cbind", benchmark[country])[1:1000]
Unemployment_Rate = do.call("cbind", unemp[country])[1:1000]
model <- lm(Stock_Index_Price ~ benchmark_rate + Unemployment_Rate)
intercept = summary(model)$coefficients[1]
X1 = summary(model)$coefficients[2]
X2 = summary(model)$coefficients[3]
retvalue = c(intercept,X1,X2)
return (retvalue)
}
us = lmcoeff('us')
uk = lmcoeff('uk')
australia = lmcoeff('australia')
germany = lmcoeff('germany')
canada = lmcoeff('canada')
df = as.data.frame(us)
df$uk = as.data.frame(uk)
df$cd = as.data.frame(canada)
df$au = as.data.frame(australia)
df$de = as.data.frame(germany)
colnames(df) <- c("us","uk","canada","australia","germany")Shock Analysis
Two different shock analysis are done where the countries unemployment and interest rates are shocked to raise and lower by 25% and see how the equity markets perform.
predict <- function(country, shock)
{
searchstr = paste(country, "$",sep ="" )
loc = grep(searchstr, colnames(unemp))
shockunemp = unemp[[loc]][1] * shock
shockrate = benchmark[[loc]][1] * shock
currstockprice = stockmarket[[loc]][1]
data = unlist(df[country])
intc = data[[1]]
x1 = data[[2]]
x2 = data[[3]]
stockprice = intc + (x1 * shockrate) + (x2 * shockunemp )
return ((stockprice/currstockprice-1)*100)
}
useqt = predict('us',1.25)
ukeqt = predict('uk',1.25)
aueqt = predict('australia',1.25)
cdeqt = predict('canada',1.25)
deeqt = predict('germany',1.25)
shockPercent <- c(25,-25)
US <- c(predict('us',1.25),predict('us',3/4))
UK <- c(predict('uk',1.25),predict('uk',3/4))
CANADA <- c(predict('canada',1.25),predict('canada',3/4))
GERMANY <- c(predict('germany',1.25),predict('germany',3/4))
AUS <- c(predict('australia',1.25),predict('australia',3/4))
result <- data.frame(shockPercent, US, UK , CANADA, GERMANY, AUS)
formattable(result)| shockPercent | US | UK | CANADA | GERMANY | AUS |
|---|---|---|---|---|---|
| 25 | -27.85372 | -9.984695 | -21.188649 | -11.43128 | -22.06333 |
| -25 | 18.61477 | 19.161167 | 6.959423 | 16.95878 | 18.77679 |
resultmod <- result[,-1]
result25up = result[result$shockPercent == 25, ]
result25down = result[result$shockPercent == -25, ]
library(reshape2)
library(ggplot2)
result25up = result25up[,-1]
result25down = result25down[,-1]Result of Increasing enmployment and Interest Rate up 25%
result25up$row <- seq_len(nrow(result25up))
dat2 <- melt(result25up, id.vars = "row")
ggplot(dat2, aes(x = variable, y = value, fill = variable)) +
geom_bar(stat = "identity" , color="black") +
xlab("\nMarkets") +
ylab("Percent\n") +
scale_fill_manual(values=c("#42f4d7", "#efc53b", "#ef3b4c","#3b80ef","#2ef289"))+
theme_minimal()Result of Increasing enmployment and Interest Rate down 25%
result25down$row <- seq_len(nrow(result25down))
dat2 <- melt(result25down, id.vars = "row")
ggplot(dat2, aes(x = variable, y = value, fill = variable)) +
geom_bar(stat = "identity" , color="black") +
xlab("\nMarkets") +
ylab("Percent\n") +
scale_fill_manual(values=c("#42f4d7", "#efc53b", "#ef3b4c","#3b80ef","#2ef289"))+
theme_minimal()Result of MLR
The conclusion that can be derived from MLR is that UK markets fare better in both scenarios not losing much equity and also raising up better when conditions are better. go UK !!
Analysis II
Analysing the factors that influence US Economic activity.
PCA Analysis
usmacrodata <- read.csv(file="https://raw.githubusercontent.com/mkunissery/Data621/master/Finals/pca.csv", header=TRUE, sep=",")
colnames(usmacrodata)## [1] "Dates" "US.Consumer.Confidence"
## [3] "US.New.Home.Sales" "US.Consumer.Core.Price.Index"
## [5] "US.Retail.Sales" "S.P.500"
## [7] "T30.Yield" "US.unemployment.Rate"
Analysis using Principal Component
usmacrodatadatestripped = usmacrodata[,-1]
macro.pca <- prcomp(usmacrodatadatestripped,center=TRUE,scale.=TRUE)
summary(macro.pca)## Importance of components:
## PC1 PC2 PC3 PC4 PC5 PC6
## Standard deviation 2.3157 0.9847 0.69103 0.35772 0.17112 0.14309
## Proportion of Variance 0.7661 0.1385 0.06822 0.01828 0.00418 0.00293
## Cumulative Proportion 0.7661 0.9046 0.97281 0.99109 0.99527 0.99820
## PC7
## Standard deviation 0.1123
## Proportion of Variance 0.0018
## Cumulative Proportion 1.0000
Explanation of PC variables using ggbiplot
#str(macro.pca)
library(ggbiplot)## Loading required package: scales
##
## Attaching package: 'scales'
## The following objects are masked from 'package:formattable':
##
## comma, percent, scientific
## Loading required package: grid
ggbiplot(macro.pca, scale=0, labels=rownames(macro.pca))Conclusion
As we can see that 76.6 Percent of variance is captured by Principal Component 1 and 95% is captured by PC1 to PC3 . 3 variables account to 95%