Serving the Quantitative Finance Community

 
User avatar
OOglesby
Posts: 1
Joined: August 26th, 2011, 5:34 am

algorithms, numerical differentiation

November 16th, 2011, 12:45 am

With regards to the coding standards, much of your comments were due to laziness for composing the message. The primary violation is with the variable names. My actual code ensures const and passing by reference.I fully agree about the compile time computation and sizes. I have a paper that uses a recurrence relation for computing the coefficients. Unfortunately, it computes a table of the coefficients from derivative 0 to derivative M, where M is input by the user. This results in needing an array that is Nx(M + 1) elements. I should be able to create a recursive compile time definition once I understand the paper. One problem with calculating the weights by hand is you have to know a priori the number of points to the left and right as well as the step between the points. I strongly suspect that I am going need your bindings for implementing a fairly general compile time solution.Right now, I am ignoring all of that so I can get an initial version coded and tested. For now, if the grid spacing does not change dynamically, the user will be able to calculate the weights once then repeatedly apply those weights to the grid points as needed.
 
User avatar
OOglesby
Posts: 1
Joined: August 26th, 2011, 5:34 am

algorithms, numerical differentiation

November 21st, 2011, 1:33 am

Here is version 0 of the finite difference code. It includes simple functions for central, forward, and backward for an equally spaced grid up to the 3rd derivative. There is additional code for computing a table of finite difference coefficients for a general N-point grid for derivatives 0 to M, where M is specified by the user. The general finite difference code still needs work and a version that is simplified for equally spaced points.I could not figure out how to post the code to the sandbox or the donations tree. If somebody could direct me to instructions or PM me with the information, I would be greatful. Suggestions, requests, or improvements are welcome.
Attachments
finite_difference.zip
(12.94 KiB) Downloaded 119 times
 
User avatar
rmax
Posts: 374
Joined: December 8th, 2005, 9:31 am

algorithms, numerical differentiation

November 21st, 2011, 8:37 am

WOW, the first piece of published code. I like the fact you have included the units tests in there. Nice touch.Do you have documentation to match as to how to use?
 
User avatar
Cuchulainn
Posts: 22924
Joined: July 16th, 2004, 7:38 am

algorithms, numerical differentiation

November 21st, 2011, 11:47 am

Had a kick at the tyres Looks good.Here are 5 scenarios (using C++ lambda, auto, Boost function and bind). Lambda is particiularly for tests as it generates the function objects for you. And boost function can be assigned to anything.Your code can be used 'as is' for func(x,y), thanks to functional programming model. f_x, f_y etc.What if you want (f_x)_y? Boost bind.
Attachments
NumericalDifferentiation.zip
(2.01 KiB) Downloaded 117 times
Last edited by Cuchulainn on November 20th, 2011, 11:00 pm, edited 1 time in total.
 
User avatar
Cuchulainn
Posts: 22924
Joined: July 16th, 2004, 7:38 am

algorithms, numerical differentiation

November 21st, 2011, 1:34 pm

Last edited by Cuchulainn on November 20th, 2011, 11:00 pm, edited 1 time in total.