Reader small image

You're reading from  Learning Quantitative Finance with R

Product typeBook
Published inMar 2017
Reading LevelIntermediate
PublisherPackt
ISBN-139781786462411
Edition1st Edition
Languages
Right arrow
Authors (2):
Dr. Param Jeet
Dr. Param Jeet
author image
Dr. Param Jeet

Dr. Param Jeet is a Ph.D. in mathematics from one of India's leading technological institute in Madras (IITM), India. Dr. Param Jeet has a couple of mathematical research papers published in various international journals. Dr. Param Jeet has been into the analytics industry for the last few years and has worked with various leading multinational companies as well as consulted few of companies as a data scientist.
Read more about Dr. Param Jeet

PRASHANT VATS
PRASHANT VATS
author image
PRASHANT VATS

Prashant Vats is a masters in mathematics from one of India's leading technological institute, IIT Mumbai. Prashant has been into analytics industry for more than 10 years and has worked with various leading multinational companies as well as consulted few of companies as data scientist across several domain.
Read more about PRASHANT VATS

View More author details
Right arrow

Chapter 7.  Risk Management

In this chapter, we are going to discuss the various types of risk associated with the banking and financial domains. Banks and financial institutions are all exposed to risk, and they need to develop risk identification and risk mitigation mechanisms with the implementation of regulatory norms to stay competitive and profitable. In this chapter, we are going to discuss various techniques to measure different types of risk using R. It also includes risk pertaining to banking operations such as credit risk, fraud detection, and Basel regulations.

The chapter covers the following topics:

  • Market risk

  • Portfolio risk

  • VaR

  • Monte Carlo simulations

  • Hedging

  • Basel regulation

  • Credit risk

  • Fraud detection

Market risk


The risk for an investor to encounter losses due to changes in overall performance of the market in which he has invested, is known as market risk. Market risk is a kind of systematic risk which cannot be tackled with diversification. It may be hedged. The risks happening due to recessions, political instability, interest rate changes, natural disasters, and terrorist attacks are examples of market risks. Market risks are measured differently for banks, individual stocks, portfolios, and so on.

Let us consider how market risks are measured for individual securities. The market risk of a stock which is a part of a portfolio is measured as the contribution of a security in the overall risk of the portfolio. The individual stock risk is measured by the beta coefficient, which is the volatility of stock with respect to the market.

Let us run regression analysis on stock IBM as dependent variable and GPSC index as the independent variable and try to estimate the beta. It can be done...

Portfolio risk


With the use of R language, we can manage portfolios better by mitigating the risk and portfolio optimization. To avoid the risk associated with portfolio analysis, diversification of the portfolio is required, with the selection of optimum weights for the portfolio's constituents.

Let us try to find the optimal weight of the portfolio whose stocks are IBM and FB, and using the CAPM. First, let us get the relevant data by executing the following code:

