Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

FINANCIAL AND RISK

ANALYTICS ASSIGNMENT
Group 4

By
Nandini Ramakumar
Swarna Chander
Aishwaryaa Parthasarathy
PROBLEM STATEMENT:

“You are an Equity fund manager focusing in large cap shares, your client has
approached you and expressed in interest in building a portfolio of INR 1 Crore,
in high quality blue chip shares”

His criteria for investment is the investment universe is only blue chip shares (share
should be part of sensex) and he would like to investment only in 5 shares among this
universe. With maximum exposure of 30% in a single share.
He has requested you to provide various portfolios with various scenarios.

SOLUTION:
We have chosen the following portfolios: State Bank of India, Standard Chartered
Bank, ICICI Bank, Yes Bank and Indian Bank.
Step 1: Installing packages

The required packages such as timeseries, fportfolio, quantmod, ggplot2,


Quand1 has been installed and loaded.

library(timeSeries)
library(fPortfolio)
library(quantmod)
library(caTools)
library(dplyr)
library(PerformanceAnalytics)
library(ggplot2)
library(Quandl)
Step 2: Creating returns time series
> #Create Vector of Tickers
> Quandl.api_key("3pHKvqUriXKYvFJWzY3-")
> tickers <- c("BSE/BOM500112","BSE/BOM580001","BSE/BOM532174",
+ "BSE/BOM532648","BSE/BOM532814")
> tickers_head <- c("SBIN","STAN","ICICIBANK","YESBANK","INDIANB")
From the Quandl library we can import the data for bluechip shares : State Bank of
India, Standard Chartered Bank, ICICI Bank, Yes Bank and Indian Bank. Also the
daily data is obtained from 1.10.2017 to 1.10.2019.
#Calculating Returns: Daily
> portfolioPrices <- NULL
>
> for (Ticker in tickers)
+ portfolioPrices <- cbind(portfolioPrices,
+ + Quandl(Ticker, type = "timeSeries", start_date ="2017-10-
01",
+ order = "asc", collapse = "daily")[,4])

#Deleting all dates with no prices


>
> portfolioPrices <- portfolioPrices[apply(portfolioPrices,1,
+ function(x) all(!is.na(x))),]

#Renaming Columns
> colnames(portfolioPrices) <- tickers_head
>
> View(portfolioPrices)
>

#Calculating Returns: Daily RoC


> portfolioReturnsDaily <- na.omit(ROC(portfolioPrices, type="discrete"))

The data need to be deleted if it has no price, then the daily returns are calculated as
portfolioReturnsDaily.

#Calculating Monthly or Weekly Returns


>
> Stock_Data <- tickers %>% lapply(function(x) Quandl(x, type = "timeSeries"
+ , start_date ="2017-10-01", order = "asc", collapse
= "daily")[,4]) %>%
+ lapply(function(x) monthlyReturn(x))

> portfolioReturnsMonthly <- do.call(merge, Stock_Data)

keeping only the dates that have closing prices for all tickers
> portfolioReturnsMonthly <-
portfolioReturnsMonthly[apply(portfolioReturnsMonthly,1,function(x) all(!is.na(x))),]
>
> colnames(portfolioReturnsMonthly) <- tickers_head
>
> portfolioReturnsMonthly <- as.timeSeries(portfolioReturnsMonthly)
>
> View(portfolioReturnsMonthly)

We can now calculate returns over different time frames with multiple functions
within the quantmod library.
The portfolioReturnsMonthly is converted into timeseries and the date which is
considered which has the closing prices of all tickers.

write.csv(portfolioReturnsMonthly, "portfolioReturnsMonthly.csv")
Then the data which is exported into csv. We can also examine returns for a specific
year or period range also by specifying including the subset .
Step 3: Examining Constraints
> #Set Specs
>
> Spec = portfolioSpec()
> setSolver(Spec) = "solveRquadprog"
> setTargetRisk(Spec) = NULL
> setNFrontierPoints(Spec) = 200
> cons <- c("minW[1:length(tickers)]= 0.05",
+ "maxW[1:length(tickers)]= 0.3","minsumW[1:length(tickers)]=1")
> effFrontierPort <- NULL
> effFrontierPort <- portfolioFrontier(portfolioReturnsMonthly,
+ Spec, constraints = cons)
> weights <- getWeights(effFrontierPort)
> colnames(weights) <- tickers_head
> plot(effFrontierPort, c(1,2,3,4,5))

The efficient frontier is the set of optimal portfolios that offer the highest expected
return for a defined level of risk or the lowest risk for a given level of expected return.
Portfolios that lie below the efficient frontier are sub-optimal because they do not
provide enough return for the level of risk.
> barplot(t(weights), main="Frontier Weights", col=cm.colors(ncol(weights)),
+ legend=colnames(weights),args.legend = list(x = "topleft"))

> setOptimize = "minRisk"


> effPortMVP <- minvariancePortfolio(portfolioReturnsMonthly,
+ Spec, constraints=cons)
> mvpWeights <- getWeights(effPortMVP)
> tanPort <- tangencyPortfolio(portfolioReturnsMonthly,
+ Spec, constraints=cons)
> tanWeights <- getWeights(tanPort)
> setOptimize = "maxReturn"
> setTargetRisk(Spec) = 0.7
> maxR <- maxreturnPortfolio(portfolioReturnsMonthly, Spec, constraints=cons)
> maxWeights <- getWeights(maxR)

Step4: Minimum variance or Minimum risk portfolio:

A portfolio of individually risky assets that, when taken together, result in the lowest p
ossible risk level for the rate of expected return.
Such a portfolio hedges each investment with an offsetting investment,
the individual investor's choice on how much to offset investments depends on the lev
elof risk and expected return he/she is willing to accept.
##Min Variance or Min Portfolio Risk
> df <- data.frame(mvpWeights)
>
> effFrontier <- portfolioFrontier(portfolioReturnsMonthly,
+ constraints = "LongOnly")
> frontierWeights <- getWeights(effFrontier)
> assets <- colnames(frontierWeights)
> ggplot(data=df, aes(x=assets, y=mvpWeights, fill=assets)) +
+ geom_bar(stat="identity", position=position_dodge(),colour="black") +
+ geom_text(aes(label=sprintf("%.02f %%",mvpWeights*100)),
+ position=position_dodge(width=0.9), vjust=-0.25,
+ check_overlap = TRUE) +
+ ggtitle("Min Variance or Min Risk Portfolio")+
+ theme(plot.title = element_text(hjust = 0.5)) +
+ labs(x= "Assets", y = "Weight (%)")

We can work with return data also and display it graphically. Let’s create a histogram
of the log returns we calculated. From the Min risk portfolio, the maximum exposure
of 30% in these shares will be Standard Chartered Bank.
Step 5: Tangential Weights

The Sharpe ratio is the ratio of the difference between the mean of portfolio returns
and the risk-free rate divided by the standard deviation of portfolio returns. The
estimateMaxSharpeRatio function maximizes the Sharpe ratio among portfolios on the
efficient frontier.
> ##Tangential weights
>
> df <- data.frame(tanWeights)
>
> assets <- colnames(frontierWeights)
>
> ggplot(data=df, aes(x=assets, y=tanWeights, fill=assets)) +
+ geom_bar(stat="identity", position=position_dodge(),colour="black") +
+ geom_text(aes(label=sprintf("%.02f %%",tanWeights*100)),
+ position=position_dodge(width=0.9), vjust=-0.25, check_overlap =
TRUE) +
+ ggtitle("Tangency or Max Sharp Ratio Portfolio ")+
+ theme(plot.title = element_text(hjust = 0.5)) +
+ labs(x= "Assets", y = "Weight (%)")

From the Max Sharp ratio Portfolio, the maximum exposure of 30% in these shares
will be Standard Chartered bank, icici bank, SBI bank Assets.
Step 6: Maximum Return Portfolio:

It reduces portfolio risk by selecting and balancing assets based on statistical


techniques that quantify the amount of diversification by calculating expected
returns, standard deviations of individual securities to assess their risk, and by
calculating the actual coefficients of correlation between assets, or by using a good
proxy, such as the single-index model, allowing a better choice of assets that have
negative or no correlation with other assets in the portfolio.

Modern portfolio management differs from the traditional approach by the use of
quantitative methods to reduce risk. The main objective of modern portfolio theory is
to have an efficient portfolio, which is a portfolio that yields the highest return for a
specific risk, or, stated in another way, the lowest risk for a given return. Profits can be
maximized by selecting an efficient portfolio that is also an optimal portfolio, which is
one that provides the most satisfaction and the greatest return for an investor based on
his tolerance for risk.

##Maximum Profit Portofolio


> df <- data.frame(maxWeights)
>
> assets <- colnames(frontierWeights)
>
> ggplot(data=df, aes(x=assets, y=maxWeights, fill=assets)) +
+ geom_bar(stat="identity", position=position_dodge(),colour="black") +
+ geom_text(aes(label=sprintf("%.02f %%",maxWeights*100)),
+ position=position_dodge(width=0.9), vjust=-0.25,
check_overlap = TRUE) +
+ ggtitle("Max Returns Portfolio")+
+ theme(plot.title = element_text(hjust = 0.5)) +
+ labs(x= "Assets", y = "Weight (%)")
From the Max returns portfolio, the maximum exposure of 30% in these shares
will be Standard Chartered Bank and ICICI bank.

You might also like