• C++ Programming for Financial Engineering
    Highly recommended by thousands of MFE students. Covers essential C++ topics with applications to financial engineering. Learn more Join!
    Python for Finance with Intro to Data Science
    Gain practical understanding of Python to read, understand, and write professional Python code for your first day on the job. Learn more Join!
    An Intuition-Based Options Primer for FE
    Ideal for entry level positions interviews and graduate studies, specializing in options trading arbitrage and options valuation models. Learn more Join!

Switching from Matlab to C++

Joined
3/27/09
Messages
28
Points
11
I am fairly proficient in Matlab/R, but would like to gradually transition my research framework to C++ as a learning experience. My research involves mostly econometrics, multivariate time series, and portfolio optimization, i.e. more emphasis on portfolio management and less on pricing. The matrix-based framework embedded in Matlab/R makes a lot of these analyses a breeze.

I wonder if anyone has made similar transition and can comment on the most effective way to create a development framework that allows prototyping in C++ as rapidly as in Matlab/R. Are there some "standard" C++ libraries that people use to perform Matlab/R functions? Or is it necessary to create everything from scratch?
 
You are going to be under a lot of pain. You will hate it and what use to take you minutes or hours to finish will change to days and weeks. You will spend more time writing C++ than solving the problems.

In today's terms, there is no such a thing as prototyping in C++. Actually C++ is not meant to build prototypes but production systems by today's standards.

Good luck!! It might be easier to still use Matlab and R, and use C++ for bits and pieces that need some speed up after you have profiled your code.
 
I agree it's going to be a lot of pain, but the fact is that 90% of the quant research(not developer) job postings require C++, not Matlab. So it seems like they use C++ for both research and production. So I guess the pain is unavoidable. That's why I wonder whether there already exists some libraries that make research more friendly.
 
I agree - I've mainly used Matlab for the past 10 years, even though I originally started in C and C++, and am now relearning C++ for the same reasons. I always loved programming, but seemed confused by the existence of a plethora of languages out there, with new ones coming in all the time, and industrial demands for particular languages. And then each one just adds features from other languages it didn't have originally, making them even more "similar".

I liken the whole process to the electoral college - it makes sense historically (and industrially) speaking, but if we had to start over from scratch today, we'd create a much simpler system, maybe with 5 languages at the most, if not 1!
 
Get some numerical linear algebra lib.
I think you might like Eigen: http://eigen.tuxfamily.org/dox-devel/
A short ASCII reference with Matlab translations: http://eigen.tuxfamily.org/dox-devel/AsciiQuickReference.txt
Active and helpful community forum: http://forum.kde.org/viewforum.php?f=74

Blaze is perhaps worth looking into: http://code.google.com/p/blaze-lib/

Note that preferably you want to focus on the libraries that beat (or at least match up to) Intel MKL, since that's what MATLAB's relying on for its vectorized operations (of course you're going to easily beat it for the non-vectorized ones, but why settle for less), and it seems sub-optimal to use anything slower; that's also the reason I'm suggesting either Eigen or Blaze:
http://eigen.tuxfamily.org/index.php?title=Benchmark
http://code.google.com/p/blaze-lib/wiki/Benchmarks

// From the above benchmarks, the Armadillo+MKL combination doesn't look bad either, but note that you *must* get an external BLAS lib (like MKL), otherwise Armadillo is not going to be very useful or fast (it takes a different design approach, relying on an external optimized BLAS instead of providing optimized numerical linear algebra implementation itself -- discussing the relative merits & trade-offs is beyond the scope of this post, but be aware that what it means for the end-user (you) is that you need to get it separately & set it up):
http://arma.sourceforge.net/faq.html#dependencies

From what I can tell, the same is true for Blaze:
"Additionally, for maximum performance Blaze expects you to have a BLAS library installed (Intel MKL, ACML, Atlas, Goto, ...). If you don't have a BLAS library installed on your system, Blaze will still work and will not be reduced in functionality, but performance may be severely limited. Thus it is strongly recommended to install a BLAS library."
http://code.google.com/p/blaze-lib/wiki/Configuration_and_Installation

In contrast, Eigen is a standalone library, highly competitive with MKL on its own.

For more choices, see this thread:
http://www.wilmott.com/messageview.cfm?catid=44&threadid=87551

It's worth mentioning that recently the Numerical Template Toolbox (NT²) has restarted its development:
http://github.com/MetaScale/nt2
It's interesting, since "provide a simple, MATLAB-like interface for users" is one of the guiding goals.
For instance, it supports select-all-rows/columns operator (colon in MATLAB, underscore in NT2) and vectorized functions:
Code:
MATLAB: B = I(:,:,3); ...; V = min(abs(0.5.*R-0.419.*G-0.081.*B),240);
C++ w/NT2: B = I(_,_,3); ...; V = min(abs(0.5*R-0.419*G-0.081*B),240);
Presentation:
[PDF] https://github.com/boostcon/2010_presentations/raw/master/thu/falcou_lapreste_boostcon.pdf
[Video] http://blip.tv/boostcon/joel-falcou...ibrary-for-high-performance-computing-4204932
However, it's a relatively new (revision of the) library under active development, so for starters you may want to consider one of the aforementioned ones at first.
 
I agree it's going to be a lot of pain, but the fact is that 90% of the quant research(not developer) job postings require C++, not Matlab. So it seems like they use C++ for both research and production. So I guess the pain is unavoidable. That's why I wonder whether there already exists some libraries that make research more friendly.

I can tell you that today, they use C++ for production, very little use in research, too much of a pain.
 
One more thing, if you are going to learn C++, learn the new standard. It will make your life way easier.
 
I can tell you that today, they use C++ for production, very little use in research, too much of a pain.
No pain, no gain.

On the other hand, knowing a couple of languages (C#, Python) is useful. But knowing C++ means learning another language is relatively easy.
 
On the other hand, knowing a couple of languages (C#, Python) is useful. But knowing C++ means learning another language is relatively easy.

I agree. In fact, I used C++ extensively 10 years ago. It's just that Matlab/R make data analysis too convenient that my memory of C++ has been fading. Now I need to re-learn C++ to do the things that I can easily do in Matlab/R just because the demand for C++ quant is much higher than Matlab quant.
 
Just to add to the discussion, from an industry perspective (here in Canada), what I realised is that most of the firms that used C++ are HFT firms and this is mainly for speed reason. Here, on the buy side and mainly in the big pension funds, MATLAB/R/Python are the primary languages used in research since speed is not a real issue. I worked last summer in Market Risks and MATLAB was the language used by the team.

Since you seems to be more research oriented, I personal think a good way of learning C++ to start would be to interface MATLAB and C++ in some of your programs. It would make your life easier and the learning curve might not be as stepped.
 
Back
Top