fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / core / opencl / opinlinefun_finacial.cxx
blobf062954d4115ee0e2c4651989d3d5c91eeb3920b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
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"
15 "{\n"
16 " if (a == b)\n"
17 " return true;\n"
18 " double x = a - b;\n"
19 " return (x < 0.0 ? -x : x) < ((a < 0.0 ? -a : a) * (1.0 / (16777216.0 *"
20 "16777216.0)));\n"
21 "}\n";
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";
32 std::string Round =
33 "double Round(double fValue)\n"
34 "{\n"
35 " if ( fValue == 0.0 )\n"
36 " return fValue;\n"
37 "\n"
38 " double fFac = 0;\n"
39 " int nExp;\n"
40 " if ( fValue > 0.0 )\n"
41 " nExp = ( floor( log10( fValue ) ) );\n"
42 " else\n"
43 " nExp = 0;\n"
44 " int nIndex = 15 - nExp;\n"
45 " if ( nIndex > 15 )\n"
46 " nIndex = 15;\n"
47 " else if ( nIndex <= 1 )\n"
48 " nIndex = 0;\n"
49 " fValue = floor( fValue + 0.5 + nKorrVal[nIndex] );\n"
50 " return fValue;\n"
51 "}\n";
53 std::string GetRmzDecl =
54 "double GetRmz( double fZins, double fZzr, double fBw, double fZw,int nF );\n";
56 std::string GetRmz=
57 "double GetRmz( double fZins, double fZzr, double fBw, double fZw, int nF )\n"
58 "{\n"
59 " double fRmz;\n"
60 " if( fZins == 0.0 )\n"
61 " fRmz = ( fBw + fZw ) / fZzr;\n"
62 " else\n"
63 " {\n"
64 " double fTerm = pow( 1.0 + fZins, fZzr );\n"
65 " if( nF > 0 )\n"
66 " fRmz = ( fZw * fZins / ( fTerm - 1.0 ) + fBw * fZins / ( 1.0 - 1."
67 "0 / fTerm ) ) / ( 1.0 + fZins );\n"
68 " else\n"
69 " fRmz = fZw * fZins / ( fTerm - 1.0 ) + fBw * fZins /( 1.0 - 1.0 "
70 "/ fTerm );\n"
71 " }\n"
72 " return -fRmz;\n"
73 "}\n";
75 std::string GetRmz_newDecl =
76 "double GetRmz_new( double fZins, double fZzr, double fBw, double fZw,"
77 "int nF );\n";
78 std::string GetRmz_new=
79 "double GetRmz_new( double fZins, double fZzr, double fBw, double fZw,"
80 "int nF)\n"
81 "{\n"
82 " double fRmz;\n"
83 " double fTerm = pow( 1.0 + fZins, fZzr );\n"
84 " if( nF > 0 )\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"
87 " else\n"
88 " fRmz = fZw * fZins *pow ( fTerm - 1.0 ,-1) + fBw * fZins *pow( "
89 "1.0 - pow( fTerm,-1),-1 );\n"
90 " return -fRmz;\n"
91 "}\n";
92 std::string GetZwDecl =
93 "double GetZw( double fZins, double fZzr, double fRmz,"
94 "double fBw, int nF );\n";
96 std::string GetZw =
97 "double GetZw( double fZins, double fZzr, double fRmz,"
98 "double fBw, int nF )\n"
99 "{\n"
100 " double fZw;\n"
101 " if( fZins == 0.0 )\n"
102 " fZw = fBw + fRmz * fZzr;\n"
103 " else\n"
104 " {\n"
105 " double fTerm = pow( 1.0 + fZins, fZzr );\n"
106 " if( nF > 0 )\n"
107 " fZw = fBw * fTerm + fRmz * ( 1.0 + fZins ) *( fTerm - 1.0 ) "
108 "/ fZins;\n"
109 " else\n"
110 " fZw = fBw * fTerm + fRmz * ( fTerm - 1.0 ) / fZins;\n"
111 " }\n"
112 " return -fZw;\n"
113 "}\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"
122 "{\n"
123 " double fZw;\n"
124 " double fTerm = pow( 1.0 + fZins, fZzr );\n"
125 " if( nF > 0 )\n"
126 " fZw = fBw * fTerm + fRmz * ( 1.0 + fZins ) *( fTerm - 1.0 ) "
127 "*pow( fZins,-1);\n"
128 " else\n"
129 " fZw = fBw * fTerm + fRmz * ( fTerm - 1.0 ) *pow( fZins,-1);\n"
130 " return -fZw;\n"
131 "}\n";
133 std::string IsLeapYearDecl =
134 "bool IsLeapYear( int n );\n";
136 std::string IsLeapYear =
137 "bool IsLeapYear( int n )\n"
138 "{\n"
139 " return ( (( ( n % 4 ) == 0 ) && ( ( n % 100 ) != 0)) || ( ( n % 400 ) == "
140 "0 ) );\n"
141 "}\n";
143 std::string DaysInMonthDecl=
144 "int DaysInMonth( int nMonth, int nYear );\n";
146 std::string DaysInMonth =
147 "int DaysInMonth( int nMonth, int nYear )\n"
148 "{\n"
149 " int aDaysInMonth[12] = { 31, 28, 31, 30, 31, 30,\n"
150 " 31, 31, 30, 31, 30, 31 };\n"
151 "\n"
152 " if ( nMonth != 2 )\n"
153 " return aDaysInMonth[nMonth-1];\n"
154 " else\n"
155 " {\n"
156 " if ( IsLeapYear(nYear) )\n"
157 " return aDaysInMonth[nMonth-1] + 1;\n"
158 " else\n"
159 " return aDaysInMonth[nMonth-1];\n"
160 " }\n"
161 "}\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"
167 "{\n"
168 " int tmp = 0;\n"
169 " switch(nMonth)\n"
170 " {\n"
171 " case 1:\n"
172 " case 3:\n"
173 " case 5:\n"
174 " case 7:\n"
175 " case 8:\n"
176 " case 10:\n"
177 " case 12:\n"
178 " tmp = 31;\n"
179 " break;\n"
180 " case 4:\n"
181 " case 6:\n"
182 " case 9:\n"
183 " case 11:\n"
184 " tmp =30;\n"
185 " break;\n"
186 " case 2:\n"
187 " if ( IsLeapYear(nYear)==1)\n"
188 " tmp = 29;\n"
189 " else\n"
190 " tmp = 28;\n"
191 " break;\n"
192 " }\n"
193 " return tmp;\n"
194 "}\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"
201 "{\n"
202 "\n"
203 " int nTempDays;\n"
204 " int i = 0;\n"
205 " bool bCalc;\n"
207 " do\n"
208 " {\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"
214 " bCalc = false;\n"
215 " if ( nTempDays < 1 )\n"
216 " {\n"
217 " i++;\n"
218 " bCalc = true;\n"
219 " }\n"
220 " else\n"
221 " {\n"
222 " if ( nTempDays > 365 )\n"
223 " {\n"
224 " if ( (nTempDays != 366) || !IsLeapYear( *rYear ) )\n"
225 " {\n"
226 " i--;\n"
227 " bCalc = true;\n"
228 " }\n"
229 " }\n"
230 " }\n"
231 " }\n"
232 " while ( bCalc );\n"
233 " if(nTempDays!=0){\n"
234 " for (*rMonth = 1; (int)nTempDays > DaysInMonth( *rMonth, *rYear );"
235 "*rMonth+=1)\n"
236 " {\n"
237 " nTempDays -= DaysInMonth( *rMonth, *rYear );\n"
238 " }\n"
239 " *rDay = (int)nTempDays;\n"
240 " }\n"
241 "}\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"
248 "{\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"
253 " nDays += nDay;\n"
254 "\n"
255 " return nDays;\n"
256 "}\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"
263 "{\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"
269 " nDays += nDay;\n"
270 "\n"
271 " return nDays;\n"
272 "}\n";
274 std::string GetNullDateDecl=
275 "int GetNullDate();\n";
277 std::string GetNullDate=
278 "int GetNullDate()\n"
279 "{\n"
280 " return DateToDays(30,12,1899 );\n"
281 "}\n";
282 std::string GetNullDate_newDecl=
283 "int GetNullDate_new();\n";
285 std::string GetNullDate_new=
286 "int GetNullDate_new()\n"
287 "{\n"
288 " return DateToDays_new(30,12,1899 );\n"
289 "}\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";
296 std::string ScaDate=
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"
300 "{\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"
306 " if( *b30Days)\n"
307 " {\n"
308 " *nDay = min( *nOrigDay, 30);\n"
309 " if( *bLastDay || (*nDay >=DaysInMonth( *nMonth, *nYear )) )\n"
310 " *nDay = 30;\n"
311 " }\n"
312 " else\n"
313 " {\n"
314 " int nLastDay = DaysInMonth( *nMonth, *nYear );\n"
315 " *nDay = *bLastDay ? nLastDay : min( *nOrigDay, nLastDay );\n"
316 " }\n"
317 "}\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"
326 "{\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"
333 "}\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"
340 "{\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"
350 " rYear=sYear;\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"
354 " {\n"
355 " rYear+=1;\n"
356 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
357 " }\n"
358 " while(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
359 "rbLastDay,sDay,rDay))\n"
360 " {\n"
361 " double d = -1*(12/nFreq);\n"
362 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,d,&rYear);\n"
363 " }\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"
368 "}\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"
375 "{\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"
385 " rYear=sYear;\n"
386 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
387 " if(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,rbLastDay"
388 ",sDay,rDay))\n"
389 " {\n"
390 " rYear-=1;\n"
391 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
392 " }\n"
393 " while(!checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
394 "rbLastDay,sDay,rDay))\n"
395 " {\n"
396 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,12/nFreq,&rYear);\n"
397 " }\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"
402 "}\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"
411 "{\n"
412 " int nNewMonth = nMonthCount + *nMonth;\n"
413 " if( nNewMonth > 12 )\n"
414 " {\n"
415 " --nNewMonth;\n"
416 " *year+=nNewMonth / 12 ;\n"
417 " *nMonth = ( nNewMonth % 12 ) + 1;\n"
418 " }\n"
419 " else if( nNewMonth < 1 )\n"
420 " {\n"
421 " *year+= nNewMonth / 12 - 1 ;\n"
422 " *nMonth = nNewMonth % 12 + 12 ;\n"
423 " }\n"
424 " else\n"
425 " *nMonth = nNewMonth ;\n"
426 " if( b30Days )\n"
427 " {\n"
428 " *nDay = min( nOrigDay, 30);\n"
429 " if( bLastDay || (*nDay >= DaysInMonth( *nMonth, *year )) )\n"
430 " *nDay = 30;\n"
431 " }\n"
432 " else\n"
433 " {\n"
434 " int nLastDay = DaysInMonth( *nMonth, *year );\n"
435 " *nDay = bLastDay ? nLastDay : min( nOrigDay, nLastDay );\n"
436 " }\n"
437 "}\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"
444 "{\n"
445 " if( nFrom > nTo )\n"
446 " return 0;\n"
447 " int nRet = 0;\n"
448 " if( b30Days )\n"
449 " nRet = (nTo - nFrom + 1) * 30;\n"
450 " else\n"
451 " {\n"
452 " for( int nMonthIx = nFrom; nMonthIx <= nTo; ++nMonthIx )\n"
453 " nRet += b30Days ? 30 : DaysInMonth( nMonthIx, year );\n"
454 " }\n"
455 " return nRet;\n"
456 "}\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"
463 "{\n"
464 " int nLeaps = 0;\n"
465 " for( int n = nYear1 ; n <= nYear2 ; n++ )\n"
466 " {\n"
467 " if( IsLeapYear( n ) )\n"
468 " nLeaps++;\n"
469 " }\n"
470 " int nSum = 1;\n"
471 " nSum += nYear2;\n"
472 " nSum -= nYear1;\n"
473 " nSum *= 365;\n"
474 " nSum += nLeaps;\n"
475 " return nSum;\n"
476 "}\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"
483 "{\n"
484 " switch( nMode )\n"
485 " {\n"
486 " case 0:\n"
487 " case 2:\n"
488 " case 4:\n"
489 " return 360;\n"
490 " case 1:\n"
491 " {\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"
496 " }\n"
497 " case 3:\n"
498 " return 365;\n"
499 " }\n"
500 "}\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"
507 "{\n"
508 " if( nFrom > nTo )\n"
509 " return 0;\n"
510 " return b30Days ? ((nTo - nFrom + 1) * 360) : GetDaysInYears( nFrom, nTo)"
511 ";\n"
512 "}\n";
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";
520 std::string getDiff=
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"
525 "{\n"
526 " if(rFrom>rTo)\n"
527 " {\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"
536 " }\n"
537 " int nDiff=0;\n"
538 " if( tb30Days )\n"
539 " {\n"
540 " if( tbUSMode )\n"
541 " {\n"
542 " if( ((fMonth == 2) || (fnDay < 30)) && (tDay == 31) )\n"
543 " tnDay = 31;\n"
544 " else if( (tMonth == 2) && tbLastDay )\n"
545 " tnDay = DaysInMonth( 2, tYear );\n"
546 " }\n"
547 " else\n"
548 " {\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"
553 " }\n"
554 " }\n"
555 " if( (fYear < tYear) || ((fYear == tYear) && (fMonth < tMonth)) )\n"
556 " {\n"
557 " int d = fb30Days ? 30:DaysInMonth(fMonth,fYear);\n"
558 " nDiff = d- fnDay + 1;\n"
559 " fDay = fnDay = 1;\n"
560 " fbLastDay = 0;\n"
561 " addMonths(fb30Days,fbLastDay,&fnDay,fDay,&fMonth,1,&fYear);\n"
562 " if( fYear < tYear )\n"
563 " {\n"
564 " nDiff += getDaysInMonthRange( fMonth, 12,fb30Days,fYear);\n"
565 " addMonths(fb30Days,fbLastDay,&fnDay,fDay,&fMonth,13-fMonth,&fYear"
566 ");\n"
567 " nDiff += getDaysInYearRange( fYear, tYear - 1,fb30Days);\n"
568 " fYear+=tYear - fYear;\n"
569 " }\n"
570 " nDiff += getDaysInMonthRange(fMonth, tMonth - 1,fb30Days ,fYear );\n"
571 " addMonths(fb30Days,fbLastDay,&fnDay,fDay,&fMonth,tMonth-fMonth,&fYear"
572 ");\n"
573 " }\n"
574 " nDiff += tnDay - fnDay;\n"
575 " return nDiff > 0 ? nDiff : 0;\n"
576 "}\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"
583 "{\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"
593 " rYear= sYear;\n"
594 " nSettle=nSettle+nNullDate;\n"
595 " aDate=DateToDays( rDay,rMonth,rYear );\n"
596 " if( aDate < nSettle )\n"
597 " {\n"
598 " rYear+= 1;\n"
599 " aDate=DateToDays( rDay,rMonth,rYear );\n"
600 " }\n"
601 " while(aDate > nSettle )\n"
602 " {\n"
603 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,-1*(12/nFreq),&rYear"
604 ");\n"
605 " aDate=DateToDays( rDay,rMonth,rYear );\n"
606 " }\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"
610 "}\n";
612 std::string lcl_Getcoupdaybs_newDecl=
613 "int lcl_Getcoupdaybs_new(int nNullDate,int nSettle,int nMat,int nFreq,"
614 "int nBase);\n";
616 std::string lcl_Getcoupdaybs_new=
617 "int lcl_Getcoupdaybs_new(int nNullDate,int nSettle,int nMat,int nFreq,"
618 "int nBase)\n"
619 "{\n"
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"
629 " rYear=sYear;\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"
634 " {\n"
635 " rYear+=1;\n"
636 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
637 " aDate=DateToDays_new( rnDay,rMonth,rYear );\n"
638 " }\n"
639 " while(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
640 "rbLastDay,sDay,rDay))\n"
641 " {\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"
645 " }\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"
649 "}\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"
658 "{\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"
668 " rYear= sYear;\n"
669 " nSettle=nSettle+nNullDate;\n"
670 " aDate=DateToDays( rDay,rMonth,rYear );\n"
671 " if( aDate < nSettle )\n"
672 " { \n"
673 " rYear+= 1;\n"
674 " aDate=DateToDays( rDay,rMonth,rYear );\n"
675 " }\n"
676 " while(aDate > nSettle )\n"
677 " {\n"
678 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,-1*(12/nFreq),&rYear"
679 ");\n"
680 " aDate=DateToDays( rDay,rMonth,rYear );\n"
681 " }\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"
689 "}\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"
698 "{\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"
708 " rYear=sYear;\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"
713 " {\n"
714 " rYear+=1;\n"
715 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
716 " aDate=DateToDays_new( rnDay,rMonth,rYear );\n"
717 " }\n"
718 " while(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
719 "rbLastDay,sDay,rDay))\n"
720 " {\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"
724 " }\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"
733 "}\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"
740 "{\n"
741 " int aDate = nMat;int rDay=0,rMonth=0, rYear=0;int mDay=0,mMonth=0, mYear="
742 "0;\n"
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"
747 " rYear= sYear;\n"
748 " nSettle=nSettle+nNullDate;\n"
749 " aDate=DateToDays( rDay,rMonth,rYear );\n"
750 " if( aDate < nSettle )\n"
751 " rYear+= 1;\n"
752 " int d=DateToDays( rDay,rMonth,rYear );\n"
753 " int nMonthCount=-1*(12 / nFreq);\n"
754 " while(d > nSettle )\n"
755 " {\n"
756 " int nNewMonth = nMonthCount + rMonth;\n"
757 " if( nNewMonth > 12 )\n"
758 " {\n"
759 " --nNewMonth;\n"
760 " rYear+=nNewMonth / 12;\n"
761 " rMonth = nNewMonth % 12 + 1;\n"
762 " }\n"
763 " else if( nNewMonth < 1 )\n"
764 " {\n"
765 " rYear+= nNewMonth / 12 - 1;\n"
766 " rMonth = nNewMonth % 12 + 12;\n"
767 " }\n"
768 " else\n"
769 " rMonth = nNewMonth;\n"
770 " d=DateToDays( rDay,rMonth,rYear );\n"
771 " }\n"
772 " int n=(mYear-rYear)*12+mMonth-rMonth;\n"
773 " n=n*nFreq/12;\n"
774 " return n;\n"
775 "}\n";
776 std::string lcl_Getcoupnum_newDecl=
777 "double lcl_Getcoupnum_new(int nNullDate,int nSettle,int nMat,int nFreq,int"
778 " nBase);\n";
779 std::string lcl_Getcoupnum_new=
780 "double lcl_Getcoupnum_new(int nNullDate,int nSettle, int nMat,int nFreq,int"
781 " nBase)\n"
782 "{\n"
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"
794 " rYear=sYear;\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"
798 " {\n"
799 " rYear+=1;\n"
800 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
801 " }\n"
802 " int m= checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
803 "rbLastDay,sDay,rDay);\n"
804 " while(m)\n"
805 " {\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"
810 " }\n"
811 " int n=(mYear-rYear)*12+mMonth-rMonth;\n"
812 " double tmp = (double)(n*nFreq)/12.0;\n"
813 " return tmp;\n"
814 "}\n";
816 std::string setDayDecl=
817 "void setDay(int nOrigDay, int nMonth,int nYear,int bLastDay,int b30Days,"
818 "int *nDay);\n";
819 std::string setDay=
820 "void setDay(int nOrigDay, int nMonth,int nYear,int bLastDay,int b30Days,"
821 "int *nDay)\n"
822 "{\n"
823 " if( b30Days )\n"
824 " {\n"
825 " *nDay = min( nOrigDay, 30);\n"
826 " if( bLastDay || (*nDay >= DaysInMonth( nMonth, nYear )) )\n"
827 " *nDay = 30;\n"
828 " }\n"
829 " else\n"
830 " {\n"
831 " int nLastDay = DaysInMonth( nMonth, nYear );\n"
832 " *nDay = bLastDay ? nLastDay : min( nOrigDay, nLastDay );\n"
833 " }\n"
834 "}\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"
841 "{\n"
842 " int nNullDate=GetNullDate();\n"
843 " if( nBase == 1 )\n"
844 " return lcl_Getcoupdays(nNullDate, nSettle, nMat,nFreq, nBase);\n"
845 " else\n"
846 " return (double)GetDaysInYear(0,0,nBase)/nFreq;\n"
847 "}\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"
853 "{\n"
854 " int nNullDate=693594;\n"
855 " if( nBase == 1 )\n"
856 " return lcl_Getcoupdays_new(nNullDate, nSettle, nMat,nFreq, nBase);\n"
857 " else\n"
858 " return (double)GetDaysInYear(0,0,nBase)*pow((double)nFreq,-1.0);\n"
859 "}\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"
866 "{\n"
867 " int nNullDate=GetNullDate();\n"
868 " return lcl_Getcoupdaybs(nNullDate, nSettle, nMat,nFreq, nBase);\n"
869 "}\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"
876 "{\n"
877 " int nNullDate=693594;\n"
878 " return lcl_Getcoupdaybs_new(nNullDate, nSettle, nMat,nFreq, nBase);\n"
879 "}\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"
886 "{\n"
887 " int nNullDate=GetNullDate();\n"
888 " if((nBase != 0) && (nBase != 4))\n"
889 " {\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"
899 " rYear= sYear;\n"
900 " nSettle=nSettle+nNullDate;\n"
901 " aDate=DateToDays( rDay,rMonth,rYear );\n"
902 " if( aDate > nSettle )\n"
903 " {\n"
904 " rYear-= 1;\n"
905 " aDate=DateToDays( rDay,rMonth,rYear );\n"
906 " }\n"
907 " while(aDate <= nSettle )\n"
908 " {\n"
909 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,12/nFreq,&rYear)"
910 ";\n"
911 " aDate=DateToDays( rDay,rMonth,rYear );\n"
912 " }\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"
916 " }\n"
917 " else\n"
918 " return coupdays(nSettle,nMat,nFreq,nBase)- coupdaybs( nSettle,nMat,"
919 "nFreq,nBase);\n"
920 "}\n";
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"
926 "{\n"
927 " int nNullDate=693594;\n"
928 " if((nBase != 0) && (nBase != 4))\n"
929 " {\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"
939 " rYear=sYear;\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"
943 ",sDay,rDay))\n"
944 " {\n"
945 " rYear-=1;\n"
946 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
947 " aDate=DateToDays( rnDay,rMonth,rYear );\n"
948 " }\n"
949 " while(!checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
950 "rbLastDay,sDay,rDay))\n"
951 " {\n"
952 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,12/nFreq,&rYear);\n"
953 " aDate=DateToDays( rnDay,rMonth,rYear );\n"
954 " }\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"
958 " }\n"
959 " else\n"
960 " return coupdays_new(nSettle,nMat,nFreq,nBase)- coupdaybs_new( nSettle,"
961 "nMat,nFreq,nBase);\n"
962 "}\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"
970 "{\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"
980 "}\n";
982 std::string coupnumDecl=
983 "double coupnum( int nSettle,int nMat,int nFreq,int nBase);\n";
985 std::string coupnum=
986 "double coupnum( int nSettle,int nMat,int nFreq,int nBase)\n"
987 "{\n"
988 " int nNullDate=GetNullDate();\n"
989 " return lcl_Getcoupnum(nNullDate,nSettle,nMat,nFreq);\n"
990 "}\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"
996 "{\n"
997 " int nNullDate=693594;\n"
998 " return lcl_Getcoupnum_new(nNullDate,nSettle,nMat,nFreq,nBase);\n"
999 "}\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"
1008 "{\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 + "
1015 "fDSC_E ) );\n"
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"
1021 " return fRet;\n"
1022 "}\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"
1030 "{\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 + "
1037 "fDSC_E ) );\n"
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"
1043 " return fRet;\n"
1044 "}\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"
1053 "{\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, "
1059 "nFreq, nBase );\n"
1060 " double fPrice2 = getPrice_(nSettle, nMat, fRate, fYield2, fRedemp, "
1061 "nFreq, nBase );\n"
1062 " double fYieldN = ( fYield2 - fYield1 ) * 0.5;\n"
1063 " for( unsigned int nIter = 0 ; nIter < 100 && fPriceN != fPrice ; nIter++ "
1064 ")\n"
1065 " {\n"
1066 " fPriceN = getPrice_(nSettle, nMat, fRate, fYieldN, fRedemp, nFreq, "
1067 "nBase );\n"
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"
1075 " {\n"
1076 " fYield2 *= 2.0;\n"
1077 " fPrice2 = getPrice_(nSettle, nMat, fRate, fYield2, fRedemp, nFreq"
1078 ", nBase );\n"
1079 " fYieldN = ( fYield2 - fYield1 ) * 0.5;\n"
1080 " }\n"
1081 " else\n"
1082 " {\n"
1083 " if( fPrice < fPriceN )\n"
1084 " {\n"
1085 " fYield1 = fYieldN;\n"
1086 " fPrice1 = fPriceN;\n"
1087 " }\n"
1088 " else\n"
1089 " {\n"
1090 " fYield2 = fYieldN;\n"
1091 " fPrice2 = fPriceN;\n"
1092 " }\n"
1093 " fYieldN = fYield2 - ( fYield2 - fYield1 ) * ( ( fPrice - fPrice2 "
1094 ") / ( fPrice1 - fPrice2 ) );\n"
1095 " }\n"
1096 " }\n"
1097 " return fYieldN;\n"
1098 "}\n";
1100 std::string GetYearFracDecl=
1101 "double GetYearFrac( int nNullDate, int nStartDate, int nEndDate,"
1102 "int nMode );\n";
1104 std::string GetYearFrac=
1105 "double GetYearFrac( int nNullDate, int nStartDate, int nEndDate,"
1106 "int nMode ) \n"
1107 "{\n"
1108 " if( nStartDate == nEndDate )\n"
1109 " return 0.0; \n"
1111 " if( nStartDate > nEndDate )\n"
1112 " {\n"
1113 " int n = nEndDate;\n"
1114 " nEndDate = nStartDate;\n"
1115 " nStartDate = n;\n"
1116 " }\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"
1128 " int nDayDiff;\n"
1129 " switch( nMode )\n"
1130 " {\n"
1131 " case 0: \n"
1132 " if ( nDay1 == 31 )\n"
1133 " {\n"
1134 " nDay1--;\n"
1135 " }\n"
1136 " if ( nDay1 == 30 && nDay2 == 31 )\n"
1137 " {\n"
1138 " nDay2--;\n"
1139 " }\n"
1140 " else\n"
1141 " {\n"
1142 " if ( nMonth1 == 2 && nDay1 == "
1143 "( IsLeapYear( nYear1 ) ? 29 : 28 ) )\n"
1144 " {\n"
1145 " nDay1 = 30;\n"
1146 " if ( nMonth2 == 2 && nDay2 == "
1147 "( IsLeapYear( nYear2 ) ? 29 : 28 ) )\n"
1148 " {\n"
1149 " nDay2 = 30;\n"
1150 " }\n"
1151 " }\n"
1152 " }\n"
1153 " nDayDiff = ( nYear2 - nYear1 ) * 360 + "
1154 "( nMonth2 - nMonth1 ) * 30 + ( nDay2 - nDay1 );\n"
1155 " break;\n"
1156 " case 1: \n"
1157 " case 2: \n"
1158 " case 3: \n"
1159 " nDayDiff = nDate2 - nDate1;\n"
1160 " break;\n"
1161 " case 4: \n"
1162 " if ( nDay1 == 31 )\n"
1163 " {\n"
1164 " nDay1--;\n"
1165 " }\n"
1166 " if ( nDay2 == 31 )\n"
1167 " {\n"
1168 " nDay2--;\n"
1169 " }\n"
1170 " nDayDiff = ( nYear2 - nYear1 ) * 360 + "
1171 "( nMonth2 - nMonth1 ) * 30 + ( nDay2 - nDay1 );\n"
1172 " break;\n"
1173 " }\n"
1175 " double nDaysInYear;\n"
1176 " switch( nMode )\n"
1177 " {\n"
1178 " case 0: \n"
1179 " case 2: \n"
1180 " case 4: \n"
1181 " nDaysInYear = 360;\n"
1182 " break;\n"
1183 " case 1: \n"
1184 " {\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"
1190 " {\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"
1198 " }\n"
1199 " else\n"
1200 " {\n"
1201 " if ( isYearDifferent && IsLeapYear( nYear1 ) )\n"
1202 " {\n"
1203 " nDaysInYear = 366;\n"
1204 " }\n"
1205 " else\n"
1206 " {\n"
1208 " if ( ( IsLeapYear( nYear1 ) && nMonth1 <= 2 "
1209 "&& nDay1 <= 29 ) ||\n"
1210 " ( IsLeapYear( nYear2 ) && ( nMonth2 > 3 || "
1211 "( nMonth2 == 2 && nDay1 == 29 ) ) ) )\n"
1212 " {\n"
1213 " nDaysInYear = 366;\n"
1214 " }\n"
1215 " else\n"
1216 " {\n"
1217 " nDaysInYear = 365;\n"
1218 " for ( int i = nYear1; i <= nYear2; i++ )\n"
1219 " {\n"
1220 " if ( IsLeapYear( i ) )\n"
1221 " {\n"
1222 " nDaysInYear = 366;\n"
1223 " break;\n"
1224 " }\n"
1225 " }\n"
1226 " }\n"
1227 " }\n"
1228 " }\n"
1229 " }\n"
1230 " break;\n"
1231 " case 3: \n"
1232 " nDaysInYear = 365;\n"
1233 " break;\n"
1234 " }\n"
1235 " return (double)( nDayDiff ) / (nDaysInYear);\n"
1236 "}\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"
1245 "{\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"
1251 " y-=1.0;\n"
1252 " y = y * pow(fSetMat,-1);\n"
1253 " return y;\n"
1254 "}\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"
1263 "{\n"
1264 " bool bNeg = nStartDate > nEndDate;\n"
1265 " if( bNeg )\n"
1266 " {\n"
1267 " int n = nEndDate;\n"
1268 " nEndDate = nStartDate;\n"
1269 " nStartDate = n;\n"
1270 " }\n"
1271 " int nRet;\n"
1272 " switch( nMode )\n"
1273 " {\n"
1274 " case 0: \n"
1275 " case 4: \n"
1276 " {\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"
1292 " }\n"
1293 " break;\n"
1294 " case 1: \n"
1295 " if( pOptDaysIn1stYear )\n"
1296 " {\n"
1297 " int nD, nM, nY;\n"
1298 " DaysToDate( nStartDate + nNullDate, &nD, &nM, &nY );\n"
1299 " *pOptDaysIn1stYear = IsLeapYear( nY )? 366 : 365;\n"
1300 " }\n"
1301 " nRet = nEndDate - nStartDate;\n"
1302 " break;\n"
1303 " case 2: \n"
1304 " nRet = nEndDate - nStartDate;\n"
1305 " if( pOptDaysIn1stYear )\n"
1306 " *pOptDaysIn1stYear = 360;\n"
1307 " break;\n"
1308 " case 3: \n"
1309 " nRet = nEndDate - nStartDate;\n"
1310 " if( pOptDaysIn1stYear )\n"
1311 " *pOptDaysIn1stYear = 365;\n"
1312 " break;\n"
1313 " }\n"
1314 " return bNeg? -nRet : nRet;\n"
1315 "}\n";
1317 std::string GetYearDiffDecl=
1318 "double GetYearDiff( int nNullDate, int nStartDate, int nEndDate,"
1319 "int nMode);\n";
1321 std::string GetYearDiff=
1322 "double GetYearDiff( int nNullDate, int nStartDate, int nEndDate,"
1323 "int nMode )\n"
1324 "{\n"
1325 " int nDays1stYear;\n"
1326 " int nTotalDays = GetDiffDate( nNullDate, nStartDate, nEndDate,"
1327 "nMode, &"
1328 "nDays1stYear );\n"
1329 " return (double)(nTotalDays)*pow((double)nDays1stYear,-1);\n"
1330 "}\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"
1343 "{\n"
1344 " if( nDay1 == 31 )\n"
1345 " nDay1--;\n"
1346 " else if( bUSAMethod && ( nMonth1 == 2 && ( nDay1 == 29 || ( nDay1 == 28 "
1347 "&& !bLeapYear1 ) ) ) )\n"
1348 " nDay1 = 30;\n"
1349 " if( nDay2 == 31 )\n"
1350 " {\n"
1351 " if( bUSAMethod && nDay1 != 30 )\n"
1352 " {\n"
1353 " nDay2 = 1;\n"
1354 " if( nMonth2 == 12 )\n"
1355 " {\n"
1356 " nYear2++;\n"
1357 " nMonth2 = 1;\n"
1358 " }\n"
1359 " else\n"
1360 " nMonth2++;\n"
1361 " }\n"
1362 " else\n"
1363 " nDay2 = 30;\n"
1364 " }\n"
1365 " return nDay2 + nMonth2 * 30 + nYear2 * 360 - nDay1 - nMonth1 * 30 - "
1366 "nYear1 * 360;\n"
1367 "}\n";
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"
1376 "{\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"
1384 "}\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"
1395 "{\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"
1402 " fYield += 1.0;\n"
1403 " double nDiff = fYearfrac * nFreq - fNumOfCoups;\n"
1404 " int t;\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"
1413 " fDur /= p;\n"
1414 " fDur /= nFreq;\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"
1426 " {\n"
1427 " double fYearfrac = GetYearFrac(nNullDate,nSettle,nMat,nBase);\n"
1428 " double fNumOfCoups = lcl_Getcoupnum_new(nNullDate,nSettle,nMat,"
1429 "nFreq,nBase);\n"
1430 " double fDur = 0.0;\n"
1431 " fCoup = fCoup * 100.0 * pow(nFreq, -1.0);\n"
1432 " fYield = fYield * pow(nFreq, -1.0);\n"
1433 " fYield += 1.0;\n"
1434 " double nDiff = fYearfrac * nFreq - fNumOfCoups;\n"
1435 " int t;\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"
1441 " fDur += tmp2;\n"
1442 " }\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"
1452 " return fDur;\n"
1453 " }\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,"
1461 "double fFaktor)\n"
1462 "{\n"
1463 " double fGda, fZins, fAlterWert, fNeuerWert;\n"
1464 " fZins = fFaktor / fDauer;\n"
1465 " if (fZins >= 1.0)\n"
1466 " {\n"
1467 " fZins = 1.0;\n"
1468 " if (fPeriode == 1.0)\n"
1469 " fAlterWert = fWert;\n"
1470 " else\n"
1471 " fAlterWert = 0.0;\n"
1472 " }\n"
1473 " else\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"
1479 " else\n"
1480 " fGda = fAlterWert - fNeuerWert;\n"
1481 " if (fGda < 0.0)\n"
1482 " fGda = 0.0;\n"
1483 " return fGda;\n"
1484 "}\n";
1486 std::string DblMinDecl=
1487 "inline double DblMin( double a, double b );\n";
1489 std::string DblMin=
1490 "inline double DblMin( double a, double b )\n"
1491 "{\n"
1492 " return (a < b) ? a : b;\n"
1493 "}\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"
1502 "{\n"
1503 " double fVdb=0;\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"
1510 " double fGda;\n"
1511 " int i;\n"
1512 " fLia=0;\n"
1513 " for ( i = 1; i <= nLoopEnd; i++)\n"
1514 " {\n"
1515 " if(!bNowLia)\n"
1516 " {\n"
1517 " fGda = ScGetGDA(fWert, fRest, fDauer, (double) i, fFaktor);\n"
1518 " fLia = fRestwert/ (fDauer1 - (double) (i-1));\n"
1519 " if (fLia > fGda)\n"
1520 " {\n"
1521 " fTerm = fLia;\n"
1522 " bNowLia = 1;\n"
1523 " }\n"
1524 " else\n"
1525 " {\n"
1526 " fTerm = fGda;\n"
1527 " fRestwert =fRestwert- fGda;\n"
1528 " }\n"
1529 " }\n"
1530 " else\n"
1531 " {\n"
1532 " fTerm = fLia;\n"
1533 " }\n"
1535 " if ( i == nLoopEnd)\n"
1536 " fTerm *= ( fPeriode + 1.0 - fIntEnd );\n"
1538 " fVdb += fTerm;\n"
1539 " }\n"
1540 " return fVdb;\n"
1541 "}\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"
1550 "{\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"
1556 " if (bFlag)\n"
1557 " {\n"
1558 " for (int i = nLoopStart + 1; i <= nLoopEnd; i++)\n"
1559 " {\n"
1560 " double fTerm = ScGetGDA(fWert, fRest, fDauer, (double) i, fFaktor"
1561 ");\n"
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"
1567 " }\n"
1568 " }\n"
1569 " else\n"
1570 " {\n"
1571 " double fDauer1=fDauer;\n"
1572 " if(!isequal(fAnfang,floor(fAnfang)))\n"
1573 " {\n"
1574 " if(fFaktor>1)\n"
1575 " {\n"
1576 " if(fAnfang>fDauer/2 || isequal(fAnfang,fDauer/2))\n"
1577 " {\n"
1578 " double fPart=fAnfang-fDauer/2;\n"
1579 " fAnfang=fDauer/2;\n"
1580 " fEnde-=fPart;\n"
1581 " fDauer1+=1;\n"
1582 " }\n"
1583 " }\n"
1584 " }\n"
1585 " fWert-=ScInterVDB(fWert,fRest,fDauer,fDauer1,fAnfang,fFaktor);\n"
1586 " result=ScInterVDB(fWert,fRest,fDauer,fDauer-fAnfang,fEnde-fAnfang,"
1587 "fFaktor);\n"
1588 " }\n"
1589 " return result;\n"
1590 "}\n";
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"
1599 "{\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"
1610 " return p;\n"
1611 "}\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"
1620 "{\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"
1627 " y -= 1.0;\n"
1628 " y *= fFreq / fDSCi;\n"
1629 " return y;\n"
1630 "}\n";
1632 std::string GetYearFrac_newDecl=
1633 "double GetYearFrac_new( int nNullDate, int nStartDate, int nEndDate,"
1634 "int nMode );\n";
1636 std::string GetYearFrac_new=
1637 "double GetYearFrac_new( int nNullDate, int nStartDate, int nEndDate,"
1638 "int nMode ) \n"
1639 "{\n"
1640 " if( nStartDate == nEndDate )\n"
1641 " return 0.0; \n"
1642 " if( nStartDate > nEndDate )\n"
1643 " {\n"
1644 " int n = nEndDate;\n"
1645 " nEndDate = nStartDate;\n"
1646 " nStartDate = n;\n"
1647 " }\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"
1655 " int nDayDiff;\n"
1656 " switch( nMode )\n"
1657 " {\n"
1658 " case 0: \n"
1659 " if ( nDay1 == 31 )\n"
1660 " {\n"
1661 " nDay1--;\n"
1662 " }\n"
1663 " if ( nDay1 == 30 && nDay2 == 31 )\n"
1664 " {\n"
1665 " nDay2--;\n"
1666 " }\n"
1667 " else\n"
1668 " {\n"
1669 " if ( nMonth1 == 2 && nDay1 == "
1670 "( IsLeapYear( nYear1 ) ? 29 : 28 ) )\n"
1671 " {\n"
1672 " nDay1 = 30;\n"
1673 " if ( nMonth2 == 2 && nDay2 == "
1674 "( IsLeapYear( nYear2 ) ? 29 : 28 ) )\n"
1675 " {\n"
1676 " nDay2 = 30;\n"
1677 " }\n"
1678 " }\n"
1679 " }\n"
1680 " nDayDiff = ( nYear2 - nYear1 ) * 360 + "
1681 "( nMonth2 - nMonth1 ) * 30 + ( nDay2 - nDay1 );\n"
1682 " break;\n"
1683 " case 1: \n"
1684 " case 2: \n"
1685 " case 3: \n"
1686 " nDayDiff = nDate2 - nDate1;\n"
1687 " break;\n"
1688 " case 4: \n"
1689 " if ( nDay1 == 31 )\n"
1690 " {\n"
1691 " nDay1--;\n"
1692 " }\n"
1693 " if ( nDay2 == 31 )\n"
1694 " {\n"
1695 " nDay2--;\n"
1696 " }\n"
1697 " nDayDiff = ( nYear2 - nYear1 ) * 360 + "
1698 "( nMonth2 - nMonth1 ) * 30 + ( nDay2 - nDay1 );\n"
1699 " break;\n"
1700 " }\n"
1701 " double nDaysInYear;\n"
1702 " switch( nMode )\n"
1703 " {\n"
1704 " case 0: \n"
1705 " case 2: \n"
1706 " case 4: \n"
1707 " nDaysInYear = 360;\n"
1708 " break;\n"
1709 " case 1: \n"
1710 " {\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"
1716 " {\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"
1722 " }\n"
1723 " else\n"
1724 " {\n"
1725 " if ( isYearDifferent && IsLeapYear( nYear1 ) )\n"
1726 " {\n"
1727 " nDaysInYear = 366;\n"
1728 " }\n"
1729 " else\n"
1730 " {\n"
1731 " if ( ( IsLeapYear( nYear1 ) && nMonth1 <= 2 "
1732 "&& nDay1 <= 29 ) ||\n"
1733 " ( IsLeapYear( nYear2 ) && ( nMonth2 > 3 || "
1734 "( nMonth2 == 2 && nDay1 == 29 ) ) ) )\n"
1735 " {\n"
1736 " nDaysInYear = 366;\n"
1737 " }\n"
1738 " else\n"
1739 " {\n"
1740 " nDaysInYear = 365;\n"
1741 " for ( int i = nYear1; i <= nYear2; i++ )\n"
1742 " {\n"
1743 " if ( IsLeapYear( i ) )\n"
1744 " {\n"
1745 " nDaysInYear = 366;\n"
1746 " break;\n"
1747 " }\n"
1748 " }\n"
1749 " }\n"
1750 " }\n"
1751 " }\n"
1752 " }\n"
1753 " break;\n"
1754 " case 3: \n"
1755 " nDaysInYear = 365;\n"
1756 " break;\n"
1757 " }\n"
1758 " return (double)( nDayDiff ) / (nDaysInYear);\n"
1759 "}\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"
1766 "{\n"
1767 " int nTempDays;\n"
1768 " int i = 0;\n"
1769 " bool bCalc;\n"
1770 " do\n"
1771 " {\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)"
1776 " / 400);\n"
1777 " bCalc = false;\n"
1778 " if ( nTempDays < 1 )\n"
1779 " {\n"
1780 " i++;\n"
1781 " bCalc = true;\n"
1782 " }\n"
1783 " else\n"
1784 " {\n"
1785 " if ( nTempDays > 365 )\n"
1786 " {\n"
1787 " if ( (nTempDays != 366) || !IsLeapYear( *rYear ) )\n"
1788 " {\n"
1789 " i--;\n"
1790 " bCalc = true;\n"
1791 " }\n"
1792 " }\n"
1793 " }\n"
1794 " }\n"
1795 " while ( bCalc );\n"
1796 " if(nTempDays != 0){\n"
1797 " for (*rMonth = 1; (int)nTempDays > DaysInMonth( *rMonth, *rYear );"
1798 " *rMonth += 1)\n"
1799 " {\n"
1800 " nTempDays -= DaysInMonth( *rMonth, *rYear ); \n"
1801 " }\n"
1802 " *rDay = (int)nTempDays;\n"
1803 " }\n"
1804 "}\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"
1811 "{\n"
1812 " int nTempDays;\n"
1813 " int i = 0;\n"
1814 " bool bCalc;\n"
1815 " do\n"
1816 " {\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)"
1821 " / 400);\n"
1822 " bCalc = false;\n"
1823 " if ( nTempDays < 1 )\n"
1824 " {\n"
1825 " i++;\n"
1826 " bCalc = true;\n"
1827 " }\n"
1828 " else\n"
1829 " {\n"
1830 " if ( nTempDays > 365 )\n"
1831 " {\n"
1832 " if ( (nTempDays != 366) || !IsLeapYear( *rYear ) )\n"
1833 " {\n"
1834 " i--;\n"
1835 " bCalc = true;\n"
1836 " }\n"
1837 " }\n"
1838 " }\n"
1839 " }\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 );"
1844 " *rMonth += 1)\n"
1845 " {\n"
1846 " nTempDays -= DaysInMonth( *rMonth, *rYear ); \n"
1847 " }\n"
1848 " *rDay = (int)nTempDays;\n"
1849 " }\n"
1850 "}\n";
1852 std::string GetYearDiff_newDecl=
1853 "double GetYearDiff_new( int nNullDate, int nStartDate, int nEndDate,"
1854 "int nMode);\n";
1856 std::string GetYearDiff_new=
1857 "double GetYearDiff_new( int nNullDate, int nStartDate, int nEndDate,"
1858 "int nMode )\n"
1859 "{\n"
1860 " int nDays1stYear;\n"
1861 " int nTotalDays = GetDiffDate_new( nNullDate, nStartDate, nEndDate,"
1862 "nMode, &"
1863 "nDays1stYear );\n"
1864 " return (double)(nTotalDays)* pow((double)nDays1stYear,-1);\n"
1865 "}\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"
1874 "{\n"
1875 " bool bNeg = nStartDate > nEndDate;\n"
1876 " if( bNeg )\n"
1877 " {\n"
1878 " int n = nEndDate;\n"
1879 " nEndDate = nStartDate;\n"
1880 " nStartDate = n;\n"
1881 " }\n"
1882 " int nRet;\n"
1883 " switch( nMode )\n"
1884 " {\n"
1885 " case 0: \n"
1886 " case 4: \n"
1887 " {\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"
1903 " }\n"
1904 " break;\n"
1905 " case 1: \n"
1906 " if( pOptDaysIn1stYear )\n"
1907 " {\n"
1908 " int nD, nM, nY;\n"
1909 " DaysToDate_new( nStartDate + nNullDate, &nD, &nM, &nY );\n"
1910 " *pOptDaysIn1stYear = IsLeapYear( nY )? 366 : 365;\n"
1911 " }\n"
1912 " nRet = nEndDate - nStartDate;\n"
1913 " break;\n"
1914 " case 2: \n"
1915 " nRet = nEndDate - nStartDate;\n"
1916 " if( pOptDaysIn1stYear )\n"
1917 " *pOptDaysIn1stYear = 360;\n"
1918 " break;\n"
1919 " case 3: \n"
1920 " nRet = nEndDate - nStartDate;\n"
1921 " if( pOptDaysIn1stYear )\n"
1922 " *pOptDaysIn1stYear = 365;\n"
1923 " break;\n"
1924 " }\n"
1925 " return bNeg? -nRet : nRet;\n"
1926 "}\n";
1928 #endif
1930 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */