Giter Site home page Giter Site logo

mmr's Introduction

mmr - Measuring Market Risk

mmr (Measuring Market Risk) is a package for computing market risk measures such as value at risk and expected shortfall. The is inspired by Kevin Dowd's Measuring Market Risk (2002) and the Matlab code associated with it.

Installation

devtools::install_github("1danjordan/mmr")

data(portfolio_returns)

# Normal VaR approximated from portfolio returns 
portfolio_returns %>% 
  value_at_risk(returns, dist = normal())

# Volatility weighted historical simulation 
# for each asset in the portfolio 
portfolio_returns %>% 
  group_by(asset) %>% 
  value_at_risk(
    returns, 
    weighting = weight_volatility(decay = 0.04)
  ) 

portfolio_returns %>% 
  expected_shortfall(returns, dist = lognormal())

This package implements an "tidy API" alla the Tidyverse. Lot's of inspiration taken from yardstick.

Motivation

Dowd provides the motivation for this package in his preface via a quote:

You are responsible for managing your company’s foreign exchange positions. Your boss, or your boss’s boss, has been reading about derivatives losses suffered by other companies, and wants to know if the same thing could happen to his company. That is, he wants to know just how much market risk the company is taking. What do you say? You could start by listing and describing the company’s positions, but this isn’t likely to be helpful unless there are only a handful. Even then, it helps only if your superiors understand all of the positions and instruments, and the risks inherent in each. Or you could talk about the portfolio’s sensitivities, i.e., how much the value of the portfolio changes when various underlying market rates or prices change, and perhaps option delta’s and gamma’s. However, you are unlikely to win favour with your superiors by putting them to sleep. Even if you are confident in your ability to explain these in English, you still have no natural way to net the risk of your short position in Deutsche marks against the long position in Dutch guilders. ... You could simply assure your superiors that you never speculate but rather use derivatives only to hedge, but they understand that this statement is vacuous. They know that the word ‘hedge’ is so ill-defined and flexible that virtually any transaction can be characterized as a hedge. So what do you say? ... Perhaps the best answer starts: ‘The value at risk is ...’”. (Linsmeier and Pearson (1996))

And to take a quote from Dowd himself:

As always in risk measurement, we should keep our wits about us and not be too trusting of the software we use or the results we get.

So I ask users to do the same of my own work. Any issues or pull requests are welcome.

To Do

Use tidyeval framework through rlang.

Decomposition of Portfolio VaR:

  • Component VaR
  • Marginal VaR
  • VaR Contribution

Vignette where we use multiple VaR functions to estimate VaR for the same portfolio returns. Do this by creating a list of functions, and mapping over the functions. Then we can gather the wide data frame and plot very easily. Use partials in the list of functions.

Example showing sub-additivity of ES and where VaR is not sub-additive. VaR is subadditive for ellitical distributions such as the normal distribution though. So maybe show that an example of it being sub-additive and not being sub-additive with distributions of losses that are more typical.

Theme this package around tidy risk analysis - so make it simple to:

  • import data (using API)
  • define risk measure (VaR, ES, etc.)
  • apply risk measure functions to data
  • plot results

Doing this analysis should be super easy using the tools the tidyverse has given us.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.