Site icon R-bloggers

MiRiM – RiskMetrics – v1.1

[This article was first published on Mirai Solutions, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Mirai RiskMetrics (MiRiM) is a Shiny app based on the RiskMetrics methodology enhanced to analyze the market risk of a portfolio.

< !--more-->

MiRiM is freely available on our Website Gallery and is designed for desktop view.

In the first release, MiRiM was mainly a PoC serving as an example for the application of the J.P.Morgan/Reuters RiskMetrics methodology to a portfolio of commodities to be provided as a CSV input, where a default portfolio of commodities from LME was initiated at the start of the app. RiskMetrics is a set of tools that enables participants in the financial markets to estimate their exposure to market risk, under what has been called the ‘Value-at-Risk framework’, in portfolios of foreign exchange, fixed income, equity and commodity products.

This MiRiM V.1.1 is a release with extensive changes and comes with the following enhancements:

The core methodology and the model parameters were not changed.

In order to operate with the MiRiM application, a user must first select a portfolio of assets in the ‘Input’ page, either from the provided list of Swiss assets on Nasdaq or by uploading a CSV file of prices with a ‘Date’ column in the specified format.

Once the portfolio is selected move to the ‘Parameters and Model’ page, visualize how the assets’ prices and your overall portfolio perform over time, check its value and composition. By assumption, a portfolio (PF) is composed of 5 shares per asset.

Select the time window to be considered and the other parameters for the RiskMetrics model, e.g. the simulation size (small for this prototype).

Run the simulation to estimate what your worst case loss at each time point would be, e.g. with 0.95 or 0.99 probability.

The output table contains the results at the last time point.

On the R/Shiny side the main updates are related to the introduction of new packages:

quantmod is the standard tool for supporting quantitative traders in their analysis. Simply using the getSymbols function we can read prices from sources like Yahoo Finance, Google, MySQL, FRED, and Oanda (our choice is for Yahoo Finance). The package contains also functionalities for drawing static financial plots like candlestick charts and line plots.

To make the plots interactive and dynamic on the Shiny app, we have used dygraphs for R, an interface to the dygraphs JavaScript library which is quite suitable for dynamic time series plots. dygraph plots react much faster than plotly on the Shiny app when the graphs contain many points and dygraph range selector allows fast zooming on a given time window.

The code below shows how to read a symbol from Yahoo Finance (quantmod) and how to create a candlestick chart with a range selector (dygraph).

quantmod::getSymbols("AAPL", src = "yahoo")
## [1] "AAPL"
dat <- AAPL %>% setNames(gsub("AAPL.", "", names(AAPL)))
datewindow <- c(tail(as.POSIXct(zoo::index(dat)), 365)[1], max(as.POSIXct(zoo::index(dat))))
dygraphs::dygraph(dat[, 1:4], main = "Apple share price over time") %>%
    dygraphs::dyCandlestick() %>%
    dygraphs::dyOptions() %>%
    dygraphs::dyRangeSelector(height = 40, dateWindow = datewindow)

The DT package provides convenient features to make static html tables look nicer.

Check the MiRiM app on our website to see the dynamic graphs, which can’t be displayed on this article, and to play with a portfolio of assets of your choice.

Do you have any suggestion for further improvement? Or if you have questions about the implementation, or about the approach of the RiskMetrics model, do not hesitate to contact us. We will be happy to hear from you and to take into consideration the relevant remarks for follow up releases.

To leave a comment for the author, please follow the link and comment on their blog: Mirai Solutions.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.