Skip to content
All library documents

Choosing Between Reusing R PerformanceAnalytics and Building C# Tools

Article Quant Q&A · Author: Matt Wolf

Summary

The discussion asks whether a C#/.NET library can provide financial performance analytics comparable to R’s PerformanceAnalytics, including return statistics, drawdowns, risk-adjusted returns, and trade measures such as MAE and MFE. One response points to using the established R package through a remote R service or a queued worker, with Redis suggested as a way to pass jobs to R while keeping the systems loosely coupled.

The questioner reports trying that direction but choosing to build a smaller library tailored to their needs on top of a math and statistics library. They cite a need for sliding lookback windows, custom distribution assumptions, and risk-adjusted-return formulas suited to very short holding periods. The exchange favors reuse of a mature package where practical, while recognizing integration friction and specialized requirements as reasons to develop a focused alternative. It offers architectural suggestions and personal experience, not a comparative benchmark, implementation guide, or evaluation of specific C# libraries.

Key ideas

  • Performance analytics for trading includes drawdowns, risk-adjusted returns, return distributions, and trade-level measures such as MAE and MFE.
  • An established analytics package can be accessed from another language through a remote service or a job queue.
  • A queued R worker can provide loose coupling between a C# application and R analytics.
  • Specialized attribution metrics and assumptions may justify a smaller custom library built on general math and statistics tools.

Tags

Full text
# Looking for C# library that provides/contains performance analytics


# Looking for C# library that provides/contains performance analytics












I am looking for a C# .Net library that provides trade performance analytics similar to R-PerformanceAnalytics. Basic return statistics, draw-downs, risk-adjusted returns, risk (variations), distributional analytics,...

I checked all the general Math/Stats C# libraries and I can certainly whip up analytics from several such libraries but something that covers more specific financial asset return analysis did not come across my search.

Even basic trade analytics such as risk/reward, MAR, MAE/MFE, drawdowns would be helpful, just to generate some quick stats for a side-project.

Edit: I am not interested in a R solution as I am already aware of the R PerformanceAnalytics package. I am looking for a C# library, commercial or open-source.

Thanks

## Answer by Matt Wolf (score 1, accepted)

https://quant.stackexchange.com/a/11335

Long story short, thanks to Dirk Eddelbuettel's suggestion I played a bit with rredis and indeed it offers quite a number interesting solutions.

However, I still decided to start to write my own performance analytics library (albeit obviously smaller and more specific to my use case) in combination with an established Math/Stats library because I need more fine-grained performance attribution metrics, such as sliding lookback windows, custom distributional assumptions, different formulaic approach to measuring risk-adjusted returns for trades of extremely short holding periods...

Having delved a bit more into parallel execution in R and understanding how to run several R sessions on a single machine or in distributed fashion explains why there is no real need/demand to equip a single R session with multithreaded capabilities. Credits to Dirk and his pointing me into the rredis and indirectly to the distributed workload processing direction in R. I so far heavily rely on a fully customized research platform and Matlab and thus have not done a whole lot with R. I left when R still could not handle larger datasets and when there was no 64-bit version available (at least not for Windows), which kind of defeated the whole purpose to peruse a statistical computing platform from the start (at least for someone working with larger time series data). Obviously, quite a number of things have changed and it is interesting to see the explosion in growth of use cases and packages such as adapters that connect R with various data stores, other libraries, languages, ...

## Answer by Dirk Eddelbuettel (score 3)

https://quant.stackexchange.com/a/11272

The PerformanceAnalytics library reflects several years worth of development by Brian Peterson and Peter Carl, as well as multiple collaborators. It is fairly widely used, tested and debugged.

Basic software engineering practices suggest that you should strive to re-use it if possible. Options for that include

- accessing a remote R instance via RServe (though you may be unhappy with the state of RServe clients on Windows / C# as per your comments)

- accessing a remote R instance via a RESTful service such as OpenCPU

- placing your jobs on a queue (for which I like Redis) and having the R worker pick'em up from the queue via rredis

The last option is the loosest coupling and may be easiest to test. I would rather go down any of these routes than trying to rewrite PerformanceAnalytics. Don't forget that the package itself has dependencies you may have to port as well.

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.