1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #ifndef SC_OPENCL_OPINLINFUN_finacial
11 #define SC_OPENCL_OPINLINFUN_finacial
12 std::string approxEqualDecl
="bool approxEqual(double a, double b);\n";
13 std::string approxEqual
=
14 "bool approxEqual(double a, double b)\n"
18 " double x = a - b;\n"
19 " return (x < 0.0 ? -x : x) < ((a < 0.0 ? -a : a) * (1.0 / (16777216.0 *"
23 std::string nKorrValDecl
="double constant nKorrVal[]"
24 "= {0, 9e-1, 9e-2, 9e-3, 9e-4, 9e-5, 9e-6, 9e-7, "
25 "9e-8,9e-9, 9e-10, 9e-11, 9e-12, 9e-13, 9e-14, 9e-15};\n";
27 std::string SCdEpsilonDecl
=
28 "constant double SCdEpsilon = 1.0E-7;\n";
30 std::string RoundDecl
= "double Round(double fValue);\n";
33 "double Round(double fValue)\n"
35 " if ( fValue == 0.0 )\n"
40 " if ( fValue > 0.0 )\n"
41 " nExp = ( floor( log10( fValue ) ) );\n"
44 " int nIndex = 15 - nExp;\n"
45 " if ( nIndex > 15 )\n"
47 " else if ( nIndex <= 1 )\n"
49 " fValue = floor( fValue + 0.5 + nKorrVal[nIndex] );\n"
53 std::string GetRmzDecl
=
54 "double GetRmz( double fZins, double fZzr, double fBw, double fZw,int nF );\n";
57 "double GetRmz( double fZins, double fZzr, double fBw, double fZw, int nF )\n"
60 " if( fZins == 0.0 )\n"
61 " fRmz = ( fBw + fZw ) / fZzr;\n"
64 " double fTerm = pow( 1.0 + fZins, fZzr );\n"
66 " fRmz = ( fZw * fZins / ( fTerm - 1.0 ) + fBw * fZins / ( 1.0 - 1."
67 "0 / fTerm ) ) / ( 1.0 + fZins );\n"
69 " fRmz = fZw * fZins / ( fTerm - 1.0 ) + fBw * fZins /( 1.0 - 1.0 "
75 std::string GetRmz_newDecl
=
76 "double GetRmz_new( double fZins, double fZzr, double fBw, double fZw,"
78 std::string GetRmz_new
=
79 "double GetRmz_new( double fZins, double fZzr, double fBw, double fZw,"
83 " double fTerm = pow( 1.0 + fZins, fZzr );\n"
85 " fRmz = ( fZw * fZins *pow ( fTerm - 1.0,-1 ) + fBw * fZins *pow( "
86 "( 1.0 - pow( fTerm,-1) ),-1) )* pow ( 1.0 + fZins,-1 );\n"
88 " fRmz = fZw * fZins *pow ( fTerm - 1.0 ,-1) + fBw * fZins *pow( "
89 "1.0 - pow( fTerm,-1),-1 );\n"
92 std::string GetZwDecl
=
93 "double GetZw( double fZins, double fZzr, double fRmz,"
94 "double fBw, int nF );\n";
97 "double GetZw( double fZins, double fZzr, double fRmz,"
98 "double fBw, int nF )\n"
101 " if( fZins == 0.0 )\n"
102 " fZw = fBw + fRmz * fZzr;\n"
105 " double fTerm = pow( 1.0 + fZins, fZzr );\n"
107 " fZw = fBw * fTerm + fRmz * ( 1.0 + fZins ) *( fTerm - 1.0 ) "
110 " fZw = fBw * fTerm + fRmz * ( fTerm - 1.0 ) / fZins;\n"
115 std::string GetZw_newDecl
=
116 "double GetZw_new( double fZins, double fZzr, double fRmz,"
117 "double fBw, int nF );\n";
119 std::string GetZw_new
=
120 "double GetZw_new( double fZins, double fZzr, double fRmz,"
121 "double fBw, int nF )\n"
124 " double fTerm = pow( 1.0 + fZins, fZzr );\n"
126 " fZw = fBw * fTerm + fRmz * ( 1.0 + fZins ) *( fTerm - 1.0 ) "
129 " fZw = fBw * fTerm + fRmz * ( fTerm - 1.0 ) *pow( fZins,-1);\n"
133 std::string IsLeapYearDecl
=
134 "bool IsLeapYear( int n );\n";
136 std::string IsLeapYear
=
137 "bool IsLeapYear( int n )\n"
139 " return ( (( ( n % 4 ) == 0 ) && ( ( n % 100 ) != 0)) || ( ( n % 400 ) == "
143 std::string DaysInMonthDecl
=
144 "int DaysInMonth( int nMonth, int nYear );\n";
146 std::string DaysInMonth
=
147 "int DaysInMonth( int nMonth, int nYear )\n"
149 " int aDaysInMonth[12] = { 31, 28, 31, 30, 31, 30,\n"
150 " 31, 31, 30, 31, 30, 31 };\n"
152 " if ( nMonth != 2 )\n"
153 " return aDaysInMonth[nMonth-1];\n"
156 " if ( IsLeapYear(nYear) )\n"
157 " return aDaysInMonth[nMonth-1] + 1;\n"
159 " return aDaysInMonth[nMonth-1];\n"
162 std::string DaysInMonth_newDecl
=
163 "int DaysInMonth( int nMonth, int nYear );\n";
165 std::string DaysInMonth_new
=
166 "int DaysInMonth( int nMonth, int nYear )\n"
187 " if ( IsLeapYear(nYear)==1)\n"
196 std::string DaysToDateDecl
=
197 "void DaysToDate( int nDays, int *rDay, int* rMonth, int* rYear );\n";
199 std::string DaysToDate
=
200 "void DaysToDate( int nDays, int *rDay, int* rMonth, int* rYear )\n"
209 " nTempDays = nDays;\n"
210 " *rYear = (int)((nTempDays / 365) - i);\n"
211 " nTempDays -= ((int) *rYear -1) * 365;\n"
212 " nTempDays -= (( *rYear -1) / 4) - (( *rYear -1) / 100) +"
213 "((*rYear -1) / 400);\n"
215 " if ( nTempDays < 1 )\n"
222 " if ( nTempDays > 365 )\n"
224 " if ( (nTempDays != 366) || !IsLeapYear( *rYear ) )\n"
232 " while ( bCalc );\n"
233 " if(nTempDays!=0){\n"
234 " for (*rMonth = 1; (int)nTempDays > DaysInMonth( *rMonth, *rYear );"
237 " nTempDays -= DaysInMonth( *rMonth, *rYear );\n"
239 " *rDay = (int)nTempDays;\n"
243 std::string DateToDaysDecl
=
244 "int DateToDays( int nDay, int nMonth, int nYear );\n";
246 std::string DateToDays
=
247 "int DateToDays( int nDay, int nMonth, int nYear )\n"
249 " int nDays = ((int)nYear-1) * 365;\n"
250 " nDays += ((nYear-1) / 4) - ((nYear-1) / 100) + ((nYear-1) / 400);\n"
251 " for( int i = 1; i < nMonth; i++ )\n"
252 " nDays += DaysInMonth(i,nYear);\n"
258 std::string DateToDays_newDecl
=
259 "int DateToDays_new( int nDay, int nMonth, int nYear );\n";
261 std::string DateToDays_new
=
262 "int DateToDays_new( int nDay, int nMonth, int nYear )\n"
264 " int nDays = (nYear-1) * 365;\n"
265 " nDays += (int)((nYear-1) *pow(4.0,-1.0)- (nYear-1) *pow( 100.0,-1.0)"
266 "+ (nYear-1) *pow(400.0,-1.0));\n"
267 " for( int i = 1; i < nMonth; i++ )\n"
268 " nDays += DaysInMonth(i,nYear);\n"
275 std::string GetNullDateDecl
=
276 "int GetNullDate(void);\n";
278 std::string GetNullDate
=
279 "int GetNullDate(void)\n"
281 " return DateToDays(30,12,1899 );\n"
283 std::string GetNullDate_newDecl
=
284 "int GetNullDate_new(void);\n";
286 std::string GetNullDate_new
=
287 "int GetNullDate_new(void)\n"
289 " return DateToDays_new(30,12,1899 );\n"
292 std::string ScaDateDecl
=
293 "void ScaDate( int nNullDate, int nDate, int nBase,int *nOrigDay, "
294 "int *nMonth,int *nYear,int *bLastDayMode,int *bLastDay,"
295 "int *b30Days,int *bUSMode,int *nDay);\n";
298 "void ScaDate( int nNullDate, int nDate, int nBase,int *nOrigDay, "
299 "int *nMonth,int *nYear,int *bLastDayMode,int *bLastDay,"
300 "int *b30Days,int *bUSMode,int *nDay)\n"
302 " DaysToDate( nNullDate + nDate, nOrigDay, nMonth, nYear );\n"
303 " *bLastDayMode = (nBase != 5);\n"
304 " *bLastDay = (*nOrigDay >= DaysInMonth( *nMonth, *nYear ));\n"
305 " *b30Days = (nBase == 0) || (nBase == 4);\n"
306 " *bUSMode = (nBase == 0);\n"
309 " *nDay = min( *nOrigDay, 30);\n"
310 " if( *bLastDay || (*nDay >=DaysInMonth( *nMonth, *nYear )) )\n"
315 " int nLastDay = DaysInMonth( *nMonth, *nYear );\n"
316 " *nDay = *bLastDay ? nLastDay : min( *nOrigDay, nLastDay );\n"
320 std::string ScaDate2Decl
=
321 "void ScaDate2( int nNullDate, int nDate, int nBase,int *bLastDayMode,int *"
322 "bLastDay,int *b30Days,int *bUSMode);\n";
324 std::string ScaDate2
=
325 "void ScaDate2( int nNullDate, int nDate, int nBase,int *bLastDayMode,int *"
326 "bLastDay,int *b30Days,int *bUSMode)\n"
328 " int nOrigDay=0, nMonth=0, nYear=0;\n"
329 " DaysToDate( nNullDate + nDate, &nOrigDay, &nMonth, &nYear );\n"
330 " *bLastDayMode = (nBase != 5);\n"
331 " *bLastDay = (nOrigDay >= DaysInMonth( nMonth, nYear ));\n"
332 " *b30Days = (nBase == 0) || (nBase == 4);\n"
333 " *bUSMode = (nBase == 0);\n"
336 std::string lcl_GetCouppcdDecl
=
337 "int lcl_GetCouppcd(int nNullDate,int nSettle,int nMat,int nFreq,int nBase);\n";
339 std::string lcl_GetCouppcd
=
340 "int lcl_GetCouppcd(int nNullDate,int nSettle, int nMat,int nFreq,int nBase)\n"
342 " int aDate = nMat;\n"
343 " int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0,"
344 "rbUSMode=0,rnDay=0;\n"
345 " int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0,"
346 "sbUSMode=0,snDay=0;\n"
347 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
348 "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
349 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,"
350 "&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
352 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
353 " if(checklessthan(rYear,sYear,rMonth,sMonth,rnDay,snDay,rbLastDay,"
354 "sbLastDay,rDay,sDay))\n"
357 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
359 " while(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
360 "rbLastDay,sDay,rDay))\n"
362 " double d = -1*(12/nFreq);\n"
363 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,d,&rYear);\n"
365 " int nLastDay = DaysInMonth( rMonth, rYear );\n"
366 " int nRealDay = (rbLastDayMode && rbLastDay) ? nLastDay :"
367 "min( nLastDay, rDay );\n"
368 " return DateToDays( nRealDay, rMonth, rYear ) - nNullDate;\n"
371 std::string lcl_GetCoupncdDecl
=
372 "int lcl_GetCoupncd(int nNullDate,int nSettle,int nMat,int nFreq,int nBase);\n";
374 std::string lcl_GetCoupncd
=
375 "int lcl_GetCoupncd(int nNullDate,int nSettle, int nMat,int nFreq,int nBase)\n"
377 " int aDate = nMat;\n"
378 " int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0,"
379 "rbUSMode=0,rnDay=0;\n"
380 " int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0,"
381 "sbUSMode=0,snDay=0;\n"
382 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
383 "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
384 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,"
385 "&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
387 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
388 " if(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,rbLastDay"
392 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
394 " while(!checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
395 "rbLastDay,sDay,rDay))\n"
397 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,12/nFreq,&rYear);\n"
399 " int nLastDay = DaysInMonth( rMonth, rYear );\n"
400 " int nRealDay = (rbLastDayMode && rbLastDay) ? nLastDay :"
401 "min( nLastDay, rDay );\n"
402 " return DateToDays( nRealDay, rMonth, rYear ) - nNullDate;\n"
405 std::string addMonthsDecl
=
406 "void addMonths(int b30Days,int bLastDay,int *nDay,int nOrigDay,"
407 "int *nMonth,int nMonthCount,int *year);\n";
409 std::string addMonths
=
410 "void addMonths(int b30Days,int bLastDay,int *nDay,int nOrigDay,"
411 "int *nMonth,int nMonthCount,int *year)\n"
413 " int nNewMonth = nMonthCount + *nMonth;\n"
414 " if( nNewMonth > 12 )\n"
417 " *year+=nNewMonth / 12 ;\n"
418 " *nMonth = ( nNewMonth % 12 ) + 1;\n"
420 " else if( nNewMonth < 1 )\n"
422 " *year+= nNewMonth / 12 - 1 ;\n"
423 " *nMonth = nNewMonth % 12 + 12 ;\n"
426 " *nMonth = nNewMonth ;\n"
429 " *nDay = min( nOrigDay, 30);\n"
430 " if( bLastDay || (*nDay >= DaysInMonth( *nMonth, *year )) )\n"
435 " int nLastDay = DaysInMonth( *nMonth, *year );\n"
436 " *nDay = bLastDay ? nLastDay : min( nOrigDay, nLastDay );\n"
440 std::string getDaysInMonthRangeDecl
=
441 "int getDaysInMonthRange( int nFrom, int nTo,int b30Days,int year);\n";
443 std::string getDaysInMonthRange
=
444 "int getDaysInMonthRange( int nFrom, int nTo,int b30Days,int year)\n"
446 " if( nFrom > nTo )\n"
450 " nRet = (nTo - nFrom + 1) * 30;\n"
453 " for( int nMonthIx = nFrom; nMonthIx <= nTo; ++nMonthIx )\n"
454 " nRet += b30Days ? 30 : DaysInMonth( nMonthIx, year );\n"
459 std::string GetDaysInYearsDecl
=
460 "int GetDaysInYears( int nYear1, int nYear2 );\n";
462 std::string GetDaysInYears
=
463 "int GetDaysInYears( int nYear1, int nYear2 )\n"
466 " for( int n = nYear1 ; n <= nYear2 ; n++ )\n"
468 " if( IsLeapYear( n ) )\n"
479 std::string GetDaysInYearDecl
=
480 "int GetDaysInYear( int nNullDate, int nDate, int nMode );\n";
482 std::string GetDaysInYear
=
483 "int GetDaysInYear( int nNullDate, int nDate, int nMode )\n"
493 " int nD=0, nM=0, nY=0;\n"
494 " nDate += nNullDate;\n"
495 " DaysToDate( nDate, &nD, &nM, &nY );\n"
496 " return IsLeapYear( nY )? 366 : 365;\n"
503 std::string getDaysInYearRangeDecl
=
504 "int getDaysInYearRange( int nFrom, int nTo,int b30Days );\n";
506 std::string getDaysInYearRange
=
507 "int getDaysInYearRange( int nFrom, int nTo,int b30Days )\n"
509 " if( nFrom > nTo )\n"
511 " return b30Days ? ((nTo - nFrom + 1) * 360) : GetDaysInYears( nFrom, nTo)"
516 std::string getDiffDecl
=
517 "int getDiff(int rFrom,int rTo,int fDay,int fMonth,int fYear,int fbLastDayMode,"
518 "int fbLastDay,int fb30Days,int fbUSMode,int fnDay,int tDay,int tMonth,"
519 "int tYear,int tbLastDayMode,int tbLastDay,int tb30Days,"
520 "int tbUSMode,int tnDay);\n";
524 "int getDiff(int rFrom,int rTo,int fDay,int fMonth,int fYear,int fbLastDayMode,"
525 "int fbLastDay,int fb30Days,int fbUSMode,int fnDay,int tDay,int tMonth,"
526 "int tYear,int tbLastDayMode,int tbLastDay,int tb30Days,"
527 "int tbUSMode,int tnDay)\n"
531 " int d=fDay;fDay=tDay;tDay=d;\n"
532 " int m=fMonth;fMonth=tMonth;tMonth=m;\n"
533 " int y=fYear;fYear=tYear;tYear=y;\n"
534 " int a=fbLastDayMode;fbLastDayMode=tbLastDayMode;tbLastDayMode=a;\n"
535 " int b=fbLastDay;fbLastDay=tbLastDay;tbLastDay=b;\n"
536 " int c=fb30Days;fb30Days=tb30Days;tb30Days=c;\n"
537 " int e=fbUSMode;fbUSMode=tbUSMode;tbUSMode=e;\n"
538 " int f=fnDay;fnDay=tnDay;tnDay=f;\n"
545 " if( ((fMonth == 2) || (fnDay < 30)) && (tDay == 31) )\n"
547 " else if( (tMonth == 2) && tbLastDay )\n"
548 " tnDay = DaysInMonth( 2, tYear );\n"
552 " if( (fMonth == 2) && (fnDay == 30) )\n"
553 " fnDay = DaysInMonth( 2, fYear );\n"
554 " if( (tMonth == 2) && (tnDay == 30) )\n"
555 " tnDay = DaysInMonth( 2, tYear );\n"
558 " if( (fYear < tYear) || ((fYear == tYear) && (fMonth < tMonth)) )\n"
560 " int d = fb30Days ? 30:DaysInMonth(fMonth,fYear);\n"
561 " nDiff = d- fnDay + 1;\n"
562 " fDay = fnDay = 1;\n"
564 " addMonths(fb30Days,fbLastDay,&fnDay,fDay,&fMonth,1,&fYear);\n"
565 " if( fYear < tYear )\n"
567 " nDiff += getDaysInMonthRange( fMonth, 12,fb30Days,fYear);\n"
568 " addMonths(fb30Days,fbLastDay,&fnDay,fDay,&fMonth,13-fMonth,&fYear"
570 " nDiff += getDaysInYearRange( fYear, tYear - 1,fb30Days);\n"
571 " fYear+=tYear - fYear;\n"
573 " nDiff += getDaysInMonthRange(fMonth, tMonth - 1,fb30Days ,fYear );\n"
574 " addMonths(fb30Days,fbLastDay,&fnDay,fDay,&fMonth,tMonth-fMonth,&fYear"
577 " nDiff += tnDay - fnDay;\n"
578 " return nDiff > 0 ? nDiff : 0;\n"
583 std::string lcl_GetcoupdaybsDecl
=
584 "int lcl_Getcoupdaybs(int nNullDate,int nSettle, int nMat,int nFreq,int nBase);\n";
587 std::string lcl_Getcoupdaybs
=
588 "int lcl_Getcoupdaybs(int nNullDate,int nSettle, int nMat,int nFreq,int nBase)\n"
590 " int aDate = nMat;\n"
591 " int rDay=0,rMonth=0, rYear=0;int mDay=0,mMonth=0, mYear=0;int sDay=0,"
592 "sMonth=0, sYear=0;\n"
593 " int rbLastDayMode=0, rbLastDay=0,rb30Days=0,rbUSMode=0,rnDay=0;\n"
594 " int sbLastDayMode=0, sbLastDay=0,sb30Days=0,sbUSMode=0,snDay=0;\n"
595 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,&"
596 "rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
597 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,&"
598 "sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
600 " nSettle=nSettle+nNullDate;\n"
601 " aDate=DateToDays( rDay,rMonth,rYear );\n"
602 " if( aDate < nSettle )\n"
605 " aDate=DateToDays( rDay,rMonth,rYear );\n"
607 " while(aDate > nSettle )\n"
609 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,-1*(12/nFreq),&rYear"
611 " aDate=DateToDays( rDay,rMonth,rYear );\n"
613 " return getDiff( aDate, nSettle, rDay, rMonth, rYear, rbLastDayMode, "
614 "rbLastDay, rb30Days, rbUSMode, rnDay, sDay, sMonth, sYear, sbLastDayMode,"
615 "sbLastDay, sb30Days, sbUSMode, snDay);\n"
618 std::string lcl_Getcoupdaybs_newDecl
=
619 "int lcl_Getcoupdaybs_new(int nNullDate,int nSettle,int nMat,int nFreq,"
622 std::string lcl_Getcoupdaybs_new
=
623 "int lcl_Getcoupdaybs_new(int nNullDate,int nSettle,int nMat,int nFreq,"
626 " int aDate = nMat;\n"
627 " int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0,"
628 "rbUSMode=0,rnDay=0;\n"
629 " int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0,"
630 "sbUSMode=0,snDay=0;\n"
631 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
632 "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
633 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,"
634 "&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
636 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
637 " aDate=DateToDays_new( rnDay,rMonth,rYear);\n"
638 " if(checklessthan(rYear,sYear,rMonth,sMonth,rnDay,snDay,rbLastDay,"
639 "sbLastDay,rDay,sDay))\n"
642 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
643 " aDate=DateToDays_new( rnDay,rMonth,rYear );\n"
645 " while(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
646 "rbLastDay,sDay,rDay))\n"
648 " double d = -1*(12/nFreq);\n"
649 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,d,&rYear);\n"
650 " aDate=DateToDays_new( rnDay,rMonth,rYear );\n"
652 " return getDiff( aDate,nSettle+nNullDate,rDay,rMonth,rYear,rbLastDayMode,"
653 "rbLastDay,rb30Days,rbUSMode,rnDay,sDay,sMonth,sYear,sbLastDayMode,sbLastDay,"
654 "sb30Days,sbUSMode, snDay);\n"
657 std::string lcl_GetcoupdaysDecl
=
658 "int lcl_Getcoupdays(int nNullDate,int nSettle, "
659 "int nMat,int nFreq,int nBase);\n";
661 std::string lcl_Getcoupdays
=
662 "int lcl_Getcoupdays(int nNullDate,int nSettle, "
663 "int nMat,int nFreq,int nBase)\n"
665 " int aDate = nMat;\n"
666 " int rDay=0,rMonth=0, rYear=0;int mDay=0,mMonth=0, mYear=0;int sDay=0,"
667 "sMonth=0, sYear=0;\n"
668 " int rbLastDayMode=0, rbLastDay=0,rb30Days=0,rbUSMode=0,rnDay=0;\n"
669 " int sbLastDayMode=0, sbLastDay=0,sb30Days=0,sbUSMode=0,snDay=0;\n"
670 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,&"
671 "rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
672 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,&"
673 "sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
675 " nSettle=nSettle+nNullDate;\n"
676 " aDate=DateToDays( rDay,rMonth,rYear );\n"
677 " if( aDate < nSettle )\n"
680 " aDate=DateToDays( rDay,rMonth,rYear );\n"
682 " while(aDate > nSettle )\n"
684 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,-1*(12/nFreq),&rYear"
686 " aDate=DateToDays( rDay,rMonth,rYear );\n"
688 " int aNextDate=aDate;int aDay=rDay,aMonth=rMonth, aYear=rYear;\n"
689 " int abLastDayMode=rbLastDayMode, abLastDay=rbLastDay,ab30Days=rb30Days,"
690 "abUSMode=rbUSMode,anDay=rnDay;\n"
691 " addMonths(ab30Days,abLastDay,&anDay,aDay,&aMonth,12/nFreq,&aYear);\n"
692 " return getDiff( aDate, aNextDate, rDay, rMonth, rYear, rbLastDayMode, "
693 "rbLastDay, rb30Days, rbUSMode, rnDay, aDay, aMonth, aYear, abLastDayMode,"
694 "abLastDay, ab30Days, abUSMode, anDay);\n"
697 std::string lcl_Getcoupdays_newDecl
=
698 "int lcl_Getcoupdays_new(int nNullDate,int nSettle, "
699 "int nMat,int nFreq,int nBase);\n";
701 std::string lcl_Getcoupdays_new
=
702 "int lcl_Getcoupdays_new(int nNullDate,int nSettle, "
703 "int nMat,int nFreq,int nBase)\n"
705 " int aDate = nMat;\n"
706 " int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0,"
707 "rbUSMode=0,rnDay=0;\n"
708 " int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0,"
709 "sbUSMode=0,snDay=0;\n"
710 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
711 "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
712 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,"
713 "&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
715 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
716 " aDate=DateToDays_new( rnDay,rMonth,rYear);\n"
717 " if(checklessthan(rYear,sYear,rMonth,sMonth,rnDay,snDay,rbLastDay,"
718 "sbLastDay,rDay,sDay))\n"
721 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
722 " aDate=DateToDays_new( rnDay,rMonth,rYear );\n"
724 " while(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
725 "rbLastDay,sDay,rDay))\n"
727 " double d = -1*12*pow((double)nFreq,-1.0);\n"
728 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,d,&rYear);\n"
729 " aDate=DateToDays_new( rnDay,rMonth,rYear );\n"
731 " int aNextDate=aDate;int aDay=rDay,aMonth=rMonth, aYear=rYear;\n"
732 " int abLastDayMode=rbLastDayMode, abLastDay=rbLastDay,ab30Days=rb30Days,"
733 "abUSMode=rbUSMode,anDay=rnDay;\n"
734 " int tmp = (int)(12*pow((double)nFreq,-1.0));\n"
735 " addMonths(ab30Days,abLastDay,&anDay,aDay,&aMonth,tmp,&aYear);\n"
736 " return getDiff( aDate, aNextDate, rDay, rMonth, rYear, rbLastDayMode, "
737 "rbLastDay, rb30Days, rbUSMode, rnDay, aDay, aMonth, aYear, abLastDayMode,"
738 "abLastDay, ab30Days, abUSMode, anDay);\n"
741 std::string lcl_GetcoupnumDecl
=
742 "int lcl_Getcoupnum(int nNullDate,int nSettle, int nMat,int nFreq);\n";
744 std::string lcl_Getcoupnum
=
745 "int lcl_Getcoupnum(int nNullDate,int nSettle, int nMat,int nFreq)\n"
747 " int aDate = nMat;int rDay=0,rMonth=0, rYear=0;int mDay=0,mMonth=0, mYear="
749 " int sDay=0,sMonth=0, sYear=0;\n"
750 " DaysToDate(aDate+nNullDate,&rDay, &rMonth, &rYear );\n"
751 " DaysToDate(nMat+nNullDate,&mDay, &mMonth, &mYear );\n"
752 " DaysToDate(nSettle+nNullDate,&sDay, &sMonth, &sYear );\n"
754 " nSettle=nSettle+nNullDate;\n"
755 " aDate=DateToDays( rDay,rMonth,rYear );\n"
756 " if( aDate < nSettle )\n"
758 " int d=DateToDays( rDay,rMonth,rYear );\n"
759 " int nMonthCount=-1*(12 / nFreq);\n"
760 " while(d > nSettle )\n"
762 " int nNewMonth = nMonthCount + rMonth;\n"
763 " if( nNewMonth > 12 )\n"
766 " rYear+=nNewMonth / 12;\n"
767 " rMonth = nNewMonth % 12 + 1;\n"
769 " else if( nNewMonth < 1 )\n"
771 " rYear+= nNewMonth / 12 - 1;\n"
772 " rMonth = nNewMonth % 12 + 12;\n"
775 " rMonth = nNewMonth;\n"
776 " d=DateToDays( rDay,rMonth,rYear );\n"
778 " int n=(mYear-rYear)*12+mMonth-rMonth;\n"
782 std::string lcl_Getcoupnum_newDecl
=
783 "double lcl_Getcoupnum_new(int nNullDate,int nSettle,int nMat,int nFreq,int"
785 std::string lcl_Getcoupnum_new
=
786 "double lcl_Getcoupnum_new(int nNullDate,int nSettle, int nMat,int nFreq,int"
789 " int aDate = nMat;\n"
790 " int mDay=0,mMonth=0, mYear=0;\n"
791 " int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0,"
792 "rbUSMode=0,rnDay=0;\n"
793 " int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0,"
794 "sbUSMode=0,snDay=0;\n"
795 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
796 "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
797 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,"
798 "&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
799 " mMonth = rMonth, mYear = rYear;\n"
801 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
802 " if(checklessthan(rYear,sYear,rMonth,sMonth,rnDay,snDay,rbLastDay,"
803 "sbLastDay,rDay,sDay))\n"
806 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
808 " int m= checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
809 "rbLastDay,sDay,rDay);\n"
812 " double d = -1*(12/nFreq);\n"
813 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,d,&rYear);\n"
814 " m = checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
815 "rbLastDay,sDay,rDay);\n"
817 " int n=(mYear-rYear)*12+mMonth-rMonth;\n"
818 " double tmp = (double)(n*nFreq)/12.0;\n"
822 std::string setDayDecl
=
823 "void setDay(int nOrigDay, int nMonth,int nYear,int bLastDay,int b30Days,"
826 "void setDay(int nOrigDay, int nMonth,int nYear,int bLastDay,int b30Days,"
831 " *nDay = min( nOrigDay, 30);\n"
832 " if( bLastDay || (*nDay >= DaysInMonth( nMonth, nYear )) )\n"
837 " int nLastDay = DaysInMonth( nMonth, nYear );\n"
838 " *nDay = bLastDay ? nLastDay : min( nOrigDay, nLastDay );\n"
843 std::string coupdaysDecl
=
844 "double coupdays(int nSettle,int nMat,int nFreq,int nBase);\n";
847 std::string coupdays
=
848 "double coupdays(int nSettle,int nMat,int nFreq,int nBase)\n"
850 " int nNullDate=GetNullDate();\n"
851 " if( nBase == 1 )\n"
852 " return lcl_Getcoupdays(nNullDate, nSettle, nMat,nFreq, nBase);\n"
854 " return (double)GetDaysInYear(0,0,nBase)/nFreq;\n"
856 std::string coupdays_newDecl
=
857 "double coupdays_new(int nSettle,int nMat,int nFreq,int nBase);\n";
859 std::string coupdays_new
=
860 "double coupdays_new(int nSettle,int nMat,int nFreq,int nBase)\n"
862 " int nNullDate=693594;\n"
863 " if( nBase == 1 )\n"
864 " return lcl_Getcoupdays_new(nNullDate, nSettle, nMat,nFreq, nBase);\n"
866 " return (double)GetDaysInYear(0,0,nBase)*pow((double)nFreq,-1.0);\n"
869 std::string coupdaybsDecl
=
870 "double coupdaybs( int nSettle,int nMat,int nFreq,int nBase);\n";
872 std::string coupdaybs
=
873 "double coupdaybs( int nSettle,int nMat,int nFreq,int nBase)\n"
875 " int nNullDate=GetNullDate();\n"
876 " return lcl_Getcoupdaybs(nNullDate, nSettle, nMat,nFreq, nBase);\n"
879 std::string coupdaybs_newDecl
=
880 "double coupdaybs_new( int nSettle,int nMat,int nFreq,int nBase);\n";
882 std::string coupdaybs_new
=
883 "double coupdaybs_new( int nSettle,int nMat,int nFreq,int nBase)\n"
885 " int nNullDate=693594;\n"
886 " return lcl_Getcoupdaybs_new(nNullDate, nSettle, nMat,nFreq, nBase);\n"
889 std::string coupdaysncDecl
=
890 "double coupdaysnc( int nSettle,int nMat,int nFreq,int nBase);\n";
893 std::string coupdaysnc
=
894 "double coupdaysnc( int nSettle,int nMat,int nFreq,int nBase)\n"
896 " int nNullDate=GetNullDate();\n"
897 " if((nBase != 0) && (nBase != 4))\n"
899 " int aDate = nMat;\n"
900 " int rDay=0,rMonth=0, rYear=0;int mDay=0,mMonth=0, mYear=0;int sDay=0,"
901 "sMonth=0, sYear=0;\n"
902 " int rbLastDayMode=0, rbLastDay=0,rb30Days=0,rbUSMode=0,rnDay=0;\n"
903 " int sbLastDayMode=0, sbLastDay=0,sb30Days=0,sbUSMode=0,snDay=0;\n"
904 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,&"
905 "rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
906 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
907 "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
909 " nSettle=nSettle+nNullDate;\n"
910 " aDate=DateToDays( rDay,rMonth,rYear );\n"
911 " if( aDate > nSettle )\n"
914 " aDate=DateToDays( rDay,rMonth,rYear );\n"
916 " while(aDate <= nSettle )\n"
918 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,12/nFreq,&rYear)"
920 " aDate=DateToDays( rDay,rMonth,rYear );\n"
922 " return getDiff( nSettle, aDate, sDay, sMonth, sYear, sbLastDayMode, "
923 "sbLastDay, sb30Days, sbUSMode, snDay, rDay, rMonth, rYear, rbLastDayMode, "
924 "rbLastDay, rb30Days, rbUSMode, rnDay);\n"
927 " return coupdays(nSettle,nMat,nFreq,nBase)- coupdaybs( nSettle,nMat,"
930 std::string coupdaysnc_newDecl
=
931 "double coupdaysnc_new( int nSettle,int nMat,int nFreq,int nBase);\n";
933 std::string coupdaysnc_new
=
934 "double coupdaysnc_new( int nSettle,int nMat,int nFreq,int nBase)\n"
936 " int nNullDate=693594;\n"
937 " if((nBase != 0) && (nBase != 4))\n"
939 " int aDate = nMat;\n"
940 " int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0,"
941 "rbUSMode=0,rnDay=0;\n"
942 " int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0,"
943 "sbUSMode=0,snDay=0;\n"
944 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,"
945 "&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
946 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
947 "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
949 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
950 " aDate=DateToDays( rnDay,rMonth,rYear);\n"
951 " if(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,rbLastDay"
955 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
956 " aDate=DateToDays( rnDay,rMonth,rYear );\n"
958 " while(!checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
959 "rbLastDay,sDay,rDay))\n"
961 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,12/nFreq,&rYear);\n"
962 " aDate=DateToDays( rnDay,rMonth,rYear );\n"
964 " return getDiff( nSettle+nNullDate,aDate,sDay,sMonth,sYear,sbLastDayMode, "
965 "sbLastDay, sb30Days, sbUSMode, snDay, rDay, rMonth, rYear, rbLastDayMode, "
966 "rbLastDay, rb30Days, rbUSMode, rnDay);\n"
969 " return coupdays_new(nSettle,nMat,nFreq,nBase)- coupdaybs_new( nSettle,"
970 "nMat,nFreq,nBase);\n"
973 std::string checklessthanDecl
=
974 "int checklessthan(int aYear,int bYear,int aMonth,int bMonth,int anDay,int "
975 "bnDay,int abLastDay,int bbLastDay,int anOrigDay,int bnOrigDay);\n";
976 std::string checklessthan
=
977 "int checklessthan(int aYear,int bYear,int aMonth,int bMonth,int anDay,int "
978 "bnDay,int abLastDay,int bbLastDay,int anOrigDay,int bnOrigDay)\n"
980 " if( aYear != bYear )\n"
981 " return aYear < bYear;\n"
982 " if( aMonth != bMonth )\n"
983 " return aMonth < bMonth;\n"
984 " if( anDay != bnDay )\n"
985 " return anDay < bnDay;\n"
986 " if( abLastDay || bbLastDay )\n"
987 " return !abLastDay && bbLastDay;\n"
988 " return anOrigDay < bnOrigDay;\n"
991 std::string coupnumDecl
=
992 "double coupnum( int nSettle,int nMat,int nFreq,int nBase);\n";
995 "double coupnum( int nSettle,int nMat,int nFreq,int nBase)\n"
997 " int nNullDate=GetNullDate();\n"
998 " return lcl_Getcoupnum(nNullDate,nSettle,nMat,nFreq);\n"
1000 std::string coupnum_newDecl
=
1001 "double coupnum_new( int nSettle,int nMat,int nFreq,int nBase);\n";
1003 std::string coupnum_new
=
1004 "double coupnum_new( int nSettle,int nMat,int nFreq,int nBase)\n"
1006 " int nNullDate=693594;\n"
1007 " return lcl_Getcoupnum_new(nNullDate,nSettle,nMat,nFreq,nBase);\n"
1010 std::string getPrice_Decl
=
1011 "double getPrice_(int nSettle, int nMat, double fRate, double fYield,\n"
1012 "double fRedemp, int nFreq, int nBase );\n";
1015 std::string getPrice_
=
1016 "double getPrice_(int nSettle, int nMat, double fRate, double fYield,\n"
1017 "double fRedemp, int nFreq, int nBase )\n"
1019 " double fFreq = nFreq;\n"
1020 " double fE = coupdays( nSettle, nMat, nFreq, nBase );\n"
1021 " double fDSC_E = coupdaysnc( nSettle, nMat, nFreq, nBase ) / fE;\n"
1022 " double fN = coupnum( nSettle, nMat, nFreq, nBase );\n"
1023 " double fA = coupdaybs( nSettle, nMat, nFreq, nBase );\n"
1024 " double fRet = fRedemp / ( pow( 1.0 + fYield / fFreq, fN - 1.0 + "
1026 " fRet -= 100.0 * fRate / fFreq * fA / fE;\n"
1027 " double fT1 = 100.0 * fRate / fFreq;\n"
1028 " double fT2 = 1.0 + fYield / fFreq;\n"
1029 " for( double fK = 0.0 ; fK < fN ; fK+=1.0 )\n"
1030 " fRet += fT1 / pow( fT2, fK + fDSC_E );\n"
1033 std::string getPrice_new_Decl
=
1034 "double getPrice_(int nSettle, int nMat, double fRate, double fYield,\n"
1035 "double fRedemp, int nFreq, int nBase );\n";
1038 std::string getPrice_new
=
1039 "double getPrice_(int nSettle, int nMat, double fRate, double fYield,\n"
1040 "double fRedemp, int nFreq, int nBase )\n"
1042 " double fFreq = nFreq;\n"
1043 " double fE = coupdays_new( nSettle, nMat, nFreq, nBase );\n"
1044 " double fDSC_E = coupdaysnc_new( nSettle, nMat, nFreq, nBase ) / fE;\n"
1045 " double fN = coupnum_new( nSettle, nMat, nFreq, nBase );\n"
1046 " double fA = coupdaybs_new( nSettle, nMat, nFreq, nBase );\n"
1047 " double fRet = fRedemp / ( pow( 1.0 + fYield / fFreq, fN - 1.0 + "
1049 " fRet -= 100.0 * fRate / fFreq * fA / fE;\n"
1050 " double fT1 = 100.0 * fRate / fFreq;\n"
1051 " double fT2 = 1.0 + fYield / fFreq;\n"
1052 " for( double fK = 0.0 ; fK < fN ; fK+=1.0 )\n"
1053 " fRet += fT1 / pow( fT2, fK + fDSC_E );\n"
1057 std::string getYield_Decl
=
1058 "double getYield_( int nNullDate, int nSettle, int nMat, double fCoup,"
1059 "double fPrice,double fRedemp, int nFreq, int nBase);\n";
1061 std::string getYield_
=
1062 "double getYield_( int nNullDate, int nSettle, int nMat, double fCoup,"
1063 "double fPrice,double fRedemp, int nFreq, int nBase )\n"
1065 " double fRate = fCoup;\n"
1066 " double fPriceN = 0.0;\n"
1067 " double fYield1 = 0.0;\n"
1068 " double fYield2 = 1.0;\n"
1069 " double fPrice1 = getPrice_(nSettle, nMat, fRate, fYield1, fRedemp, "
1071 " double fPrice2 = getPrice_(nSettle, nMat, fRate, fYield2, fRedemp, "
1073 " double fYieldN = ( fYield2 - fYield1 ) * 0.5;\n"
1074 " for( unsigned int nIter = 0 ; nIter < 100 && fPriceN != fPrice ; nIter++ "
1077 " fPriceN = getPrice_(nSettle, nMat, fRate, fYieldN, fRedemp, nFreq, "
1079 " if( fPrice == fPrice1 )\n"
1080 " return fYield1;\n"
1081 " else if( fPrice == fPrice2 )\n"
1082 " return fYield2;\n"
1083 " else if( fPrice == fPriceN )\n"
1084 " return fYieldN;\n"
1085 " else if( fPrice < fPrice2 )\n"
1087 " fYield2 *= 2.0;\n"
1088 " fPrice2 = getPrice_(nSettle, nMat, fRate, fYield2, fRedemp, nFreq"
1090 " fYieldN = ( fYield2 - fYield1 ) * 0.5;\n"
1094 " if( fPrice < fPriceN )\n"
1096 " fYield1 = fYieldN;\n"
1097 " fPrice1 = fPriceN;\n"
1101 " fYield2 = fYieldN;\n"
1102 " fPrice2 = fPriceN;\n"
1104 " fYieldN = fYield2 - ( fYield2 - fYield1 ) * ( ( fPrice - fPrice2 "
1105 ") / ( fPrice1 - fPrice2 ) );\n"
1108 " return fYieldN;\n"
1111 std::string GetYearFracDecl
=
1112 "double GetYearFrac( int nNullDate, int nStartDate, int nEndDate,"
1115 std::string GetYearFrac
=
1116 "double GetYearFrac( int nNullDate, int nStartDate, int nEndDate,"
1119 " if( nStartDate == nEndDate )\n"
1122 " if( nStartDate > nEndDate )\n"
1124 " int n = nEndDate;\n"
1125 " nEndDate = nStartDate;\n"
1126 " nStartDate = n;\n"
1129 " int nDate1 = nStartDate + nNullDate;\n"
1130 " int nDate2 = nEndDate + nNullDate;\n"
1132 " int nDay1, nDay2;\n"
1133 " int nMonth1, nMonth2;\n"
1134 " int nYear1, nYear2;\n"
1136 " DaysToDate( nDate1, &nDay1, &nMonth1, &nYear1 );\n"
1137 " DaysToDate( nDate2, &nDay2, &nMonth2, &nYear2 );\n"
1140 " switch( nMode )\n"
1143 " if ( nDay1 == 31 )\n"
1147 " if ( nDay1 == 30 && nDay2 == 31 )\n"
1153 " if ( nMonth1 == 2 && nDay1 == "
1154 "( IsLeapYear( nYear1 ) ? 29 : 28 ) )\n"
1157 " if ( nMonth2 == 2 && nDay2 == "
1158 "( IsLeapYear( nYear2 ) ? 29 : 28 ) )\n"
1164 " nDayDiff = ( nYear2 - nYear1 ) * 360 + "
1165 "( nMonth2 - nMonth1 ) * 30 + ( nDay2 - nDay1 );\n"
1170 " nDayDiff = nDate2 - nDate1;\n"
1173 " if ( nDay1 == 31 )\n"
1177 " if ( nDay2 == 31 )\n"
1181 " nDayDiff = ( nYear2 - nYear1 ) * 360 + "
1182 "( nMonth2 - nMonth1 ) * 30 + ( nDay2 - nDay1 );\n"
1186 " double nDaysInYear;\n"
1187 " switch( nMode )\n"
1192 " nDaysInYear = 360;\n"
1196 " bool isYearDifferent = ( nYear1 != nYear2 );\n"
1197 " if ( isYearDifferent &&\n"
1198 " ( ( nYear2 != nYear1 + 1 ) ||\n"
1199 " ( nMonth1 < nMonth2 ) ||\n"
1200 " ( nMonth1 == nMonth2 && nDay1 < nDay2 ) ) )\n"
1203 " int nDayCount = 0;\n"
1204 " for ( int i = nYear1; i <= nYear2; i++ )\n"
1205 " nDayCount += ( IsLeapYear( i ) ? 366 : 365 );\n"
1207 " nDaysInYear = ( double ) nDayCount / "
1208 "( double ) ( nYear2 - nYear1 + 1 );\n"
1212 " if ( isYearDifferent && IsLeapYear( nYear1 ) )\n"
1214 " nDaysInYear = 366;\n"
1219 " if ( ( IsLeapYear( nYear1 ) && nMonth1 <= 2 "
1220 "&& nDay1 <= 29 ) ||\n"
1221 " ( IsLeapYear( nYear2 ) && ( nMonth2 > 3 || "
1222 "( nMonth2 == 2 && nDay1 == 29 ) ) ) )\n"
1224 " nDaysInYear = 366;\n"
1228 " nDaysInYear = 365;\n"
1229 " for ( int i = nYear1; i <= nYear2; i++ )\n"
1231 " if ( IsLeapYear( i ) )\n"
1233 " nDaysInYear = 366;\n"
1243 " nDaysInYear = 365;\n"
1246 " return (double)( nDayDiff ) / (nDaysInYear);\n"
1250 std::string GetYieldmatDecl
=
1251 "double GetYieldmat( int nNullDate, int nSettle, int nMat, int nIssue,\n"
1252 "double fRate, double fPrice, int nBase );\n";
1255 std::string GetYieldmat
=
1256 "double GetYieldmat( int nNullDate, int nSettle, int nMat, int nIssue,\n"
1257 "double fRate, double fPrice, int nBase )\n"
1259 " double fIssMat = GetYearFrac_new( nNullDate, nIssue, nMat, nBase );\n"
1260 " double fIssSet = GetYearFrac_new( nNullDate, nIssue, nSettle, nBase );\n"
1261 " double fSetMat = GetYearFrac_new( nNullDate, nSettle, nMat, nBase );\n"
1262 " double y = 1.0 + fIssMat * fRate;\n"
1263 " y =y * pow( (fPrice / 100.0 + fIssSet * fRate),-1);\n"
1265 " y = y * pow(fSetMat,-1);\n"
1269 std::string GetDiffDateDecl
=
1270 "int GetDiffDate( int nNullDate, int nStartDate, int nEndDate, int nMode,"
1271 " int* pOptDaysIn1stYear );\n";
1273 std::string GetDiffDate
=
1274 "int GetDiffDate( int nNullDate, int nStartDate, int nEndDate, int nMode,"
1275 " int* pOptDaysIn1stYear )\n"
1277 " bool bNeg = nStartDate > nEndDate;\n"
1280 " int n = nEndDate;\n"
1281 " nEndDate = nStartDate;\n"
1282 " nStartDate = n;\n"
1285 " switch( nMode )\n"
1290 " int nD1, nM1, nY1, nD2, nM2, nY2;\n"
1291 " nStartDate += nNullDate;\n"
1292 " nEndDate += nNullDate;\n"
1293 " DaysToDate( nStartDate, &nD1, &nM1, &nY1 );\n"
1294 " DaysToDate( nEndDate, &nD2, &nM2, &nY2 );\n"
1295 " bool bLeap = IsLeapYear( nY1 );\n"
1296 " int nDays, nMonths;\n"
1297 " nMonths = nM2 - nM1;\n"
1298 " nDays = nD2 - nD1;\n"
1299 " nMonths += ( nY2 - nY1 ) * 12;\n"
1300 " nRet = nMonths * 30 + nDays;\n"
1301 " if( nMode == 0 && nM1 == 2 && nM2 != 2 && nY1 == nY2 )\n"
1302 " nRet -= bLeap? 1 : 2;\n"
1303 " if( pOptDaysIn1stYear )\n"
1304 " *pOptDaysIn1stYear = 360;\n"
1308 " if( pOptDaysIn1stYear )\n"
1310 " int nD, nM, nY;\n"
1311 " DaysToDate( nStartDate + nNullDate, &nD, &nM, &nY );\n"
1312 " *pOptDaysIn1stYear = IsLeapYear( nY )? 366 : 365;\n"
1314 " nRet = nEndDate - nStartDate;\n"
1317 " nRet = nEndDate - nStartDate;\n"
1318 " if( pOptDaysIn1stYear )\n"
1319 " *pOptDaysIn1stYear = 360;\n"
1322 " nRet = nEndDate - nStartDate;\n"
1323 " if( pOptDaysIn1stYear )\n"
1324 " *pOptDaysIn1stYear = 365;\n"
1327 " return bNeg? -nRet : nRet;\n"
1330 std::string GetYearDiffDecl
=
1331 "double GetYearDiff( int nNullDate, int nStartDate, int nEndDate,"
1334 std::string GetYearDiff
=
1335 "double GetYearDiff( int nNullDate, int nStartDate, int nEndDate,"
1338 " int nDays1stYear;\n"
1339 " int nTotalDays = GetDiffDate( nNullDate, nStartDate, nEndDate,"
1342 " return (double)(nTotalDays)*pow((double)nDays1stYear,-1);\n"
1345 std::string GetDiffDate360_Decl
=
1346 "int GetDiffDate360_(\n"
1347 " int nDay1, int nMonth1, int nYear1, bool bLeapYear1,\n"
1348 " int nDay2, int nMonth2, int nYear2,\n"
1349 " bool bUSAMethod );\n";
1351 std::string GetDiffDate360_
=
1352 "int GetDiffDate360_(\n"
1353 " int nDay1, int nMonth1, int nYear1, bool bLeapYear1,\n"
1354 " int nDay2, int nMonth2, int nYear2,\n"
1355 " bool bUSAMethod )\n"
1357 " if( nDay1 == 31 )\n"
1359 " else if( bUSAMethod && ( nMonth1 == 2 && ( nDay1 == 29 || ( nDay1 == 28 "
1360 "&& !bLeapYear1 ) ) ) )\n"
1362 " if( nDay2 == 31 )\n"
1364 " if( bUSAMethod && nDay1 != 30 )\n"
1367 " if( nMonth2 == 12 )\n"
1378 " return nDay2 + nMonth2 * 30 + nYear2 * 360 - nDay1 - nMonth1 * 30 - "
1382 std::string GetDiffDate360Decl
=
1383 "int GetDiffDate360( int nNullDate, int nDate1, int nDate2,"
1384 "bool bUSAMethod);\n";
1387 std::string GetDiffDate360
=
1388 "int GetDiffDate360( int nNullDate, int nDate1, int nDate2,"
1389 "bool bUSAMethod )\n"
1391 " nDate1 += nNullDate;\n"
1392 " nDate2 += nNullDate;\n"
1393 " int nDay1, nMonth1, nYear1, nDay2, nMonth2, nYear2;\n"
1394 " DaysToDate( nDate1, &nDay1, &nMonth1, &nYear1 );\n"
1395 " DaysToDate( nDate2, &nDay2, &nMonth2, &nYear2 );\n"
1396 " return GetDiffDate360_( nDay1, nMonth1, nYear1, IsLeapYear( nYear1 ), "
1397 "nDay2, nMonth2, nYear2, bUSAMethod );\n"
1400 std::string GetDurationDecl
=
1401 "double GetDuration( \n"
1402 " int nNullDate, int nSettle, int nMat, double fCoup,\n"
1403 " double fYield, int nFreq, int nBase );\n";
1405 std::string GetDuration
=
1406 "double GetDuration( \n"
1407 " int nNullDate, int nSettle, int nMat, double fCoup,\n"
1408 " double fYield, int nFreq, int nBase )\n"
1410 " double fYearfrac = GetYearFrac( nNullDate, nSettle, nMat, nBase );\n"
1411 " double fNumOfCoups = lcl_Getcoupnum(nNullDate,nSettle,nMat,nFreq);\n"
1412 " double fDur = 0.0;\n"
1413 " double f100 = 100.0;\n"
1414 " fCoup *= f100 / nFreq;\n"
1415 " fYield /= nFreq;\n"
1417 " double nDiff = fYearfrac * nFreq - fNumOfCoups;\n"
1419 " for( t = 1 ; t < fNumOfCoups ; t++ )\n"
1420 " fDur += ( t + nDiff ) * ( fCoup ) / pow( fYield, t + nDiff );\n"
1421 " fDur += ( fNumOfCoups + nDiff ) * ( fCoup + f100 ) /"
1422 " pow( fYield, fNumOfCoups + nDiff );\n"
1423 " double p = 0.0;\n"
1424 " for( t = 1 ; t < fNumOfCoups ; t++ )\n"
1425 " p += fCoup / pow( fYield, t + nDiff );\n"
1426 " p += ( fCoup + f100 ) / pow( fYield, fNumOfCoups + nDiff );\n"
1429 " return fDur;\n""}\n";
1431 std::string GetDuration_newDecl
=
1432 "double GetDuration_new( \n"
1433 " int nNullDate, int nSettle, int nMat, double fCoup,\n"
1434 " double fYield, int nFreq, int nBase );\n";
1436 std::string GetDuration_new
=
1437 "double GetDuration_new( \n"
1438 " int nNullDate, int nSettle, int nMat, double fCoup,\n"
1439 " double fYield, int nFreq, int nBase )\n"
1441 " double fYearfrac = GetYearFrac(nNullDate,nSettle,nMat,nBase);\n"
1442 " double fNumOfCoups = lcl_Getcoupnum_new(nNullDate,nSettle,nMat,"
1444 " double fDur = 0.0;\n"
1445 " fCoup = fCoup * 100.0 * pow(nFreq, -1.0);\n"
1446 " fYield = fYield * pow(nFreq, -1.0);\n"
1448 " double nDiff = fYearfrac * nFreq - fNumOfCoups;\n"
1450 " double tmp0 = 0, tmp1 = 0, tmp2 = 0;\n"
1451 " for( t = 1 ; t < fNumOfCoups ; t++ ){\n"
1452 " tmp0 = (t + nDiff) * ( fCoup ) ;\n"
1453 " tmp1 = pow( fYield, t + nDiff ) ;\n"
1454 " tmp2 = tmp0 * pow(tmp1, -1);\n"
1457 " fDur += (fNumOfCoups + nDiff) * (fCoup + 100.0) * pow(pow(fYield,"
1458 " fNumOfCoups + nDiff ),-1);\n"
1459 " double p = 0.0;\n"
1460 " for( t = 1 ; t < fNumOfCoups ; t++ ){\n"
1461 " tmp0 = pow( fYield, t + nDiff );\n"
1462 " p += fCoup * pow(tmp0, -1);}\n"
1463 " p += (fCoup + 100.0) * pow(pow(fYield, fNumOfCoups + nDiff), -1);\n"
1464 " fDur = fDur * pow(p, -1.0);\n"
1465 " fDur = fDur * pow(nFreq, -1.0);\n"
1469 std::string ScGetGDADecl
=
1470 "double ScGetGDA(double fWert, double fRest, double fDauer, double fPeriode,"
1471 "double fFaktor);\n";
1473 std::string ScGetGDA
=
1474 "double ScGetGDA(double fWert, double fRest, double fDauer, double fPeriode,"
1477 " double fGda, fZins, fAlterWert, fNeuerWert;\n"
1478 " fZins = fFaktor / fDauer;\n"
1479 " if (fZins >= 1.0)\n"
1482 " if (fPeriode == 1.0)\n"
1483 " fAlterWert = fWert;\n"
1485 " fAlterWert = 0.0;\n"
1488 " fAlterWert = fWert * pow(1.0 - fZins, fPeriode - 1.0);\n"
1489 " fNeuerWert = fWert * pow(1.0 - fZins, fPeriode);\n"
1491 " if (fNeuerWert < fRest)\n"
1492 " fGda = fAlterWert - fRest;\n"
1494 " fGda = fAlterWert - fNeuerWert;\n"
1495 " if (fGda < 0.0)\n"
1500 std::string DblMinDecl
=
1501 "inline double DblMin( double a, double b );\n";
1504 "inline double DblMin( double a, double b )\n"
1506 " return (a < b) ? a : b;\n"
1509 std::string ScInterVDBDecl
=
1510 "double ScInterVDB(double fWert,double fRest,double fDauer, double fDauer1,"
1511 "double fPeriode,double fFaktor);\n";
1513 std::string ScInterVDB
=
1514 "double ScInterVDB(double fWert,double fRest,double fDauer, double fDauer1,"
1515 "double fPeriode,double fFaktor)\n"
1518 " double fIntEnd = ceil(fPeriode);\n"
1519 " int nLoopEnd = fIntEnd;\n"
1521 " double fTerm, fLia;\n"
1522 " double fRestwert = fWert - fRest;\n"
1523 " int bNowLia = 0;\n"
1527 " for ( i = 1; i <= nLoopEnd; i++)\n"
1531 " fGda = ScGetGDA(fWert, fRest, fDauer, (double) i, fFaktor);\n"
1532 " fLia = fRestwert/ (fDauer1 - (double) (i-1));\n"
1533 " if (fLia > fGda)\n"
1541 " fRestwert =fRestwert- fGda;\n"
1549 " if ( i == nLoopEnd)\n"
1550 " fTerm *= ( fPeriode + 1.0 - fIntEnd );\n"
1557 std::string VDBImplementDecl
=
1558 "double VDBImplement(double fWert,double fRest, double fDauer, double fAnfang"
1559 ", double fEnde, double fFaktor,int bFlag);\n";
1561 std::string VDBImplement
=
1562 "double VDBImplement(double fWert,double fRest, double fDauer, double fAnfang"
1563 ", double fEnde, double fFaktor,int bFlag)\n"
1565 " double result=0;\n"
1566 " double fIntStart = floor(fAnfang);\n"
1567 " double fIntEnd = ceil(fEnde);\n"
1568 " int nLoopStart = (int) fIntStart;\n"
1569 " int nLoopEnd = (int) fIntEnd;\n"
1572 " for (int i = nLoopStart + 1; i <= nLoopEnd; i++)\n"
1574 " double fTerm = ScGetGDA(fWert, fRest, fDauer, (double) i, fFaktor"
1576 " if ( i == nLoopStart+1 )\n"
1577 " fTerm *= ( DblMin( fEnde, fIntStart + 1.0 ) - fAnfang );\n"
1578 " else if ( i == nLoopEnd )\n"
1579 " fTerm *= ( fEnde + 1.0 - fIntEnd );\n"
1580 " result += fTerm;\n"
1585 " double fDauer1=fDauer;\n"
1586 " if(!isequal(fAnfang,floor(fAnfang)))\n"
1590 " if(fAnfang>fDauer/2 || isequal(fAnfang,fDauer/2))\n"
1592 " double fPart=fAnfang-fDauer/2;\n"
1593 " fAnfang=fDauer/2;\n"
1599 " fWert-=ScInterVDB(fWert,fRest,fDauer,fDauer1,fAnfang,fFaktor);\n"
1600 " result=ScInterVDB(fWert,fRest,fDauer,fDauer-fAnfang,fEnde-fAnfang,"
1606 std::string GetOddlpriceDecl
=
1607 "double GetOddlprice( int nNullDate, int nSettle, int nMat, int nLastCoup,\n"
1608 " double fRate, double fYield, double fRedemp, int nFreq, int nBase );\n";
1610 std::string GetOddlprice
=
1611 "double GetOddlprice( int nNullDate, int nSettle, int nMat, int nLastCoup,\n"
1612 " double fRate, double fYield, double fRedemp, int nFreq, int nBase )\n"
1614 " double fFreq = nFreq ;\n"
1615 " double fDCi = GetYearFrac( nNullDate, nLastCoup,"
1616 "nMat, nBase ) * fFreq;\n"
1617 " double fDSCi = GetYearFrac( nNullDate, nSettle,"
1618 "nMat, nBase ) * fFreq;\n"
1619 " double fAi = GetYearFrac( nNullDate, nLastCoup,"
1620 "nSettle, nBase ) * fFreq;\n"
1621 " double p = fRedemp + fDCi * 100.0 * fRate / fFreq;\n"
1622 " p /= fDSCi * fYield / fFreq + 1.0;\n"
1623 " p -= fAi * 100.0 * fRate / fFreq;\n"
1627 std::string GetOddlyieldDecl
=
1628 "double GetOddlyield( int nNullDate, int nSettle, int nMat, int nLastCoup,\n"
1629 " double fRate, double fPrice, double fRedemp, int nFreq, int nBase );\n";
1631 std::string GetOddlyield
=
1632 "double GetOddlyield( int nNullDate, int nSettle, int nMat, int nLastCoup,\n"
1633 " double fRate, double fPrice, double fRedemp, int nFreq, int nBase ) \n"
1635 " double fFreq = nFreq ;\n"
1636 " double fDCi= GetYearFrac( nNullDate, nLastCoup, nMat, nBase ) * fFreq;\n"
1637 " double fDSCi= GetYearFrac( nNullDate, nSettle, nMat, nBase ) * fFreq;\n"
1638 " double fAi= GetYearFrac( nNullDate, nLastCoup, nSettle, nBase )*fFreq;\n"
1639 " double y = fRedemp + fDCi * 100.0 * fRate / fFreq;\n"
1640 " y /= fPrice + fAi * 100.0 * fRate / fFreq;\n"
1642 " y *= fFreq / fDSCi;\n"
1646 std::string GetYearFrac_newDecl
=
1647 "double GetYearFrac_new( int nNullDate, int nStartDate, int nEndDate,"
1650 std::string GetYearFrac_new
=
1651 "double GetYearFrac_new( int nNullDate, int nStartDate, int nEndDate,"
1654 " if( nStartDate == nEndDate )\n"
1656 " if( nStartDate > nEndDate )\n"
1658 " int n = nEndDate;\n"
1659 " nEndDate = nStartDate;\n"
1660 " nStartDate = n;\n"
1662 " int nDate1 = nStartDate + nNullDate;\n"
1663 " int nDate2 = nEndDate + nNullDate;\n"
1664 " int nDay1, nDay2;\n"
1665 " int nMonth1, nMonth2;\n"
1666 " int nYear1, nYear2;\n"
1667 " DaysToDate_new( nDate1, &nDay1, &nMonth1, &nYear1 );\n"
1668 " DaysToDate_new( nDate2, &nDay2, &nMonth2, &nYear2 );\n"
1670 " switch( nMode )\n"
1673 " if ( nDay1 == 31 )\n"
1677 " if ( nDay1 == 30 && nDay2 == 31 )\n"
1683 " if ( nMonth1 == 2 && nDay1 == "
1684 "( IsLeapYear( nYear1 ) ? 29 : 28 ) )\n"
1687 " if ( nMonth2 == 2 && nDay2 == "
1688 "( IsLeapYear( nYear2 ) ? 29 : 28 ) )\n"
1694 " nDayDiff = ( nYear2 - nYear1 ) * 360 + "
1695 "( nMonth2 - nMonth1 ) * 30 + ( nDay2 - nDay1 );\n"
1700 " nDayDiff = nDate2 - nDate1;\n"
1703 " if ( nDay1 == 31 )\n"
1707 " if ( nDay2 == 31 )\n"
1711 " nDayDiff = ( nYear2 - nYear1 ) * 360 + "
1712 "( nMonth2 - nMonth1 ) * 30 + ( nDay2 - nDay1 );\n"
1715 " double nDaysInYear;\n"
1716 " switch( nMode )\n"
1721 " nDaysInYear = 360;\n"
1725 " bool isYearDifferent = ( nYear1 != nYear2 );\n"
1726 " if ( isYearDifferent &&\n"
1727 " ( ( nYear2 != nYear1 + 1 ) ||\n"
1728 " ( nMonth1 < nMonth2 ) ||\n"
1729 " ( nMonth1 == nMonth2 && nDay1 < nDay2 ) ) )\n"
1731 " int nDayCount = 0;\n"
1732 " for ( int i = nYear1; i <= nYear2; i++ )\n"
1733 " nDayCount += ( IsLeapYear( i ) ? 366 : 365 );\n"
1734 " nDaysInYear = ( double ) nDayCount / "
1735 "( double ) ( nYear2 - nYear1 + 1 );\n"
1739 " if ( isYearDifferent && IsLeapYear( nYear1 ) )\n"
1741 " nDaysInYear = 366;\n"
1745 " if ( ( IsLeapYear( nYear1 ) && nMonth1 <= 2 "
1746 "&& nDay1 <= 29 ) ||\n"
1747 " ( IsLeapYear( nYear2 ) && ( nMonth2 > 3 || "
1748 "( nMonth2 == 2 && nDay1 == 29 ) ) ) )\n"
1750 " nDaysInYear = 366;\n"
1754 " nDaysInYear = 365;\n"
1755 " for ( int i = nYear1; i <= nYear2; i++ )\n"
1757 " if ( IsLeapYear( i ) )\n"
1759 " nDaysInYear = 366;\n"
1769 " nDaysInYear = 365;\n"
1772 " return (double)( nDayDiff ) / (nDaysInYear);\n"
1775 std::string DaysToDate_newDecl
=
1776 "void DaysToDate_new( int nDays, int *rDay, int* rMonth, int* rYear );\n";
1778 std::string DaysToDate_new
=
1779 "void DaysToDate_new( int nDays, int *rDay, int* rMonth, int* rYear )\n"
1786 " nTempDays = nDays;\n"
1787 " *rYear = (int)((nTempDays / 365) - i);\n"
1788 " nTempDays -= ((int) *rYear -1) * 365;\n"
1789 " nTempDays -= ((*rYear -1) / 4) - ((*rYear -1) / 100) + ((*rYear -1)"
1792 " if ( nTempDays < 1 )\n"
1799 " if ( nTempDays > 365 )\n"
1801 " if ( (nTempDays != 366) || !IsLeapYear( *rYear ) )\n"
1809 " while ( bCalc );\n"
1810 " if(nTempDays != 0){\n"
1811 " for (*rMonth = 1; (int)nTempDays > DaysInMonth( *rMonth, *rYear );"
1814 " nTempDays -= DaysInMonth( *rMonth, *rYear ); \n"
1816 " *rDay = (int)nTempDays;\n"
1820 std::string DaysToDate_LocalBarrierDecl
=
1821 "void DaysToDate( int nDays, int *rDay, int* rMonth, int* rYear );\n";
1823 std::string DaysToDate_LocalBarrier
=
1824 "void DaysToDate( int nDays, int *rDay, int* rMonth, int* rYear )\n"
1831 " nTempDays = nDays;\n"
1832 " *rYear = (int)((nTempDays / 365) - i);\n"
1833 " nTempDays -= ((int) *rYear -1) * 365;\n"
1834 " nTempDays -= ((*rYear -1) / 4) - ((*rYear -1) / 100) + ((*rYear -1)"
1837 " if ( nTempDays < 1 )\n"
1844 " if ( nTempDays > 365 )\n"
1846 " if ( (nTempDays != 366) || !IsLeapYear( *rYear ) )\n"
1854 " while ( bCalc );\n"
1855 " barrier(CLK_LOCAL_MEM_FENCE);\n"
1856 " if(nTempDays != 0){\n"
1857 " for (*rMonth = 1; (int)nTempDays > DaysInMonth( *rMonth, *rYear );"
1860 " nTempDays -= DaysInMonth( *rMonth, *rYear ); \n"
1862 " *rDay = (int)nTempDays;\n"
1866 std::string GetYearDiff_newDecl
=
1867 "double GetYearDiff_new( int nNullDate, int nStartDate, int nEndDate,"
1870 std::string GetYearDiff_new
=
1871 "double GetYearDiff_new( int nNullDate, int nStartDate, int nEndDate,"
1874 " int nDays1stYear;\n"
1875 " int nTotalDays = GetDiffDate_new( nNullDate, nStartDate, nEndDate,"
1878 " return (double)(nTotalDays)* pow((double)nDays1stYear,-1);\n"
1881 std::string GetDiffDate_newDecl
=
1882 "int GetDiffDate_new( int nNullDate, int nStartDate, int nEndDate, int nMode,"
1883 " int* pOptDaysIn1stYear );\n";
1885 std::string GetDiffDate_new
=
1886 "int GetDiffDate_new( int nNullDate, int nStartDate, int nEndDate, int nMode,"
1887 " int* pOptDaysIn1stYear )\n"
1889 " bool bNeg = nStartDate > nEndDate;\n"
1892 " int n = nEndDate;\n"
1893 " nEndDate = nStartDate;\n"
1894 " nStartDate = n;\n"
1897 " switch( nMode )\n"
1902 " int nD1, nM1, nY1, nD2, nM2, nY2;\n"
1903 " nStartDate += nNullDate;\n"
1904 " nEndDate += nNullDate;\n"
1905 " DaysToDate_new( nStartDate, &nD1, &nM1, &nY1 );\n"
1906 " DaysToDate_new( nEndDate, &nD2, &nM2, &nY2 );\n"
1907 " bool bLeap = IsLeapYear( nY1 );\n"
1908 " int nDays, nMonths;\n"
1909 " nMonths = nM2 - nM1;\n"
1910 " nDays = nD2 - nD1;\n"
1911 " nMonths += ( nY2 - nY1 ) * 12;\n"
1912 " nRet = nMonths * 30 + nDays;\n"
1913 " if( nMode == 0 && nM1 == 2 && nM2 != 2 && nY1 == nY2 )\n"
1914 " nRet -= bLeap? 1 : 2;\n"
1915 " if( pOptDaysIn1stYear )\n"
1916 " *pOptDaysIn1stYear = 360;\n"
1920 " if( pOptDaysIn1stYear )\n"
1922 " int nD, nM, nY;\n"
1923 " DaysToDate_new( nStartDate + nNullDate, &nD, &nM, &nY );\n"
1924 " *pOptDaysIn1stYear = IsLeapYear( nY )? 366 : 365;\n"
1926 " nRet = nEndDate - nStartDate;\n"
1929 " nRet = nEndDate - nStartDate;\n"
1930 " if( pOptDaysIn1stYear )\n"
1931 " *pOptDaysIn1stYear = 360;\n"
1934 " nRet = nEndDate - nStartDate;\n"
1935 " if( pOptDaysIn1stYear )\n"
1936 " *pOptDaysIn1stYear = 365;\n"
1939 " return bNeg? -nRet : nRet;\n"
1944 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */