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"
274 std::string GetNullDateDecl
=
275 "int GetNullDate();\n";
277 std::string GetNullDate
=
278 "int GetNullDate()\n"
280 " return DateToDays(30,12,1899 );\n"
282 std::string GetNullDate_newDecl
=
283 "int GetNullDate_new();\n";
285 std::string GetNullDate_new
=
286 "int GetNullDate_new()\n"
288 " return DateToDays_new(30,12,1899 );\n"
291 std::string ScaDateDecl
=
292 "void ScaDate( int nNullDate, int nDate, int nBase,int *nOrigDay, "
293 "int *nMonth,int *nYear,int *bLastDayMode,int *bLastDay,"
294 "int *b30Days,int *bUSMode,int *nDay);\n";
297 "void ScaDate( int nNullDate, int nDate, int nBase,int *nOrigDay, "
298 "int *nMonth,int *nYear,int *bLastDayMode,int *bLastDay,"
299 "int *b30Days,int *bUSMode,int *nDay)\n"
301 " DaysToDate( nNullDate + nDate, nOrigDay, nMonth, nYear );\n"
302 " *bLastDayMode = (nBase != 5);\n"
303 " *bLastDay = (*nOrigDay >= DaysInMonth( *nMonth, *nYear ));\n"
304 " *b30Days = (nBase == 0) || (nBase == 4);\n"
305 " *bUSMode = (nBase == 0);\n"
308 " *nDay = min( *nOrigDay, 30);\n"
309 " if( *bLastDay || (*nDay >=DaysInMonth( *nMonth, *nYear )) )\n"
314 " int nLastDay = DaysInMonth( *nMonth, *nYear );\n"
315 " *nDay = *bLastDay ? nLastDay : min( *nOrigDay, nLastDay );\n"
319 std::string ScaDate2Decl
=
320 "void ScaDate2( int nNullDate, int nDate, int nBase,int *bLastDayMode,int *"
321 "bLastDay,int *b30Days,int *bUSMode);\n";
323 std::string ScaDate2
=
324 "void ScaDate2( int nNullDate, int nDate, int nBase,int *bLastDayMode,int *"
325 "bLastDay,int *b30Days,int *bUSMode)\n"
327 " int nOrigDay=0, nMonth=0, nYear=0;\n"
328 " DaysToDate( nNullDate + nDate, &nOrigDay, &nMonth, &nYear );\n"
329 " *bLastDayMode = (nBase != 5);\n"
330 " *bLastDay = (nOrigDay >= DaysInMonth( nMonth, nYear ));\n"
331 " *b30Days = (nBase == 0) || (nBase == 4);\n"
332 " *bUSMode = (nBase == 0);\n"
335 std::string lcl_GetCouppcdDecl
=
336 "int lcl_GetCouppcd(int nNullDate,int nSettle,int nMat,int nFreq,int nBase);\n";
338 std::string lcl_GetCouppcd
=
339 "int lcl_GetCouppcd(int nNullDate,int nSettle, int nMat,int nFreq,int nBase)\n"
341 " int aDate = nMat;\n"
342 " int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0,"
343 "rbUSMode=0,rnDay=0;\n"
344 " int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0,"
345 "sbUSMode=0,snDay=0;\n"
346 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
347 "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
348 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,"
349 "&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
351 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
352 " if(checklessthan(rYear,sYear,rMonth,sMonth,rnDay,snDay,rbLastDay,"
353 "sbLastDay,rDay,sDay))\n"
356 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
358 " while(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
359 "rbLastDay,sDay,rDay))\n"
361 " double d = -1*(12/nFreq);\n"
362 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,d,&rYear);\n"
364 " int nLastDay = DaysInMonth( rMonth, rYear );\n"
365 " int nRealDay = (rbLastDayMode && rbLastDay) ? nLastDay :"
366 "min( nLastDay, rDay );\n"
367 " return DateToDays( nRealDay, rMonth, rYear ) - nNullDate;\n"
370 std::string lcl_GetCoupncdDecl
=
371 "int lcl_GetCoupncd(int nNullDate,int nSettle,int nMat,int nFreq,int nBase);\n";
373 std::string lcl_GetCoupncd
=
374 "int lcl_GetCoupncd(int nNullDate,int nSettle, int nMat,int nFreq,int nBase)\n"
376 " int aDate = nMat;\n"
377 " int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0,"
378 "rbUSMode=0,rnDay=0;\n"
379 " int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0,"
380 "sbUSMode=0,snDay=0;\n"
381 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
382 "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
383 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,"
384 "&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
386 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
387 " if(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,rbLastDay"
391 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
393 " while(!checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
394 "rbLastDay,sDay,rDay))\n"
396 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,12/nFreq,&rYear);\n"
398 " int nLastDay = DaysInMonth( rMonth, rYear );\n"
399 " int nRealDay = (rbLastDayMode && rbLastDay) ? nLastDay :"
400 "min( nLastDay, rDay );\n"
401 " return DateToDays( nRealDay, rMonth, rYear ) - nNullDate;\n"
404 std::string addMonthsDecl
=
405 "void addMonths(int b30Days,int bLastDay,int *nDay,int nOrigDay,"
406 "int *nMonth,int nMonthCount,int *year);\n";
408 std::string addMonths
=
409 "void addMonths(int b30Days,int bLastDay,int *nDay,int nOrigDay,"
410 "int *nMonth,int nMonthCount,int *year)\n"
412 " int nNewMonth = nMonthCount + *nMonth;\n"
413 " if( nNewMonth > 12 )\n"
416 " *year+=nNewMonth / 12 ;\n"
417 " *nMonth = ( nNewMonth % 12 ) + 1;\n"
419 " else if( nNewMonth < 1 )\n"
421 " *year+= nNewMonth / 12 - 1 ;\n"
422 " *nMonth = nNewMonth % 12 + 12 ;\n"
425 " *nMonth = nNewMonth ;\n"
428 " *nDay = min( nOrigDay, 30);\n"
429 " if( bLastDay || (*nDay >= DaysInMonth( *nMonth, *year )) )\n"
434 " int nLastDay = DaysInMonth( *nMonth, *year );\n"
435 " *nDay = bLastDay ? nLastDay : min( nOrigDay, nLastDay );\n"
439 std::string getDaysInMonthRangeDecl
=
440 "int getDaysInMonthRange( int nFrom, int nTo,int b30Days,int year);\n";
442 std::string getDaysInMonthRange
=
443 "int getDaysInMonthRange( int nFrom, int nTo,int b30Days,int year)\n"
445 " if( nFrom > nTo )\n"
449 " nRet = (nTo - nFrom + 1) * 30;\n"
452 " for( int nMonthIx = nFrom; nMonthIx <= nTo; ++nMonthIx )\n"
453 " nRet += b30Days ? 30 : DaysInMonth( nMonthIx, year );\n"
458 std::string GetDaysInYearsDecl
=
459 "int GetDaysInYears( int nYear1, int nYear2 );\n";
461 std::string GetDaysInYears
=
462 "int GetDaysInYears( int nYear1, int nYear2 )\n"
465 " for( int n = nYear1 ; n <= nYear2 ; n++ )\n"
467 " if( IsLeapYear( n ) )\n"
478 std::string GetDaysInYearDecl
=
479 "int GetDaysInYear( int nNullDate, int nDate, int nMode );\n";
481 std::string GetDaysInYear
=
482 "int GetDaysInYear( int nNullDate, int nDate, int nMode )\n"
492 " int nD=0, nM=0, nY=0;\n"
493 " nDate += nNullDate;\n"
494 " DaysToDate( nDate, &nD, &nM, &nY );\n"
495 " return IsLeapYear( nY )? 366 : 365;\n"
502 std::string getDaysInYearRangeDecl
=
503 "int getDaysInYearRange( int nFrom, int nTo,int b30Days );\n";
505 std::string getDaysInYearRange
=
506 "int getDaysInYearRange( int nFrom, int nTo,int b30Days )\n"
508 " if( nFrom > nTo )\n"
510 " return b30Days ? ((nTo - nFrom + 1) * 360) : GetDaysInYears( nFrom, nTo)"
514 std::string getDiffDecl
=
515 "int getDiff(int rFrom,int rTo,int fDay,int fMonth,int fYear,int fbLastDayMode,"
516 "int fbLastDay,int fb30Days,int fbUSMode,int fnDay,int tDay,int tMonth,"
517 "int tYear,int tbLastDayMode,int tbLastDay,int tb30Days,"
518 "int tbUSMode,int tnDay);\n";
521 "int getDiff(int rFrom,int rTo,int fDay,int fMonth,int fYear,int fbLastDayMode,"
522 "int fbLastDay,int fb30Days,int fbUSMode,int fnDay,int tDay,int tMonth,"
523 "int tYear,int tbLastDayMode,int tbLastDay,int tb30Days,"
524 "int tbUSMode,int tnDay)\n"
528 " int d=fDay;fDay=tDay;tDay=d;\n"
529 " int m=fMonth;fMonth=tMonth;tMonth=m;\n"
530 " int y=fYear;fYear=tYear;tYear=y;\n"
531 " int a=fbLastDayMode;fbLastDayMode=tbLastDayMode;tbLastDayMode=a;\n"
532 " int b=fbLastDay;fbLastDay=tbLastDay;tbLastDay=b;\n"
533 " int c=fb30Days;fb30Days=tb30Days;tb30Days=c;\n"
534 " int e=fbUSMode;fbUSMode=tbUSMode;tbUSMode=e;\n"
535 " int f=fnDay;fnDay=tnDay;tnDay=f;\n"
542 " if( ((fMonth == 2) || (fnDay < 30)) && (tDay == 31) )\n"
544 " else if( (tMonth == 2) && tbLastDay )\n"
545 " tnDay = DaysInMonth( 2, tYear );\n"
549 " if( (fMonth == 2) && (fnDay == 30) )\n"
550 " fnDay = DaysInMonth( 2, fYear );\n"
551 " if( (tMonth == 2) && (tnDay == 30) )\n"
552 " tnDay = DaysInMonth( 2, tYear );\n"
555 " if( (fYear < tYear) || ((fYear == tYear) && (fMonth < tMonth)) )\n"
557 " int d = fb30Days ? 30:DaysInMonth(fMonth,fYear);\n"
558 " nDiff = d- fnDay + 1;\n"
559 " fDay = fnDay = 1;\n"
561 " addMonths(fb30Days,fbLastDay,&fnDay,fDay,&fMonth,1,&fYear);\n"
562 " if( fYear < tYear )\n"
564 " nDiff += getDaysInMonthRange( fMonth, 12,fb30Days,fYear);\n"
565 " addMonths(fb30Days,fbLastDay,&fnDay,fDay,&fMonth,13-fMonth,&fYear"
567 " nDiff += getDaysInYearRange( fYear, tYear - 1,fb30Days);\n"
568 " fYear+=tYear - fYear;\n"
570 " nDiff += getDaysInMonthRange(fMonth, tMonth - 1,fb30Days ,fYear );\n"
571 " addMonths(fb30Days,fbLastDay,&fnDay,fDay,&fMonth,tMonth-fMonth,&fYear"
574 " nDiff += tnDay - fnDay;\n"
575 " return nDiff > 0 ? nDiff : 0;\n"
578 std::string lcl_GetcoupdaybsDecl
=
579 "int lcl_Getcoupdaybs(int nNullDate,int nSettle, int nMat,int nFreq,int nBase);\n";
581 std::string lcl_Getcoupdaybs
=
582 "int lcl_Getcoupdaybs(int nNullDate,int nSettle, int nMat,int nFreq,int nBase)\n"
584 " int aDate = nMat;\n"
585 " int rDay=0,rMonth=0, rYear=0;int mDay=0,mMonth=0, mYear=0;int sDay=0,"
586 "sMonth=0, sYear=0;\n"
587 " int rbLastDayMode=0, rbLastDay=0,rb30Days=0,rbUSMode=0,rnDay=0;\n"
588 " int sbLastDayMode=0, sbLastDay=0,sb30Days=0,sbUSMode=0,snDay=0;\n"
589 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,&"
590 "rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
591 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,&"
592 "sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
594 " nSettle=nSettle+nNullDate;\n"
595 " aDate=DateToDays( rDay,rMonth,rYear );\n"
596 " if( aDate < nSettle )\n"
599 " aDate=DateToDays( rDay,rMonth,rYear );\n"
601 " while(aDate > nSettle )\n"
603 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,-1*(12/nFreq),&rYear"
605 " aDate=DateToDays( rDay,rMonth,rYear );\n"
607 " return getDiff( aDate, nSettle, rDay, rMonth, rYear, rbLastDayMode, "
608 "rbLastDay, rb30Days, rbUSMode, rnDay, sDay, sMonth, sYear, sbLastDayMode,"
609 "sbLastDay, sb30Days, sbUSMode, snDay);\n"
612 std::string lcl_Getcoupdaybs_newDecl
=
613 "int lcl_Getcoupdaybs_new(int nNullDate,int nSettle,int nMat,int nFreq,"
616 std::string lcl_Getcoupdaybs_new
=
617 "int lcl_Getcoupdaybs_new(int nNullDate,int nSettle,int nMat,int nFreq,"
620 " int aDate = nMat;\n"
621 " int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0,"
622 "rbUSMode=0,rnDay=0;\n"
623 " int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0,"
624 "sbUSMode=0,snDay=0;\n"
625 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
626 "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
627 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,"
628 "&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
630 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
631 " aDate=DateToDays_new( rnDay,rMonth,rYear);\n"
632 " if(checklessthan(rYear,sYear,rMonth,sMonth,rnDay,snDay,rbLastDay,"
633 "sbLastDay,rDay,sDay))\n"
636 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
637 " aDate=DateToDays_new( rnDay,rMonth,rYear );\n"
639 " while(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
640 "rbLastDay,sDay,rDay))\n"
642 " double d = -1*(12/nFreq);\n"
643 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,d,&rYear);\n"
644 " aDate=DateToDays_new( rnDay,rMonth,rYear );\n"
646 " return getDiff( aDate,nSettle+nNullDate,rDay,rMonth,rYear,rbLastDayMode,"
647 "rbLastDay,rb30Days,rbUSMode,rnDay,sDay,sMonth,sYear,sbLastDayMode,sbLastDay,"
648 "sb30Days,sbUSMode, snDay);\n"
651 std::string lcl_GetcoupdaysDecl
=
652 "int lcl_Getcoupdays(int nNullDate,int nSettle, "
653 "int nMat,int nFreq,int nBase);\n";
655 std::string lcl_Getcoupdays
=
656 "int lcl_Getcoupdays(int nNullDate,int nSettle, "
657 "int nMat,int nFreq,int nBase)\n"
659 " int aDate = nMat;\n"
660 " int rDay=0,rMonth=0, rYear=0;int mDay=0,mMonth=0, mYear=0;int sDay=0,"
661 "sMonth=0, sYear=0;\n"
662 " int rbLastDayMode=0, rbLastDay=0,rb30Days=0,rbUSMode=0,rnDay=0;\n"
663 " int sbLastDayMode=0, sbLastDay=0,sb30Days=0,sbUSMode=0,snDay=0;\n"
664 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,&"
665 "rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
666 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,&"
667 "sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
669 " nSettle=nSettle+nNullDate;\n"
670 " aDate=DateToDays( rDay,rMonth,rYear );\n"
671 " if( aDate < nSettle )\n"
674 " aDate=DateToDays( rDay,rMonth,rYear );\n"
676 " while(aDate > nSettle )\n"
678 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,-1*(12/nFreq),&rYear"
680 " aDate=DateToDays( rDay,rMonth,rYear );\n"
682 " int aNextDate=aDate;int aDay=rDay,aMonth=rMonth, aYear=rYear;\n"
683 " int abLastDayMode=rbLastDayMode, abLastDay=rbLastDay,ab30Days=rb30Days,"
684 "abUSMode=rbUSMode,anDay=rnDay;\n"
685 " addMonths(ab30Days,abLastDay,&anDay,aDay,&aMonth,12/nFreq,&aYear);\n"
686 " return getDiff( aDate, aNextDate, rDay, rMonth, rYear, rbLastDayMode, "
687 "rbLastDay, rb30Days, rbUSMode, rnDay, aDay, aMonth, aYear, abLastDayMode,"
688 "abLastDay, ab30Days, abUSMode, anDay);\n"
691 std::string lcl_Getcoupdays_newDecl
=
692 "int lcl_Getcoupdays_new(int nNullDate,int nSettle, "
693 "int nMat,int nFreq,int nBase);\n";
695 std::string lcl_Getcoupdays_new
=
696 "int lcl_Getcoupdays_new(int nNullDate,int nSettle, "
697 "int nMat,int nFreq,int nBase)\n"
699 " int aDate = nMat;\n"
700 " int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0,"
701 "rbUSMode=0,rnDay=0;\n"
702 " int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0,"
703 "sbUSMode=0,snDay=0;\n"
704 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
705 "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
706 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,"
707 "&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
709 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
710 " aDate=DateToDays_new( rnDay,rMonth,rYear);\n"
711 " if(checklessthan(rYear,sYear,rMonth,sMonth,rnDay,snDay,rbLastDay,"
712 "sbLastDay,rDay,sDay))\n"
715 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
716 " aDate=DateToDays_new( rnDay,rMonth,rYear );\n"
718 " while(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
719 "rbLastDay,sDay,rDay))\n"
721 " double d = -1*12*pow((double)nFreq,-1.0);\n"
722 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,d,&rYear);\n"
723 " aDate=DateToDays_new( rnDay,rMonth,rYear );\n"
725 " int aNextDate=aDate;int aDay=rDay,aMonth=rMonth, aYear=rYear;\n"
726 " int abLastDayMode=rbLastDayMode, abLastDay=rbLastDay,ab30Days=rb30Days,"
727 "abUSMode=rbUSMode,anDay=rnDay;\n"
728 " int tmp = (int)(12*pow((double)nFreq,-1.0));\n"
729 " addMonths(ab30Days,abLastDay,&anDay,aDay,&aMonth,tmp,&aYear);\n"
730 " return getDiff( aDate, aNextDate, rDay, rMonth, rYear, rbLastDayMode, "
731 "rbLastDay, rb30Days, rbUSMode, rnDay, aDay, aMonth, aYear, abLastDayMode,"
732 "abLastDay, ab30Days, abUSMode, anDay);\n"
735 std::string lcl_GetcoupnumDecl
=
736 "int lcl_Getcoupnum(int nNullDate,int nSettle, int nMat,int nFreq);\n";
738 std::string lcl_Getcoupnum
=
739 "int lcl_Getcoupnum(int nNullDate,int nSettle, int nMat,int nFreq)\n"
741 " int aDate = nMat;int rDay=0,rMonth=0, rYear=0;int mDay=0,mMonth=0, mYear="
743 " int sDay=0,sMonth=0, sYear=0;\n"
744 " DaysToDate(aDate+nNullDate,&rDay, &rMonth, &rYear );\n"
745 " DaysToDate(nMat+nNullDate,&mDay, &mMonth, &mYear );\n"
746 " DaysToDate(nSettle+nNullDate,&sDay, &sMonth, &sYear );\n"
748 " nSettle=nSettle+nNullDate;\n"
749 " aDate=DateToDays( rDay,rMonth,rYear );\n"
750 " if( aDate < nSettle )\n"
752 " int d=DateToDays( rDay,rMonth,rYear );\n"
753 " int nMonthCount=-1*(12 / nFreq);\n"
754 " while(d > nSettle )\n"
756 " int nNewMonth = nMonthCount + rMonth;\n"
757 " if( nNewMonth > 12 )\n"
760 " rYear+=nNewMonth / 12;\n"
761 " rMonth = nNewMonth % 12 + 1;\n"
763 " else if( nNewMonth < 1 )\n"
765 " rYear+= nNewMonth / 12 - 1;\n"
766 " rMonth = nNewMonth % 12 + 12;\n"
769 " rMonth = nNewMonth;\n"
770 " d=DateToDays( rDay,rMonth,rYear );\n"
772 " int n=(mYear-rYear)*12+mMonth-rMonth;\n"
776 std::string lcl_Getcoupnum_newDecl
=
777 "double lcl_Getcoupnum_new(int nNullDate,int nSettle,int nMat,int nFreq,int"
779 std::string lcl_Getcoupnum_new
=
780 "double lcl_Getcoupnum_new(int nNullDate,int nSettle, int nMat,int nFreq,int"
783 " int aDate = nMat;\n"
784 " int mDay=0,mMonth=0, mYear=0;\n"
785 " int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0,"
786 "rbUSMode=0,rnDay=0;\n"
787 " int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0,"
788 "sbUSMode=0,snDay=0;\n"
789 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
790 "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
791 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,"
792 "&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
793 " mMonth = rMonth, mYear = rYear;\n"
795 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
796 " if(checklessthan(rYear,sYear,rMonth,sMonth,rnDay,snDay,rbLastDay,"
797 "sbLastDay,rDay,sDay))\n"
800 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
802 " int m= checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
803 "rbLastDay,sDay,rDay);\n"
806 " double d = -1*(12/nFreq);\n"
807 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,d,&rYear);\n"
808 " m = checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
809 "rbLastDay,sDay,rDay);\n"
811 " int n=(mYear-rYear)*12+mMonth-rMonth;\n"
812 " double tmp = (double)(n*nFreq)/12.0;\n"
816 std::string setDayDecl
=
817 "void setDay(int nOrigDay, int nMonth,int nYear,int bLastDay,int b30Days,"
820 "void setDay(int nOrigDay, int nMonth,int nYear,int bLastDay,int b30Days,"
825 " *nDay = min( nOrigDay, 30);\n"
826 " if( bLastDay || (*nDay >= DaysInMonth( nMonth, nYear )) )\n"
831 " int nLastDay = DaysInMonth( nMonth, nYear );\n"
832 " *nDay = bLastDay ? nLastDay : min( nOrigDay, nLastDay );\n"
836 std::string coupdaysDecl
=
837 "double coupdays(int nSettle,int nMat,int nFreq,int nBase);\n";
839 std::string coupdays
=
840 "double coupdays(int nSettle,int nMat,int nFreq,int nBase)\n"
842 " int nNullDate=GetNullDate();\n"
843 " if( nBase == 1 )\n"
844 " return lcl_Getcoupdays(nNullDate, nSettle, nMat,nFreq, nBase);\n"
846 " return (double)GetDaysInYear(0,0,nBase)/nFreq;\n"
848 std::string coupdays_newDecl
=
849 "double coupdays_new(int nSettle,int nMat,int nFreq,int nBase);\n";
851 std::string coupdays_new
=
852 "double coupdays_new(int nSettle,int nMat,int nFreq,int nBase)\n"
854 " int nNullDate=693594;\n"
855 " if( nBase == 1 )\n"
856 " return lcl_Getcoupdays_new(nNullDate, nSettle, nMat,nFreq, nBase);\n"
858 " return (double)GetDaysInYear(0,0,nBase)*pow((double)nFreq,-1.0);\n"
861 std::string coupdaybsDecl
=
862 "double coupdaybs( int nSettle,int nMat,int nFreq,int nBase);\n";
864 std::string coupdaybs
=
865 "double coupdaybs( int nSettle,int nMat,int nFreq,int nBase)\n"
867 " int nNullDate=GetNullDate();\n"
868 " return lcl_Getcoupdaybs(nNullDate, nSettle, nMat,nFreq, nBase);\n"
871 std::string coupdaybs_newDecl
=
872 "double coupdaybs_new( int nSettle,int nMat,int nFreq,int nBase);\n";
874 std::string coupdaybs_new
=
875 "double coupdaybs_new( int nSettle,int nMat,int nFreq,int nBase)\n"
877 " int nNullDate=693594;\n"
878 " return lcl_Getcoupdaybs_new(nNullDate, nSettle, nMat,nFreq, nBase);\n"
881 std::string coupdaysncDecl
=
882 "double coupdaysnc( int nSettle,int nMat,int nFreq,int nBase);\n";
884 std::string coupdaysnc
=
885 "double coupdaysnc( int nSettle,int nMat,int nFreq,int nBase)\n"
887 " int nNullDate=GetNullDate();\n"
888 " if((nBase != 0) && (nBase != 4))\n"
890 " int aDate = nMat;\n"
891 " int rDay=0,rMonth=0, rYear=0;int mDay=0,mMonth=0, mYear=0;int sDay=0,"
892 "sMonth=0, sYear=0;\n"
893 " int rbLastDayMode=0, rbLastDay=0,rb30Days=0,rbUSMode=0,rnDay=0;\n"
894 " int sbLastDayMode=0, sbLastDay=0,sb30Days=0,sbUSMode=0,snDay=0;\n"
895 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,&"
896 "rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
897 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
898 "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
900 " nSettle=nSettle+nNullDate;\n"
901 " aDate=DateToDays( rDay,rMonth,rYear );\n"
902 " if( aDate > nSettle )\n"
905 " aDate=DateToDays( rDay,rMonth,rYear );\n"
907 " while(aDate <= nSettle )\n"
909 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,12/nFreq,&rYear)"
911 " aDate=DateToDays( rDay,rMonth,rYear );\n"
913 " return getDiff( nSettle, aDate, sDay, sMonth, sYear, sbLastDayMode, "
914 "sbLastDay, sb30Days, sbUSMode, snDay, rDay, rMonth, rYear, rbLastDayMode, "
915 "rbLastDay, rb30Days, rbUSMode, rnDay);\n"
918 " return coupdays(nSettle,nMat,nFreq,nBase)- coupdaybs( nSettle,nMat,"
921 std::string coupdaysnc_newDecl
=
922 "double coupdaysnc_new( int nSettle,int nMat,int nFreq,int nBase);\n";
924 std::string coupdaysnc_new
=
925 "double coupdaysnc_new( int nSettle,int nMat,int nFreq,int nBase)\n"
927 " int nNullDate=693594;\n"
928 " if((nBase != 0) && (nBase != 4))\n"
930 " int aDate = nMat;\n"
931 " int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0,"
932 "rbUSMode=0,rnDay=0;\n"
933 " int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0,"
934 "sbUSMode=0,snDay=0;\n"
935 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,"
936 "&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
937 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
938 "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
940 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
941 " aDate=DateToDays( rnDay,rMonth,rYear);\n"
942 " if(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,rbLastDay"
946 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
947 " aDate=DateToDays( rnDay,rMonth,rYear );\n"
949 " while(!checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
950 "rbLastDay,sDay,rDay))\n"
952 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,12/nFreq,&rYear);\n"
953 " aDate=DateToDays( rnDay,rMonth,rYear );\n"
955 " return getDiff( nSettle+nNullDate,aDate,sDay,sMonth,sYear,sbLastDayMode, "
956 "sbLastDay, sb30Days, sbUSMode, snDay, rDay, rMonth, rYear, rbLastDayMode, "
957 "rbLastDay, rb30Days, rbUSMode, rnDay);\n"
960 " return coupdays_new(nSettle,nMat,nFreq,nBase)- coupdaybs_new( nSettle,"
961 "nMat,nFreq,nBase);\n"
964 std::string checklessthanDecl
=
965 "int checklessthan(int aYear,int bYear,int aMonth,int bMonth,int anDay,int "
966 "bnDay,int abLastDay,int bbLastDay,int anOrigDay,int bnOrigDay);\n";
967 std::string checklessthan
=
968 "int checklessthan(int aYear,int bYear,int aMonth,int bMonth,int anDay,int "
969 "bnDay,int abLastDay,int bbLastDay,int anOrigDay,int bnOrigDay)\n"
971 " if( aYear != bYear )\n"
972 " return aYear < bYear;\n"
973 " if( aMonth != bMonth )\n"
974 " return aMonth < bMonth;\n"
975 " if( anDay != bnDay )\n"
976 " return anDay < bnDay;\n"
977 " if( abLastDay || bbLastDay )\n"
978 " return !abLastDay && bbLastDay;\n"
979 " return anOrigDay < bnOrigDay;\n"
982 std::string coupnumDecl
=
983 "double coupnum( int nSettle,int nMat,int nFreq,int nBase);\n";
986 "double coupnum( int nSettle,int nMat,int nFreq,int nBase)\n"
988 " int nNullDate=GetNullDate();\n"
989 " return lcl_Getcoupnum(nNullDate,nSettle,nMat,nFreq);\n"
991 std::string coupnum_newDecl
=
992 "double coupnum_new( int nSettle,int nMat,int nFreq,int nBase);\n";
994 std::string coupnum_new
=
995 "double coupnum_new( int nSettle,int nMat,int nFreq,int nBase)\n"
997 " int nNullDate=693594;\n"
998 " return lcl_Getcoupnum_new(nNullDate,nSettle,nMat,nFreq,nBase);\n"
1001 std::string getPrice_Decl
=
1002 "double getPrice_(int nSettle, int nMat, double fRate, double fYield,\n"
1003 "double fRedemp, int nFreq, int nBase );\n";
1005 std::string getPrice_
=
1006 "double getPrice_(int nSettle, int nMat, double fRate, double fYield,\n"
1007 "double fRedemp, int nFreq, int nBase )\n"
1009 " double fFreq = nFreq;\n"
1010 " double fE = coupdays( nSettle, nMat, nFreq, nBase );\n"
1011 " double fDSC_E = coupdaysnc( nSettle, nMat, nFreq, nBase ) / fE;\n"
1012 " double fN = coupnum( nSettle, nMat, nFreq, nBase );\n"
1013 " double fA = coupdaybs( nSettle, nMat, nFreq, nBase );\n"
1014 " double fRet = fRedemp / ( pow( 1.0 + fYield / fFreq, fN - 1.0 + "
1016 " fRet -= 100.0 * fRate / fFreq * fA / fE;\n"
1017 " double fT1 = 100.0 * fRate / fFreq;\n"
1018 " double fT2 = 1.0 + fYield / fFreq;\n"
1019 " for( double fK = 0.0 ; fK < fN ; fK+=1.0 )\n"
1020 " fRet += fT1 / pow( fT2, fK + fDSC_E );\n"
1023 std::string getPrice_new_Decl
=
1024 "double getPrice_(int nSettle, int nMat, double fRate, double fYield,\n"
1025 "double fRedemp, int nFreq, int nBase );\n";
1027 std::string getPrice_new
=
1028 "double getPrice_(int nSettle, int nMat, double fRate, double fYield,\n"
1029 "double fRedemp, int nFreq, int nBase )\n"
1031 " double fFreq = nFreq;\n"
1032 " double fE = coupdays_new( nSettle, nMat, nFreq, nBase );\n"
1033 " double fDSC_E = coupdaysnc_new( nSettle, nMat, nFreq, nBase ) / fE;\n"
1034 " double fN = coupnum_new( nSettle, nMat, nFreq, nBase );\n"
1035 " double fA = coupdaybs_new( nSettle, nMat, nFreq, nBase );\n"
1036 " double fRet = fRedemp / ( pow( 1.0 + fYield / fFreq, fN - 1.0 + "
1038 " fRet -= 100.0 * fRate / fFreq * fA / fE;\n"
1039 " double fT1 = 100.0 * fRate / fFreq;\n"
1040 " double fT2 = 1.0 + fYield / fFreq;\n"
1041 " for( double fK = 0.0 ; fK < fN ; fK+=1.0 )\n"
1042 " fRet += fT1 / pow( fT2, fK + fDSC_E );\n"
1046 std::string getYield_Decl
=
1047 "double getYield_( int nNullDate, int nSettle, int nMat, double fCoup,"
1048 "double fPrice,double fRedemp, int nFreq, int nBase);\n";
1050 std::string getYield_
=
1051 "double getYield_( int nNullDate, int nSettle, int nMat, double fCoup,"
1052 "double fPrice,double fRedemp, int nFreq, int nBase )\n"
1054 " double fRate = fCoup;\n"
1055 " double fPriceN = 0.0;\n"
1056 " double fYield1 = 0.0;\n"
1057 " double fYield2 = 1.0;\n"
1058 " double fPrice1 = getPrice_(nSettle, nMat, fRate, fYield1, fRedemp, "
1060 " double fPrice2 = getPrice_(nSettle, nMat, fRate, fYield2, fRedemp, "
1062 " double fYieldN = ( fYield2 - fYield1 ) * 0.5;\n"
1063 " for( unsigned int nIter = 0 ; nIter < 100 && fPriceN != fPrice ; nIter++ "
1066 " fPriceN = getPrice_(nSettle, nMat, fRate, fYieldN, fRedemp, nFreq, "
1068 " if( fPrice == fPrice1 )\n"
1069 " return fYield1;\n"
1070 " else if( fPrice == fPrice2 )\n"
1071 " return fYield2;\n"
1072 " else if( fPrice == fPriceN )\n"
1073 " return fYieldN;\n"
1074 " else if( fPrice < fPrice2 )\n"
1076 " fYield2 *= 2.0;\n"
1077 " fPrice2 = getPrice_(nSettle, nMat, fRate, fYield2, fRedemp, nFreq"
1079 " fYieldN = ( fYield2 - fYield1 ) * 0.5;\n"
1083 " if( fPrice < fPriceN )\n"
1085 " fYield1 = fYieldN;\n"
1086 " fPrice1 = fPriceN;\n"
1090 " fYield2 = fYieldN;\n"
1091 " fPrice2 = fPriceN;\n"
1093 " fYieldN = fYield2 - ( fYield2 - fYield1 ) * ( ( fPrice - fPrice2 "
1094 ") / ( fPrice1 - fPrice2 ) );\n"
1097 " return fYieldN;\n"
1100 std::string GetYearFracDecl
=
1101 "double GetYearFrac( int nNullDate, int nStartDate, int nEndDate,"
1104 std::string GetYearFrac
=
1105 "double GetYearFrac( int nNullDate, int nStartDate, int nEndDate,"
1108 " if( nStartDate == nEndDate )\n"
1111 " if( nStartDate > nEndDate )\n"
1113 " int n = nEndDate;\n"
1114 " nEndDate = nStartDate;\n"
1115 " nStartDate = n;\n"
1118 " int nDate1 = nStartDate + nNullDate;\n"
1119 " int nDate2 = nEndDate + nNullDate;\n"
1121 " int nDay1, nDay2;\n"
1122 " int nMonth1, nMonth2;\n"
1123 " int nYear1, nYear2;\n"
1125 " DaysToDate( nDate1, &nDay1, &nMonth1, &nYear1 );\n"
1126 " DaysToDate( nDate2, &nDay2, &nMonth2, &nYear2 );\n"
1129 " switch( nMode )\n"
1132 " if ( nDay1 == 31 )\n"
1136 " if ( nDay1 == 30 && nDay2 == 31 )\n"
1142 " if ( nMonth1 == 2 && nDay1 == "
1143 "( IsLeapYear( nYear1 ) ? 29 : 28 ) )\n"
1146 " if ( nMonth2 == 2 && nDay2 == "
1147 "( IsLeapYear( nYear2 ) ? 29 : 28 ) )\n"
1153 " nDayDiff = ( nYear2 - nYear1 ) * 360 + "
1154 "( nMonth2 - nMonth1 ) * 30 + ( nDay2 - nDay1 );\n"
1159 " nDayDiff = nDate2 - nDate1;\n"
1162 " if ( nDay1 == 31 )\n"
1166 " if ( nDay2 == 31 )\n"
1170 " nDayDiff = ( nYear2 - nYear1 ) * 360 + "
1171 "( nMonth2 - nMonth1 ) * 30 + ( nDay2 - nDay1 );\n"
1175 " double nDaysInYear;\n"
1176 " switch( nMode )\n"
1181 " nDaysInYear = 360;\n"
1185 " bool isYearDifferent = ( nYear1 != nYear2 );\n"
1186 " if ( isYearDifferent &&\n"
1187 " ( ( nYear2 != nYear1 + 1 ) ||\n"
1188 " ( nMonth1 < nMonth2 ) ||\n"
1189 " ( nMonth1 == nMonth2 && nDay1 < nDay2 ) ) )\n"
1192 " int nDayCount = 0;\n"
1193 " for ( int i = nYear1; i <= nYear2; i++ )\n"
1194 " nDayCount += ( IsLeapYear( i ) ? 366 : 365 );\n"
1196 " nDaysInYear = ( double ) nDayCount / "
1197 "( double ) ( nYear2 - nYear1 + 1 );\n"
1201 " if ( isYearDifferent && IsLeapYear( nYear1 ) )\n"
1203 " nDaysInYear = 366;\n"
1208 " if ( ( IsLeapYear( nYear1 ) && nMonth1 <= 2 "
1209 "&& nDay1 <= 29 ) ||\n"
1210 " ( IsLeapYear( nYear2 ) && ( nMonth2 > 3 || "
1211 "( nMonth2 == 2 && nDay1 == 29 ) ) ) )\n"
1213 " nDaysInYear = 366;\n"
1217 " nDaysInYear = 365;\n"
1218 " for ( int i = nYear1; i <= nYear2; i++ )\n"
1220 " if ( IsLeapYear( i ) )\n"
1222 " nDaysInYear = 366;\n"
1232 " nDaysInYear = 365;\n"
1235 " return (double)( nDayDiff ) / (nDaysInYear);\n"
1238 std::string GetYieldmatDecl
=
1239 "double GetYieldmat( int nNullDate, int nSettle, int nMat, int nIssue,\n"
1240 "double fRate, double fPrice, int nBase );\n";
1242 std::string GetYieldmat
=
1243 "double GetYieldmat( int nNullDate, int nSettle, int nMat, int nIssue,\n"
1244 "double fRate, double fPrice, int nBase )\n"
1246 " double fIssMat = GetYearFrac_new( nNullDate, nIssue, nMat, nBase );\n"
1247 " double fIssSet = GetYearFrac_new( nNullDate, nIssue, nSettle, nBase );\n"
1248 " double fSetMat = GetYearFrac_new( nNullDate, nSettle, nMat, nBase );\n"
1249 " double y = 1.0 + fIssMat * fRate;\n"
1250 " y =y * pow( (fPrice / 100.0 + fIssSet * fRate),-1);\n"
1252 " y = y * pow(fSetMat,-1);\n"
1256 std::string GetDiffDateDecl
=
1257 "int GetDiffDate( int nNullDate, int nStartDate, int nEndDate, int nMode,"
1258 " int* pOptDaysIn1stYear );\n";
1260 std::string GetDiffDate
=
1261 "int GetDiffDate( int nNullDate, int nStartDate, int nEndDate, int nMode,"
1262 " int* pOptDaysIn1stYear )\n"
1264 " bool bNeg = nStartDate > nEndDate;\n"
1267 " int n = nEndDate;\n"
1268 " nEndDate = nStartDate;\n"
1269 " nStartDate = n;\n"
1272 " switch( nMode )\n"
1277 " int nD1, nM1, nY1, nD2, nM2, nY2;\n"
1278 " nStartDate += nNullDate;\n"
1279 " nEndDate += nNullDate;\n"
1280 " DaysToDate( nStartDate, &nD1, &nM1, &nY1 );\n"
1281 " DaysToDate( nEndDate, &nD2, &nM2, &nY2 );\n"
1282 " bool bLeap = IsLeapYear( nY1 );\n"
1283 " int nDays, nMonths;\n"
1284 " nMonths = nM2 - nM1;\n"
1285 " nDays = nD2 - nD1;\n"
1286 " nMonths += ( nY2 - nY1 ) * 12;\n"
1287 " nRet = nMonths * 30 + nDays;\n"
1288 " if( nMode == 0 && nM1 == 2 && nM2 != 2 && nY1 == nY2 )\n"
1289 " nRet -= bLeap? 1 : 2;\n"
1290 " if( pOptDaysIn1stYear )\n"
1291 " *pOptDaysIn1stYear = 360;\n"
1295 " if( pOptDaysIn1stYear )\n"
1297 " int nD, nM, nY;\n"
1298 " DaysToDate( nStartDate + nNullDate, &nD, &nM, &nY );\n"
1299 " *pOptDaysIn1stYear = IsLeapYear( nY )? 366 : 365;\n"
1301 " nRet = nEndDate - nStartDate;\n"
1304 " nRet = nEndDate - nStartDate;\n"
1305 " if( pOptDaysIn1stYear )\n"
1306 " *pOptDaysIn1stYear = 360;\n"
1309 " nRet = nEndDate - nStartDate;\n"
1310 " if( pOptDaysIn1stYear )\n"
1311 " *pOptDaysIn1stYear = 365;\n"
1314 " return bNeg? -nRet : nRet;\n"
1317 std::string GetYearDiffDecl
=
1318 "double GetYearDiff( int nNullDate, int nStartDate, int nEndDate,"
1321 std::string GetYearDiff
=
1322 "double GetYearDiff( int nNullDate, int nStartDate, int nEndDate,"
1325 " int nDays1stYear;\n"
1326 " int nTotalDays = GetDiffDate( nNullDate, nStartDate, nEndDate,"
1329 " return (double)(nTotalDays)*pow((double)nDays1stYear,-1);\n"
1332 std::string GetDiffDate360_Decl
=
1333 "int GetDiffDate360_(\n"
1334 " int nDay1, int nMonth1, int nYear1, bool bLeapYear1,\n"
1335 " int nDay2, int nMonth2, int nYear2,\n"
1336 " bool bUSAMethod );\n";
1338 std::string GetDiffDate360_
=
1339 "int GetDiffDate360_(\n"
1340 " int nDay1, int nMonth1, int nYear1, bool bLeapYear1,\n"
1341 " int nDay2, int nMonth2, int nYear2,\n"
1342 " bool bUSAMethod )\n"
1344 " if( nDay1 == 31 )\n"
1346 " else if( bUSAMethod && ( nMonth1 == 2 && ( nDay1 == 29 || ( nDay1 == 28 "
1347 "&& !bLeapYear1 ) ) ) )\n"
1349 " if( nDay2 == 31 )\n"
1351 " if( bUSAMethod && nDay1 != 30 )\n"
1354 " if( nMonth2 == 12 )\n"
1365 " return nDay2 + nMonth2 * 30 + nYear2 * 360 - nDay1 - nMonth1 * 30 - "
1369 std::string GetDiffDate360Decl
=
1370 "int GetDiffDate360( int nNullDate, int nDate1, int nDate2,"
1371 "bool bUSAMethod);\n";
1373 std::string GetDiffDate360
=
1374 "int GetDiffDate360( int nNullDate, int nDate1, int nDate2,"
1375 "bool bUSAMethod )\n"
1377 " nDate1 += nNullDate;\n"
1378 " nDate2 += nNullDate;\n"
1379 " int nDay1, nMonth1, nYear1, nDay2, nMonth2, nYear2;\n"
1380 " DaysToDate( nDate1, &nDay1, &nMonth1, &nYear1 );\n"
1381 " DaysToDate( nDate2, &nDay2, &nMonth2, &nYear2 );\n"
1382 " return GetDiffDate360_( nDay1, nMonth1, nYear1, IsLeapYear( nYear1 ), "
1383 "nDay2, nMonth2, nYear2, bUSAMethod );\n"
1386 std::string GetDurationDecl
=
1387 "double GetDuration( \n"
1388 " int nNullDate, int nSettle, int nMat, double fCoup,\n"
1389 " double fYield, int nFreq, int nBase );\n";
1391 std::string GetDuration
=
1392 "double GetDuration( \n"
1393 " int nNullDate, int nSettle, int nMat, double fCoup,\n"
1394 " double fYield, int nFreq, int nBase )\n"
1396 " double fYearfrac = GetYearFrac( nNullDate, nSettle, nMat, nBase );\n"
1397 " double fNumOfCoups = lcl_Getcoupnum(nNullDate,nSettle,nMat,nFreq);\n"
1398 " double fDur = 0.0;\n"
1399 " double f100 = 100.0;\n"
1400 " fCoup *= f100 / nFreq;\n"
1401 " fYield /= nFreq;\n"
1403 " double nDiff = fYearfrac * nFreq - fNumOfCoups;\n"
1405 " for( t = 1 ; t < fNumOfCoups ; t++ )\n"
1406 " fDur += ( t + nDiff ) * ( fCoup ) / pow( fYield, t + nDiff );\n"
1407 " fDur += ( fNumOfCoups + nDiff ) * ( fCoup + f100 ) /"
1408 " pow( fYield, fNumOfCoups + nDiff );\n"
1409 " double p = 0.0;\n"
1410 " for( t = 1 ; t < fNumOfCoups ; t++ )\n"
1411 " p += fCoup / pow( fYield, t + nDiff );\n"
1412 " p += ( fCoup + f100 ) / pow( fYield, fNumOfCoups + nDiff );\n"
1415 " return fDur;\n""}\n";
1417 std::string GetDuration_newDecl
=
1418 "double GetDuration_new( \n"
1419 " int nNullDate, int nSettle, int nMat, double fCoup,\n"
1420 " double fYield, int nFreq, int nBase );\n";
1422 std::string GetDuration_new
=
1423 "double GetDuration_new( \n"
1424 " int nNullDate, int nSettle, int nMat, double fCoup,\n"
1425 " double fYield, int nFreq, int nBase )\n"
1427 " double fYearfrac = GetYearFrac(nNullDate,nSettle,nMat,nBase);\n"
1428 " double fNumOfCoups = lcl_Getcoupnum_new(nNullDate,nSettle,nMat,"
1430 " double fDur = 0.0;\n"
1431 " fCoup = fCoup * 100.0 * pow(nFreq, -1.0);\n"
1432 " fYield = fYield * pow(nFreq, -1.0);\n"
1434 " double nDiff = fYearfrac * nFreq - fNumOfCoups;\n"
1436 " double tmp0 = 0, tmp1 = 0, tmp2 = 0;\n"
1437 " for( t = 1 ; t < fNumOfCoups ; t++ ){\n"
1438 " tmp0 = (t + nDiff) * ( fCoup ) ;\n"
1439 " tmp1 = pow( fYield, t + nDiff ) ;\n"
1440 " tmp2 = tmp0 * pow(tmp1, -1);\n"
1443 " fDur += (fNumOfCoups + nDiff) * (fCoup + 100.0) * pow(pow(fYield,"
1444 " fNumOfCoups + nDiff ),-1);\n"
1445 " double p = 0.0;\n"
1446 " for( t = 1 ; t < fNumOfCoups ; t++ ){\n"
1447 " tmp0 = pow( fYield, t + nDiff );\n"
1448 " p += fCoup * pow(tmp0, -1);}\n"
1449 " p += (fCoup + 100.0) * pow(pow(fYield, fNumOfCoups + nDiff), -1);\n"
1450 " fDur = fDur * pow(p, -1.0);\n"
1451 " fDur = fDur * pow(nFreq, -1.0);\n"
1455 std::string ScGetGDADecl
=
1456 "double ScGetGDA(double fWert, double fRest, double fDauer, double fPeriode,"
1457 "double fFaktor);\n";
1459 std::string ScGetGDA
=
1460 "double ScGetGDA(double fWert, double fRest, double fDauer, double fPeriode,"
1463 " double fGda, fZins, fAlterWert, fNeuerWert;\n"
1464 " fZins = fFaktor / fDauer;\n"
1465 " if (fZins >= 1.0)\n"
1468 " if (fPeriode == 1.0)\n"
1469 " fAlterWert = fWert;\n"
1471 " fAlterWert = 0.0;\n"
1474 " fAlterWert = fWert * pow(1.0 - fZins, fPeriode - 1.0);\n"
1475 " fNeuerWert = fWert * pow(1.0 - fZins, fPeriode);\n"
1477 " if (fNeuerWert < fRest)\n"
1478 " fGda = fAlterWert - fRest;\n"
1480 " fGda = fAlterWert - fNeuerWert;\n"
1481 " if (fGda < 0.0)\n"
1486 std::string DblMinDecl
=
1487 "inline double DblMin( double a, double b );\n";
1490 "inline double DblMin( double a, double b )\n"
1492 " return (a < b) ? a : b;\n"
1495 std::string ScInterVDBDecl
=
1496 "double ScInterVDB(double fWert,double fRest,double fDauer, double fDauer1,"
1497 "double fPeriode,double fFaktor);\n";
1499 std::string ScInterVDB
=
1500 "double ScInterVDB(double fWert,double fRest,double fDauer, double fDauer1,"
1501 "double fPeriode,double fFaktor)\n"
1504 " double fIntEnd = ceil(fPeriode);\n"
1505 " int nLoopEnd = fIntEnd;\n"
1507 " double fTerm, fLia;\n"
1508 " double fRestwert = fWert - fRest;\n"
1509 " int bNowLia = 0;\n"
1513 " for ( i = 1; i <= nLoopEnd; i++)\n"
1517 " fGda = ScGetGDA(fWert, fRest, fDauer, (double) i, fFaktor);\n"
1518 " fLia = fRestwert/ (fDauer1 - (double) (i-1));\n"
1519 " if (fLia > fGda)\n"
1527 " fRestwert =fRestwert- fGda;\n"
1535 " if ( i == nLoopEnd)\n"
1536 " fTerm *= ( fPeriode + 1.0 - fIntEnd );\n"
1543 std::string VDBImplementDecl
=
1544 "double VDBImplement(double fWert,double fRest, double fDauer, double fAnfang"
1545 ", double fEnde, double fFaktor,int bFlag);\n";
1547 std::string VDBImplement
=
1548 "double VDBImplement(double fWert,double fRest, double fDauer, double fAnfang"
1549 ", double fEnde, double fFaktor,int bFlag)\n"
1551 " double result=0;\n"
1552 " double fIntStart = floor(fAnfang);\n"
1553 " double fIntEnd = ceil(fEnde);\n"
1554 " int nLoopStart = (int) fIntStart;\n"
1555 " int nLoopEnd = (int) fIntEnd;\n"
1558 " for (int i = nLoopStart + 1; i <= nLoopEnd; i++)\n"
1560 " double fTerm = ScGetGDA(fWert, fRest, fDauer, (double) i, fFaktor"
1562 " if ( i == nLoopStart+1 )\n"
1563 " fTerm *= ( DblMin( fEnde, fIntStart + 1.0 ) - fAnfang );\n"
1564 " else if ( i == nLoopEnd )\n"
1565 " fTerm *= ( fEnde + 1.0 - fIntEnd );\n"
1566 " result += fTerm;\n"
1571 " double fDauer1=fDauer;\n"
1572 " if(!isequal(fAnfang,floor(fAnfang)))\n"
1576 " if(fAnfang>fDauer/2 || isequal(fAnfang,fDauer/2))\n"
1578 " double fPart=fAnfang-fDauer/2;\n"
1579 " fAnfang=fDauer/2;\n"
1585 " fWert-=ScInterVDB(fWert,fRest,fDauer,fDauer1,fAnfang,fFaktor);\n"
1586 " result=ScInterVDB(fWert,fRest,fDauer,fDauer-fAnfang,fEnde-fAnfang,"
1592 std::string GetOddlpriceDecl
=
1593 "double GetOddlprice( int nNullDate, int nSettle, int nMat, int nLastCoup,\n"
1594 " double fRate, double fYield, double fRedemp, int nFreq, int nBase );\n";
1596 std::string GetOddlprice
=
1597 "double GetOddlprice( int nNullDate, int nSettle, int nMat, int nLastCoup,\n"
1598 " double fRate, double fYield, double fRedemp, int nFreq, int nBase )\n"
1600 " double fFreq = nFreq ;\n"
1601 " double fDCi = GetYearFrac( nNullDate, nLastCoup,"
1602 "nMat, nBase ) * fFreq;\n"
1603 " double fDSCi = GetYearFrac( nNullDate, nSettle,"
1604 "nMat, nBase ) * fFreq;\n"
1605 " double fAi = GetYearFrac( nNullDate, nLastCoup,"
1606 "nSettle, nBase ) * fFreq;\n"
1607 " double p = fRedemp + fDCi * 100.0 * fRate / fFreq;\n"
1608 " p /= fDSCi * fYield / fFreq + 1.0;\n"
1609 " p -= fAi * 100.0 * fRate / fFreq;\n"
1613 std::string GetOddlyieldDecl
=
1614 "double GetOddlyield( int nNullDate, int nSettle, int nMat, int nLastCoup,\n"
1615 " double fRate, double fPrice, double fRedemp, int nFreq, int nBase );\n";
1617 std::string GetOddlyield
=
1618 "double GetOddlyield( int nNullDate, int nSettle, int nMat, int nLastCoup,\n"
1619 " double fRate, double fPrice, double fRedemp, int nFreq, int nBase ) \n"
1621 " double fFreq = nFreq ;\n"
1622 " double fDCi= GetYearFrac( nNullDate, nLastCoup, nMat, nBase ) * fFreq;\n"
1623 " double fDSCi= GetYearFrac( nNullDate, nSettle, nMat, nBase ) * fFreq;\n"
1624 " double fAi= GetYearFrac( nNullDate, nLastCoup, nSettle, nBase )*fFreq;\n"
1625 " double y = fRedemp + fDCi * 100.0 * fRate / fFreq;\n"
1626 " y /= fPrice + fAi * 100.0 * fRate / fFreq;\n"
1628 " y *= fFreq / fDSCi;\n"
1632 std::string GetYearFrac_newDecl
=
1633 "double GetYearFrac_new( int nNullDate, int nStartDate, int nEndDate,"
1636 std::string GetYearFrac_new
=
1637 "double GetYearFrac_new( int nNullDate, int nStartDate, int nEndDate,"
1640 " if( nStartDate == nEndDate )\n"
1642 " if( nStartDate > nEndDate )\n"
1644 " int n = nEndDate;\n"
1645 " nEndDate = nStartDate;\n"
1646 " nStartDate = n;\n"
1648 " int nDate1 = nStartDate + nNullDate;\n"
1649 " int nDate2 = nEndDate + nNullDate;\n"
1650 " int nDay1, nDay2;\n"
1651 " int nMonth1, nMonth2;\n"
1652 " int nYear1, nYear2;\n"
1653 " DaysToDate_new( nDate1, &nDay1, &nMonth1, &nYear1 );\n"
1654 " DaysToDate_new( nDate2, &nDay2, &nMonth2, &nYear2 );\n"
1656 " switch( nMode )\n"
1659 " if ( nDay1 == 31 )\n"
1663 " if ( nDay1 == 30 && nDay2 == 31 )\n"
1669 " if ( nMonth1 == 2 && nDay1 == "
1670 "( IsLeapYear( nYear1 ) ? 29 : 28 ) )\n"
1673 " if ( nMonth2 == 2 && nDay2 == "
1674 "( IsLeapYear( nYear2 ) ? 29 : 28 ) )\n"
1680 " nDayDiff = ( nYear2 - nYear1 ) * 360 + "
1681 "( nMonth2 - nMonth1 ) * 30 + ( nDay2 - nDay1 );\n"
1686 " nDayDiff = nDate2 - nDate1;\n"
1689 " if ( nDay1 == 31 )\n"
1693 " if ( nDay2 == 31 )\n"
1697 " nDayDiff = ( nYear2 - nYear1 ) * 360 + "
1698 "( nMonth2 - nMonth1 ) * 30 + ( nDay2 - nDay1 );\n"
1701 " double nDaysInYear;\n"
1702 " switch( nMode )\n"
1707 " nDaysInYear = 360;\n"
1711 " bool isYearDifferent = ( nYear1 != nYear2 );\n"
1712 " if ( isYearDifferent &&\n"
1713 " ( ( nYear2 != nYear1 + 1 ) ||\n"
1714 " ( nMonth1 < nMonth2 ) ||\n"
1715 " ( nMonth1 == nMonth2 && nDay1 < nDay2 ) ) )\n"
1717 " int nDayCount = 0;\n"
1718 " for ( int i = nYear1; i <= nYear2; i++ )\n"
1719 " nDayCount += ( IsLeapYear( i ) ? 366 : 365 );\n"
1720 " nDaysInYear = ( double ) nDayCount / "
1721 "( double ) ( nYear2 - nYear1 + 1 );\n"
1725 " if ( isYearDifferent && IsLeapYear( nYear1 ) )\n"
1727 " nDaysInYear = 366;\n"
1731 " if ( ( IsLeapYear( nYear1 ) && nMonth1 <= 2 "
1732 "&& nDay1 <= 29 ) ||\n"
1733 " ( IsLeapYear( nYear2 ) && ( nMonth2 > 3 || "
1734 "( nMonth2 == 2 && nDay1 == 29 ) ) ) )\n"
1736 " nDaysInYear = 366;\n"
1740 " nDaysInYear = 365;\n"
1741 " for ( int i = nYear1; i <= nYear2; i++ )\n"
1743 " if ( IsLeapYear( i ) )\n"
1745 " nDaysInYear = 366;\n"
1755 " nDaysInYear = 365;\n"
1758 " return (double)( nDayDiff ) / (nDaysInYear);\n"
1761 std::string DaysToDate_newDecl
=
1762 "void DaysToDate_new( int nDays, int *rDay, int* rMonth, int* rYear );\n";
1764 std::string DaysToDate_new
=
1765 "void DaysToDate_new( int nDays, int *rDay, int* rMonth, int* rYear )\n"
1772 " nTempDays = nDays;\n"
1773 " *rYear = (int)((nTempDays / 365) - i);\n"
1774 " nTempDays -= ((int) *rYear -1) * 365;\n"
1775 " nTempDays -= ((*rYear -1) / 4) - ((*rYear -1) / 100) + ((*rYear -1)"
1778 " if ( nTempDays < 1 )\n"
1785 " if ( nTempDays > 365 )\n"
1787 " if ( (nTempDays != 366) || !IsLeapYear( *rYear ) )\n"
1795 " while ( bCalc );\n"
1796 " if(nTempDays != 0){\n"
1797 " for (*rMonth = 1; (int)nTempDays > DaysInMonth( *rMonth, *rYear );"
1800 " nTempDays -= DaysInMonth( *rMonth, *rYear ); \n"
1802 " *rDay = (int)nTempDays;\n"
1806 std::string DaysToDate_LocalBarrierDecl
=
1807 "void DaysToDate( int nDays, int *rDay, int* rMonth, int* rYear );\n";
1809 std::string DaysToDate_LocalBarrier
=
1810 "void DaysToDate( int nDays, int *rDay, int* rMonth, int* rYear )\n"
1817 " nTempDays = nDays;\n"
1818 " *rYear = (int)((nTempDays / 365) - i);\n"
1819 " nTempDays -= ((int) *rYear -1) * 365;\n"
1820 " nTempDays -= ((*rYear -1) / 4) - ((*rYear -1) / 100) + ((*rYear -1)"
1823 " if ( nTempDays < 1 )\n"
1830 " if ( nTempDays > 365 )\n"
1832 " if ( (nTempDays != 366) || !IsLeapYear( *rYear ) )\n"
1840 " while ( bCalc );\n"
1841 " barrier(CLK_LOCAL_MEM_FENCE);\n"
1842 " if(nTempDays != 0){\n"
1843 " for (*rMonth = 1; (int)nTempDays > DaysInMonth( *rMonth, *rYear );"
1846 " nTempDays -= DaysInMonth( *rMonth, *rYear ); \n"
1848 " *rDay = (int)nTempDays;\n"
1852 std::string GetYearDiff_newDecl
=
1853 "double GetYearDiff_new( int nNullDate, int nStartDate, int nEndDate,"
1856 std::string GetYearDiff_new
=
1857 "double GetYearDiff_new( int nNullDate, int nStartDate, int nEndDate,"
1860 " int nDays1stYear;\n"
1861 " int nTotalDays = GetDiffDate_new( nNullDate, nStartDate, nEndDate,"
1864 " return (double)(nTotalDays)* pow((double)nDays1stYear,-1);\n"
1867 std::string GetDiffDate_newDecl
=
1868 "int GetDiffDate_new( int nNullDate, int nStartDate, int nEndDate, int nMode,"
1869 " int* pOptDaysIn1stYear );\n";
1871 std::string GetDiffDate_new
=
1872 "int GetDiffDate_new( int nNullDate, int nStartDate, int nEndDate, int nMode,"
1873 " int* pOptDaysIn1stYear )\n"
1875 " bool bNeg = nStartDate > nEndDate;\n"
1878 " int n = nEndDate;\n"
1879 " nEndDate = nStartDate;\n"
1880 " nStartDate = n;\n"
1883 " switch( nMode )\n"
1888 " int nD1, nM1, nY1, nD2, nM2, nY2;\n"
1889 " nStartDate += nNullDate;\n"
1890 " nEndDate += nNullDate;\n"
1891 " DaysToDate_new( nStartDate, &nD1, &nM1, &nY1 );\n"
1892 " DaysToDate_new( nEndDate, &nD2, &nM2, &nY2 );\n"
1893 " bool bLeap = IsLeapYear( nY1 );\n"
1894 " int nDays, nMonths;\n"
1895 " nMonths = nM2 - nM1;\n"
1896 " nDays = nD2 - nD1;\n"
1897 " nMonths += ( nY2 - nY1 ) * 12;\n"
1898 " nRet = nMonths * 30 + nDays;\n"
1899 " if( nMode == 0 && nM1 == 2 && nM2 != 2 && nY1 == nY2 )\n"
1900 " nRet -= bLeap? 1 : 2;\n"
1901 " if( pOptDaysIn1stYear )\n"
1902 " *pOptDaysIn1stYear = 360;\n"
1906 " if( pOptDaysIn1stYear )\n"
1908 " int nD, nM, nY;\n"
1909 " DaysToDate_new( nStartDate + nNullDate, &nD, &nM, &nY );\n"
1910 " *pOptDaysIn1stYear = IsLeapYear( nY )? 366 : 365;\n"
1912 " nRet = nEndDate - nStartDate;\n"
1915 " nRet = nEndDate - nStartDate;\n"
1916 " if( pOptDaysIn1stYear )\n"
1917 " *pOptDaysIn1stYear = 360;\n"
1920 " nRet = nEndDate - nStartDate;\n"
1921 " if( pOptDaysIn1stYear )\n"
1922 " *pOptDaysIn1stYear = 365;\n"
1925 " return bNeg? -nRet : nRet;\n"
1930 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */