Forums  > Software  > Risk System in R for a small Asset Management company  
Page 1 of 1
Display using:  


Total Posts: 57
Joined: May 2010
Posted: 2017-03-18 06:25
Has anybody implemented a Risk System purely in R for identifying, measuring, managing, and reporting risks? Do you think it is feasible to create such a system/platform from scratch? What are the pros and cons of developing it in R? What packages could be used?

70-80% of the traded instruments are ETFs. There are some single name stocks and bonds as well.

Third party products like RiskMetrics/BarraOne, Axioma, etc. are not being considered at this point. And we think that having our own system would give us more flexibility as compared to BBG risk tools.

Any ideas/resources appreciated. Thanks.



Total Posts: 922
Joined: Jun 2007
Posted: 2017-03-18 20:29
That depends on the scope of your risk system. If doind all the ETL and data cleaning and management is included in your risk system, R is without a doubt capable....but I would not recommend to do everything in R for a productive System. If I had to take a script language with some scientific packages I would take python.

I did implement a reporting pipeline for an energy commodities company in R and Oracle. It did work and was in production for some time. But I still wouldn't recommend creating a complete Risk Engine in R

Just my humble opinion

Ich kam hierher und sah dich und deine Leute lächeln, und sagte mir: Maggette, scheiss auf den small talk, lass lieber deine Fäuste sprechen...


Total Posts: 92
Joined: Feb 2011
Posted: 2017-03-19 12:31
Agree with Maggette!
R is great for rapid prototyping and research but if a system needs to be robust and fast (and it likely needs) than a pure R solution is suboptimal.

I, myself, when I need speed, first develop an model in R and then rewrite critical parts in C++ or even CUDA.

As to my experience with "industrial level" software (where I was just one of many developers), the calculation kernel was developed in C++ and the front-end in Java.
Probably, one can do everything in Java, like e.g. OpenGamma did.

As to Python, I cannot say anything due to lack of experience.
But anyway, I don't like weakly typed languages for big projects. - Knowledge rather than Hope: A Book for Retail Investors and Mathematical Finance Students


Total Posts: 922
Joined: Jun 2007
Posted: 2017-03-19 14:15
On a more constructive note (if you insist on R) I used: Shiny to create some reporting dashboards and some technical dashboards for myself (checksums, counts, ranges and moments of input data vs their historical development)

Sweave for pdf generation(which was in a horrible state back then)

Ich kam hierher und sah dich und deine Leute lächeln, und sagte mir: Maggette, scheiss auf den small talk, lass lieber deine Fäuste sprechen...


Total Posts: 405
Joined: Apr 2005
Posted: 2017-03-19 14:19
With Maggette here - you CAN create a simple enough risk / reporting system in R - it's very easy to do - although the term "Risk System" can be taken to different levels.

If you want to automate some analysis, consolidate some reporting, some conditional stuff - then R is more than fine.

If you want really interactive, whatif, proposing different positions, adding multiple asset classes - then while a lot of the stats work is good in R - might want to consider other options..


Total Posts: 292
Joined: Mar 2010
Posted: 2017-03-19 17:08
We built a R based equity risk model over the last few years with the bulk done the first six months and then constant refinements. We'd previously built screening, backtesting and various analytics in R so we were quite familiar with it and have built quite a bit on top of the vanilla language to escape from it's shortcomings as a language and ecosystem.

With the risk model we expanded to risk reporting, portfolio optimization based on risk factors, attributions etc. This was in order to offer an internal alternative to Barra and BBG PORT with something more bespoke and flexible to our needs.

We then exposed the functionality to other systems via C# based WebAPI services that connect to web application user interfaces but most of the use is directly in R for research, bespoke analytics and reporting. We generally do ETL first in R and then refine in C# once we understand the dataset and cleaning required better.

My view in hindsight.

* R allows you to express complex logic quickly and elegantly
* R packages allow you to solve common problems quickly
* You can easily go into C++ via Rcpp for the bottlenecks

