понедельник, 8 ноября 2021 г.

MathLib, Projects, BlackModel, BlackScholesModel, Cpp,C++

extern "C" MATHLIB_API class BlackScholesModel

    {

    public:

        MATHLIB_API static double premium_call(double S, double K, double T, double sigma, double r, double q);

        MATHLIB_API static double premium_put(double S, double K, double T, double sigma, double r, double q);

        MATHLIB_API static double delta_call(double S, double K, double T, double sigma, double r, double q);

        MATHLIB_API static double delta_put(double S, double K, double T, double sigma, double r, double q);

        MATHLIB_API static double vega(double S, double K, double T, double sigma, double r, double q);

        MATHLIB_API static double theta_call(double S, double K, double T, double sigma, double r, double q);

        MATHLIB_API static double theta_put(double S, double K, double T, double sigma, double r, double q);

    MATHLIB_API static double gamma(double S, double K, double T, double sigma, double r, double q);

        MATHLIB_API static double d1(double S, double K, double T, double sigma, double r, double q);

        MATHLIB_API static double d2(double T, double sigma, double d1);

    };

    extern "C" MATHLIB_API class BlackModel

    {

    public:

        MATHLIB_API static double d1(double F, double K, double T, double sigma);

        MATHLIB_API static double d2(double F, double K, double T, double sigma);

        MATHLIB_API static double d2(double T, double sigma, double d1);

        MATHLIB_API static double premium_call(double F, double K, double T, double sigma, double r);

        MATHLIB_API static double premium_put(double F, double K, double T, double sigma,  double r);

        MATHLIB_API static double delta_call(double F, double K, double T, double sigma, double r);

        MATHLIB_API static double delta_put(double F, double K, double T, double sigma, double r);

        MATHLIB_API static double vega(double F, double K, double T, double sigma, double r);

        MATHLIB_API static double vega_test(double F, double K, double T, double sigma, double r);

        MATHLIB_API static double theta_call(double F, double K, double T, double sigma, double r);

        MATHLIB_API static double theta_put(double F, double K, double T, double sigma, double r);

        MATHLIB_API static double rho_call(double F, double K, double T, double sigma, double r);

        MATHLIB_API static double rho_put(double F, double K, double T, double sigma, double r);

        MATHLIB_API static double gamma(double F, double K, double T, double sigma, double r);

        MATHLIB_API static double gamma_test(double F, double K, double T, double sigma, double r);

        MATHLIB_API static double vanna(double F, double K, double T, double sigma, double r);

        MATHLIB_API static double vanna_test(double F, double K, double T, double sigma, double r);

        MATHLIB_API static double vomma(double F, double K, double T, double sigma, double r);

        MATHLIB_API static double vomma_test(double F, double K, double T, double sigma, double r);

    };

BlackModel: Rho from BlackScholesModel to be uptodate with Quik

суббота, 6 ноября 2021 г.

Lambda, Projects, Cpp, C++

https://docs.microsoft.com/ru-ru/cpp/cpp/lambda-expressions-in-cpp?view=msvc-160

https://en.cppreference.com/w/cpp/language/lambda



[&total, factor]
[factor, &total]
[&, factor]
[factor, &]
[=, &total]
[&total, =]






#include <algorithm>
#include <cmath>

void abssort(float* x, unsigned n) {
    std::sort(x, x + n,
        // Lambda expression begins
        [](float a, float b) {
            return (std::abs(a) < std::abs(b));
        } // end of lambda expression
    );
}

struct S { void f(int i); };

void S::f(int i) {
    [&, i]{};      // OK
    [&, &i]{};     // ERROR: i preceded by & when & is the default
    [=, this]{};   // ERROR: this when = is the default
    [=, *this]{ }; // OK: captures this by value. See below.
    [i, i]{};      // ERROR: i repeated
}

template<class... Args>
void f(Args... args) {
    auto x = [args...] { return g(args...); };
    x();
}

pNums = make_unique<vector<int>>(nums);
//...
      auto a = [ptr = move(pNums)]()
        {
           // use ptr
        };

auto y = [] (int first, int second)
{
    return first + second;
};

auto y = [] (auto first, auto second)
{
    return first + second;
};

// throw_lambda_expression.cpp
// compile with: /W4 /EHsc
int main() // C4297 expected
{
   []() noexcept { throw 5; }();
}

auto x1 = [](int i){ return i; }; // OK: return type is int
auto x2 = []{ return{ 1, 2 }; };  // ERROR: return type is void, deducing
                                  // return type from braced-init-list isn't valid

// captures_lambda_expression.cpp
// compile with: /W4 /EHsc
#include <iostream>
using namespace std;

int main()
{
   int m = 0;
   int n = 0;
   [&, n] (int a) mutable { m = ++n + a; }(4);
   cout << m << endl << n << endl;
}

