summaryrefslogtreecommitdiffstats
path: root/c_layer/curve.hpp
blob: 22a6cc9e66a8098e026eed08953d80d2a91846b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#pragma once

#include <vector>
#include <string>
#include "isda/bastypes.h"
#include "isda/cdate.h"
#include "isda/tcurve.h"

namespace pyisda {
    class Curve {

    public:
        Curve(TCurve* const curve) : ptr(curve) {};
        Curve(const Curve &curve2) :
            ptr(JpmcdsCopyCurve(curve2.ptr)) {};

        ~Curve() {
            JpmcdsFreeTCurve(ptr);
        }
        explicit operator TCurve*() const { return ptr; }
        unsigned char* serialize(unsigned char* buf);
        double zeroPrice(const TDate date);
        double zeroPrice(const TDate date1, const TDate date2);
        double survivalProb(const TDate start_date, const TDate maturity_date);
        double survivalProb(const TDate start_date, const TDate maturity_date, double eps);
        static void tweak(TCurve* ptr, double epsilon);
        static void tweak(TCurve* ptr, double epsilon, unsigned long mask);
        void tweak(double epsilon);
        void tweak(double epsilon, unsigned long mask);
        size_t size();
    private:
        TCurve* ptr;
    };

    class YieldCurve : public Curve {
    public:
        YieldCurve(TCurve* const curve, const std::vector<TDate>& dates);
        YieldCurve(const YieldCurve &curve2) :
            Curve(curve2),
            dates(std::move(curve2.dates)) {};
        size_t size();
        unsigned char* serialize(unsigned char* buf);
        std::vector<TDate> dates;
    };

    class SpreadCurve : public Curve {
    public:
        SpreadCurve(TCurve* const curve, const std::vector<double>& recovery_rates,
                    const std::string& ticker);
        SpreadCurve(const SpreadCurve &curve2) :
            Curve(curve2),
            recovery_rates(std::move(curve2.recovery_rates)),
            ticker(std::move(curve2.ticker)) {};

        std::vector<double> recovery_rates;
        std::string ticker;
        size_t size();
        unsigned char* serialize(unsigned char* buf);
    };

}