* R is by default single threaded and splitting things up is doable but creates many problems
* Incorrectly written base R is crazy slow
* R packages can be very low quality
* You need to solve a lot of tooling, interoperability and ecosystem problems yourself if you want things running in production.

Some questions you should ask yourself before hand:
* How many people will be the main contributors for this and how experienced are they with R?
* How confident are you that the people that will develop this either have enough experience to build it themselves (both finance, math and dev side)?
* Are those people comfortable with building R packages? Can they write clean testable R code? Can they set up their own package repository? Can they write to a style guide with comments etc such that if they go away someone else can continue the work?
* How confident are you that you can easily onboard another person with similar skills to work on the system in the future?
* How do you currently handle connectivity with other systems and how do you want to handle it in the future?
* Does this need to scale to run everything, everywhere?

Could give a few extra pointers but would depend on:
* Size of team working on this.
* Structure of team (quants only vs devs + quants + BA + IT stuff etc)
* Number of instruments and portfolio groupings (e.g. we built ours for 15K equity line universe, 10 portfolios. Now supports 180K equity lines and 150 portfolios, scaling that in R was hard).

If I was building this thing again today I’d maybe consider C#, Java or maybe C++ but only with good developers to support that flow around it. The reason we did it R only for us was that it had to be built by quants only in something that could easily be understood and run on desk and expanded and changed as it evolved. Going with a main stream primary language will solve a lot of tooling problems, scalability and maintainability and then going only to R for the stats and math stuff is an option but will most likely take more time to get to a minimum viable product.

As noted Python is an option because it has slightly better tooling, interoperability and maintainability options but end of the day it’s not much better and there might well be other issues on that side.

As with everything when it comes to this stuff the devil is in the details.


Total Posts: 7
Joined: Nov 2016
Posted: 2017-03-19 23:08
As quite a few have mentioned, Python is probably a good balance. If development time, skill and costs aren't an issue, likely a compiled language will give a better outcome.

A few libraries in Python (i.e. Pandas) give you a large number of nice, R-like dataframe manipulation methods, plus I believe the amount of extensions, and the "glue" libraries are either a higher quality, or more maintained (i.e. database connections, tooling, etc). Multithreading is not impossible, but must be careful about the Global Interpreter Lock. FWIW, the Pandas author built it at AQR and now works at 2sigma.

If you have a small team, Python is probably a safe option. If you come across an unavoidable bottleneck, it's often possible to write that portion in C, Fortran, or CUDA if you need to run calculations on a GPU.

I think a rough rule of thumb is that R > Python for raw 'data science' or stats, but Python > R for a long term, critical piece of production software.


Total Posts: 57
Joined: May 2010
Posted: 2017-03-20 04:49
Thank you all for the replies. Appreciate them.

Some details:
- currently everything is done based on BBG PORT/MARS functionality. Plus Excel for other ad-hoc stuff;
- risk team is 3 people with some experience in R and no expertise in other programming languages; we are not supported by developers or IT; relationship with the company is hopefully long term and don't think there will be new hires in the foreseeable future;
- the number of traded instruments is <100; so there shouldn't be any issues with R in terms of robustness and speed (I guess?).

As you can see, considering C++/Java/C# is not an option and whether it is worth spending time on learning Python is a big dilemma for us. And obviously, having some sort of automated system would be a lot better than nothing. That is why we were leaning towards R.

What we would like to have is (both at individual instruments and portfolio level):
1) portfolio breakdown - positions, weights, sectors, risk contribution/attribution, performance attribution;
2) a comprehensive risk measures -, VaR, ES, betas, drawdown measures, limits, correlation/covariance matrices;

As soon as we get these, we may try to include other fancy stuff - factor analysis, portfolio optimization, etc. What do you think? I would really appreciate if you could comment on what else could be included here.

Also, what resources would you recommend to get things started? I would appreciate if you could share names of the books and websites that might be of help.

Previous Thread :: Next Thread 
Page 1 of 1