Login  Register

Market Models, TODOs, scripting

Posted by Roland Lichters-2 on Nov 19, 2006; 7:23pm
URL: http://quantlib.414.s1.nabble.com/Market-Models-TODOs-scripting-tp11365.html

Hello Market Model team,

I have read the TODOs in the Market Models section and saw the item on
scripting, specify new payoffs "without code recompilation".

I am not sure whether this helps in this exercise - I came across a
free/open mathematical expression parser written by Yann Ollivier
(http://www.eleves.ens.fr/home/ollivier), wrapped and  used it with
some minor extensions so that it understands max, min, step functions
in addition to the bulk that Yann had already coded. For example, I
evaluate formulas as follows:

...

#define LENGTH(a) (sizeof(a)/sizeof(a[0]))

string name[]  = { "a", "b", "c" };
double value[] = {  1,   2,   3 };

string formula = "sqrt (max (step(5a-10) + min(3b, 4c), 0)) * 15";

 vector<string> variableNames;
 vector<double> variableValues;
 for (int i = 0; i < LENGTH(name); i++) {
    variableNames.push_back(name[i]);
    variableValues.push_back(value[i]);
  }

Formula form (formula, variableNames, variableValues);

cout << "formula = " << formula << " = " << form.eval() << endl;

... and changing the variableValue vector after creating the formula
object allows revaluing the formula with the amended variable input,
calling form.eval() again. That might be useful, not only for the
Market Models.

Yann's license is currently not compatible with the QuantLib license,
as far as I understand - he does not allow selling the code unless one
contacts him. Maybe he is willing to change the license if you are
interested in including his code or a modified version of it in the
library?

Regards,
Roland