• 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!

C# Pricing options using the finite difference method

Joined
4/14/12
Messages
5
Points
11
Hello there

I'm currently developing a toolbox that enables comparison of options pricing using Black&Scholes, binominal tree and finit difference method. I have Black&Scholes and binominal tree so far, but I'm kinda struggling with the finit difference method. Has anyone already implemented this method and has sample code?

Thanks in advance.

Cheers
Fabian
 
How is the performance? A couple of people at uni told me that MatLab would be more suitable. C# would cause memory problems when solving the thousands of matrix operations. Any experience with that?
 
Thanks for your prompt responses. You are of great help.
I just downloaded the zip on https://www.quantnet.com/code-for-financial-engineering-study/ and tried to start the solution. I'm using VS2010 and get the following error:
Error 1 error C1083: Cannot open source file: '..\..\..\..\..\Fall 2006\9815\Matrix\MainProg.cpp': No such file or directory ..\Desktop\Quantnet.com-C++code-for-Financial-Engineering-Students\Matrix\c1xx Matrix

I'm a doing anything wrong or are there any prerequisites?
 
Thanks for your prompt responses. You are of great help.
I just downloaded the zip on https://www.quantnet.com/code-for-financial-engineering-study/ and tried to start the solution. I'm using VS2010 and get the following error:
Error 1 error C1083: Cannot open source file: '..\..\..\..\..\Fall 2006\9815\Matrix\MainProg.cpp': No such file or directory ..\Desktop\Quantnet.com-C++code-for-Financial-Engineering-Students\Matrix\c1xx Matrix

I'm a doing anything wrong or are there any prerequisites?

Looks like the project folder path from Andy's Fall 2006 workstation was included in the solution config.

On Visual Studio leftclick on the file and look at the Properties window. You can see a 'Relative Path' property which has a value like "..\..\..\..\..\..\Fall 2006\9815\Matrix\FiniteDifference.cpp". Just change this to "./FiniteDifference.cpp" and you'll be able to view the file on VS.

Some of the project files like MainProg.cpp aren't included in the zip file though. But I guess you can write your own tester class.
 
How is the performance? A couple of people at uni told me that MatLab would be more suitable. C# would cause memory problems when solving the thousands of matrix operations. Any experience with that?

Can you explain???

C# for FDM is fine as fast as C++.

On source, see forthcoming book German+Duffy.

http://www.amazon.co.uk/Financial-Markets-Wiley-Finance-Series/dp/0470030089

//
AFAIK, Matlab is not suitable for PDE, at all or when you need mucho memory. But maybe I'm wrong.
 
Hello there

I'm currently developing a toolbox that enables comparison of options pricing using Black&Scholes, binominal tree and finit difference method. I have Black&Scholes and binominal tree so far, but I'm kinda struggling with the finit difference method. Has anyone already implemented this method and has sample code?

Thanks in advance.

Cheers
Fabian

Another, relatively easy project (plan B) is to port C++ FDM code to C#.
BTW are you creating code from scratch or is it a question of posting others' code into the toolbox?
 
I have implementend the Crank Nicolson method and it takes like 5s in MatLab (1000 steps) and 1.5min in C#. Maybe MatLab has some default optimization when using matrix, as Andy might have noticed as well.

Even though the toolbox is for my sole usage, I want to understand it and therefore just look at a finished code and see how it is done. I want to do it by myself from scratch afterwards.
 
1.5 minutes for CN in C# does not look right. It should be << 1 second.
What matrix structure do you use and how is LU implemented? I hope you don't us dense matrices?

I use ADE code in C# and it is even faster than C++ code. But I don't need to invert matrices.

On a more general remark, Crank Nicolson is not a 'good' scheme in a sense that can be quantified. This is well-known.

http://www.wilmott.com/pdfs/071203_duffy.pdf
 
How is the performance? A couple of people at uni told me that MatLab would be more suitable. C# would cause memory problems when solving the thousands of matrix operations. Any experience with that?

I'm no expert, but I understand most FDS guys use a compiled language like C++ or Fortran for the exact reason that it is MUCH faster and efficient than MATLAB with FDS problems.
 
I'm no expert, but I understand most FDS guys use a compiled language like C++ or Fortran for the exact reason that it is MUCH faster and efficient than MATLAB with FDS problems.
Matlab is generally optimized for matrix/vector operations as overhead in such cases are negligible.On the other hand things like running multiple for loops etc isn't something that you would like to do using Matlab.That's why i think people recommend using Matlab where your data can be vectorized and in this case its possible.
 
Not sure if this adds to the discussion.
Afaik, running a C++ executable on .Net Managed Code environment will be slow compared to in other environments, like un-managed, ?nix, etc.
 
Back
Top