Serving the Quantitative Finance Community

• 1
• 2

Cuchulainn
Posts: 64971
Joined: July 16th, 2004, 7:38 am
Location: Drosophila melanogaster
Contact:

### No new C++ until 2010, no concepts

QuoteModules directly address a problem (scalability) listed as one of the three major areas where C++17 is expected to significantly improve daily experience of the working C++ programmerModules and top-down decompositions is good. It allows a *direct* mapping to C++.
Last edited by Cuchulainn on November 3rd, 2015, 11:00 pm, edited 1 time in total.
"Compatibility means deliberately repeating other people's mistakes."
David Wheeler

http://www.datasimfinancial.com
http://www.datasim.nl

Cuchulainn
Posts: 64971
Joined: July 16th, 2004, 7:38 am
Location: Drosophila melanogaster
Contact:

### No new C++ until 2010, no concepts

Here is the same prototype in C#.
"Compatibility means deliberately repeating other people's mistakes."
David Wheeler

http://www.datasimfinancial.com
http://www.datasim.nl

Cuchulainn
Posts: 64971
Joined: July 16th, 2004, 7:38 am
Location: Drosophila melanogaster
Contact:

### Re: No new C++ until 2010, no concepts

Introducing Concepts -- http://accu.org/index.php/journals/2157 -- Concepts in C++11 had many false starts. Andrew Sutton show why they are a big deal now they are with us. by Andrew SuttonAn Inline-variant-visitor with C++ Concepts -- http://accu.org/index.php/journals/2160 -- Concepts are abstract. Jonathan Coe and Andrew Sutton provide us with a concrete example of their use.
Concepts and constraints in C++20 work .. I have just redesigned the Gamma GOF patterns using them. Goodbye GOF, really.
"Compatibility means deliberately repeating other people's mistakes."
David Wheeler

http://www.datasimfinancial.com
http://www.datasim.nl

Cuchulainn
Posts: 64971
Joined: July 16th, 2004, 7:38 am
Location: Drosophila melanogaster
Contact:

### Re: No new C++ until 2010, no concepts

// Test101Concepts.cpp
//
// Simplest example of a system. Context diagram consists only
// of Input and Output systems.
//
// We use C++20 Concepts to replace policy-based design
//
// Composition
//
//  V2: design using C++20 modules
//
// (C) Datasim Education BV 2015-2021
//

#include <string>
#include <iostream>

// Interface contract specification
template<typename T>
concept IInput = requires (T x) { x.message(); };

template<typename T>
concept IOutput = requires (T x, const std::string& s) { x.print(s); };

// I/O stuff
template <typename I, typename O> requires IInput<I> && IOutput<O>
class SUD
{ // System under discussion, using composition

private:
I i;
O o;
public:
SUD(const I& input, const O& output) : i(input), o(output) {}
void run()
{
o.print(i.message());
}
};

// Instance Systems
class Input
{
public:

std::string message() const
{
// Get data from hardware device
return std::string("Good morning");
}

};

class Output
{
public:

void print(const std::string& s) const
{
std::cout << s << std::endl;
}

};

int main()
{
Input i; Output o;
SUD<Input, Output> s(i,o);
s.run();

return 0;
}

"Compatibility means deliberately repeating other people's mistakes."
David Wheeler

http://www.datasimfinancial.com
http://www.datasim.nl

bearish
Posts: 6626
Joined: February 3rd, 2011, 2:19 pm

### Re: No new C++ until 2010, no concepts

Ah - that clears it right up! I promise to do all my PDE work in C++20 from now on.

Cuchulainn
Posts: 64971
Joined: July 16th, 2004, 7:38 am
Location: Drosophila melanogaster
Contact:

### Re: No new C++ until 2010, no concepts

Ah - that clears it right up! I promise to do all my PDE work in C++20 from now on.
A very perceptive insight! Concepts are a big deal and quant developers need to reject Rand's Objectivist Epistemology mindset that has polluted mainstream software development in the last 35 years.

1. What are Concepts?
2. How do I use them?
3. How do I apply them? (the process )

the step 2->3 is a yuge leap of cognition, it could be a bridge too far..
"Good Heavens! For more than forty years I have been speaking prose without knowing it."

Watch this space.
"Compatibility means deliberately repeating other people's mistakes."
David Wheeler

http://www.datasimfinancial.com
http://www.datasim.nl

Cuchulainn
Posts: 64971
Joined: July 16th, 2004, 7:38 am
Location: Drosophila melanogaster
Contact:

### Re: No new C++ until 2010, no concepts

Don't tell anyone but this is the Bridge pattern anno 2021.
// Interface contract specification
template<typename T, typename Data>
concept IDiffusion = requires (T c, Data t, Data x) { c.diffusion(t,x); };

template<typename T, typename Data>
concept IDrift = requires (T c, Data t, Data x) { c.drift(t, x); };

template<typename T, typename Data>
concept IDriftDiffusion = IDiffusion<T, Data> && IDrift<T, Data>;

template <typename T, typename Data> requires IDriftDiffusion<T, Data>
class SUD
{ // System under discussion, using composition
// Really a Bridge pattern

private:
T _t;
public:
SUD(const T& t) : _t(t) {}
Data diffusion(Data t, Data x)
{
return _t.diffusion(t, x);
}
Data drift(Data t, Data x)
{
return _t.drift(t, x);
}

};
"Compatibility means deliberately repeating other people's mistakes."
David Wheeler

http://www.datasimfinancial.com
http://www.datasim.nl

Cuchulainn
Posts: 64971
Joined: July 16th, 2004, 7:38 am
Location: Drosophila melanogaster
Contact:

### Re: No new C++ until 2010, no concepts

Ah - that clears it right up! I promise to do all my PDE work in C++20 from now on.
Have a look at the SDE/GBM model I just posted. For a PDE, just add a reaction term. Ups-a-daisy.
"Compatibility means deliberately repeating other people's mistakes."
David Wheeler

http://www.datasimfinancial.com
http://www.datasim.nl

Cuchulainn
Posts: 64971
Joined: July 16th, 2004, 7:38 am
Location: Drosophila melanogaster
Contact:

### Re: No new C++ until 2010, no concepts

Concepts and this (?)

A final remark on the relative merits of producing analytical solutions versus defining a finite difference framework that subsumes and supports a range of pdes sharing similar structure and functionality: in the former case each new specific option type will need its own specific formula (at great expense in human resource terms and in terms of the origination and testing of analytical option pricing formulae). Reusability of the algorithm and of code is not guaranteed and the algorithm may place restrictions on the parameters if it is to converge. Furthermore, the accuracy is fixed (and cannot be measure a priori) and it is usually not possible to customise the algorithm to suit difference performance needs. For example, it is difficult to customise the algorithm that produces six-digit accuracy to produce results to two-digit accuracy. In the latter case (using finite differences) we only need to set up a flexible software framework once and then it can be instantiated for specific types, for example spread options. A priori accuracy is determined by the mesh sizes. This usually involves nothing more than using a different payoff function with no modification of the rest of the code being needed. This is the stage in which we can apply software design patterns to achieve this desired level of flexibility. Finally, the framework can even be used for problems for which an analytical solution is not forthcoming.
"Compatibility means deliberately repeating other people's mistakes."
David Wheeler

http://www.datasimfinancial.com
http://www.datasim.nl