void fillVector(vector<int>& v)
{
    // A local static variable.
    static int nextValue = 1;

    // The lambda expression that appears in the following call to
    // the generate function modifies and uses the local static
    // variable nextValue.
    generate(v.begin(), v.end(), [] { return nextValue++; });
    //WARNING: this isn't thread-safe and is shown for illustration only
}

// compile with: /W4 /EHsc
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

template <typename C> void print(const string& s, const C& c) {
    cout << s;

    for (const auto& e : c) {
        cout << e << " ";
    }

    cout << endl;
}

void fillVector(vector<int>& v)
{
    // A local static variable.
    static int nextValue = 1;

    // The lambda expression that appears in the following call to
    // the generate function modifies and uses the local static
    // variable nextValue.
    generate(v.begin(), v.end(), [] { return nextValue++; });
    //WARNING: this isn't thread-safe and is shown for illustration only
}

int main()
{
    // The number of elements in the vector.
    const int elementCount = 9;

    // Create a vector object with each element set to 1.
    vector<int> v(elementCount, 1);

    // These variables hold the previous two elements of the vector.
    int x = 1;
    int y = 1;

    // Sets each element in the vector to the sum of the
    // previous two elements.
    generate_n(v.begin() + 2,
        elementCount - 2,
        [=]() mutable throw() -> int { // lambda is the 3rd parameter
        // Generate current value.
        int n = x + y;
        // Update previous two values.
        x = y;
        y = n;
        return n;
    });
    print("vector v after call to generate_n() with lambda: ", v);

    // Print the local variables x and y.
    // The values of x and y hold their initial values because
    // they are captured by value.
    cout << "x: " << x << " y: " << y << endl;

    // Fill the vector with a sequence of numbers
    fillVector(v);
    print("vector v after 1st call to fillVector(): ", v);
    // Fill the vector with the next sequence of numbers
    fillVector(v);
    print("vector v after 2nd call to fillVector(): ", v);
}

int y = 32;
    auto answer = [y]() constexpr
    {
        int x = 10;
        return y + x;
    };

    constexpr int Increment(int n)
    {
        return [n] { return n + 1; }();
    }

auto answer = [](int n)
    {
        return 32 + n;
    };

    constexpr int response = answer(10);


auto Sqr = [](int t) __declspec(code_seg("PagedMem")) -> int { return t*t; };

SharedPtr, UniquePtr, Projects, Cpp, C++

 https://docs.microsoft.com/ru-ru/cpp/cpp/how-to-create-and-use-shared-ptr-instances?view=msvc-160#example-4

https://docs.microsoft.com/ru-ru/cpp/cpp/smart-pointers-modern-cpp?view=msvc-160

https://docs.microsoft.com/ru-ru/cpp/cpp/how-to-create-and-use-unique-ptr-instances?view=msvc-160

D:\VC\Cpp\CppSln\Cpp01\CaSharedPtr01\CaSharedPtr01.vcxproj

D:\VC\Cpp\CppSln\Cpp01\CaUniquePtr01\CaUniquePtr01.vcxproj

Next step

https://docs.microsoft.com/ru-ru/cpp/cpp/lambda-expressions-in-cpp?view=msvc-160


четверг, 4 ноября 2021 г.

MathLib, C++, Cpp, Projects, DLL,

 D:\VC\Cpp\CppSln\GS.Math\GS.Math01

NamespaceS

1. HelloWorld - begin

----------------------------------------------------------------------------------------------------

2. Stewbond namespace

http://cplusplus.com/forum/beginner/62864/

// Returns the erf() of a value (not super precice, but ok)

    double erf(double x)

// Returns the probability of x, given the distribution described by mu and sigma.

    double pdf(double x, double mu, double sigma)

 // Returns the probability of [-inf,x] of a gaussian distribution

    double cdf(double x, double mu, double sigma)

// Returns the integral from -inf to x of any function that accepts x and 2 other parameters

    double cdf_func(double x, double mu, double sigma, double(*ptr_pdf)(double, double, double))

 // function which will approximate an integral of f(x) between a and b:

    double integral(double a, double b, double(*f)(double))

    class NormalDistribution

    Stewbond::NormalDistribution(double _mu, double _sigma) : mu(_mu), sigma(_sigma) 

    inline double Stewbond::NormalDistribution::pdf(double x) const

    double Stewbond::NormalDistribution::cdf(double x) const

-----------------------------------------------------------------------------------------------------------------

3. Horner Namespace

1. Horner functions. Poly 10 degree

Armstrong norm_cdv, norm_cdf_inverse

double norm_cdf(double x)

double norm_cdf_inverse(double x)

MathLib-Test1 Google Test OK

UnitTest_MathLib std::cout does not work