File: DayCounters.i

package info (click to toggle)
quantlib-python 0.2.1.cvs20020322-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,040 kB
  • ctags: 3,245
  • sloc: cpp: 32,997; python: 7,156; makefile: 70
file content (81 lines) | stat: -rw-r--r-- 2,823 bytes parent folder | download
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

/*
 Copyright (C) 2000, 2001, 2002 RiskMap srl

 This file is part of QuantLib, a free-software/open-source library
 for financial quantitative analysts and developers - http://quantlib.org/

 QuantLib is free software: you can redistribute it and/or modify it under the
 terms of the QuantLib license.  You should have received a copy of the
 license along with this program; if not, please email ferdinando@ametrano.net
 The license is also available online at http://quantlib.org/html/license.html

 This program is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE.  See the license for more details.
*/

// $Id: DayCounters.i,v 1.22 2002/02/18 14:11:33 nando Exp $

#ifndef quantlib_day_counters_i
#define quantlib_day_counters_i

%include Date.i
%include Types.i
%include String.i

%{
using QuantLib::DayCounter;
using QuantLib::DayCounters::Actual360;
using QuantLib::DayCounters::Actual365;
using QuantLib::DayCounters::ActualActual;
using QuantLib::DayCounters::Thirty360;
%}

class DayCounter {
  public:
    // constructor redefined below as string-based factory
    ~DayCounter();
    int dayCount(const Date& d1, const Date& d2);
    Time yearFraction(const Date& d1, const Date& d2,
        const Date& startRef, const Date& endRef);
};

// replicate the DayCounter interface
%addmethods DayCounter {
    DayCounter(const String& name) {
        String s = StringFormatter::toLowercase(name);

        if (s == "act365" || s == "act/365")
            return new Actual365;
        else if (s == "act360" || s == "act/360")
            return new Actual360;
        else if (s == "actacte" || s == "act/act(e)" || s == "act/act(Euro)")
            return new ActualActual(ActualActual::Euro);
        else if (s == "30/360" || s == "30/360us")
            return new Thirty360(Thirty360::USA);
        else if (s == "30e/360" || s == "30/360e" || s == "30/360eu")
            return new Thirty360(Thirty360::European);
        else if (s == "30/360i" || s == "30/360it")
            return new Thirty360(Thirty360::Italian);
        else if (s == "actact" || s == "act/act" || s == "act/act(b)" || s == "act/act (Bond)")
            return new ActualActual(ActualActual::Bond);
        else if (s == "actacth" || s == "act/act(h)" || s == "act/act (ISDA)")
            return new ActualActual(ActualActual::Historical);
        else
            throw Error("Unknown day counter: " + name);
        QL_DUMMY_RETURN((DayCounter*)(0));
    }
    String __str__() {
        return self->name()+" day counter";
    }
    String __repr__() {
        return "DayCounter('"+self->name()+"')";
    }
    int __cmp__(const DayCounter& other) {
        return ((*self) == other ? 0 : 1);
    }
}


#endif