Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / core / opencl / opinlinefun_finacial.cxx
blob154a9f5eebff9122001a485ae08a754335e951c7
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";
275 std::string GetNullDateDecl=
276 "int GetNullDate(void);\n";
278 std::string GetNullDate=
279 "int GetNullDate(void)\n"
280 "{\n"
281 " return DateToDays(30,12,1899 );\n"
282 "}\n";
283 std::string GetNullDate_newDecl=
284 "int GetNullDate_new(void);\n";
286 std::string GetNullDate_new=
287 "int GetNullDate_new(void)\n"
288 "{\n"
289 " return DateToDays_new(30,12,1899 );\n"
290 "}\n";
292 std::string ScaDateDecl=
293 "void ScaDate( int nNullDate, int nDate, int nBase,int *nOrigDay, "
294 "int *nMonth,int *nYear,int *bLastDayMode,int *bLastDay,"
295 "int *b30Days,int *bUSMode,int *nDay);\n";
297 std::string ScaDate=
298 "void ScaDate( int nNullDate, int nDate, int nBase,int *nOrigDay, "
299 "int *nMonth,int *nYear,int *bLastDayMode,int *bLastDay,"
300 "int *b30Days,int *bUSMode,int *nDay)\n"
301 "{\n"
302 " DaysToDate( nNullDate + nDate, nOrigDay, nMonth, nYear );\n"
303 " *bLastDayMode = (nBase != 5);\n"
304 " *bLastDay = (*nOrigDay >= DaysInMonth( *nMonth, *nYear ));\n"
305 " *b30Days = (nBase == 0) || (nBase == 4);\n"
306 " *bUSMode = (nBase == 0);\n"
307 " if( *b30Days)\n"
308 " {\n"
309 " *nDay = min( *nOrigDay, 30);\n"
310 " if( *bLastDay || (*nDay >=DaysInMonth( *nMonth, *nYear )) )\n"
311 " *nDay = 30;\n"
312 " }\n"
313 " else\n"
314 " {\n"
315 " int nLastDay = DaysInMonth( *nMonth, *nYear );\n"
316 " *nDay = *bLastDay ? nLastDay : min( *nOrigDay, nLastDay );\n"
317 " }\n"
318 "}\n";
320 std::string ScaDate2Decl=
321 "void ScaDate2( int nNullDate, int nDate, int nBase,int *bLastDayMode,int *"
322 "bLastDay,int *b30Days,int *bUSMode);\n";
324 std::string ScaDate2=
325 "void ScaDate2( int nNullDate, int nDate, int nBase,int *bLastDayMode,int *"
326 "bLastDay,int *b30Days,int *bUSMode)\n"
327 "{\n"
328 " int nOrigDay=0, nMonth=0, nYear=0;\n"
329 " DaysToDate( nNullDate + nDate, &nOrigDay, &nMonth, &nYear );\n"
330 " *bLastDayMode = (nBase != 5);\n"
331 " *bLastDay = (nOrigDay >= DaysInMonth( nMonth, nYear ));\n"
332 " *b30Days = (nBase == 0) || (nBase == 4);\n"
333 " *bUSMode = (nBase == 0);\n"
334 "}\n";
336 std::string lcl_GetCouppcdDecl=
337 "int lcl_GetCouppcd(int nNullDate,int nSettle,int nMat,int nFreq,int nBase);\n";
339 std::string lcl_GetCouppcd=
340 "int lcl_GetCouppcd(int nNullDate,int nSettle, int nMat,int nFreq,int nBase)\n"
341 "{\n"
342 " int aDate = nMat;\n"
343 " int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0,"
344 "rbUSMode=0,rnDay=0;\n"
345 " int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0,"
346 "sbUSMode=0,snDay=0;\n"
347 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
348 "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
349 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,"
350 "&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
351 " rYear=sYear;\n"
352 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
353 " if(checklessthan(rYear,sYear,rMonth,sMonth,rnDay,snDay,rbLastDay,"
354 "sbLastDay,rDay,sDay))\n"
355 " {\n"
356 " rYear+=1;\n"
357 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
358 " }\n"
359 " while(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
360 "rbLastDay,sDay,rDay))\n"
361 " {\n"
362 " double d = -1*(12/nFreq);\n"
363 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,d,&rYear);\n"
364 " }\n"
365 " int nLastDay = DaysInMonth( rMonth, rYear );\n"
366 " int nRealDay = (rbLastDayMode && rbLastDay) ? nLastDay :"
367 "min( nLastDay, rDay );\n"
368 " return DateToDays( nRealDay, rMonth, rYear ) - nNullDate;\n"
369 "}\n";
371 std::string lcl_GetCoupncdDecl=
372 "int lcl_GetCoupncd(int nNullDate,int nSettle,int nMat,int nFreq,int nBase);\n";
374 std::string lcl_GetCoupncd=
375 "int lcl_GetCoupncd(int nNullDate,int nSettle, int nMat,int nFreq,int nBase)\n"
376 "{\n"
377 " int aDate = nMat;\n"
378 " int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0,"
379 "rbUSMode=0,rnDay=0;\n"
380 " int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0,"
381 "sbUSMode=0,snDay=0;\n"
382 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
383 "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
384 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,"
385 "&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
386 " rYear=sYear;\n"
387 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
388 " if(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,rbLastDay"
389 ",sDay,rDay))\n"
390 " {\n"
391 " rYear-=1;\n"
392 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
393 " }\n"
394 " while(!checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
395 "rbLastDay,sDay,rDay))\n"
396 " {\n"
397 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,12/nFreq,&rYear);\n"
398 " }\n"
399 " int nLastDay = DaysInMonth( rMonth, rYear );\n"
400 " int nRealDay = (rbLastDayMode && rbLastDay) ? nLastDay :"
401 "min( nLastDay, rDay );\n"
402 " return DateToDays( nRealDay, rMonth, rYear ) - nNullDate;\n"
403 "}\n";
405 std::string addMonthsDecl=
406 "void addMonths(int b30Days,int bLastDay,int *nDay,int nOrigDay,"
407 "int *nMonth,int nMonthCount,int *year);\n";
409 std::string addMonths=
410 "void addMonths(int b30Days,int bLastDay,int *nDay,int nOrigDay,"
411 "int *nMonth,int nMonthCount,int *year)\n"
412 "{\n"
413 " int nNewMonth = nMonthCount + *nMonth;\n"
414 " if( nNewMonth > 12 )\n"
415 " {\n"
416 " --nNewMonth;\n"
417 " *year+=nNewMonth / 12 ;\n"
418 " *nMonth = ( nNewMonth % 12 ) + 1;\n"
419 " }\n"
420 " else if( nNewMonth < 1 )\n"
421 " {\n"
422 " *year+= nNewMonth / 12 - 1 ;\n"
423 " *nMonth = nNewMonth % 12 + 12 ;\n"
424 " }\n"
425 " else\n"
426 " *nMonth = nNewMonth ;\n"
427 " if( b30Days )\n"
428 " {\n"
429 " *nDay = min( nOrigDay, 30);\n"
430 " if( bLastDay || (*nDay >= DaysInMonth( *nMonth, *year )) )\n"
431 " *nDay = 30;\n"
432 " }\n"
433 " else\n"
434 " {\n"
435 " int nLastDay = DaysInMonth( *nMonth, *year );\n"
436 " *nDay = bLastDay ? nLastDay : min( nOrigDay, nLastDay );\n"
437 " }\n"
438 "}\n";
440 std::string getDaysInMonthRangeDecl=
441 "int getDaysInMonthRange( int nFrom, int nTo,int b30Days,int year);\n";
443 std::string getDaysInMonthRange=
444 "int getDaysInMonthRange( int nFrom, int nTo,int b30Days,int year)\n"
445 "{\n"
446 " if( nFrom > nTo )\n"
447 " return 0;\n"
448 " int nRet = 0;\n"
449 " if( b30Days )\n"
450 " nRet = (nTo - nFrom + 1) * 30;\n"
451 " else\n"
452 " {\n"
453 " for( int nMonthIx = nFrom; nMonthIx <= nTo; ++nMonthIx )\n"
454 " nRet += b30Days ? 30 : DaysInMonth( nMonthIx, year );\n"
455 " }\n"
456 " return nRet;\n"
457 "}\n";
459 std::string GetDaysInYearsDecl=
460 "int GetDaysInYears( int nYear1, int nYear2 );\n";
462 std::string GetDaysInYears=
463 "int GetDaysInYears( int nYear1, int nYear2 )\n"
464 "{\n"
465 " int nLeaps = 0;\n"
466 " for( int n = nYear1 ; n <= nYear2 ; n++ )\n"
467 " {\n"
468 " if( IsLeapYear( n ) )\n"
469 " nLeaps++;\n"
470 " }\n"
471 " int nSum = 1;\n"
472 " nSum += nYear2;\n"
473 " nSum -= nYear1;\n"
474 " nSum *= 365;\n"
475 " nSum += nLeaps;\n"
476 " return nSum;\n"
477 "}\n";
479 std::string GetDaysInYearDecl=
480 "int GetDaysInYear( int nNullDate, int nDate, int nMode );\n";
482 std::string GetDaysInYear=
483 "int GetDaysInYear( int nNullDate, int nDate, int nMode )\n"
484 "{\n"
485 " switch( nMode )\n"
486 " {\n"
487 " case 0:\n"
488 " case 2:\n"
489 " case 4:\n"
490 " return 360;\n"
491 " case 1:\n"
492 " {\n"
493 " int nD=0, nM=0, nY=0;\n"
494 " nDate += nNullDate;\n"
495 " DaysToDate( nDate, &nD, &nM, &nY );\n"
496 " return IsLeapYear( nY )? 366 : 365;\n"
497 " }\n"
498 " case 3:\n"
499 " return 365;\n"
500 " }\n"
501 "}\n";
503 std::string getDaysInYearRangeDecl =
504 "int getDaysInYearRange( int nFrom, int nTo,int b30Days );\n";
506 std::string getDaysInYearRange=
507 "int getDaysInYearRange( int nFrom, int nTo,int b30Days )\n"
508 "{\n"
509 " if( nFrom > nTo )\n"
510 " return 0;\n"
511 " return b30Days ? ((nTo - nFrom + 1) * 360) : GetDaysInYears( nFrom, nTo)"
512 ";\n"
513 "}\n";
516 std::string getDiffDecl=
517 "int getDiff(int rFrom,int rTo,int fDay,int fMonth,int fYear,int fbLastDayMode,"
518 "int fbLastDay,int fb30Days,int fbUSMode,int fnDay,int tDay,int tMonth,"
519 "int tYear,int tbLastDayMode,int tbLastDay,int tb30Days,"
520 "int tbUSMode,int tnDay);\n";
523 std::string getDiff=
524 "int getDiff(int rFrom,int rTo,int fDay,int fMonth,int fYear,int fbLastDayMode,"
525 "int fbLastDay,int fb30Days,int fbUSMode,int fnDay,int tDay,int tMonth,"
526 "int tYear,int tbLastDayMode,int tbLastDay,int tb30Days,"
527 "int tbUSMode,int tnDay)\n"
528 "{\n"
529 " if(rFrom>rTo)\n"
530 " {\n"
531 " int d=fDay;fDay=tDay;tDay=d;\n"
532 " int m=fMonth;fMonth=tMonth;tMonth=m;\n"
533 " int y=fYear;fYear=tYear;tYear=y;\n"
534 " int a=fbLastDayMode;fbLastDayMode=tbLastDayMode;tbLastDayMode=a;\n"
535 " int b=fbLastDay;fbLastDay=tbLastDay;tbLastDay=b;\n"
536 " int c=fb30Days;fb30Days=tb30Days;tb30Days=c;\n"
537 " int e=fbUSMode;fbUSMode=tbUSMode;tbUSMode=e;\n"
538 " int f=fnDay;fnDay=tnDay;tnDay=f;\n"
539 " }\n"
540 " int nDiff=0;\n"
541 " if( tb30Days )\n"
542 " {\n"
543 " if( tbUSMode )\n"
544 " {\n"
545 " if( ((fMonth == 2) || (fnDay < 30)) && (tDay == 31) )\n"
546 " tnDay = 31;\n"
547 " else if( (tMonth == 2) && tbLastDay )\n"
548 " tnDay = DaysInMonth( 2, tYear );\n"
549 " }\n"
550 " else\n"
551 " {\n"
552 " if( (fMonth == 2) && (fnDay == 30) )\n"
553 " fnDay = DaysInMonth( 2, fYear );\n"
554 " if( (tMonth == 2) && (tnDay == 30) )\n"
555 " tnDay = DaysInMonth( 2, tYear );\n"
556 " }\n"
557 " }\n"
558 " if( (fYear < tYear) || ((fYear == tYear) && (fMonth < tMonth)) )\n"
559 " {\n"
560 " int d = fb30Days ? 30:DaysInMonth(fMonth,fYear);\n"
561 " nDiff = d- fnDay + 1;\n"
562 " fDay = fnDay = 1;\n"
563 " fbLastDay = 0;\n"
564 " addMonths(fb30Days,fbLastDay,&fnDay,fDay,&fMonth,1,&fYear);\n"
565 " if( fYear < tYear )\n"
566 " {\n"
567 " nDiff += getDaysInMonthRange( fMonth, 12,fb30Days,fYear);\n"
568 " addMonths(fb30Days,fbLastDay,&fnDay,fDay,&fMonth,13-fMonth,&fYear"
569 ");\n"
570 " nDiff += getDaysInYearRange( fYear, tYear - 1,fb30Days);\n"
571 " fYear+=tYear - fYear;\n"
572 " }\n"
573 " nDiff += getDaysInMonthRange(fMonth, tMonth - 1,fb30Days ,fYear );\n"
574 " addMonths(fb30Days,fbLastDay,&fnDay,fDay,&fMonth,tMonth-fMonth,&fYear"
575 ");\n"
576 " }\n"
577 " nDiff += tnDay - fnDay;\n"
578 " return nDiff > 0 ? nDiff : 0;\n"
579 "}\n";
583 std::string lcl_GetcoupdaybsDecl=
584 "int lcl_Getcoupdaybs(int nNullDate,int nSettle, int nMat,int nFreq,int nBase);\n";
587 std::string lcl_Getcoupdaybs=
588 "int lcl_Getcoupdaybs(int nNullDate,int nSettle, int nMat,int nFreq,int nBase)\n"
589 "{\n"
590 " int aDate = nMat;\n"
591 " int rDay=0,rMonth=0, rYear=0;int mDay=0,mMonth=0, mYear=0;int sDay=0,"
592 "sMonth=0, sYear=0;\n"
593 " int rbLastDayMode=0, rbLastDay=0,rb30Days=0,rbUSMode=0,rnDay=0;\n"
594 " int sbLastDayMode=0, sbLastDay=0,sb30Days=0,sbUSMode=0,snDay=0;\n"
595 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,&"
596 "rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
597 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,&"
598 "sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
599 " rYear= sYear;\n"
600 " nSettle=nSettle+nNullDate;\n"
601 " aDate=DateToDays( rDay,rMonth,rYear );\n"
602 " if( aDate < nSettle )\n"
603 " {\n"
604 " rYear+= 1;\n"
605 " aDate=DateToDays( rDay,rMonth,rYear );\n"
606 " }\n"
607 " while(aDate > nSettle )\n"
608 " {\n"
609 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,-1*(12/nFreq),&rYear"
610 ");\n"
611 " aDate=DateToDays( rDay,rMonth,rYear );\n"
612 " }\n"
613 " return getDiff( aDate, nSettle, rDay, rMonth, rYear, rbLastDayMode, "
614 "rbLastDay, rb30Days, rbUSMode, rnDay, sDay, sMonth, sYear, sbLastDayMode,"
615 "sbLastDay, sb30Days, sbUSMode, snDay);\n"
616 "}\n";
618 std::string lcl_Getcoupdaybs_newDecl=
619 "int lcl_Getcoupdaybs_new(int nNullDate,int nSettle,int nMat,int nFreq,"
620 "int nBase);\n";
622 std::string lcl_Getcoupdaybs_new=
623 "int lcl_Getcoupdaybs_new(int nNullDate,int nSettle,int nMat,int nFreq,"
624 "int nBase)\n"
625 "{\n"
626 " int aDate = nMat;\n"
627 " int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0,"
628 "rbUSMode=0,rnDay=0;\n"
629 " int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0,"
630 "sbUSMode=0,snDay=0;\n"
631 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
632 "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
633 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,"
634 "&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
635 " rYear=sYear;\n"
636 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
637 " aDate=DateToDays_new( rnDay,rMonth,rYear);\n"
638 " if(checklessthan(rYear,sYear,rMonth,sMonth,rnDay,snDay,rbLastDay,"
639 "sbLastDay,rDay,sDay))\n"
640 " {\n"
641 " rYear+=1;\n"
642 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
643 " aDate=DateToDays_new( rnDay,rMonth,rYear );\n"
644 " }\n"
645 " while(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
646 "rbLastDay,sDay,rDay))\n"
647 " {\n"
648 " double d = -1*(12/nFreq);\n"
649 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,d,&rYear);\n"
650 " aDate=DateToDays_new( rnDay,rMonth,rYear );\n"
651 " }\n"
652 " return getDiff( aDate,nSettle+nNullDate,rDay,rMonth,rYear,rbLastDayMode,"
653 "rbLastDay,rb30Days,rbUSMode,rnDay,sDay,sMonth,sYear,sbLastDayMode,sbLastDay,"
654 "sb30Days,sbUSMode, snDay);\n"
655 "}\n";
657 std::string lcl_GetcoupdaysDecl=
658 "int lcl_Getcoupdays(int nNullDate,int nSettle, "
659 "int nMat,int nFreq,int nBase);\n";
661 std::string lcl_Getcoupdays=
662 "int lcl_Getcoupdays(int nNullDate,int nSettle, "
663 "int nMat,int nFreq,int nBase)\n"
664 "{\n"
665 " int aDate = nMat;\n"
666 " int rDay=0,rMonth=0, rYear=0;int mDay=0,mMonth=0, mYear=0;int sDay=0,"
667 "sMonth=0, sYear=0;\n"
668 " int rbLastDayMode=0, rbLastDay=0,rb30Days=0,rbUSMode=0,rnDay=0;\n"
669 " int sbLastDayMode=0, sbLastDay=0,sb30Days=0,sbUSMode=0,snDay=0;\n"
670 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,&"
671 "rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
672 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,&"
673 "sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
674 " rYear= sYear;\n"
675 " nSettle=nSettle+nNullDate;\n"
676 " aDate=DateToDays( rDay,rMonth,rYear );\n"
677 " if( aDate < nSettle )\n"
678 " { \n"
679 " rYear+= 1;\n"
680 " aDate=DateToDays( rDay,rMonth,rYear );\n"
681 " }\n"
682 " while(aDate > nSettle )\n"
683 " {\n"
684 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,-1*(12/nFreq),&rYear"
685 ");\n"
686 " aDate=DateToDays( rDay,rMonth,rYear );\n"
687 " }\n"
688 " int aNextDate=aDate;int aDay=rDay,aMonth=rMonth, aYear=rYear;\n"
689 " int abLastDayMode=rbLastDayMode, abLastDay=rbLastDay,ab30Days=rb30Days,"
690 "abUSMode=rbUSMode,anDay=rnDay;\n"
691 " addMonths(ab30Days,abLastDay,&anDay,aDay,&aMonth,12/nFreq,&aYear);\n"
692 " return getDiff( aDate, aNextDate, rDay, rMonth, rYear, rbLastDayMode, "
693 "rbLastDay, rb30Days, rbUSMode, rnDay, aDay, aMonth, aYear, abLastDayMode,"
694 "abLastDay, ab30Days, abUSMode, anDay);\n"
695 "}\n";
697 std::string lcl_Getcoupdays_newDecl=
698 "int lcl_Getcoupdays_new(int nNullDate,int nSettle, "
699 "int nMat,int nFreq,int nBase);\n";
701 std::string lcl_Getcoupdays_new=
702 "int lcl_Getcoupdays_new(int nNullDate,int nSettle, "
703 "int nMat,int nFreq,int nBase)\n"
704 "{\n"
705 " int aDate = nMat;\n"
706 " int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0,"
707 "rbUSMode=0,rnDay=0;\n"
708 " int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0,"
709 "sbUSMode=0,snDay=0;\n"
710 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
711 "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
712 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,"
713 "&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
714 " rYear=sYear;\n"
715 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
716 " aDate=DateToDays_new( rnDay,rMonth,rYear);\n"
717 " if(checklessthan(rYear,sYear,rMonth,sMonth,rnDay,snDay,rbLastDay,"
718 "sbLastDay,rDay,sDay))\n"
719 " {\n"
720 " rYear+=1;\n"
721 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
722 " aDate=DateToDays_new( rnDay,rMonth,rYear );\n"
723 " }\n"
724 " while(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
725 "rbLastDay,sDay,rDay))\n"
726 " {\n"
727 " double d = -1*12*pow((double)nFreq,-1.0);\n"
728 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,d,&rYear);\n"
729 " aDate=DateToDays_new( rnDay,rMonth,rYear );\n"
730 " }\n"
731 " int aNextDate=aDate;int aDay=rDay,aMonth=rMonth, aYear=rYear;\n"
732 " int abLastDayMode=rbLastDayMode, abLastDay=rbLastDay,ab30Days=rb30Days,"
733 "abUSMode=rbUSMode,anDay=rnDay;\n"
734 " int tmp = (int)(12*pow((double)nFreq,-1.0));\n"
735 " addMonths(ab30Days,abLastDay,&anDay,aDay,&aMonth,tmp,&aYear);\n"
736 " return getDiff( aDate, aNextDate, rDay, rMonth, rYear, rbLastDayMode, "
737 "rbLastDay, rb30Days, rbUSMode, rnDay, aDay, aMonth, aYear, abLastDayMode,"
738 "abLastDay, ab30Days, abUSMode, anDay);\n"
739 "}\n";
741 std::string lcl_GetcoupnumDecl=
742 "int lcl_Getcoupnum(int nNullDate,int nSettle, int nMat,int nFreq);\n";
744 std::string lcl_Getcoupnum=
745 "int lcl_Getcoupnum(int nNullDate,int nSettle, int nMat,int nFreq)\n"
746 "{\n"
747 " int aDate = nMat;int rDay=0,rMonth=0, rYear=0;int mDay=0,mMonth=0, mYear="
748 "0;\n"
749 " int sDay=0,sMonth=0, sYear=0;\n"
750 " DaysToDate(aDate+nNullDate,&rDay, &rMonth, &rYear );\n"
751 " DaysToDate(nMat+nNullDate,&mDay, &mMonth, &mYear );\n"
752 " DaysToDate(nSettle+nNullDate,&sDay, &sMonth, &sYear );\n"
753 " rYear= sYear;\n"
754 " nSettle=nSettle+nNullDate;\n"
755 " aDate=DateToDays( rDay,rMonth,rYear );\n"
756 " if( aDate < nSettle )\n"
757 " rYear+= 1;\n"
758 " int d=DateToDays( rDay,rMonth,rYear );\n"
759 " int nMonthCount=-1*(12 / nFreq);\n"
760 " while(d > nSettle )\n"
761 " {\n"
762 " int nNewMonth = nMonthCount + rMonth;\n"
763 " if( nNewMonth > 12 )\n"
764 " {\n"
765 " --nNewMonth;\n"
766 " rYear+=nNewMonth / 12;\n"
767 " rMonth = nNewMonth % 12 + 1;\n"
768 " }\n"
769 " else if( nNewMonth < 1 )\n"
770 " {\n"
771 " rYear+= nNewMonth / 12 - 1;\n"
772 " rMonth = nNewMonth % 12 + 12;\n"
773 " }\n"
774 " else\n"
775 " rMonth = nNewMonth;\n"
776 " d=DateToDays( rDay,rMonth,rYear );\n"
777 " }\n"
778 " int n=(mYear-rYear)*12+mMonth-rMonth;\n"
779 " n=n*nFreq/12;\n"
780 " return n;\n"
781 "}\n";
782 std::string lcl_Getcoupnum_newDecl=
783 "double lcl_Getcoupnum_new(int nNullDate,int nSettle,int nMat,int nFreq,int"
784 " nBase);\n";
785 std::string lcl_Getcoupnum_new=
786 "double lcl_Getcoupnum_new(int nNullDate,int nSettle, int nMat,int nFreq,int"
787 " nBase)\n"
788 "{\n"
789 " int aDate = nMat;\n"
790 " int mDay=0,mMonth=0, mYear=0;\n"
791 " int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0,"
792 "rbUSMode=0,rnDay=0;\n"
793 " int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0,"
794 "sbUSMode=0,snDay=0;\n"
795 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
796 "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
797 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,"
798 "&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
799 " mMonth = rMonth, mYear = rYear;\n"
800 " rYear=sYear;\n"
801 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
802 " if(checklessthan(rYear,sYear,rMonth,sMonth,rnDay,snDay,rbLastDay,"
803 "sbLastDay,rDay,sDay))\n"
804 " {\n"
805 " rYear+=1;\n"
806 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
807 " }\n"
808 " int m= checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
809 "rbLastDay,sDay,rDay);\n"
810 " while(m)\n"
811 " {\n"
812 " double d = -1*(12/nFreq);\n"
813 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,d,&rYear);\n"
814 " m = checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
815 "rbLastDay,sDay,rDay);\n"
816 " }\n"
817 " int n=(mYear-rYear)*12+mMonth-rMonth;\n"
818 " double tmp = (double)(n*nFreq)/12.0;\n"
819 " return tmp;\n"
820 "}\n";
822 std::string setDayDecl=
823 "void setDay(int nOrigDay, int nMonth,int nYear,int bLastDay,int b30Days,"
824 "int *nDay);\n";
825 std::string setDay=
826 "void setDay(int nOrigDay, int nMonth,int nYear,int bLastDay,int b30Days,"
827 "int *nDay)\n"
828 "{\n"
829 " if( b30Days )\n"
830 " {\n"
831 " *nDay = min( nOrigDay, 30);\n"
832 " if( bLastDay || (*nDay >= DaysInMonth( nMonth, nYear )) )\n"
833 " *nDay = 30;\n"
834 " }\n"
835 " else\n"
836 " {\n"
837 " int nLastDay = DaysInMonth( nMonth, nYear );\n"
838 " *nDay = bLastDay ? nLastDay : min( nOrigDay, nLastDay );\n"
839 " }\n"
840 "}\n";
843 std::string coupdaysDecl=
844 "double coupdays(int nSettle,int nMat,int nFreq,int nBase);\n";
847 std::string coupdays=
848 "double coupdays(int nSettle,int nMat,int nFreq,int nBase)\n"
849 "{\n"
850 " int nNullDate=GetNullDate();\n"
851 " if( nBase == 1 )\n"
852 " return lcl_Getcoupdays(nNullDate, nSettle, nMat,nFreq, nBase);\n"
853 " else\n"
854 " return (double)GetDaysInYear(0,0,nBase)/nFreq;\n"
855 "}\n";
856 std::string coupdays_newDecl=
857 "double coupdays_new(int nSettle,int nMat,int nFreq,int nBase);\n";
859 std::string coupdays_new=
860 "double coupdays_new(int nSettle,int nMat,int nFreq,int nBase)\n"
861 "{\n"
862 " int nNullDate=693594;\n"
863 " if( nBase == 1 )\n"
864 " return lcl_Getcoupdays_new(nNullDate, nSettle, nMat,nFreq, nBase);\n"
865 " else\n"
866 " return (double)GetDaysInYear(0,0,nBase)*pow((double)nFreq,-1.0);\n"
867 "}\n";
869 std::string coupdaybsDecl=
870 "double coupdaybs( int nSettle,int nMat,int nFreq,int nBase);\n";
872 std::string coupdaybs=
873 "double coupdaybs( int nSettle,int nMat,int nFreq,int nBase)\n"
874 "{\n"
875 " int nNullDate=GetNullDate();\n"
876 " return lcl_Getcoupdaybs(nNullDate, nSettle, nMat,nFreq, nBase);\n"
877 "}\n";
879 std::string coupdaybs_newDecl=
880 "double coupdaybs_new( int nSettle,int nMat,int nFreq,int nBase);\n";
882 std::string coupdaybs_new=
883 "double coupdaybs_new( int nSettle,int nMat,int nFreq,int nBase)\n"
884 "{\n"
885 " int nNullDate=693594;\n"
886 " return lcl_Getcoupdaybs_new(nNullDate, nSettle, nMat,nFreq, nBase);\n"
887 "}\n";
889 std::string coupdaysncDecl=
890 "double coupdaysnc( int nSettle,int nMat,int nFreq,int nBase);\n";
893 std::string coupdaysnc=
894 "double coupdaysnc( int nSettle,int nMat,int nFreq,int nBase)\n"
895 "{\n"
896 " int nNullDate=GetNullDate();\n"
897 " if((nBase != 0) && (nBase != 4))\n"
898 " {\n"
899 " int aDate = nMat;\n"
900 " int rDay=0,rMonth=0, rYear=0;int mDay=0,mMonth=0, mYear=0;int sDay=0,"
901 "sMonth=0, sYear=0;\n"
902 " int rbLastDayMode=0, rbLastDay=0,rb30Days=0,rbUSMode=0,rnDay=0;\n"
903 " int sbLastDayMode=0, sbLastDay=0,sb30Days=0,sbUSMode=0,snDay=0;\n"
904 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,&"
905 "rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
906 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
907 "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
908 " rYear= sYear;\n"
909 " nSettle=nSettle+nNullDate;\n"
910 " aDate=DateToDays( rDay,rMonth,rYear );\n"
911 " if( aDate > nSettle )\n"
912 " {\n"
913 " rYear-= 1;\n"
914 " aDate=DateToDays( rDay,rMonth,rYear );\n"
915 " }\n"
916 " while(aDate <= nSettle )\n"
917 " {\n"
918 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,12/nFreq,&rYear)"
919 ";\n"
920 " aDate=DateToDays( rDay,rMonth,rYear );\n"
921 " }\n"
922 " return getDiff( nSettle, aDate, sDay, sMonth, sYear, sbLastDayMode, "
923 "sbLastDay, sb30Days, sbUSMode, snDay, rDay, rMonth, rYear, rbLastDayMode, "
924 "rbLastDay, rb30Days, rbUSMode, rnDay);\n"
925 " }\n"
926 " else\n"
927 " return coupdays(nSettle,nMat,nFreq,nBase)- coupdaybs( nSettle,nMat,"
928 "nFreq,nBase);\n"
929 "}\n";
930 std::string coupdaysnc_newDecl=
931 "double coupdaysnc_new( int nSettle,int nMat,int nFreq,int nBase);\n";
933 std::string coupdaysnc_new=
934 "double coupdaysnc_new( int nSettle,int nMat,int nFreq,int nBase)\n"
935 "{\n"
936 " int nNullDate=693594;\n"
937 " if((nBase != 0) && (nBase != 4))\n"
938 " {\n"
939 " int aDate = nMat;\n"
940 " int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0,"
941 "rbUSMode=0,rnDay=0;\n"
942 " int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0,"
943 "sbUSMode=0,snDay=0;\n"
944 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,"
945 "&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
946 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
947 "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
948 " rYear=sYear;\n"
949 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
950 " aDate=DateToDays( rnDay,rMonth,rYear);\n"
951 " if(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,rbLastDay"
952 ",sDay,rDay))\n"
953 " {\n"
954 " rYear-=1;\n"
955 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
956 " aDate=DateToDays( rnDay,rMonth,rYear );\n"
957 " }\n"
958 " while(!checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
959 "rbLastDay,sDay,rDay))\n"
960 " {\n"
961 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,12/nFreq,&rYear);\n"
962 " aDate=DateToDays( rnDay,rMonth,rYear );\n"
963 " }\n"
964 " return getDiff( nSettle+nNullDate,aDate,sDay,sMonth,sYear,sbLastDayMode, "
965 "sbLastDay, sb30Days, sbUSMode, snDay, rDay, rMonth, rYear, rbLastDayMode, "
966 "rbLastDay, rb30Days, rbUSMode, rnDay);\n"
967 " }\n"
968 " else\n"
969 " return coupdays_new(nSettle,nMat,nFreq,nBase)- coupdaybs_new( nSettle,"
970 "nMat,nFreq,nBase);\n"
971 "}\n";
973 std::string checklessthanDecl=
974 "int checklessthan(int aYear,int bYear,int aMonth,int bMonth,int anDay,int "
975 "bnDay,int abLastDay,int bbLastDay,int anOrigDay,int bnOrigDay);\n";
976 std::string checklessthan=
977 "int checklessthan(int aYear,int bYear,int aMonth,int bMonth,int anDay,int "
978 "bnDay,int abLastDay,int bbLastDay,int anOrigDay,int bnOrigDay)\n"
979 "{\n"
980 " if( aYear != bYear )\n"
981 " return aYear < bYear;\n"
982 " if( aMonth != bMonth )\n"
983 " return aMonth < bMonth;\n"
984 " if( anDay != bnDay )\n"
985 " return anDay < bnDay;\n"
986 " if( abLastDay || bbLastDay )\n"
987 " return !abLastDay && bbLastDay;\n"
988 " return anOrigDay < bnOrigDay;\n"
989 "}\n";
991 std::string coupnumDecl=
992 "double coupnum( int nSettle,int nMat,int nFreq,int nBase);\n";
994 std::string coupnum=
995 "double coupnum( int nSettle,int nMat,int nFreq,int nBase)\n"
996 "{\n"
997 " int nNullDate=GetNullDate();\n"
998 " return lcl_Getcoupnum(nNullDate,nSettle,nMat,nFreq);\n"
999 "}\n";
1000 std::string coupnum_newDecl=
1001 "double coupnum_new( int nSettle,int nMat,int nFreq,int nBase);\n";
1003 std::string coupnum_new=
1004 "double coupnum_new( int nSettle,int nMat,int nFreq,int nBase)\n"
1005 "{\n"
1006 " int nNullDate=693594;\n"
1007 " return lcl_Getcoupnum_new(nNullDate,nSettle,nMat,nFreq,nBase);\n"
1008 "}\n";
1010 std::string getPrice_Decl=
1011 "double getPrice_(int nSettle, int nMat, double fRate, double fYield,\n"
1012 "double fRedemp, int nFreq, int nBase );\n";
1015 std::string getPrice_=
1016 "double getPrice_(int nSettle, int nMat, double fRate, double fYield,\n"
1017 "double fRedemp, int nFreq, int nBase )\n"
1018 "{\n"
1019 " double fFreq = nFreq;\n"
1020 " double fE = coupdays( nSettle, nMat, nFreq, nBase );\n"
1021 " double fDSC_E = coupdaysnc( nSettle, nMat, nFreq, nBase ) / fE;\n"
1022 " double fN = coupnum( nSettle, nMat, nFreq, nBase );\n"
1023 " double fA = coupdaybs( nSettle, nMat, nFreq, nBase );\n"
1024 " double fRet = fRedemp / ( pow( 1.0 + fYield / fFreq, fN - 1.0 + "
1025 "fDSC_E ) );\n"
1026 " fRet -= 100.0 * fRate / fFreq * fA / fE;\n"
1027 " double fT1 = 100.0 * fRate / fFreq;\n"
1028 " double fT2 = 1.0 + fYield / fFreq;\n"
1029 " for( double fK = 0.0 ; fK < fN ; fK+=1.0 )\n"
1030 " fRet += fT1 / pow( fT2, fK + fDSC_E );\n"
1031 " return fRet;\n"
1032 "}\n";
1033 std::string getPrice_new_Decl=
1034 "double getPrice_(int nSettle, int nMat, double fRate, double fYield,\n"
1035 "double fRedemp, int nFreq, int nBase );\n";
1038 std::string getPrice_new=
1039 "double getPrice_(int nSettle, int nMat, double fRate, double fYield,\n"
1040 "double fRedemp, int nFreq, int nBase )\n"
1041 "{\n"
1042 " double fFreq = nFreq;\n"
1043 " double fE = coupdays_new( nSettle, nMat, nFreq, nBase );\n"
1044 " double fDSC_E = coupdaysnc_new( nSettle, nMat, nFreq, nBase ) / fE;\n"
1045 " double fN = coupnum_new( nSettle, nMat, nFreq, nBase );\n"
1046 " double fA = coupdaybs_new( nSettle, nMat, nFreq, nBase );\n"
1047 " double fRet = fRedemp / ( pow( 1.0 + fYield / fFreq, fN - 1.0 + "
1048 "fDSC_E ) );\n"
1049 " fRet -= 100.0 * fRate / fFreq * fA / fE;\n"
1050 " double fT1 = 100.0 * fRate / fFreq;\n"
1051 " double fT2 = 1.0 + fYield / fFreq;\n"
1052 " for( double fK = 0.0 ; fK < fN ; fK+=1.0 )\n"
1053 " fRet += fT1 / pow( fT2, fK + fDSC_E );\n"
1054 " return fRet;\n"
1055 "}\n";
1057 std::string getYield_Decl=
1058 "double getYield_( int nNullDate, int nSettle, int nMat, double fCoup,"
1059 "double fPrice,double fRedemp, int nFreq, int nBase);\n";
1061 std::string getYield_=
1062 "double getYield_( int nNullDate, int nSettle, int nMat, double fCoup,"
1063 "double fPrice,double fRedemp, int nFreq, int nBase )\n"
1064 "{\n"
1065 " double fRate = fCoup;\n"
1066 " double fPriceN = 0.0;\n"
1067 " double fYield1 = 0.0;\n"
1068 " double fYield2 = 1.0;\n"
1069 " double fPrice1 = getPrice_(nSettle, nMat, fRate, fYield1, fRedemp, "
1070 "nFreq, nBase );\n"
1071 " double fPrice2 = getPrice_(nSettle, nMat, fRate, fYield2, fRedemp, "
1072 "nFreq, nBase );\n"
1073 " double fYieldN = ( fYield2 - fYield1 ) * 0.5;\n"
1074 " for( unsigned int nIter = 0 ; nIter < 100 && fPriceN != fPrice ; nIter++ "
1075 ")\n"
1076 " {\n"
1077 " fPriceN = getPrice_(nSettle, nMat, fRate, fYieldN, fRedemp, nFreq, "
1078 "nBase );\n"
1079 " if( fPrice == fPrice1 )\n"
1080 " return fYield1;\n"
1081 " else if( fPrice == fPrice2 )\n"
1082 " return fYield2;\n"
1083 " else if( fPrice == fPriceN )\n"
1084 " return fYieldN;\n"
1085 " else if( fPrice < fPrice2 )\n"
1086 " {\n"
1087 " fYield2 *= 2.0;\n"
1088 " fPrice2 = getPrice_(nSettle, nMat, fRate, fYield2, fRedemp, nFreq"
1089 ", nBase );\n"
1090 " fYieldN = ( fYield2 - fYield1 ) * 0.5;\n"
1091 " }\n"
1092 " else\n"
1093 " {\n"
1094 " if( fPrice < fPriceN )\n"
1095 " {\n"
1096 " fYield1 = fYieldN;\n"
1097 " fPrice1 = fPriceN;\n"
1098 " }\n"
1099 " else\n"
1100 " {\n"
1101 " fYield2 = fYieldN;\n"
1102 " fPrice2 = fPriceN;\n"
1103 " }\n"
1104 " fYieldN = fYield2 - ( fYield2 - fYield1 ) * ( ( fPrice - fPrice2 "
1105 ") / ( fPrice1 - fPrice2 ) );\n"
1106 " }\n"
1107 " }\n"
1108 " return fYieldN;\n"
1109 "}\n";
1111 std::string GetYearFracDecl=
1112 "double GetYearFrac( int nNullDate, int nStartDate, int nEndDate,"
1113 "int nMode );\n";
1115 std::string GetYearFrac=
1116 "double GetYearFrac( int nNullDate, int nStartDate, int nEndDate,"
1117 "int nMode ) \n"
1118 "{\n"
1119 " if( nStartDate == nEndDate )\n"
1120 " return 0.0; \n"
1122 " if( nStartDate > nEndDate )\n"
1123 " {\n"
1124 " int n = nEndDate;\n"
1125 " nEndDate = nStartDate;\n"
1126 " nStartDate = n;\n"
1127 " }\n"
1129 " int nDate1 = nStartDate + nNullDate;\n"
1130 " int nDate2 = nEndDate + nNullDate;\n"
1132 " int nDay1, nDay2;\n"
1133 " int nMonth1, nMonth2;\n"
1134 " int nYear1, nYear2;\n"
1136 " DaysToDate( nDate1, &nDay1, &nMonth1, &nYear1 );\n"
1137 " DaysToDate( nDate2, &nDay2, &nMonth2, &nYear2 );\n"
1139 " int nDayDiff;\n"
1140 " switch( nMode )\n"
1141 " {\n"
1142 " case 0: \n"
1143 " if ( nDay1 == 31 )\n"
1144 " {\n"
1145 " nDay1--;\n"
1146 " }\n"
1147 " if ( nDay1 == 30 && nDay2 == 31 )\n"
1148 " {\n"
1149 " nDay2--;\n"
1150 " }\n"
1151 " else\n"
1152 " {\n"
1153 " if ( nMonth1 == 2 && nDay1 == "
1154 "( IsLeapYear( nYear1 ) ? 29 : 28 ) )\n"
1155 " {\n"
1156 " nDay1 = 30;\n"
1157 " if ( nMonth2 == 2 && nDay2 == "
1158 "( IsLeapYear( nYear2 ) ? 29 : 28 ) )\n"
1159 " {\n"
1160 " nDay2 = 30;\n"
1161 " }\n"
1162 " }\n"
1163 " }\n"
1164 " nDayDiff = ( nYear2 - nYear1 ) * 360 + "
1165 "( nMonth2 - nMonth1 ) * 30 + ( nDay2 - nDay1 );\n"
1166 " break;\n"
1167 " case 1: \n"
1168 " case 2: \n"
1169 " case 3: \n"
1170 " nDayDiff = nDate2 - nDate1;\n"
1171 " break;\n"
1172 " case 4: \n"
1173 " if ( nDay1 == 31 )\n"
1174 " {\n"
1175 " nDay1--;\n"
1176 " }\n"
1177 " if ( nDay2 == 31 )\n"
1178 " {\n"
1179 " nDay2--;\n"
1180 " }\n"
1181 " nDayDiff = ( nYear2 - nYear1 ) * 360 + "
1182 "( nMonth2 - nMonth1 ) * 30 + ( nDay2 - nDay1 );\n"
1183 " break;\n"
1184 " }\n"
1186 " double nDaysInYear;\n"
1187 " switch( nMode )\n"
1188 " {\n"
1189 " case 0: \n"
1190 " case 2: \n"
1191 " case 4: \n"
1192 " nDaysInYear = 360;\n"
1193 " break;\n"
1194 " case 1: \n"
1195 " {\n"
1196 " bool isYearDifferent = ( nYear1 != nYear2 );\n"
1197 " if ( isYearDifferent &&\n"
1198 " ( ( nYear2 != nYear1 + 1 ) ||\n"
1199 " ( nMonth1 < nMonth2 ) ||\n"
1200 " ( nMonth1 == nMonth2 && nDay1 < nDay2 ) ) )\n"
1201 " {\n"
1203 " int nDayCount = 0;\n"
1204 " for ( int i = nYear1; i <= nYear2; i++ )\n"
1205 " nDayCount += ( IsLeapYear( i ) ? 366 : 365 );\n"
1207 " nDaysInYear = ( double ) nDayCount / "
1208 "( double ) ( nYear2 - nYear1 + 1 );\n"
1209 " }\n"
1210 " else\n"
1211 " {\n"
1212 " if ( isYearDifferent && IsLeapYear( nYear1 ) )\n"
1213 " {\n"
1214 " nDaysInYear = 366;\n"
1215 " }\n"
1216 " else\n"
1217 " {\n"
1219 " if ( ( IsLeapYear( nYear1 ) && nMonth1 <= 2 "
1220 "&& nDay1 <= 29 ) ||\n"
1221 " ( IsLeapYear( nYear2 ) && ( nMonth2 > 3 || "
1222 "( nMonth2 == 2 && nDay1 == 29 ) ) ) )\n"
1223 " {\n"
1224 " nDaysInYear = 366;\n"
1225 " }\n"
1226 " else\n"
1227 " {\n"
1228 " nDaysInYear = 365;\n"
1229 " for ( int i = nYear1; i <= nYear2; i++ )\n"
1230 " {\n"
1231 " if ( IsLeapYear( i ) )\n"
1232 " {\n"
1233 " nDaysInYear = 366;\n"
1234 " break;\n"
1235 " }\n"
1236 " }\n"
1237 " }\n"
1238 " }\n"
1239 " }\n"
1240 " }\n"
1241 " break;\n"
1242 " case 3: \n"
1243 " nDaysInYear = 365;\n"
1244 " break;\n"
1245 " }\n"
1246 " return (double)( nDayDiff ) / (nDaysInYear);\n"
1247 "}\n";
1250 std::string GetYieldmatDecl=
1251 "double GetYieldmat( int nNullDate, int nSettle, int nMat, int nIssue,\n"
1252 "double fRate, double fPrice, int nBase );\n";
1255 std::string GetYieldmat=
1256 "double GetYieldmat( int nNullDate, int nSettle, int nMat, int nIssue,\n"
1257 "double fRate, double fPrice, int nBase )\n"
1258 "{\n"
1259 " double fIssMat = GetYearFrac_new( nNullDate, nIssue, nMat, nBase );\n"
1260 " double fIssSet = GetYearFrac_new( nNullDate, nIssue, nSettle, nBase );\n"
1261 " double fSetMat = GetYearFrac_new( nNullDate, nSettle, nMat, nBase );\n"
1262 " double y = 1.0 + fIssMat * fRate;\n"
1263 " y =y * pow( (fPrice / 100.0 + fIssSet * fRate),-1);\n"
1264 " y-=1.0;\n"
1265 " y = y * pow(fSetMat,-1);\n"
1266 " return y;\n"
1267 "}\n";
1269 std::string GetDiffDateDecl=
1270 "int GetDiffDate( int nNullDate, int nStartDate, int nEndDate, int nMode,"
1271 " int* pOptDaysIn1stYear );\n";
1273 std::string GetDiffDate=
1274 "int GetDiffDate( int nNullDate, int nStartDate, int nEndDate, int nMode,"
1275 " int* pOptDaysIn1stYear )\n"
1276 "{\n"
1277 " bool bNeg = nStartDate > nEndDate;\n"
1278 " if( bNeg )\n"
1279 " {\n"
1280 " int n = nEndDate;\n"
1281 " nEndDate = nStartDate;\n"
1282 " nStartDate = n;\n"
1283 " }\n"
1284 " int nRet;\n"
1285 " switch( nMode )\n"
1286 " {\n"
1287 " case 0: \n"
1288 " case 4: \n"
1289 " {\n"
1290 " int nD1, nM1, nY1, nD2, nM2, nY2;\n"
1291 " nStartDate += nNullDate;\n"
1292 " nEndDate += nNullDate;\n"
1293 " DaysToDate( nStartDate, &nD1, &nM1, &nY1 );\n"
1294 " DaysToDate( nEndDate, &nD2, &nM2, &nY2 );\n"
1295 " bool bLeap = IsLeapYear( nY1 );\n"
1296 " int nDays, nMonths;\n"
1297 " nMonths = nM2 - nM1;\n"
1298 " nDays = nD2 - nD1;\n"
1299 " nMonths += ( nY2 - nY1 ) * 12;\n"
1300 " nRet = nMonths * 30 + nDays;\n"
1301 " if( nMode == 0 && nM1 == 2 && nM2 != 2 && nY1 == nY2 )\n"
1302 " nRet -= bLeap? 1 : 2;\n"
1303 " if( pOptDaysIn1stYear )\n"
1304 " *pOptDaysIn1stYear = 360;\n"
1305 " }\n"
1306 " break;\n"
1307 " case 1: \n"
1308 " if( pOptDaysIn1stYear )\n"
1309 " {\n"
1310 " int nD, nM, nY;\n"
1311 " DaysToDate( nStartDate + nNullDate, &nD, &nM, &nY );\n"
1312 " *pOptDaysIn1stYear = IsLeapYear( nY )? 366 : 365;\n"
1313 " }\n"
1314 " nRet = nEndDate - nStartDate;\n"
1315 " break;\n"
1316 " case 2: \n"
1317 " nRet = nEndDate - nStartDate;\n"
1318 " if( pOptDaysIn1stYear )\n"
1319 " *pOptDaysIn1stYear = 360;\n"
1320 " break;\n"
1321 " case 3: \n"
1322 " nRet = nEndDate - nStartDate;\n"
1323 " if( pOptDaysIn1stYear )\n"
1324 " *pOptDaysIn1stYear = 365;\n"
1325 " break;\n"
1326 " }\n"
1327 " return bNeg? -nRet : nRet;\n"
1328 "}\n";
1330 std::string GetYearDiffDecl=
1331 "double GetYearDiff( int nNullDate, int nStartDate, int nEndDate,"
1332 "int nMode);\n";
1334 std::string GetYearDiff=
1335 "double GetYearDiff( int nNullDate, int nStartDate, int nEndDate,"
1336 "int nMode )\n"
1337 "{\n"
1338 " int nDays1stYear;\n"
1339 " int nTotalDays = GetDiffDate( nNullDate, nStartDate, nEndDate,"
1340 "nMode, &"
1341 "nDays1stYear );\n"
1342 " return (double)(nTotalDays)*pow((double)nDays1stYear,-1);\n"
1343 "}\n";
1345 std::string GetDiffDate360_Decl=
1346 "int GetDiffDate360_(\n"
1347 " int nDay1, int nMonth1, int nYear1, bool bLeapYear1,\n"
1348 " int nDay2, int nMonth2, int nYear2,\n"
1349 " bool bUSAMethod );\n";
1351 std::string GetDiffDate360_=
1352 "int GetDiffDate360_(\n"
1353 " int nDay1, int nMonth1, int nYear1, bool bLeapYear1,\n"
1354 " int nDay2, int nMonth2, int nYear2,\n"
1355 " bool bUSAMethod )\n"
1356 "{\n"
1357 " if( nDay1 == 31 )\n"
1358 " nDay1--;\n"
1359 " else if( bUSAMethod && ( nMonth1 == 2 && ( nDay1 == 29 || ( nDay1 == 28 "
1360 "&& !bLeapYear1 ) ) ) )\n"
1361 " nDay1 = 30;\n"
1362 " if( nDay2 == 31 )\n"
1363 " {\n"
1364 " if( bUSAMethod && nDay1 != 30 )\n"
1365 " {\n"
1366 " nDay2 = 1;\n"
1367 " if( nMonth2 == 12 )\n"
1368 " {\n"
1369 " nYear2++;\n"
1370 " nMonth2 = 1;\n"
1371 " }\n"
1372 " else\n"
1373 " nMonth2++;\n"
1374 " }\n"
1375 " else\n"
1376 " nDay2 = 30;\n"
1377 " }\n"
1378 " return nDay2 + nMonth2 * 30 + nYear2 * 360 - nDay1 - nMonth1 * 30 - "
1379 "nYear1 * 360;\n"
1380 "}\n";
1382 std::string GetDiffDate360Decl=
1383 "int GetDiffDate360( int nNullDate, int nDate1, int nDate2,"
1384 "bool bUSAMethod);\n";
1387 std::string GetDiffDate360=
1388 "int GetDiffDate360( int nNullDate, int nDate1, int nDate2,"
1389 "bool bUSAMethod )\n"
1390 "{\n"
1391 " nDate1 += nNullDate;\n"
1392 " nDate2 += nNullDate;\n"
1393 " int nDay1, nMonth1, nYear1, nDay2, nMonth2, nYear2;\n"
1394 " DaysToDate( nDate1, &nDay1, &nMonth1, &nYear1 );\n"
1395 " DaysToDate( nDate2, &nDay2, &nMonth2, &nYear2 );\n"
1396 " return GetDiffDate360_( nDay1, nMonth1, nYear1, IsLeapYear( nYear1 ), "
1397 "nDay2, nMonth2, nYear2, bUSAMethod );\n"
1398 "}\n";
1400 std::string GetDurationDecl=
1401 "double GetDuration( \n"
1402 " int nNullDate, int nSettle, int nMat, double fCoup,\n"
1403 " double fYield, int nFreq, int nBase );\n";
1405 std::string GetDuration=
1406 "double GetDuration( \n"
1407 " int nNullDate, int nSettle, int nMat, double fCoup,\n"
1408 " double fYield, int nFreq, int nBase )\n"
1409 "{\n"
1410 " double fYearfrac = GetYearFrac( nNullDate, nSettle, nMat, nBase );\n"
1411 " double fNumOfCoups = lcl_Getcoupnum(nNullDate,nSettle,nMat,nFreq);\n"
1412 " double fDur = 0.0;\n"
1413 " double f100 = 100.0;\n"
1414 " fCoup *= f100 / nFreq;\n"
1415 " fYield /= nFreq;\n"
1416 " fYield += 1.0;\n"
1417 " double nDiff = fYearfrac * nFreq - fNumOfCoups;\n"
1418 " int t;\n"
1419 " for( t = 1 ; t < fNumOfCoups ; t++ )\n"
1420 " fDur += ( t + nDiff ) * ( fCoup ) / pow( fYield, t + nDiff );\n"
1421 " fDur += ( fNumOfCoups + nDiff ) * ( fCoup + f100 ) /"
1422 " pow( fYield, fNumOfCoups + nDiff );\n"
1423 " double p = 0.0;\n"
1424 " for( t = 1 ; t < fNumOfCoups ; t++ )\n"
1425 " p += fCoup / pow( fYield, t + nDiff );\n"
1426 " p += ( fCoup + f100 ) / pow( fYield, fNumOfCoups + nDiff );\n"
1427 " fDur /= p;\n"
1428 " fDur /= nFreq;\n"
1429 " return fDur;\n""}\n";
1431 std::string GetDuration_newDecl=
1432 "double GetDuration_new( \n"
1433 " int nNullDate, int nSettle, int nMat, double fCoup,\n"
1434 " double fYield, int nFreq, int nBase );\n";
1436 std::string GetDuration_new=
1437 "double GetDuration_new( \n"
1438 " int nNullDate, int nSettle, int nMat, double fCoup,\n"
1439 " double fYield, int nFreq, int nBase )\n"
1440 " {\n"
1441 " double fYearfrac = GetYearFrac(nNullDate,nSettle,nMat,nBase);\n"
1442 " double fNumOfCoups = lcl_Getcoupnum_new(nNullDate,nSettle,nMat,"
1443 "nFreq,nBase);\n"
1444 " double fDur = 0.0;\n"
1445 " fCoup = fCoup * 100.0 * pow(nFreq, -1.0);\n"
1446 " fYield = fYield * pow(nFreq, -1.0);\n"
1447 " fYield += 1.0;\n"
1448 " double nDiff = fYearfrac * nFreq - fNumOfCoups;\n"
1449 " int t;\n"
1450 " double tmp0 = 0, tmp1 = 0, tmp2 = 0;\n"
1451 " for( t = 1 ; t < fNumOfCoups ; t++ ){\n"
1452 " tmp0 = (t + nDiff) * ( fCoup ) ;\n"
1453 " tmp1 = pow( fYield, t + nDiff ) ;\n"
1454 " tmp2 = tmp0 * pow(tmp1, -1);\n"
1455 " fDur += tmp2;\n"
1456 " }\n"
1457 " fDur += (fNumOfCoups + nDiff) * (fCoup + 100.0) * pow(pow(fYield,"
1458 " fNumOfCoups + nDiff ),-1);\n"
1459 " double p = 0.0;\n"
1460 " for( t = 1 ; t < fNumOfCoups ; t++ ){\n"
1461 " tmp0 = pow( fYield, t + nDiff );\n"
1462 " p += fCoup * pow(tmp0, -1);}\n"
1463 " p += (fCoup + 100.0) * pow(pow(fYield, fNumOfCoups + nDiff), -1);\n"
1464 " fDur = fDur * pow(p, -1.0);\n"
1465 " fDur = fDur * pow(nFreq, -1.0);\n"
1466 " return fDur;\n"
1467 " }\n";
1469 std::string ScGetGDADecl=
1470 "double ScGetGDA(double fWert, double fRest, double fDauer, double fPeriode,"
1471 "double fFaktor);\n";
1473 std::string ScGetGDA=
1474 "double ScGetGDA(double fWert, double fRest, double fDauer, double fPeriode,"
1475 "double fFaktor)\n"
1476 "{\n"
1477 " double fGda, fZins, fAlterWert, fNeuerWert;\n"
1478 " fZins = fFaktor / fDauer;\n"
1479 " if (fZins >= 1.0)\n"
1480 " {\n"
1481 " fZins = 1.0;\n"
1482 " if (fPeriode == 1.0)\n"
1483 " fAlterWert = fWert;\n"
1484 " else\n"
1485 " fAlterWert = 0.0;\n"
1486 " }\n"
1487 " else\n"
1488 " fAlterWert = fWert * pow(1.0 - fZins, fPeriode - 1.0);\n"
1489 " fNeuerWert = fWert * pow(1.0 - fZins, fPeriode);\n"
1491 " if (fNeuerWert < fRest)\n"
1492 " fGda = fAlterWert - fRest;\n"
1493 " else\n"
1494 " fGda = fAlterWert - fNeuerWert;\n"
1495 " if (fGda < 0.0)\n"
1496 " fGda = 0.0;\n"
1497 " return fGda;\n"
1498 "}\n";
1500 std::string DblMinDecl=
1501 "inline double DblMin( double a, double b );\n";
1503 std::string DblMin=
1504 "inline double DblMin( double a, double b )\n"
1505 "{\n"
1506 " return (a < b) ? a : b;\n"
1507 "}\n";
1509 std::string ScInterVDBDecl=
1510 "double ScInterVDB(double fWert,double fRest,double fDauer, double fDauer1,"
1511 "double fPeriode,double fFaktor);\n";
1513 std::string ScInterVDB=
1514 "double ScInterVDB(double fWert,double fRest,double fDauer, double fDauer1,"
1515 "double fPeriode,double fFaktor)\n"
1516 "{\n"
1517 " double fVdb=0;\n"
1518 " double fIntEnd = ceil(fPeriode);\n"
1519 " int nLoopEnd = fIntEnd;\n"
1521 " double fTerm, fLia;\n"
1522 " double fRestwert = fWert - fRest;\n"
1523 " int bNowLia = 0;\n"
1524 " double fGda;\n"
1525 " int i;\n"
1526 " fLia=0;\n"
1527 " for ( i = 1; i <= nLoopEnd; i++)\n"
1528 " {\n"
1529 " if(!bNowLia)\n"
1530 " {\n"
1531 " fGda = ScGetGDA(fWert, fRest, fDauer, (double) i, fFaktor);\n"
1532 " fLia = fRestwert/ (fDauer1 - (double) (i-1));\n"
1533 " if (fLia > fGda)\n"
1534 " {\n"
1535 " fTerm = fLia;\n"
1536 " bNowLia = 1;\n"
1537 " }\n"
1538 " else\n"
1539 " {\n"
1540 " fTerm = fGda;\n"
1541 " fRestwert =fRestwert- fGda;\n"
1542 " }\n"
1543 " }\n"
1544 " else\n"
1545 " {\n"
1546 " fTerm = fLia;\n"
1547 " }\n"
1549 " if ( i == nLoopEnd)\n"
1550 " fTerm *= ( fPeriode + 1.0 - fIntEnd );\n"
1552 " fVdb += fTerm;\n"
1553 " }\n"
1554 " return fVdb;\n"
1555 "}\n";
1557 std::string VDBImplementDecl=
1558 "double VDBImplement(double fWert,double fRest, double fDauer, double fAnfang"
1559 ", double fEnde, double fFaktor,int bFlag);\n";
1561 std::string VDBImplement=
1562 "double VDBImplement(double fWert,double fRest, double fDauer, double fAnfang"
1563 ", double fEnde, double fFaktor,int bFlag)\n"
1564 "{\n"
1565 " double result=0;\n"
1566 " double fIntStart = floor(fAnfang);\n"
1567 " double fIntEnd = ceil(fEnde);\n"
1568 " int nLoopStart = (int) fIntStart;\n"
1569 " int nLoopEnd = (int) fIntEnd;\n"
1570 " if (bFlag)\n"
1571 " {\n"
1572 " for (int i = nLoopStart + 1; i <= nLoopEnd; i++)\n"
1573 " {\n"
1574 " double fTerm = ScGetGDA(fWert, fRest, fDauer, (double) i, fFaktor"
1575 ");\n"
1576 " if ( i == nLoopStart+1 )\n"
1577 " fTerm *= ( DblMin( fEnde, fIntStart + 1.0 ) - fAnfang );\n"
1578 " else if ( i == nLoopEnd )\n"
1579 " fTerm *= ( fEnde + 1.0 - fIntEnd );\n"
1580 " result += fTerm;\n"
1581 " }\n"
1582 " }\n"
1583 " else\n"
1584 " {\n"
1585 " double fDauer1=fDauer;\n"
1586 " if(!isequal(fAnfang,floor(fAnfang)))\n"
1587 " {\n"
1588 " if(fFaktor>1)\n"
1589 " {\n"
1590 " if(fAnfang>fDauer/2 || isequal(fAnfang,fDauer/2))\n"
1591 " {\n"
1592 " double fPart=fAnfang-fDauer/2;\n"
1593 " fAnfang=fDauer/2;\n"
1594 " fEnde-=fPart;\n"
1595 " fDauer1+=1;\n"
1596 " }\n"
1597 " }\n"
1598 " }\n"
1599 " fWert-=ScInterVDB(fWert,fRest,fDauer,fDauer1,fAnfang,fFaktor);\n"
1600 " result=ScInterVDB(fWert,fRest,fDauer,fDauer-fAnfang,fEnde-fAnfang,"
1601 "fFaktor);\n"
1602 " }\n"
1603 " return result;\n"
1604 "}\n";
1606 std::string GetOddlpriceDecl=
1607 "double GetOddlprice( int nNullDate, int nSettle, int nMat, int nLastCoup,\n"
1608 " double fRate, double fYield, double fRedemp, int nFreq, int nBase );\n";
1610 std::string GetOddlprice=
1611 "double GetOddlprice( int nNullDate, int nSettle, int nMat, int nLastCoup,\n"
1612 " double fRate, double fYield, double fRedemp, int nFreq, int nBase )\n"
1613 "{\n"
1614 " double fFreq = nFreq ;\n"
1615 " double fDCi = GetYearFrac( nNullDate, nLastCoup,"
1616 "nMat, nBase ) * fFreq;\n"
1617 " double fDSCi = GetYearFrac( nNullDate, nSettle,"
1618 "nMat, nBase ) * fFreq;\n"
1619 " double fAi = GetYearFrac( nNullDate, nLastCoup,"
1620 "nSettle, nBase ) * fFreq;\n"
1621 " double p = fRedemp + fDCi * 100.0 * fRate / fFreq;\n"
1622 " p /= fDSCi * fYield / fFreq + 1.0;\n"
1623 " p -= fAi * 100.0 * fRate / fFreq;\n"
1624 " return p;\n"
1625 "}\n";
1627 std::string GetOddlyieldDecl=
1628 "double GetOddlyield( int nNullDate, int nSettle, int nMat, int nLastCoup,\n"
1629 " double fRate, double fPrice, double fRedemp, int nFreq, int nBase );\n";
1631 std::string GetOddlyield=
1632 "double GetOddlyield( int nNullDate, int nSettle, int nMat, int nLastCoup,\n"
1633 " double fRate, double fPrice, double fRedemp, int nFreq, int nBase ) \n"
1634 "{\n"
1635 " double fFreq = nFreq ;\n"
1636 " double fDCi= GetYearFrac( nNullDate, nLastCoup, nMat, nBase ) * fFreq;\n"
1637 " double fDSCi= GetYearFrac( nNullDate, nSettle, nMat, nBase ) * fFreq;\n"
1638 " double fAi= GetYearFrac( nNullDate, nLastCoup, nSettle, nBase )*fFreq;\n"
1639 " double y = fRedemp + fDCi * 100.0 * fRate / fFreq;\n"
1640 " y /= fPrice + fAi * 100.0 * fRate / fFreq;\n"
1641 " y -= 1.0;\n"
1642 " y *= fFreq / fDSCi;\n"
1643 " return y;\n"
1644 "}\n";
1646 std::string GetYearFrac_newDecl=
1647 "double GetYearFrac_new( int nNullDate, int nStartDate, int nEndDate,"
1648 "int nMode );\n";
1650 std::string GetYearFrac_new=
1651 "double GetYearFrac_new( int nNullDate, int nStartDate, int nEndDate,"
1652 "int nMode ) \n"
1653 "{\n"
1654 " if( nStartDate == nEndDate )\n"
1655 " return 0.0; \n"
1656 " if( nStartDate > nEndDate )\n"
1657 " {\n"
1658 " int n = nEndDate;\n"
1659 " nEndDate = nStartDate;\n"
1660 " nStartDate = n;\n"
1661 " }\n"
1662 " int nDate1 = nStartDate + nNullDate;\n"
1663 " int nDate2 = nEndDate + nNullDate;\n"
1664 " int nDay1, nDay2;\n"
1665 " int nMonth1, nMonth2;\n"
1666 " int nYear1, nYear2;\n"
1667 " DaysToDate_new( nDate1, &nDay1, &nMonth1, &nYear1 );\n"
1668 " DaysToDate_new( nDate2, &nDay2, &nMonth2, &nYear2 );\n"
1669 " int nDayDiff;\n"
1670 " switch( nMode )\n"
1671 " {\n"
1672 " case 0: \n"
1673 " if ( nDay1 == 31 )\n"
1674 " {\n"
1675 " nDay1--;\n"
1676 " }\n"
1677 " if ( nDay1 == 30 && nDay2 == 31 )\n"
1678 " {\n"
1679 " nDay2--;\n"
1680 " }\n"
1681 " else\n"
1682 " {\n"
1683 " if ( nMonth1 == 2 && nDay1 == "
1684 "( IsLeapYear( nYear1 ) ? 29 : 28 ) )\n"
1685 " {\n"
1686 " nDay1 = 30;\n"
1687 " if ( nMonth2 == 2 && nDay2 == "
1688 "( IsLeapYear( nYear2 ) ? 29 : 28 ) )\n"
1689 " {\n"
1690 " nDay2 = 30;\n"
1691 " }\n"
1692 " }\n"
1693 " }\n"
1694 " nDayDiff = ( nYear2 - nYear1 ) * 360 + "
1695 "( nMonth2 - nMonth1 ) * 30 + ( nDay2 - nDay1 );\n"
1696 " break;\n"
1697 " case 1: \n"
1698 " case 2: \n"
1699 " case 3: \n"
1700 " nDayDiff = nDate2 - nDate1;\n"
1701 " break;\n"
1702 " case 4: \n"
1703 " if ( nDay1 == 31 )\n"
1704 " {\n"
1705 " nDay1--;\n"
1706 " }\n"
1707 " if ( nDay2 == 31 )\n"
1708 " {\n"
1709 " nDay2--;\n"
1710 " }\n"
1711 " nDayDiff = ( nYear2 - nYear1 ) * 360 + "
1712 "( nMonth2 - nMonth1 ) * 30 + ( nDay2 - nDay1 );\n"
1713 " break;\n"
1714 " }\n"
1715 " double nDaysInYear;\n"
1716 " switch( nMode )\n"
1717 " {\n"
1718 " case 0: \n"
1719 " case 2: \n"
1720 " case 4: \n"
1721 " nDaysInYear = 360;\n"
1722 " break;\n"
1723 " case 1: \n"
1724 " {\n"
1725 " bool isYearDifferent = ( nYear1 != nYear2 );\n"
1726 " if ( isYearDifferent &&\n"
1727 " ( ( nYear2 != nYear1 + 1 ) ||\n"
1728 " ( nMonth1 < nMonth2 ) ||\n"
1729 " ( nMonth1 == nMonth2 && nDay1 < nDay2 ) ) )\n"
1730 " {\n"
1731 " int nDayCount = 0;\n"
1732 " for ( int i = nYear1; i <= nYear2; i++ )\n"
1733 " nDayCount += ( IsLeapYear( i ) ? 366 : 365 );\n"
1734 " nDaysInYear = ( double ) nDayCount / "
1735 "( double ) ( nYear2 - nYear1 + 1 );\n"
1736 " }\n"
1737 " else\n"
1738 " {\n"
1739 " if ( isYearDifferent && IsLeapYear( nYear1 ) )\n"
1740 " {\n"
1741 " nDaysInYear = 366;\n"
1742 " }\n"
1743 " else\n"
1744 " {\n"
1745 " if ( ( IsLeapYear( nYear1 ) && nMonth1 <= 2 "
1746 "&& nDay1 <= 29 ) ||\n"
1747 " ( IsLeapYear( nYear2 ) && ( nMonth2 > 3 || "
1748 "( nMonth2 == 2 && nDay1 == 29 ) ) ) )\n"
1749 " {\n"
1750 " nDaysInYear = 366;\n"
1751 " }\n"
1752 " else\n"
1753 " {\n"
1754 " nDaysInYear = 365;\n"
1755 " for ( int i = nYear1; i <= nYear2; i++ )\n"
1756 " {\n"
1757 " if ( IsLeapYear( i ) )\n"
1758 " {\n"
1759 " nDaysInYear = 366;\n"
1760 " break;\n"
1761 " }\n"
1762 " }\n"
1763 " }\n"
1764 " }\n"
1765 " }\n"
1766 " }\n"
1767 " break;\n"
1768 " case 3: \n"
1769 " nDaysInYear = 365;\n"
1770 " break;\n"
1771 " }\n"
1772 " return (double)( nDayDiff ) / (nDaysInYear);\n"
1773 "}\n";
1775 std::string DaysToDate_newDecl =
1776 "void DaysToDate_new( int nDays, int *rDay, int* rMonth, int* rYear );\n";
1778 std::string DaysToDate_new =
1779 "void DaysToDate_new( int nDays, int *rDay, int* rMonth, int* rYear )\n"
1780 "{\n"
1781 " int nTempDays;\n"
1782 " int i = 0;\n"
1783 " bool bCalc;\n"
1784 " do\n"
1785 " {\n"
1786 " nTempDays = nDays;\n"
1787 " *rYear = (int)((nTempDays / 365) - i);\n"
1788 " nTempDays -= ((int) *rYear -1) * 365;\n"
1789 " nTempDays -= ((*rYear -1) / 4) - ((*rYear -1) / 100) + ((*rYear -1)"
1790 " / 400);\n"
1791 " bCalc = false;\n"
1792 " if ( nTempDays < 1 )\n"
1793 " {\n"
1794 " i++;\n"
1795 " bCalc = true;\n"
1796 " }\n"
1797 " else\n"
1798 " {\n"
1799 " if ( nTempDays > 365 )\n"
1800 " {\n"
1801 " if ( (nTempDays != 366) || !IsLeapYear( *rYear ) )\n"
1802 " {\n"
1803 " i--;\n"
1804 " bCalc = true;\n"
1805 " }\n"
1806 " }\n"
1807 " }\n"
1808 " }\n"
1809 " while ( bCalc );\n"
1810 " if(nTempDays != 0){\n"
1811 " for (*rMonth = 1; (int)nTempDays > DaysInMonth( *rMonth, *rYear );"
1812 " *rMonth += 1)\n"
1813 " {\n"
1814 " nTempDays -= DaysInMonth( *rMonth, *rYear ); \n"
1815 " }\n"
1816 " *rDay = (int)nTempDays;\n"
1817 " }\n"
1818 "}\n";
1820 std::string DaysToDate_LocalBarrierDecl =
1821 "void DaysToDate( int nDays, int *rDay, int* rMonth, int* rYear );\n";
1823 std::string DaysToDate_LocalBarrier =
1824 "void DaysToDate( int nDays, int *rDay, int* rMonth, int* rYear )\n"
1825 "{\n"
1826 " int nTempDays;\n"
1827 " int i = 0;\n"
1828 " bool bCalc;\n"
1829 " do\n"
1830 " {\n"
1831 " nTempDays = nDays;\n"
1832 " *rYear = (int)((nTempDays / 365) - i);\n"
1833 " nTempDays -= ((int) *rYear -1) * 365;\n"
1834 " nTempDays -= ((*rYear -1) / 4) - ((*rYear -1) / 100) + ((*rYear -1)"
1835 " / 400);\n"
1836 " bCalc = false;\n"
1837 " if ( nTempDays < 1 )\n"
1838 " {\n"
1839 " i++;\n"
1840 " bCalc = true;\n"
1841 " }\n"
1842 " else\n"
1843 " {\n"
1844 " if ( nTempDays > 365 )\n"
1845 " {\n"
1846 " if ( (nTempDays != 366) || !IsLeapYear( *rYear ) )\n"
1847 " {\n"
1848 " i--;\n"
1849 " bCalc = true;\n"
1850 " }\n"
1851 " }\n"
1852 " }\n"
1853 " }\n"
1854 " while ( bCalc );\n"
1855 " barrier(CLK_LOCAL_MEM_FENCE);\n"
1856 " if(nTempDays != 0){\n"
1857 " for (*rMonth = 1; (int)nTempDays > DaysInMonth( *rMonth, *rYear );"
1858 " *rMonth += 1)\n"
1859 " {\n"
1860 " nTempDays -= DaysInMonth( *rMonth, *rYear ); \n"
1861 " }\n"
1862 " *rDay = (int)nTempDays;\n"
1863 " }\n"
1864 "}\n";
1866 std::string GetYearDiff_newDecl=
1867 "double GetYearDiff_new( int nNullDate, int nStartDate, int nEndDate,"
1868 "int nMode);\n";
1870 std::string GetYearDiff_new=
1871 "double GetYearDiff_new( int nNullDate, int nStartDate, int nEndDate,"
1872 "int nMode )\n"
1873 "{\n"
1874 " int nDays1stYear;\n"
1875 " int nTotalDays = GetDiffDate_new( nNullDate, nStartDate, nEndDate,"
1876 "nMode, &"
1877 "nDays1stYear );\n"
1878 " return (double)(nTotalDays)* pow((double)nDays1stYear,-1);\n"
1879 "}\n";
1881 std::string GetDiffDate_newDecl=
1882 "int GetDiffDate_new( int nNullDate, int nStartDate, int nEndDate, int nMode,"
1883 " int* pOptDaysIn1stYear );\n";
1885 std::string GetDiffDate_new=
1886 "int GetDiffDate_new( int nNullDate, int nStartDate, int nEndDate, int nMode,"
1887 " int* pOptDaysIn1stYear )\n"
1888 "{\n"
1889 " bool bNeg = nStartDate > nEndDate;\n"
1890 " if( bNeg )\n"
1891 " {\n"
1892 " int n = nEndDate;\n"
1893 " nEndDate = nStartDate;\n"
1894 " nStartDate = n;\n"
1895 " }\n"
1896 " int nRet;\n"
1897 " switch( nMode )\n"
1898 " {\n"
1899 " case 0: \n"
1900 " case 4: \n"
1901 " {\n"
1902 " int nD1, nM1, nY1, nD2, nM2, nY2;\n"
1903 " nStartDate += nNullDate;\n"
1904 " nEndDate += nNullDate;\n"
1905 " DaysToDate_new( nStartDate, &nD1, &nM1, &nY1 );\n"
1906 " DaysToDate_new( nEndDate, &nD2, &nM2, &nY2 );\n"
1907 " bool bLeap = IsLeapYear( nY1 );\n"
1908 " int nDays, nMonths;\n"
1909 " nMonths = nM2 - nM1;\n"
1910 " nDays = nD2 - nD1;\n"
1911 " nMonths += ( nY2 - nY1 ) * 12;\n"
1912 " nRet = nMonths * 30 + nDays;\n"
1913 " if( nMode == 0 && nM1 == 2 && nM2 != 2 && nY1 == nY2 )\n"
1914 " nRet -= bLeap? 1 : 2;\n"
1915 " if( pOptDaysIn1stYear )\n"
1916 " *pOptDaysIn1stYear = 360;\n"
1917 " }\n"
1918 " break;\n"
1919 " case 1: \n"
1920 " if( pOptDaysIn1stYear )\n"
1921 " {\n"
1922 " int nD, nM, nY;\n"
1923 " DaysToDate_new( nStartDate + nNullDate, &nD, &nM, &nY );\n"
1924 " *pOptDaysIn1stYear = IsLeapYear( nY )? 366 : 365;\n"
1925 " }\n"
1926 " nRet = nEndDate - nStartDate;\n"
1927 " break;\n"
1928 " case 2: \n"
1929 " nRet = nEndDate - nStartDate;\n"
1930 " if( pOptDaysIn1stYear )\n"
1931 " *pOptDaysIn1stYear = 360;\n"
1932 " break;\n"
1933 " case 3: \n"
1934 " nRet = nEndDate - nStartDate;\n"
1935 " if( pOptDaysIn1stYear )\n"
1936 " *pOptDaysIn1stYear = 365;\n"
1937 " break;\n"
1938 " }\n"
1939 " return bNeg? -nRet : nRet;\n"
1940 "}\n";
1942 #endif
1944 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */