Vietnam Quantitative Finance Society

User Name
Password
Reply
09-05-2007, 11:05 PM   #1
learner

Member
No Avatar
 
Join Date: Sep 2007
Posts: 9
Thanks: 3
Thanked 0 Times in 0 Posts




Default Numerics in C++

Em đang lấy một lớp numerical methods in finance, yêu cầu phải lập trình bằng C++ mà em trước giờ chưa bao giờ lập trình numerics với C++ nên hơi lúng túng. Mong các anh chị ở đây giúp em mấy câu hỏi sau.

Mọi người dùng numerics library nào để tìm roots of polynomials, matrix multiplication, solving linear systems, ... và để plot đồ thị (2D,3D)?

Em đang có homework implementing an implicit finite difference scheme. Toán thì đơn giản nhưng em không biết dùng cái gì để tìm roots và dùng cái gì để plot .
learner is offline Reply With Quote
09-06-2007, 03:33 AM   #2
Khoa Tran

Core Member
Master Sergeant
 
Khoa Tran's Avatar
 
Join Date: Jun 2007
Posts: 211
Thanks: 28
Thanked 19 Times in 16 Posts




Default

Holy cow, I'm facing a similar situation. Years of no Java/C++ programming have transformed me to a programming illiterate .

Regarding C++ numerics libraries, there are tons available for free. I choose GSL - GNU Scientific Library for standard numerical methods (you mentioned some). Whenever it comes to plotting, many of my friends use Matlab to read the data file and then plot. But you have raised a good question. I'm also interested in knowing how quants code. Let me post a follow-up question:

I know that we can call C++ routines directly from Matlab, i.e. you don't have to export data files and then read them from Matlab. Anyone having experience with this?
Khoa Tran is offline Reply With Quote
09-06-2007, 05:18 AM   #3
dryland

Member
No Avatar
 
Join Date: Aug 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts




Default

To Khoa: That's correct, you can call C++ exported functions (in a dll) from Matlab; but doing it isn't exactly easy. First, you have to create a .mex file in Matlab to act as an interface to call those functions in the dll. Also, all the parameters have to be marshaled to match those in C++.

Basically, it's a mess. I don't recommend anyone doing this way unless you really really need the speed of C++ code when running time-consuming algorithms.

However, my experiences were with Matlab 6.5 around 3 years ago. I don't know if they make the process any easier with the new version now. If not, plain data file is still the way to go. Good luck.
dryland is offline Reply With Quote
09-06-2007, 08:48 PM   #4
learner

Member
No Avatar
 
Join Date: Sep 2007
Posts: 9
Thanks: 3
Thanked 0 Times in 0 Posts




Default

Quote:
Originally Posted by Khoa Tran View Post
Regarding C++ numerics libraries, there are tons available for free. I choose GSL - GNU Scientific Library for standard numerical methods (you mentioned some).
Thanks. I've tried this library and realized that they also link with some other standard libraries like CBLAS.
learner is offline Reply With Quote
09-06-2007, 08:59 PM   #5
nguyenxuanson

Core Member
Corporal
No Avatar
 
Join Date: Aug 2007
Posts: 58
Thanks: 1
Thanked 1 Time in 1 Post




Default

http://gnuwin32.sourceforge.net/packages/gsl.htm
you can compile and link it with out CBLAS.

to plot, try to export data to a text file and use http://matplotlib.sourceforge.net/

for testing ideas, python is a quite good, you have lot of math functions.

SOn
nguyenxuanson is offline Reply With Quote
09-07-2007, 11:32 PM   #6
Khoa Tran

Core Member
Master Sergeant
 
Khoa Tran's Avatar
 
Join Date: Jun 2007
Posts: 211
Thanks: 28
Thanked 19 Times in 16 Posts




Default

During the debugging phase, exporting data and plotting it from another application many times can be annoying. Using a plotting library seems a better approach here. The initial cost may be hight but then it costs you none when debugging and very little for coding another project.

Hey, I've tried googling "C++ plot". The first link's library looks pretty simple to use.
Khoa Tran is offline Reply With Quote
09-08-2007, 07:13 AM   #7
learner

Member
No Avatar
 
Join Date: Sep 2007
Posts: 9
Thanks: 3
Thanked 0 Times in 0 Posts




Default

That plot library is actually crap. It has its own console and IDE. You need to complile your program either in that console or in that IDE if you want to use the library.

I did like anh Son said: export the data file and plot in GNU Plot.

Thanks all for your help.
learner is offline Reply With Quote
09-13-2007, 10:55 AM   #8
Khoa Tran

Core Member
Master Sergeant
 
Khoa Tran's Avatar
 
Join Date: Jun 2007
Posts: 211
Thanks: 28
Thanked 19 Times in 16 Posts




Default

I've recently put my hands in.

1. Scientific Library: my Linux server already has GSL installed and I haven't had any problem of using it.

I've recently tried installing GSL for Cygwin (my laptop runs on Windows). Compiling, linking, and running in the Cygwin shell is ok. However, it's much more annoying to do it in Windows (because of the path environment difference: you may need to copy some libraries dll files to the project directory or specify an LD path somehow.)

2. For plotting purpose, PGPlot (thanks to hntuyen) is a decent one (for the sake of plotting during the debugging phase). Installing PGPlot and using it are fairly easy in Linux. However, doing so in Cygwin is quite problematic. My friend (hntuyen) and I spent a couple of hours yesterday trying to make the installation work (you may need to install more modules for Cygwin such as XWindow library, etc. to support the plotting drivers).

Even so, since PGPlot relies on XWindow (which is different from the graphics engine by Windows), you can only compile and run the program in Cygwin. This is very annoying, particularly if you use an IDE (like Eclipse) and code in Windows. Exporting data and plotting on a second party application is even better in this case.


So my take-away is that if you program in C++, do it in Linux. (Or use Visual Studio. As I don't use and don't intend to use Visual Studio, I have no comment on it.)
Khoa Tran is offline Reply With Quote
The Following User Says Thank You to Khoa Tran For This Useful Post:
learner (09-14-2007)
09-13-2007, 08:22 PM   #9
nguyenxuanson

Core Member
Corporal
No Avatar
 
Join Date: Aug 2007
Posts: 58
Thanks: 1
Thanked 1 Time in 1 Post




Default

hi Khoa
do you know how to set up Eclipse as an IDE for C++ on Windows(either use gcc in cygwin or Visual C++ compiler).

Son
nguyenxuanson is offline Reply With Quote
09-14-2007, 01:00 PM   #10
Khoa Tran

Core Member
Master Sergeant
 
Khoa Tran's Avatar
 
Join Date: Jun 2007
Posts: 211
Thanks: 28
Thanked 19 Times in 16 Posts




Default

Anh Son,

Setting up Eclipse is pretty easy. If you haven't had Eclipse, download Eclipse IDE for C/C++ Developers here. If you already had Eclipse (for Java, etc.) and would like to add the Eclipse CDT (C/C++ Development Toolkit), download it here. Extract the compressed file to any place you want and that's it: no need to run any installation.

When you first run Eclipse CDT, it will ask if you want to use either Cygwin or MinGW as the compiler. Visual C++ compiler is not officially supported here. Although you can create a make file manually to call the Visual C++ compiler, you still need "make.exe", which is not in the definition of Visual S.

I know at least a few members here that are Eclipse experts. Feel free to ask if you have any specific question about it. The best manuals are of course by Google and www.eclipse.org
Khoa Tran is offline Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Save or bookmark this site with: Del.icio.usStumble It!AddThis.com
All times are GMT +7. The time now is 01:28 AM.
Powered by vBulletin Version 3.7.2