Take the 2-minute tour ×
Quantitative Finance Stack Exchange is a question and answer site for finance professionals and academics. It's 100% free, no registration required.

I am about to implement a variation of the LIBOR-Market-Model (complete with Least-Square-Montecarlo, calibration, pricing etc.) and decided to implement it in C#.

The implementation will involve working with statistical data, numerical optimisation and monte carlo. Being fluent in R, C++, C# and Mathematica I usually distribute the workload among the platforms according to their strengths. Thus: Mathematica for optimization, R for statisical analysis and C#/C++ for brutforce montecarlo etc.

Last week I was given the task to create a distributable pricing-/risk-management-environment for the Libor-Market-Model that can be accessed via MS-Excel.

I opted for C# because it is very easy to interface with Excel via Excel-DNA (I did the interface with C++ once but it is no where as convenient as C#)

Thus I am looking for well documented solutions for:

  • statistics (for the estimation of a convariance matrix) - perhaps linking to R ?
  • numerics (rank reduction, matrix decomposition) - ALGLIB - is there an alternative ?
  • optimization ( for calibration - above all I need non-gradient methods)
  • visualisation (people from risk management usually like pretty graphs :) - C# has a charting environment. I have never used it before and do not know whether it is any good.

Also note: I am allowed to make a somewhat altered version of the code avaliable to the public. Thus it would be nice for the packages/add-ins to be avaliable for free for non commercial usage.

share|improve this question

2 Answers 2

up vote 6 down vote accepted

A popular open-source option for the numerics in .NET is Math.NET (https://github.com/mathnet/mathnet-numerics). It has both managed implementations and allows you to use the optimized MKL native libraries. This use of .NET as a front-end to an optimized native library is quite common.

Meta.Numerics (http://www.meta-numerics.net) is an alternative open-source library which is quite strong on various statistical distributions.

ILNumerics (http://ilnumerics.net/) is free or paid for, and gives a highly optimized managed numerics library - with performance that is comparable with C or Fortran, though not as fast as MKL. It also has rich visualization tools.

Extreme Optimization (http://www.extremeoptimization.com/) is a rich commercial library.

For linking to R, you'd use R.NET (https://rdotnet.codeplex.com/).

For charting (WinForms or WPF), OxyPlot (https://oxyplot.codeplex.com/) is a great open-source project. If you already use Excel as your substrate, you might rather use Excel's charting - you'll probably have a more coherent solution.

For optimization (and stuff like machine learning) you might consider Accord.NET (http://accord-framework.net/) (LGPL license). However, the built-in GRG solver in Excel is excellent if your problem fits. Constrained, non-linear, derivative-free optimization codes (some merged into Accord.NET) are discussed here: http://cureos.blogspot.com/2012/05/derivative-free-nonlinear-optimization.html .

Another optimization library is from Microsoft - the Microsoft Solver Foundation 3.1 now has a Nelder-Mead solver for nonlinear programming problems. While there is a matching Excel add-in for driving the Solver Foundation, you might also integrate it as worksheet functions using Excel-DNA. The licensing is a bit confusing though, and I'm not sure it's being actively developed any more.

As a final link, I'll add Dodoni.net (https://dodoni.codeplex.com/): "Dodoni.net is a free/open-source library with the aim to provide a framework for quantitative finance (pricing and risk management) as well as for general numerical methods (i.e. numerical integration, FFT, optimization etc.). The main idea is to construct a flexible and easy to use toolbox which is easy extendable by 3th party libraries." It includes native back-end bindings, and integration into Excel via Excel-DNA.

share|improve this answer
    
how well tested/peer reviewed is the accord-framework ? Also which package supports non-gradient (e.g. Nelder mead) optimization ? –  Probilitator Mar 3 at 7:17
1  
Accord.NET has a Nelder-Mead solver, as does Microsoft Solver Foundation. The COBYLA solver in Accord might also be a good fit for unconstrained problems. Not sure about the maturity of Accord.NET, but it is actively being worked on so any problems you report are likely to be fixed quickly. But the quality of any numerics code, on any language or platform, is a huge problem. The moment you move beyond something like MKL, you have to take responsibility for whatever code you use. Open-source helps a bit, and the alternative is an expensive contract with a supplier you trust. Math is hard. –  Govert Mar 3 at 12:02
    
it is hard indeed. As for the Nelder-Mead method - I looked into the documentation and could not find it. –  Probilitator Mar 3 at 12:28
    
Ah - sorry, looks like I was wrong about Nelder-Mead in Accord.NET. –  Govert Mar 3 at 13:47
    
Also, a good list of .NET math libraries was published on 'Using F# for Math and Statistics' page on fsharp.org. –  Sergey Tihon Mar 9 at 20:22

the usual suspects have .NET/C# bindings or implementations: IMSL, NAG

Another interesting alternative is the developers of Excel Solver add-in. They have an advanced package way beyond Excel's add-in. Do I recommend it? Of course, not, but it's an option nevertheless.

I would forget C#, and use a proper binary libraray, tried and tested, anything from BLAS to GSL. In the end you're using Excel, it's a binary code, so there's no point in using VM-based solutions.

UPDATE: The reasons why I recommend binary library:

  • it's always better to use the library which is popular, because that way it has a lesser chance of containing an error. imagine the matrix inversion code written in Fortran, which was in use since '60s. what is a chance of a serious error in it? everyone knows how they behave. so you take the binary code of this library, and pretty much guarantee that it has no bugs. who writes numerical code in C#?! very few people. basically, nobody. what's the point? it'll work only on Windows, and scientists use all sorts of hardware, most of it on Unix flavors.
  • if you were writing pure .NET app, then it makes a sense to at least consider a library written in C#, because that would be native to its host platform. you're developing Excel app, which is a binary application. connecting to VM-executed code brings no advantages, and potentially introduces problems, e.g. with performance
share|improve this answer
    
+1 for I have't been aware of IMSL before. I thought about using ALGLIB. What is the adventage in using a binary library? –  Probilitator Mar 2 at 17:08
    
I haven't used IMSL in awhile, but it used to be one of my favorite libraries in '90s, when it came with sources in FORTRAN. these days they have bindings to several languages, but stopped shipping the source codes –  Aksakal Mar 3 at 15:43
    
"Do I recommend it? Of course, not" -- you need to explain why not. –  Dmitri Nesteruk Mar 10 at 7:14
    
@DmitriNesteruk, I don't recommend it because I don't think it's very popular. I don't trust packages, which are not widely used –  Aksakal Mar 10 at 20:55
    
@Aksakal the Excel solver is rather widely used by those who need quick-and-dirty optimization. –  Dmitri Nesteruk Mar 12 at 10:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.