>GPSCMonthlyUrl<-'http://ichart.yahoo.com/table.csv?s=%5EGSPC&a=00&b=1&c=2015&d=00&e=1&f=2017&g=m' 
>GPSCMonthlyData <- read.csv(GPSCMonthlyUrl) 
>IBMMonthlyUrl<-'http://ichart.yahoo.com/table.csv?s=IBM&a=00&b=1&c=2015&d=00&e=1&f=2017&g=m' 
>IBMMonthlyData <- read.csv(IBMMonthlyUrl) 
>FBMonthlyUrl<-'http://ichart.yahoo.com/table.csv?s=FB&a=00&b=1&c=2015&d=00&e=1&f=2017&g=m' 
>FBMonthlyData <- read.csv(FBMonthlyUrl...

VaR


Value at risk is a measure in risk management to measure the potential risk which can occur to the portfolio of an investor. VaR imputed at 5% confidence means that the loss will not be less than predicted value 95% of the time or, in other words, loss will be greater in 5% of times than predicted value.

There are three common ways of computing value at risk:

  • Parametric VaR

  • Historical VaR

  • Monte Carlo VaR

In this section, we will be capturing the first two, and the third one will be captured in the next section.

Parametric VaR

Parametric VaR is also known as the variance-covariance method and is used to find VaR using mean and standard deviation as parameters.

qnorm is used for value at risk calculation using parametric methods. It uses the parameters mean and standard deviation. The general syntax is as follows:

qnorm(p,mean,sd) 

Here, p is the desired percentile; mean is the given mean of the sample; and sd is the standard deviation of the sample.

Let us assume that the average return of a stock...

Monte Carlo simulation


Monte Carlo simulation plays a very important role in risk management. Even if we have access to all the relevant information pertaining to risk associated with a firm, it is still not possible to predict the associated risk and quantify it. By the means of Monte Carlo simulation, we can generate all the possible scenarios of risk and using it, we can evaluate the impact of risk and build a better risk mitigation strategy.

Monte Carlo simulation is a computational mathematical approach which gives the user the option of creating a range of possible outcome scenarios, including extreme ones, with the probability associated with each outcome. The possible outcomes are also drawn on the expected line of distribution, which may be closer to real outcomes. The range of possible outcomes can be used in risk analysis for building the models and drawing the inferences. Analysis is repeated again and again using a different set of random values from the probability function...

Hedging


Hedging is basically taking a position in the market to reduce the risk. It is a strategy built to reduce the risk in investment using call/put options/futures short selling. The idea of hedging is to reduce the volatility of a portfolio by reducing the potential risk to loss. Hedging especially protects small businesses against catastrophic or extreme risk by protecting the cost at the time of distress. The tax laws also benefit those who do hedging. For firms who do hedging, it works like insurance and they have more independence to make their financial decisions without thinking about the risks.

Now, let us consider some scenarios of hedging:

  • Currency risk: Also known as exchange-rate risk, it happens due to fluctuations in the prices of one currency with respect to another. Investors or companies who operate across the world are exposed to currency risk, which may lead to profit and losses. This risk can be reduced by hedging, which can prevent losses happening due to price fluctuation...

Basel regulation


The main goal for the Basel Committee on Banking Supervision is to improve understanding of key supervisory issues to set a healthy banking supervision worldwide. Its main objective is to develop regulatory frameworks in order to improve banking systems. Currently, Basel III has been developed to meet the deficiencies in financial regulations exposed during the financial crisis of 2007-2008. Basel III is a global voluntary regulatory framework on bank capital adequacy, stress testing, and market liquidity risk. It is assumed to strengthen bank capital requirements by decreasing bank leverage and increasing bank liquidity. The objective of implementing Basel III is to make the banking sector more robust so that it can absorb shocks arising from financial and economic stress, improve risk management and governance, and strengthen banks' transparency and disclosures.

The R community has developed a library, SACCR, keeping in mind the regulations of Basel III. This library has...

Credit risk


Credit risk is the risk associated with an investment where the borrower is not able to repay the amount to the lender. This can happen on account of poor financial conditions of the borrower, and it represents a risk for the lender. The risk is for the lender to incur loss due to non-payment and hence disruption of cash flows and increased collection costs. The loss may be complete or partial. There are multiple scenarios in which a lender can suffer loss. Some of the scenarios are given here:

  • A customer not making a payment on a mortgage loan, credit card, line of credit, or other type of loan

  • Business/consumer not paying due trade invoice

  • A business not paying an employee's due earned wages

  • A business/government bond issuer not making payment on a due coupon or principal

  • An insurance company not obliging its policy obligation due

  • A bank not returning funds of depositors

It is a practice of mitigating losses by understanding the adequacy of a bank's capital and loan loss reserves...

Fraud detection


Identifying fraudulent transactions is one of the most important components of risk management. R has many functions and packages that can be used to find fraudulent transactions, including binary classification techniques such as logistic regression, decision tree, random forest, and so on. We will be again using a subset of the German Credit data available in R library. In this section, we are going to use random forest for fraud detection. Just like logistic regression, we can do basic exploratory analysis to understand the attributes. Here we are not going to do the basic exploratory analysis but will be using the labeled data to train the model using random forest, and then will try to do the prediction of fraud on validation data.

So the dataset used for the analysis will be given by executing the following code:

>data(GermanCredit) 
>FraudData<-GermanCredit[,1:10] 
> head(FraudData) 

It generates a few lines of the sample data:

Figure 7.17: Sample data used...

Liability management


Liability management is the process of keeping appropriate liquidity reserves and allocating assets by financial institutions to balance outstanding liabilities such as deposits, CDs, and so on to obtain best performance by simultaneously meeting liabilities and growing net assets. Banks have several risks - asset management risk, interest rate risk, and currency exchange risks - and by using liability management, banks and financial institutions try to minimize the risk.

In this chapter, we have discussed several topics, such as market risk, portfolio risk, credit risk, fraud detection, diversification of portfolios, optimization of portfolios, and rebalancing of the portfolio, which can help financial in situation with liability management.

Questions


  1. What is market risk and how can R help in measuring market risk? Please give an example.

  2. What are the ways of measuring risk associated with the portfolio?

  3. What are the most common ways of measuring VaR? Please construct a portfolio and find VaR using all the methods.

  4. How do you compute ES/CVAR in R?

  5. Construct a sample using normal and lognormal distribution using the Monte Carlo method and find the historical VaR for each of them.

  6. How do you find component and marginal VaR for a portfolio in R?

  7. What is credit scoring and how do you execute it in R? Construct an example and build a scoring example along with validation.

  8. What are the ways to identify fraud? How do you execute them in R?

Summary


In this chapter, we have covered the types of risks associated with financial institutions, such as market risk, portfolio risk, VaR, Monte Carlo simulation, hedging, Basel regulations, credit risk, and fraud detection. Also, we have discussed how the strengths of R can be leveraged for measuring different types of risk. In this chapter, we have demonstrated examples of measuring risks such as market, portfolio, and credit using R, and also how to use techniques such as random forest classification for fraud detection.

In the next chapter, we will be covering various optimization techniques used in trading algorithms and parameter estimation. Optimization techniques such as dynamic rebalancing, walk forward testing, grid testing, and genetic algorithm will be covered.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Learning Quantitative Finance with R
Published in: Mar 2017Publisher: PacktISBN-13: 9781786462411
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Dr. Param Jeet

Dr. Param Jeet is a Ph.D. in mathematics from one of India's leading technological institute in Madras (IITM), India. Dr. Param Jeet has a couple of mathematical research papers published in various international journals. Dr. Param Jeet has been into the analytics industry for the last few years and has worked with various leading multinational companies as well as consulted few of companies as a data scientist.
Read more about Dr. Param Jeet

author image
PRASHANT VATS

Prashant Vats is a masters in mathematics from one of India's leading technological institute, IIT Mumbai. Prashant has been into analytics industry for more than 10 years and has worked with various leading multinational companies as well as consulted few of companies as data scientist across several domain.
Read more about PRASHANT VATS