LibreOffice Module sc (master)  1
opinlinefun_finacial.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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  */
9 
10 #ifndef SC_OPENCL_OPINLINFUN_finacial
11 #define SC_OPENCL_OPINLINFUN_finacial
12 
13 std::string nCorrValDecl ="double constant nCorrVal[]"
14 "= {0, 9e-1, 9e-2, 9e-3, 9e-4, 9e-5, 9e-6, 9e-7, "
15 "9e-8,9e-9, 9e-10, 9e-11, 9e-12, 9e-13, 9e-14, 9e-15};\n";
16 
17 std::string SCdEpsilonDecl =
18 "constant double SCdEpsilon = 1.0E-7;\n";
19 
20 std::string RoundDecl = "double Round(double fValue);\n";
21 
22 std::string Round =
23 "double Round(double fValue)\n"
24 "{\n"
25 " if ( fValue == 0.0 )\n"
26 " return fValue;\n"
27 "\n"
28 " double fFac = 0;\n"
29 " int nExp;\n"
30 " if ( fValue > 0.0 )\n"
31 " nExp = ( floor( log10( fValue ) ) );\n"
32 " else\n"
33 " nExp = 0;\n"
34 " int nIndex = 15 - nExp;\n"
35 " if ( nIndex > 15 )\n"
36 " nIndex = 15;\n"
37 " else if ( nIndex <= 1 )\n"
38 " nIndex = 0;\n"
39 " fValue = floor( fValue + 0.5 + nCorrVal[nIndex] );\n"
40 " return fValue;\n"
41 "}\n";
42 
43 std::string GetPMT_newDecl =
44 "double GetPMT_new( double fRate, double fNper, double fPv, double fFv,"
45 "int nPayType );\n";
46 std::string GetPMT_new=
47 "double GetPMT_new( double fRate, double fNper, double fPv, double fFv,"
48 "int nPayType)\n"
49 "{\n"
50 " double fPmt;\n"
51 " double fTerm = pow( 1.0 + fRate, fNper );\n"
52 " if( nPayType > 0 )\n"
53 " fPmt = ( fFv * fRate *pow ( fTerm - 1.0,-1 ) + fPv * fRate *pow( "
54 "( 1.0 - pow( fTerm,-1) ),-1) )* pow ( 1.0 + fRate,-1 );\n"
55 " else\n"
56 " fPmt = fFv * fRate *pow ( fTerm - 1.0 ,-1) + fPv * fRate *pow( "
57 "1.0 - pow( fTerm,-1),-1 );\n"
58 " return -fPmt;\n"
59 "}\n";
60 std::string GetFVDecl =
61 "double GetFV( double fRate, double fNper, double fPmt,"
62 "double fPv, int nPayType );\n";
63 
64 std::string GetFV =
65 "double GetFV( double fRate, double fNper, double fPmt,"
66 "double fPv, int nPayType )\n"
67 "{\n"
68 " double fFv;\n"
69 " if( fRate == 0.0 )\n"
70 " fFv = fPv + fPmt * fNper;\n"
71 " else\n"
72 " {\n"
73 " double fTerm = pow( 1.0 + fRate, fNper );\n"
74 " if( nPayType > 0 )\n"
75 " fFv = fPv * fTerm + fPmt * ( 1.0 + fRate ) *( fTerm - 1.0 ) "
76 "/ fRate;\n"
77 " else\n"
78 " fFv = fPv * fTerm + fPmt * ( fTerm - 1.0 ) / fRate;\n"
79 " }\n"
80 " return -fFv;\n"
81 "}\n";
82 
83 std::string GetFV_newDecl =
84 "double GetFV_new( double fRate, double fNper, double fPmt,"
85 "double fPv, int nPayType );\n";
86 
87 std::string GetFV_new =
88 "double GetFV_new( double fRate, double fNper, double fPmt,"
89 "double fPv, int nPayType )\n"
90 "{\n"
91 " double fFv;\n"
92 " double fTerm = pow( 1.0 + fRate, fNper );\n"
93 " if( nPayType > 0 )\n"
94 " fFv = fPv * fTerm + fPmt * ( 1.0 + fRate ) *( fTerm - 1.0 ) "
95 "*pow( fRate,-1);\n"
96 " else\n"
97 " fFv = fPv * fTerm + fPmt * ( fTerm - 1.0 ) *pow( fRate,-1);\n"
98 " return -fFv;\n"
99 "}\n";
100 
101 std::string IsLeapYearDecl =
102 "bool IsLeapYear( int n );\n";
103 
104 std::string IsLeapYear =
105 "bool IsLeapYear( int n )\n"
106 "{\n"
107 " return ( (( ( n % 4 ) == 0 ) && ( ( n % 100 ) != 0)) || ( ( n % 400 ) == "
108 "0 ) );\n"
109 "}\n";
110 
111 std::string DaysInMonthDecl=
112 "int DaysInMonth( int nMonth, int nYear );\n";
113 
114 std::string DaysInMonth =
115 "int DaysInMonth( int nMonth, int nYear )\n"
116 "{\n"
117 " int aDaysInMonth[12] = { 31, 28, 31, 30, 31, 30,\n"
118 " 31, 31, 30, 31, 30, 31 };\n"
119 "\n"
120 " if ( nMonth != 2 )\n"
121 " return aDaysInMonth[nMonth-1];\n"
122 " else\n"
123 " {\n"
124 " if ( IsLeapYear(nYear) )\n"
125 " return aDaysInMonth[nMonth-1] + 1;\n"
126 " else\n"
127 " return aDaysInMonth[nMonth-1];\n"
128 " }\n"
129 "}\n";
131 "int DaysInMonth( int nMonth, int nYear );\n";
132 
133 std::string DaysInMonth_new =
134 "int DaysInMonth( int nMonth, int nYear )\n"
135 "{\n"
136 " int tmp = 0;\n"
137 " switch(nMonth)\n"
138 " {\n"
139 " case 1:\n"
140 " case 3:\n"
141 " case 5:\n"
142 " case 7:\n"
143 " case 8:\n"
144 " case 10:\n"
145 " case 12:\n"
146 " tmp = 31;\n"
147 " break;\n"
148 " case 4:\n"
149 " case 6:\n"
150 " case 9:\n"
151 " case 11:\n"
152 " tmp =30;\n"
153 " break;\n"
154 " case 2:\n"
155 " if ( IsLeapYear(nYear)==1)\n"
156 " tmp = 29;\n"
157 " else\n"
158 " tmp = 28;\n"
159 " break;\n"
160 " }\n"
161 " return tmp;\n"
162 "}\n";
163 
164 std::string DaysToDateDecl =
165 "void DaysToDate( int nDays, int *rDay, int* rMonth, int* rYear );\n";
166 
167 std::string DaysToDate =
168 "void DaysToDate( int nDays, int *rDay, int* rMonth, int* rYear )\n"
169 "{\n"
170 "\n"
171 " int nTempDays;\n"
172 " int i = 0;\n"
173 " bool bCalc;\n"
174 
175 " do\n"
176 " {\n"
177 " nTempDays = nDays;\n"
178 " *rYear = (int)((nTempDays / 365) - i);\n"
179 " nTempDays -= ((int) *rYear -1) * 365;\n"
180 " nTempDays -= (( *rYear -1) / 4) - (( *rYear -1) / 100) +"
181 "((*rYear -1) / 400);\n"
182 " bCalc = false;\n"
183 " if ( nTempDays < 1 )\n"
184 " {\n"
185 " i++;\n"
186 " bCalc = true;\n"
187 " }\n"
188 " else\n"
189 " {\n"
190 " if ( nTempDays > 365 )\n"
191 " {\n"
192 " if ( (nTempDays != 366) || !IsLeapYear( *rYear ) )\n"
193 " {\n"
194 " i--;\n"
195 " bCalc = true;\n"
196 " }\n"
197 " }\n"
198 " }\n"
199 " }\n"
200 " while ( bCalc );\n"
201 " if(nTempDays!=0){\n"
202 " for (*rMonth = 1; (int)nTempDays > DaysInMonth( *rMonth, *rYear );"
203 "*rMonth+=1)\n"
204 " {\n"
205 " nTempDays -= DaysInMonth( *rMonth, *rYear );\n"
206 " }\n"
207 " *rDay = (int)nTempDays;\n"
208 " }\n"
209 "}\n";
210 
211 std::string DateToDaysDecl=
212 "int DateToDays( int nDay, int nMonth, int nYear );\n";
213 
214 std::string DateToDays=
215 "int DateToDays( int nDay, int nMonth, int nYear )\n"
216 "{\n"
217 " int nDays = ((int)nYear-1) * 365;\n"
218 " nDays += ((nYear-1) / 4) - ((nYear-1) / 100) + ((nYear-1) / 400);\n"
219 " for( int i = 1; i < nMonth; i++ )\n"
220 " nDays += DaysInMonth(i,nYear);\n"
221 " nDays += nDay;\n"
222 "\n"
223 " return nDays;\n"
224 "}\n";
225 
226 std::string DateToDays_newDecl=
227 "int DateToDays_new( int nDay, int nMonth, int nYear );\n";
228 
229 std::string DateToDays_new=
230 "int DateToDays_new( int nDay, int nMonth, int nYear )\n"
231 "{\n"
232 " int nDays = (nYear-1) * 365;\n"
233 " nDays += (int)((nYear-1) *pow(4.0,-1.0)- (nYear-1) *pow( 100.0,-1.0)"
234 "+ (nYear-1) *pow(400.0,-1.0));\n"
235 " for( int i = 1; i < nMonth; i++ )\n"
236 " nDays += DaysInMonth(i,nYear);\n"
237 " nDays += nDay;\n"
238 "\n"
239 " return nDays;\n"
240 "}\n";
241 
242 std::string GetNullDateDecl=
243 "int GetNullDate();\n";
244 
245 std::string GetNullDate=
246 "int GetNullDate()\n"
247 "{\n"
248 " return DateToDays(30,12,1899 );\n"
249 "}\n";
251 "int GetNullDate_new();\n";
252 
253 std::string GetNullDate_new=
254 "int GetNullDate_new()\n"
255 "{\n"
256 " return DateToDays_new(30,12,1899 );\n"
257 "}\n";
258 
259 std::string ScaDateDecl=
260 "void ScaDate( int nNullDate, int nDate, int nBase,int *nOrigDay, "
261 "int *nMonth,int *nYear,int *bLastDayMode,int *bLastDay,"
262 "int *b30Days,int *bUSMode,int *nDay);\n";
263 
264 std::string ScaDate=
265 "void ScaDate( int nNullDate, int nDate, int nBase,int *nOrigDay, "
266 "int *nMonth,int *nYear,int *bLastDayMode,int *bLastDay,"
267 "int *b30Days,int *bUSMode,int *nDay)\n"
268 "{\n"
269 " DaysToDate( nNullDate + nDate, nOrigDay, nMonth, nYear );\n"
270 " *bLastDayMode = (nBase != 5);\n"
271 " *bLastDay = (*nOrigDay >= DaysInMonth( *nMonth, *nYear ));\n"
272 " *b30Days = (nBase == 0) || (nBase == 4);\n"
273 " *bUSMode = (nBase == 0);\n"
274 " if( *b30Days)\n"
275 " {\n"
276 " *nDay = min( *nOrigDay, 30);\n"
277 " if( *bLastDay || (*nDay >=DaysInMonth( *nMonth, *nYear )) )\n"
278 " *nDay = 30;\n"
279 " }\n"
280 " else\n"
281 " {\n"
282 " int nLastDay = DaysInMonth( *nMonth, *nYear );\n"
283 " *nDay = *bLastDay ? nLastDay : min( *nOrigDay, nLastDay );\n"
284 " }\n"
285 "}\n";
286 
287 std::string lcl_GetCouppcdDecl=
288 "int lcl_GetCouppcd(int nNullDate,int nSettle,int nMat,int nFreq,int nBase);\n";
289 
290 std::string lcl_GetCouppcd=
291 "int lcl_GetCouppcd(int nNullDate,int nSettle, int nMat,int nFreq,int nBase)\n"
292 "{\n"
293 " int aDate = nMat;\n"
294 " int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0,"
295 "rbUSMode=0,rnDay=0;\n"
296 " int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0,"
297 "sbUSMode=0,snDay=0;\n"
298 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
299 "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
300 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,"
301 "&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
302 " rYear=sYear;\n"
303 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
304 " if(checklessthan(rYear,sYear,rMonth,sMonth,rnDay,snDay,rbLastDay,"
305 "sbLastDay,rDay,sDay))\n"
306 " {\n"
307 " rYear+=1;\n"
308 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
309 " }\n"
310 " while(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
311 "rbLastDay,sDay,rDay))\n"
312 " {\n"
313 " double d = -1*(12/nFreq);\n"
314 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,d,&rYear);\n"
315 " }\n"
316 " int nLastDay = DaysInMonth( rMonth, rYear );\n"
317 " int nRealDay = (rbLastDayMode && rbLastDay) ? nLastDay :"
318 "min( nLastDay, rDay );\n"
319 " return DateToDays( nRealDay, rMonth, rYear ) - nNullDate;\n"
320 "}\n";
321 
322 std::string lcl_GetCoupncdDecl=
323 "int lcl_GetCoupncd(int nNullDate,int nSettle,int nMat,int nFreq,int nBase);\n";
324 
325 std::string lcl_GetCoupncd=
326 "int lcl_GetCoupncd(int nNullDate,int nSettle, int nMat,int nFreq,int nBase)\n"
327 "{\n"
328 " int aDate = nMat;\n"
329 " int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0,"
330 "rbUSMode=0,rnDay=0;\n"
331 " int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0,"
332 "sbUSMode=0,snDay=0;\n"
333 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
334 "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
335 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,"
336 "&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
337 " rYear=sYear;\n"
338 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
339 " if(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,rbLastDay"
340 ",sDay,rDay))\n"
341 " {\n"
342 " rYear-=1;\n"
343 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
344 " }\n"
345 " while(!checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
346 "rbLastDay,sDay,rDay))\n"
347 " {\n"
348 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,12/nFreq,&rYear);\n"
349 " }\n"
350 " int nLastDay = DaysInMonth( rMonth, rYear );\n"
351 " int nRealDay = (rbLastDayMode && rbLastDay) ? nLastDay :"
352 "min( nLastDay, rDay );\n"
353 " return DateToDays( nRealDay, rMonth, rYear ) - nNullDate;\n"
354 "}\n";
355 
356 std::string addMonthsDecl=
357 "void addMonths(int b30Days,int bLastDay,int *nDay,int nOrigDay,"
358 "int *nMonth,int nMonthCount,int *year);\n";
359 
360 std::string addMonths=
361 "void addMonths(int b30Days,int bLastDay,int *nDay,int nOrigDay,"
362 "int *nMonth,int nMonthCount,int *year)\n"
363 "{\n"
364 " int nNewMonth = nMonthCount + *nMonth;\n"
365 " if( nNewMonth > 12 )\n"
366 " {\n"
367 " --nNewMonth;\n"
368 " *year+=nNewMonth / 12 ;\n"
369 " *nMonth = ( nNewMonth % 12 ) + 1;\n"
370 " }\n"
371 " else if( nNewMonth < 1 )\n"
372 " {\n"
373 " *year+= nNewMonth / 12 - 1 ;\n"
374 " *nMonth = nNewMonth % 12 + 12 ;\n"
375 " }\n"
376 " else\n"
377 " *nMonth = nNewMonth ;\n"
378 " if( b30Days )\n"
379 " {\n"
380 " *nDay = min( nOrigDay, 30);\n"
381 " if( bLastDay || (*nDay >= DaysInMonth( *nMonth, *year )) )\n"
382 " *nDay = 30;\n"
383 " }\n"
384 " else\n"
385 " {\n"
386 " int nLastDay = DaysInMonth( *nMonth, *year );\n"
387 " *nDay = bLastDay ? nLastDay : min( nOrigDay, nLastDay );\n"
388 " }\n"
389 "}\n";
390 
392 "int getDaysInMonthRange( int nFrom, int nTo,int b30Days,int year);\n";
393 
395 "int getDaysInMonthRange( int nFrom, int nTo,int b30Days,int year)\n"
396 "{\n"
397 " if( nFrom > nTo )\n"
398 " return 0;\n"
399 " int nRet = 0;\n"
400 " if( b30Days )\n"
401 " nRet = (nTo - nFrom + 1) * 30;\n"
402 " else\n"
403 " {\n"
404 " for( int nMonthIx = nFrom; nMonthIx <= nTo; ++nMonthIx )\n"
405 " nRet += b30Days ? 30 : DaysInMonth( nMonthIx, year );\n"
406 " }\n"
407 " return nRet;\n"
408 "}\n";
409 
410 std::string GetDaysInYearsDecl=
411 "int GetDaysInYears( int nYear1, int nYear2 );\n";
412 
413 std::string GetDaysInYears=
414 "int GetDaysInYears( int nYear1, int nYear2 )\n"
415 "{\n"
416 " int nLeaps = 0;\n"
417 " for( int n = nYear1 ; n <= nYear2 ; n++ )\n"
418 " {\n"
419 " if( IsLeapYear( n ) )\n"
420 " nLeaps++;\n"
421 " }\n"
422 " int nSum = 1;\n"
423 " nSum += nYear2;\n"
424 " nSum -= nYear1;\n"
425 " nSum *= 365;\n"
426 " nSum += nLeaps;\n"
427 " return nSum;\n"
428 "}\n";
429 
430 std::string GetDaysInYearDecl=
431 "int GetDaysInYear( int nNullDate, int nDate, int nMode );\n";
432 
433 std::string GetDaysInYear=
434 "int GetDaysInYear( int nNullDate, int nDate, int nMode )\n"
435 "{\n"
436 " switch( nMode )\n"
437 " {\n"
438 " case 0:\n"
439 " case 2:\n"
440 " case 4:\n"
441 " return 360;\n"
442 " case 1:\n"
443 " {\n"
444 " int nD=0, nM=0, nY=0;\n"
445 " nDate += nNullDate;\n"
446 " DaysToDate( nDate, &nD, &nM, &nY );\n"
447 " return IsLeapYear( nY )? 366 : 365;\n"
448 " }\n"
449 " case 3:\n"
450 " return 365;\n"
451 " }\n"
452 "}\n";
453 
455 "int getDaysInYearRange( int nFrom, int nTo,int b30Days );\n";
456 
457 std::string getDaysInYearRange=
458 "int getDaysInYearRange( int nFrom, int nTo,int b30Days )\n"
459 "{\n"
460 " if( nFrom > nTo )\n"
461 " return 0;\n"
462 " return b30Days ? ((nTo - nFrom + 1) * 360) : GetDaysInYears( nFrom, nTo)"
463 ";\n"
464 "}\n";
465 
466 std::string getDiffDecl=
467 "int getDiff(int rFrom,int rTo,int fDay,int fMonth,int fYear,int fbLastDayMode,"
468 "int fbLastDay,int fb30Days,int fbUSMode,int fnDay,int tDay,int tMonth,"
469 "int tYear,int tbLastDayMode,int tbLastDay,int tb30Days,"
470 "int tbUSMode,int tnDay);\n";
471 
472 std::string getDiff=
473 "int getDiff(int rFrom,int rTo,int fDay,int fMonth,int fYear,int fbLastDayMode,"
474 "int fbLastDay,int fb30Days,int fbUSMode,int fnDay,int tDay,int tMonth,"
475 "int tYear,int tbLastDayMode,int tbLastDay,int tb30Days,"
476 "int tbUSMode,int tnDay)\n"
477 "{\n"
478 " if(rFrom>rTo)\n"
479 " {\n"
480 " int d=fDay;fDay=tDay;tDay=d;\n"
481 " int m=fMonth;fMonth=tMonth;tMonth=m;\n"
482 " int y=fYear;fYear=tYear;tYear=y;\n"
483 " int a=fbLastDayMode;fbLastDayMode=tbLastDayMode;tbLastDayMode=a;\n"
484 " int b=fbLastDay;fbLastDay=tbLastDay;tbLastDay=b;\n"
485 " int c=fb30Days;fb30Days=tb30Days;tb30Days=c;\n"
486 " int e=fbUSMode;fbUSMode=tbUSMode;tbUSMode=e;\n"
487 " int f=fnDay;fnDay=tnDay;tnDay=f;\n"
488 " }\n"
489 " int nDiff=0;\n"
490 " if( tb30Days )\n"
491 " {\n"
492 " if( tbUSMode )\n"
493 " {\n"
494 " if( ((fMonth == 2) || (fnDay < 30)) && (tDay == 31) )\n"
495 " tnDay = 31;\n"
496 " else if( (tMonth == 2) && tbLastDay )\n"
497 " tnDay = DaysInMonth( 2, tYear );\n"
498 " }\n"
499 " else\n"
500 " {\n"
501 " if( (fMonth == 2) && (fnDay == 30) )\n"
502 " fnDay = DaysInMonth( 2, fYear );\n"
503 " if( (tMonth == 2) && (tnDay == 30) )\n"
504 " tnDay = DaysInMonth( 2, tYear );\n"
505 " }\n"
506 " }\n"
507 " if( (fYear < tYear) || ((fYear == tYear) && (fMonth < tMonth)) )\n"
508 " {\n"
509 " int d = fb30Days ? 30:DaysInMonth(fMonth,fYear);\n"
510 " nDiff = d- fnDay + 1;\n"
511 " fDay = fnDay = 1;\n"
512 " fbLastDay = 0;\n"
513 " addMonths(fb30Days,fbLastDay,&fnDay,fDay,&fMonth,1,&fYear);\n"
514 " if( fYear < tYear )\n"
515 " {\n"
516 " nDiff += getDaysInMonthRange( fMonth, 12,fb30Days,fYear);\n"
517 " addMonths(fb30Days,fbLastDay,&fnDay,fDay,&fMonth,13-fMonth,&fYear"
518 ");\n"
519 " nDiff += getDaysInYearRange( fYear, tYear - 1,fb30Days);\n"
520 " fYear+=tYear - fYear;\n"
521 " }\n"
522 " nDiff += getDaysInMonthRange(fMonth, tMonth - 1,fb30Days ,fYear );\n"
523 " addMonths(fb30Days,fbLastDay,&fnDay,fDay,&fMonth,tMonth-fMonth,&fYear"
524 ");\n"
525 " }\n"
526 " nDiff += tnDay - fnDay;\n"
527 " return nDiff > 0 ? nDiff : 0;\n"
528 "}\n";
529 
531 "int lcl_Getcoupdaybs(int nNullDate,int nSettle, int nMat,int nFreq,int nBase);\n";
532 
533 std::string lcl_Getcoupdaybs=
534 "int lcl_Getcoupdaybs(int nNullDate,int nSettle, int nMat,int nFreq,int nBase)\n"
535 "{\n"
536 " int aDate = nMat;\n"
537 " int rDay=0,rMonth=0, rYear=0;int mDay=0,mMonth=0, mYear=0;int sDay=0,"
538 "sMonth=0, sYear=0;\n"
539 " int rbLastDayMode=0, rbLastDay=0,rb30Days=0,rbUSMode=0,rnDay=0;\n"
540 " int sbLastDayMode=0, sbLastDay=0,sb30Days=0,sbUSMode=0,snDay=0;\n"
541 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,&"
542 "rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
543 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,&"
544 "sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
545 " rYear= sYear;\n"
546 " nSettle=nSettle+nNullDate;\n"
547 " aDate=DateToDays( rDay,rMonth,rYear );\n"
548 " if( aDate < nSettle )\n"
549 " {\n"
550 " rYear+= 1;\n"
551 " aDate=DateToDays( rDay,rMonth,rYear );\n"
552 " }\n"
553 " while(aDate > nSettle )\n"
554 " {\n"
555 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,-1*(12/nFreq),&rYear"
556 ");\n"
557 " aDate=DateToDays( rDay,rMonth,rYear );\n"
558 " }\n"
559 " return getDiff( aDate, nSettle, rDay, rMonth, rYear, rbLastDayMode, "
560 "rbLastDay, rb30Days, rbUSMode, rnDay, sDay, sMonth, sYear, sbLastDayMode,"
561 "sbLastDay, sb30Days, sbUSMode, snDay);\n"
562 "}\n";
563 
565 "int lcl_Getcoupdaybs_new(int nNullDate,int nSettle,int nMat,int nFreq,"
566 "int nBase);\n";
567 
569 "int lcl_Getcoupdaybs_new(int nNullDate,int nSettle,int nMat,int nFreq,"
570 "int nBase)\n"
571 "{\n"
572 " int aDate = nMat;\n"
573 " int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0,"
574 "rbUSMode=0,rnDay=0;\n"
575 " int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0,"
576 "sbUSMode=0,snDay=0;\n"
577 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
578 "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
579 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,"
580 "&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
581 " rYear=sYear;\n"
582 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
583 " aDate=DateToDays_new( rnDay,rMonth,rYear);\n"
584 " if(checklessthan(rYear,sYear,rMonth,sMonth,rnDay,snDay,rbLastDay,"
585 "sbLastDay,rDay,sDay))\n"
586 " {\n"
587 " rYear+=1;\n"
588 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
589 " aDate=DateToDays_new( rnDay,rMonth,rYear );\n"
590 " }\n"
591 " while(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
592 "rbLastDay,sDay,rDay))\n"
593 " {\n"
594 " double d = -1*(12/nFreq);\n"
595 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,d,&rYear);\n"
596 " aDate=DateToDays_new( rnDay,rMonth,rYear );\n"
597 " }\n"
598 " return getDiff( aDate,nSettle+nNullDate,rDay,rMonth,rYear,rbLastDayMode,"
599 "rbLastDay,rb30Days,rbUSMode,rnDay,sDay,sMonth,sYear,sbLastDayMode,sbLastDay,"
600 "sb30Days,sbUSMode, snDay);\n"
601 "}\n";
602 
604 "int lcl_Getcoupdays(int nNullDate,int nSettle, "
605 "int nMat,int nFreq,int nBase);\n";
606 
607 std::string lcl_Getcoupdays=
608 "int lcl_Getcoupdays(int nNullDate,int nSettle, "
609 "int nMat,int nFreq,int nBase)\n"
610 "{\n"
611 " int aDate = nMat;\n"
612 " int rDay=0,rMonth=0, rYear=0;int mDay=0,mMonth=0, mYear=0;int sDay=0,"
613 "sMonth=0, sYear=0;\n"
614 " int rbLastDayMode=0, rbLastDay=0,rb30Days=0,rbUSMode=0,rnDay=0;\n"
615 " int sbLastDayMode=0, sbLastDay=0,sb30Days=0,sbUSMode=0,snDay=0;\n"
616 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,&"
617 "rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
618 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,&"
619 "sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
620 " rYear= sYear;\n"
621 " nSettle=nSettle+nNullDate;\n"
622 " aDate=DateToDays( rDay,rMonth,rYear );\n"
623 " if( aDate < nSettle )\n"
624 " { \n"
625 " rYear+= 1;\n"
626 " aDate=DateToDays( rDay,rMonth,rYear );\n"
627 " }\n"
628 " while(aDate > nSettle )\n"
629 " {\n"
630 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,-1*(12/nFreq),&rYear"
631 ");\n"
632 " aDate=DateToDays( rDay,rMonth,rYear );\n"
633 " }\n"
634 " int aNextDate=aDate;int aDay=rDay,aMonth=rMonth, aYear=rYear;\n"
635 " int abLastDayMode=rbLastDayMode, abLastDay=rbLastDay,ab30Days=rb30Days,"
636 "abUSMode=rbUSMode,anDay=rnDay;\n"
637 " addMonths(ab30Days,abLastDay,&anDay,aDay,&aMonth,12/nFreq,&aYear);\n"
638 " return getDiff( aDate, aNextDate, rDay, rMonth, rYear, rbLastDayMode, "
639 "rbLastDay, rb30Days, rbUSMode, rnDay, aDay, aMonth, aYear, abLastDayMode,"
640 "abLastDay, ab30Days, abUSMode, anDay);\n"
641 "}\n";
642 
644 "int lcl_Getcoupdays_new(int nNullDate,int nSettle, "
645 "int nMat,int nFreq,int nBase);\n";
646 
648 "int lcl_Getcoupdays_new(int nNullDate,int nSettle, "
649 "int nMat,int nFreq,int nBase)\n"
650 "{\n"
651 " int aDate = nMat;\n"
652 " int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0,"
653 "rbUSMode=0,rnDay=0;\n"
654 " int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0,"
655 "sbUSMode=0,snDay=0;\n"
656 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
657 "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
658 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,"
659 "&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
660 " rYear=sYear;\n"
661 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
662 " aDate=DateToDays_new( rnDay,rMonth,rYear);\n"
663 " if(checklessthan(rYear,sYear,rMonth,sMonth,rnDay,snDay,rbLastDay,"
664 "sbLastDay,rDay,sDay))\n"
665 " {\n"
666 " rYear+=1;\n"
667 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
668 " aDate=DateToDays_new( rnDay,rMonth,rYear );\n"
669 " }\n"
670 " while(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
671 "rbLastDay,sDay,rDay))\n"
672 " {\n"
673 " double d = -1*12*pow((double)nFreq,-1.0);\n"
674 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,d,&rYear);\n"
675 " aDate=DateToDays_new( rnDay,rMonth,rYear );\n"
676 " }\n"
677 " int aNextDate=aDate;int aDay=rDay,aMonth=rMonth, aYear=rYear;\n"
678 " int abLastDayMode=rbLastDayMode, abLastDay=rbLastDay,ab30Days=rb30Days,"
679 "abUSMode=rbUSMode,anDay=rnDay;\n"
680 " int tmp = (int)(12*pow((double)nFreq,-1.0));\n"
681 " addMonths(ab30Days,abLastDay,&anDay,aDay,&aMonth,tmp,&aYear);\n"
682 " return getDiff( aDate, aNextDate, rDay, rMonth, rYear, rbLastDayMode, "
683 "rbLastDay, rb30Days, rbUSMode, rnDay, aDay, aMonth, aYear, abLastDayMode,"
684 "abLastDay, ab30Days, abUSMode, anDay);\n"
685 "}\n";
686 
687 std::string lcl_GetcoupnumDecl=
688 "int lcl_Getcoupnum(int nNullDate,int nSettle, int nMat,int nFreq);\n";
689 
690 std::string lcl_Getcoupnum=
691 "int lcl_Getcoupnum(int nNullDate,int nSettle, int nMat,int nFreq)\n"
692 "{\n"
693 " int aDate = nMat;int rDay=0,rMonth=0, rYear=0;int mDay=0,mMonth=0, mYear="
694 "0;\n"
695 " int sDay=0,sMonth=0, sYear=0;\n"
696 " DaysToDate(aDate+nNullDate,&rDay, &rMonth, &rYear );\n"
697 " DaysToDate(nMat+nNullDate,&mDay, &mMonth, &mYear );\n"
698 " DaysToDate(nSettle+nNullDate,&sDay, &sMonth, &sYear );\n"
699 " rYear= sYear;\n"
700 " nSettle=nSettle+nNullDate;\n"
701 " aDate=DateToDays( rDay,rMonth,rYear );\n"
702 " if( aDate < nSettle )\n"
703 " rYear+= 1;\n"
704 " int d=DateToDays( rDay,rMonth,rYear );\n"
705 " int nMonthCount=-1*(12 / nFreq);\n"
706 " while(d > nSettle )\n"
707 " {\n"
708 " int nNewMonth = nMonthCount + rMonth;\n"
709 " if( nNewMonth > 12 )\n"
710 " {\n"
711 " --nNewMonth;\n"
712 " rYear+=nNewMonth / 12;\n"
713 " rMonth = nNewMonth % 12 + 1;\n"
714 " }\n"
715 " else if( nNewMonth < 1 )\n"
716 " {\n"
717 " rYear+= nNewMonth / 12 - 1;\n"
718 " rMonth = nNewMonth % 12 + 12;\n"
719 " }\n"
720 " else\n"
721 " rMonth = nNewMonth;\n"
722 " d=DateToDays( rDay,rMonth,rYear );\n"
723 " }\n"
724 " int n=(mYear-rYear)*12+mMonth-rMonth;\n"
725 " n=n*nFreq/12;\n"
726 " return n;\n"
727 "}\n";
729 "double lcl_Getcoupnum_new(int nNullDate,int nSettle,int nMat,int nFreq,int"
730 " nBase);\n";
731 std::string lcl_Getcoupnum_new=
732 "double lcl_Getcoupnum_new(int nNullDate,int nSettle, int nMat,int nFreq,int"
733 " nBase)\n"
734 "{\n"
735 " int aDate = nMat;\n"
736 " int mDay=0,mMonth=0, mYear=0;\n"
737 " int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0,"
738 "rbUSMode=0,rnDay=0;\n"
739 " int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0,"
740 "sbUSMode=0,snDay=0;\n"
741 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
742 "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
743 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,"
744 "&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
745 " mMonth = rMonth, mYear = rYear;\n"
746 " rYear=sYear;\n"
747 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
748 " if(checklessthan(rYear,sYear,rMonth,sMonth,rnDay,snDay,rbLastDay,"
749 "sbLastDay,rDay,sDay))\n"
750 " {\n"
751 " rYear+=1;\n"
752 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
753 " }\n"
754 " int m= checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
755 "rbLastDay,sDay,rDay);\n"
756 " while(m)\n"
757 " {\n"
758 " double d = -1*(12/nFreq);\n"
759 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,d,&rYear);\n"
760 " m = checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
761 "rbLastDay,sDay,rDay);\n"
762 " }\n"
763 " int n=(mYear-rYear)*12+mMonth-rMonth;\n"
764 " double tmp = (double)(n*nFreq)/12.0;\n"
765 " return tmp;\n"
766 "}\n";
767 
768 std::string setDayDecl=
769 "void setDay(int nOrigDay, int nMonth,int nYear,int bLastDay,int b30Days,"
770 "int *nDay);\n";
771 std::string setDay=
772 "void setDay(int nOrigDay, int nMonth,int nYear,int bLastDay,int b30Days,"
773 "int *nDay)\n"
774 "{\n"
775 " if( b30Days )\n"
776 " {\n"
777 " *nDay = min( nOrigDay, 30);\n"
778 " if( bLastDay || (*nDay >= DaysInMonth( nMonth, nYear )) )\n"
779 " *nDay = 30;\n"
780 " }\n"
781 " else\n"
782 " {\n"
783 " int nLastDay = DaysInMonth( nMonth, nYear );\n"
784 " *nDay = bLastDay ? nLastDay : min( nOrigDay, nLastDay );\n"
785 " }\n"
786 "}\n";
787 
788 std::string coupdaysDecl=
789 "double coupdays(int nSettle,int nMat,int nFreq,int nBase);\n";
790 
791 std::string coupdays=
792 "double coupdays(int nSettle,int nMat,int nFreq,int nBase)\n"
793 "{\n"
794 " int nNullDate=GetNullDate();\n"
795 " if( nBase == 1 )\n"
796 " return lcl_Getcoupdays(nNullDate, nSettle, nMat,nFreq, nBase);\n"
797 " else\n"
798 " return (double)GetDaysInYear(0,0,nBase)/nFreq;\n"
799 "}\n";
800 std::string coupdays_newDecl=
801 "double coupdays_new(int nSettle,int nMat,int nFreq,int nBase);\n";
802 
803 std::string coupdays_new=
804 "double coupdays_new(int nSettle,int nMat,int nFreq,int nBase)\n"
805 "{\n"
806 " int nNullDate=693594;\n"
807 " if( nBase == 1 )\n"
808 " return lcl_Getcoupdays_new(nNullDate, nSettle, nMat,nFreq, nBase);\n"
809 " else\n"
810 " return (double)GetDaysInYear(0,0,nBase)*pow((double)nFreq,-1.0);\n"
811 "}\n";
812 
813 std::string coupdaybsDecl=
814 "double coupdaybs( int nSettle,int nMat,int nFreq,int nBase);\n";
815 
816 std::string coupdaybs=
817 "double coupdaybs( int nSettle,int nMat,int nFreq,int nBase)\n"
818 "{\n"
819 " int nNullDate=GetNullDate();\n"
820 " return lcl_Getcoupdaybs(nNullDate, nSettle, nMat,nFreq, nBase);\n"
821 "}\n";
822 
823 std::string coupdaybs_newDecl=
824 "double coupdaybs_new( int nSettle,int nMat,int nFreq,int nBase);\n";
825 
826 std::string coupdaybs_new=
827 "double coupdaybs_new( int nSettle,int nMat,int nFreq,int nBase)\n"
828 "{\n"
829 " int nNullDate=693594;\n"
830 " return lcl_Getcoupdaybs_new(nNullDate, nSettle, nMat,nFreq, nBase);\n"
831 "}\n";
832 
833 std::string coupdaysncDecl=
834 "double coupdaysnc( int nSettle,int nMat,int nFreq,int nBase);\n";
835 
836 std::string coupdaysnc=
837  "double coupdaysnc( int nSettle,int nMat,int nFreq,int nBase)\n"
838 "{\n"
839 " int nNullDate=GetNullDate();\n"
840 " if((nBase != 0) && (nBase != 4))\n"
841 " {\n"
842 " int aDate = nMat;\n"
843 " int rDay=0,rMonth=0, rYear=0;int mDay=0,mMonth=0, mYear=0;int sDay=0,"
844 "sMonth=0, sYear=0;\n"
845 " int rbLastDayMode=0, rbLastDay=0,rb30Days=0,rbUSMode=0,rnDay=0;\n"
846 " int sbLastDayMode=0, sbLastDay=0,sb30Days=0,sbUSMode=0,snDay=0;\n"
847 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,&"
848 "rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
849 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
850 "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
851 " rYear= sYear;\n"
852 " nSettle=nSettle+nNullDate;\n"
853 " aDate=DateToDays( rDay,rMonth,rYear );\n"
854 " if( aDate > nSettle )\n"
855 " {\n"
856 " rYear-= 1;\n"
857 " aDate=DateToDays( rDay,rMonth,rYear );\n"
858 " }\n"
859 " while(aDate <= nSettle )\n"
860 " {\n"
861 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,12/nFreq,&rYear)"
862 ";\n"
863 " aDate=DateToDays( rDay,rMonth,rYear );\n"
864 " }\n"
865 " return getDiff( nSettle, aDate, sDay, sMonth, sYear, sbLastDayMode, "
866 "sbLastDay, sb30Days, sbUSMode, snDay, rDay, rMonth, rYear, rbLastDayMode, "
867 "rbLastDay, rb30Days, rbUSMode, rnDay);\n"
868 " }\n"
869 " else\n"
870 " return coupdays(nSettle,nMat,nFreq,nBase)- coupdaybs( nSettle,nMat,"
871 "nFreq,nBase);\n"
872 "}\n";
873 std::string coupdaysnc_newDecl=
874 "double coupdaysnc_new( int nSettle,int nMat,int nFreq,int nBase);\n";
875 
876 std::string coupdaysnc_new=
877 "double coupdaysnc_new( int nSettle,int nMat,int nFreq,int nBase)\n"
878 "{\n"
879 " int nNullDate=693594;\n"
880 " if((nBase != 0) && (nBase != 4))\n"
881 " {\n"
882 " int aDate = nMat;\n"
883 " int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0,"
884 "rbUSMode=0,rnDay=0;\n"
885 " int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0,"
886 "sbUSMode=0,snDay=0;\n"
887 " ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,"
888 "&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
889 " ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
890 "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
891 " rYear=sYear;\n"
892 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
893 " aDate=DateToDays( rnDay,rMonth,rYear);\n"
894 " if(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,rbLastDay"
895 ",sDay,rDay))\n"
896 " {\n"
897 " rYear-=1;\n"
898 " setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
899 " aDate=DateToDays( rnDay,rMonth,rYear );\n"
900 " }\n"
901 " while(!checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
902 "rbLastDay,sDay,rDay))\n"
903 " {\n"
904 " addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,12/nFreq,&rYear);\n"
905 " aDate=DateToDays( rnDay,rMonth,rYear );\n"
906 " }\n"
907 " return getDiff( nSettle+nNullDate,aDate,sDay,sMonth,sYear,sbLastDayMode, "
908 "sbLastDay, sb30Days, sbUSMode, snDay, rDay, rMonth, rYear, rbLastDayMode, "
909 "rbLastDay, rb30Days, rbUSMode, rnDay);\n"
910 " }\n"
911 " else\n"
912 " return coupdays_new(nSettle,nMat,nFreq,nBase)- coupdaybs_new( nSettle,"
913 "nMat,nFreq,nBase);\n"
914 "}\n";
915 
916 std::string checklessthanDecl=
917 "int checklessthan(int aYear,int bYear,int aMonth,int bMonth,int anDay,int "
918 "bnDay,int abLastDay,int bbLastDay,int anOrigDay,int bnOrigDay);\n";
919 std::string checklessthan=
920 "int checklessthan(int aYear,int bYear,int aMonth,int bMonth,int anDay,int "
921 "bnDay,int abLastDay,int bbLastDay,int anOrigDay,int bnOrigDay)\n"
922 "{\n"
923 " if( aYear != bYear )\n"
924 " return aYear < bYear;\n"
925 " if( aMonth != bMonth )\n"
926 " return aMonth < bMonth;\n"
927 " if( anDay != bnDay )\n"
928 " return anDay < bnDay;\n"
929 " if( abLastDay || bbLastDay )\n"
930 " return !abLastDay && bbLastDay;\n"
931 " return anOrigDay < bnOrigDay;\n"
932 "}\n";
933 
934 std::string coupnumDecl=
935 "double coupnum( int nSettle,int nMat,int nFreq,int nBase);\n";
936 
937 std::string coupnum=
938 "double coupnum( int nSettle,int nMat,int nFreq,int nBase)\n"
939 "{\n"
940 " int nNullDate=GetNullDate();\n"
941 " return lcl_Getcoupnum(nNullDate,nSettle,nMat,nFreq);\n"
942 "}\n";
943 std::string coupnum_newDecl=
944 "double coupnum_new( int nSettle,int nMat,int nFreq,int nBase);\n";
945 
946 std::string coupnum_new=
947 "double coupnum_new( int nSettle,int nMat,int nFreq,int nBase)\n"
948 "{\n"
949 " int nNullDate=693594;\n"
950 " return lcl_Getcoupnum_new(nNullDate,nSettle,nMat,nFreq,nBase);\n"
951 "}\n";
952 
953 std::string getPrice_Decl=
954 "double getPrice_(int nSettle, int nMat, double fRate, double fYield,\n"
955  "double fRedemp, int nFreq, int nBase );\n";
956 
957 std::string getPrice_=
958 "double getPrice_(int nSettle, int nMat, double fRate, double fYield,\n"
959  "double fRedemp, int nFreq, int nBase )\n"
960 "{\n"
961 " double fFreq = nFreq;\n"
962 " double fE = coupdays( nSettle, nMat, nFreq, nBase );\n"
963 " double fDSC_E = coupdaysnc( nSettle, nMat, nFreq, nBase ) / fE;\n"
964 " double fN = coupnum( nSettle, nMat, nFreq, nBase );\n"
965 " double fA = coupdaybs( nSettle, nMat, nFreq, nBase );\n"
966 " double fRet = fRedemp / ( pow( 1.0 + fYield / fFreq, fN - 1.0 + "
967 "fDSC_E ) );\n"
968 " fRet -= 100.0 * fRate / fFreq * fA / fE;\n"
969 " double fT1 = 100.0 * fRate / fFreq;\n"
970 " double fT2 = 1.0 + fYield / fFreq;\n"
971 " for( double fK = 0.0 ; fK < fN ; fK+=1.0 )\n"
972 " fRet += fT1 / pow( fT2, fK + fDSC_E );\n"
973 " return fRet;\n"
974 "}\n";
975 std::string getPrice_new_Decl=
976 "double getPrice_(int nSettle, int nMat, double fRate, double fYield,\n"
977  "double fRedemp, int nFreq, int nBase );\n";
978 
979 std::string getPrice_new=
980 "double getPrice_(int nSettle, int nMat, double fRate, double fYield,\n"
981  "double fRedemp, int nFreq, int nBase )\n"
982 "{\n"
983 " double fFreq = nFreq;\n"
984 " double fE = coupdays_new( nSettle, nMat, nFreq, nBase );\n"
985 " double fDSC_E = coupdaysnc_new( nSettle, nMat, nFreq, nBase ) / fE;\n"
986 " double fN = coupnum_new( nSettle, nMat, nFreq, nBase );\n"
987 " double fA = coupdaybs_new( nSettle, nMat, nFreq, nBase );\n"
988 " double fRet = fRedemp / ( pow( 1.0 + fYield / fFreq, fN - 1.0 + "
989 "fDSC_E ) );\n"
990 " fRet -= 100.0 * fRate / fFreq * fA / fE;\n"
991 " double fT1 = 100.0 * fRate / fFreq;\n"
992 " double fT2 = 1.0 + fYield / fFreq;\n"
993 " for( double fK = 0.0 ; fK < fN ; fK+=1.0 )\n"
994 " fRet += fT1 / pow( fT2, fK + fDSC_E );\n"
995 " return fRet;\n"
996 "}\n";
997 
998 std::string getYield_Decl=
999 "double getYield_( int nNullDate, int nSettle, int nMat, double fCoup,"
1000 "double fPrice,double fRedemp, int nFreq, int nBase);\n";
1001 
1002 std::string getYield_=
1003 "double getYield_( int nNullDate, int nSettle, int nMat, double fCoup,"
1004 "double fPrice,double fRedemp, int nFreq, int nBase )\n"
1005 "{\n"
1006 " double fRate = fCoup;\n"
1007 " double fPriceN = 0.0;\n"
1008 " double fYield1 = 0.0;\n"
1009 " double fYield2 = 1.0;\n"
1010 " double fPrice1 = getPrice_(nSettle, nMat, fRate, fYield1, fRedemp, "
1011 "nFreq, nBase );\n"
1012 " double fPrice2 = getPrice_(nSettle, nMat, fRate, fYield2, fRedemp, "
1013 "nFreq, nBase );\n"
1014 " double fYieldN = ( fYield2 - fYield1 ) * 0.5;\n"
1015 " for( unsigned int nIter = 0 ; nIter < 100 && fPriceN != fPrice ; nIter++ "
1016 ")\n"
1017 " {\n"
1018 " fPriceN = getPrice_(nSettle, nMat, fRate, fYieldN, fRedemp, nFreq, "
1019 "nBase );\n"
1020 " if( fPrice == fPrice1 )\n"
1021 " return fYield1;\n"
1022 " else if( fPrice == fPrice2 )\n"
1023 " return fYield2;\n"
1024 " else if( fPrice == fPriceN )\n"
1025 " return fYieldN;\n"
1026 " else if( fPrice < fPrice2 )\n"
1027 " {\n"
1028 " fYield2 *= 2.0;\n"
1029 " fPrice2 = getPrice_(nSettle, nMat, fRate, fYield2, fRedemp, nFreq"
1030 ", nBase );\n"
1031 " fYieldN = ( fYield2 - fYield1 ) * 0.5;\n"
1032 " }\n"
1033 " else\n"
1034 " {\n"
1035 " if( fPrice < fPriceN )\n"
1036 " {\n"
1037 " fYield1 = fYieldN;\n"
1038 " fPrice1 = fPriceN;\n"
1039 " }\n"
1040 " else\n"
1041 " {\n"
1042 " fYield2 = fYieldN;\n"
1043 " fPrice2 = fPriceN;\n"
1044 " }\n"
1045 " fYieldN = fYield2 - ( fYield2 - fYield1 ) * ( ( fPrice - fPrice2 "
1046 ") / ( fPrice1 - fPrice2 ) );\n"
1047 " }\n"
1048 " }\n"
1049 " return fYieldN;\n"
1050 "}\n";
1051 
1052 std::string GetYearFracDecl=
1053 "double GetYearFrac( int nNullDate, int nStartDate, int nEndDate,"
1054 "int nMode );\n";
1055 
1056 std::string GetYearFrac=
1057 "double GetYearFrac( int nNullDate, int nStartDate, int nEndDate,"
1058 "int nMode ) \n"
1059 "{\n"
1060 " if( nStartDate == nEndDate )\n"
1061 " return 0.0; \n"
1062 
1063  " if( nStartDate > nEndDate )\n"
1064  " {\n"
1065  " int n = nEndDate;\n"
1066  " nEndDate = nStartDate;\n"
1067  " nStartDate = n;\n"
1068  " }\n"
1069 
1070  " int nDate1 = nStartDate + nNullDate;\n"
1071  " int nDate2 = nEndDate + nNullDate;\n"
1072 
1073  " int nDay1, nDay2;\n"
1074  " int nMonth1, nMonth2;\n"
1075  " int nYear1, nYear2;\n"
1076 
1077  " DaysToDate( nDate1, &nDay1, &nMonth1, &nYear1 );\n"
1078  " DaysToDate( nDate2, &nDay2, &nMonth2, &nYear2 );\n"
1079 
1080  " int nDayDiff;\n"
1081  " switch( nMode )\n"
1082  " {\n"
1083  " case 0: \n"
1084  " if ( nDay1 == 31 )\n"
1085  " {\n"
1086  " nDay1--;\n"
1087  " }\n"
1088  " if ( nDay1 == 30 && nDay2 == 31 )\n"
1089  " {\n"
1090  " nDay2--;\n"
1091  " }\n"
1092  " else\n"
1093  " {\n"
1094  " if ( nMonth1 == 2 && nDay1 == "
1095  "( IsLeapYear( nYear1 ) ? 29 : 28 ) )\n"
1096  " {\n"
1097  " nDay1 = 30;\n"
1098  " if ( nMonth2 == 2 && nDay2 == "
1099  "( IsLeapYear( nYear2 ) ? 29 : 28 ) )\n"
1100  " {\n"
1101  " nDay2 = 30;\n"
1102  " }\n"
1103  " }\n"
1104  " }\n"
1105  " nDayDiff = ( nYear2 - nYear1 ) * 360 + "
1106  "( nMonth2 - nMonth1 ) * 30 + ( nDay2 - nDay1 );\n"
1107  " break;\n"
1108  " case 1: \n"
1109  " case 2: \n"
1110  " case 3: \n"
1111  " nDayDiff = nDate2 - nDate1;\n"
1112  " break;\n"
1113  " case 4: \n"
1114  " if ( nDay1 == 31 )\n"
1115  " {\n"
1116  " nDay1--;\n"
1117  " }\n"
1118  " if ( nDay2 == 31 )\n"
1119  " {\n"
1120  " nDay2--;\n"
1121  " }\n"
1122  " nDayDiff = ( nYear2 - nYear1 ) * 360 + "
1123  "( nMonth2 - nMonth1 ) * 30 + ( nDay2 - nDay1 );\n"
1124  " break;\n"
1125  " }\n"
1126 
1127  " double nDaysInYear;\n"
1128  " switch( nMode )\n"
1129  " {\n"
1130  " case 0: \n"
1131  " case 2: \n"
1132  " case 4: \n"
1133  " nDaysInYear = 360;\n"
1134  " break;\n"
1135  " case 1: \n"
1136  " {\n"
1137  " bool isYearDifferent = ( nYear1 != nYear2 );\n"
1138  " if ( isYearDifferent &&\n"
1139  " ( ( nYear2 != nYear1 + 1 ) ||\n"
1140  " ( nMonth1 < nMonth2 ) ||\n"
1141  " ( nMonth1 == nMonth2 && nDay1 < nDay2 ) ) )\n"
1142  " {\n"
1143 
1144  " int nDayCount = 0;\n"
1145  " for ( int i = nYear1; i <= nYear2; i++ )\n"
1146  " nDayCount += ( IsLeapYear( i ) ? 366 : 365 );\n"
1147 
1148  " nDaysInYear = ( double ) nDayCount / "
1149  "( double ) ( nYear2 - nYear1 + 1 );\n"
1150  " }\n"
1151  " else\n"
1152  " {\n"
1153  " if ( isYearDifferent && IsLeapYear( nYear1 ) )\n"
1154  " {\n"
1155  " nDaysInYear = 366;\n"
1156  " }\n"
1157  " else\n"
1158  " {\n"
1159 
1160  " if ( ( IsLeapYear( nYear1 ) && nMonth1 <= 2 "
1161  "&& nDay1 <= 29 ) ||\n"
1162  " ( IsLeapYear( nYear2 ) && ( nMonth2 > 3 || "
1163  "( nMonth2 == 2 && nDay1 == 29 ) ) ) )\n"
1164  " {\n"
1165  " nDaysInYear = 366;\n"
1166  " }\n"
1167  " else\n"
1168  " {\n"
1169  " nDaysInYear = 365;\n"
1170  " for ( int i = nYear1; i <= nYear2; i++ )\n"
1171  " {\n"
1172  " if ( IsLeapYear( i ) )\n"
1173  " {\n"
1174  " nDaysInYear = 366;\n"
1175  " break;\n"
1176  " }\n"
1177  " }\n"
1178  " }\n"
1179  " }\n"
1180  " }\n"
1181  " }\n"
1182  " break;\n"
1183  " case 3: \n"
1184  " nDaysInYear = 365;\n"
1185  " break;\n"
1186  " }\n"
1187  " return (double)( nDayDiff ) / (nDaysInYear);\n"
1188 "}\n";
1189 
1190 std::string GetYieldmatDecl=
1191  "double GetYieldmat( int nNullDate, int nSettle, int nMat, int nIssue,\n"
1192  "double fRate, double fPrice, int nBase );\n";
1193 
1194 std::string GetYieldmat=
1195  "double GetYieldmat( int nNullDate, int nSettle, int nMat, int nIssue,\n"
1196  "double fRate, double fPrice, int nBase )\n"
1197 "{\n"
1198 " double fIssMat = GetYearFrac_new( nNullDate, nIssue, nMat, nBase );\n"
1199 " double fIssSet = GetYearFrac_new( nNullDate, nIssue, nSettle, nBase );\n"
1200 " double fSetMat = GetYearFrac_new( nNullDate, nSettle, nMat, nBase );\n"
1201 " double y = 1.0 + fIssMat * fRate;\n"
1202 " y =y * pow( (fPrice / 100.0 + fIssSet * fRate),-1);\n"
1203 " y-=1.0;\n"
1204 " y = y * pow(fSetMat,-1);\n"
1205 " return y;\n"
1206 "}\n";
1207 
1208 std::string GetDiffDateDecl=
1209 "int GetDiffDate( int nNullDate, int nStartDate, int nEndDate, int nMode,"
1210 " int* pOptDaysIn1stYear );\n";
1211 
1212 std::string GetDiffDate=
1213 "int GetDiffDate( int nNullDate, int nStartDate, int nEndDate, int nMode,"
1214 " int* pOptDaysIn1stYear )\n"
1215 "{\n"
1216 " bool bNeg = nStartDate > nEndDate;\n"
1217 " if( bNeg )\n"
1218 " {\n"
1219 " int n = nEndDate;\n"
1220 " nEndDate = nStartDate;\n"
1221 " nStartDate = n;\n"
1222 " }\n"
1223 " int nRet;\n"
1224 " switch( nMode )\n"
1225 " {\n"
1226 " case 0: \n"
1227 " case 4: \n"
1228 " {\n"
1229 " int nD1, nM1, nY1, nD2, nM2, nY2;\n"
1230 " nStartDate += nNullDate;\n"
1231 " nEndDate += nNullDate;\n"
1232 " DaysToDate( nStartDate, &nD1, &nM1, &nY1 );\n"
1233 " DaysToDate( nEndDate, &nD2, &nM2, &nY2 );\n"
1234 " bool bLeap = IsLeapYear( nY1 );\n"
1235 " int nDays, nMonths;\n"
1236 " nMonths = nM2 - nM1;\n"
1237 " nDays = nD2 - nD1;\n"
1238 " nMonths += ( nY2 - nY1 ) * 12;\n"
1239 " nRet = nMonths * 30 + nDays;\n"
1240 " if( nMode == 0 && nM1 == 2 && nM2 != 2 && nY1 == nY2 )\n"
1241 " nRet -= bLeap? 1 : 2;\n"
1242 " if( pOptDaysIn1stYear )\n"
1243 " *pOptDaysIn1stYear = 360;\n"
1244 " }\n"
1245 " break;\n"
1246 " case 1: \n"
1247 " if( pOptDaysIn1stYear )\n"
1248 " {\n"
1249 " int nD, nM, nY;\n"
1250 " DaysToDate( nStartDate + nNullDate, &nD, &nM, &nY );\n"
1251 " *pOptDaysIn1stYear = IsLeapYear( nY )? 366 : 365;\n"
1252 " }\n"
1253 " nRet = nEndDate - nStartDate;\n"
1254 " break;\n"
1255 " case 2: \n"
1256 " nRet = nEndDate - nStartDate;\n"
1257 " if( pOptDaysIn1stYear )\n"
1258 " *pOptDaysIn1stYear = 360;\n"
1259 " break;\n"
1260 " case 3: \n"
1261 " nRet = nEndDate - nStartDate;\n"
1262 " if( pOptDaysIn1stYear )\n"
1263 " *pOptDaysIn1stYear = 365;\n"
1264 " break;\n"
1265 " }\n"
1266 " return bNeg? -nRet : nRet;\n"
1267 "}\n";
1268 
1269 std::string GetYearDiffDecl=
1270 "double GetYearDiff( int nNullDate, int nStartDate, int nEndDate,"
1271 "int nMode);\n";
1272 
1273 std::string GetYearDiff=
1274 "double GetYearDiff( int nNullDate, int nStartDate, int nEndDate,"
1275 "int nMode )\n"
1276 "{\n"
1277 " int nDays1stYear;\n"
1278 " int nTotalDays = GetDiffDate( nNullDate, nStartDate, nEndDate,"
1279 "nMode, &"
1280 "nDays1stYear );\n"
1281 " return (double)(nTotalDays)*pow((double)nDays1stYear,-1);\n"
1282 "}\n";
1283 
1285 "int GetDiffDate360_(\n"
1286 " int nDay1, int nMonth1, int nYear1, bool bLeapYear1,\n"
1287 " int nDay2, int nMonth2, int nYear2,\n"
1288 " bool bUSAMethod );\n";
1289 
1290 std::string GetDiffDate360_=
1291 "int GetDiffDate360_(\n"
1292 " int nDay1, int nMonth1, int nYear1, bool bLeapYear1,\n"
1293 " int nDay2, int nMonth2, int nYear2,\n"
1294 " bool bUSAMethod )\n"
1295 "{\n"
1296 " if( nDay1 == 31 )\n"
1297 " nDay1--;\n"
1298 " else if( bUSAMethod && ( nMonth1 == 2 && ( nDay1 == 29 || ( nDay1 == 28 "
1299 "&& !bLeapYear1 ) ) ) )\n"
1300 " nDay1 = 30;\n"
1301 " if( nDay2 == 31 )\n"
1302 " {\n"
1303 " if( bUSAMethod && nDay1 != 30 )\n"
1304 " {\n"
1305 " nDay2 = 1;\n"
1306 " if( nMonth2 == 12 )\n"
1307 " {\n"
1308 " nYear2++;\n"
1309 " nMonth2 = 1;\n"
1310 " }\n"
1311 " else\n"
1312 " nMonth2++;\n"
1313 " }\n"
1314 " else\n"
1315 " nDay2 = 30;\n"
1316 " }\n"
1317 " return nDay2 + nMonth2 * 30 + nYear2 * 360 - nDay1 - nMonth1 * 30 - "
1318 "nYear1 * 360;\n"
1319 "}\n";
1320 
1322 "int GetDiffDate360( int nNullDate, int nDate1, int nDate2,"
1323 "bool bUSAMethod);\n";
1324 
1325 std::string GetDiffDate360=
1326 "int GetDiffDate360( int nNullDate, int nDate1, int nDate2,"
1327 "bool bUSAMethod )\n"
1328 "{\n"
1329 " nDate1 += nNullDate;\n"
1330 " nDate2 += nNullDate;\n"
1331 " int nDay1, nMonth1, nYear1, nDay2, nMonth2, nYear2;\n"
1332 " DaysToDate( nDate1, &nDay1, &nMonth1, &nYear1 );\n"
1333 " DaysToDate( nDate2, &nDay2, &nMonth2, &nYear2 );\n"
1334 " return GetDiffDate360_( nDay1, nMonth1, nYear1, IsLeapYear( nYear1 ), "
1335 "nDay2, nMonth2, nYear2, bUSAMethod );\n"
1336 "}\n";
1337 
1338 std::string GetDurationDecl=
1339 "double GetDuration( \n"
1340 " int nNullDate, int nSettle, int nMat, double fCoup,\n"
1341 " double fYield, int nFreq, int nBase );\n";
1342 
1343 std::string GetDuration=
1344 "double GetDuration( \n"
1345 " int nNullDate, int nSettle, int nMat, double fCoup,\n"
1346 " double fYield, int nFreq, int nBase )\n"
1347 "{\n"
1348 " double fYearfrac = GetYearFrac( nNullDate, nSettle, nMat, nBase );\n"
1349 " double fNumOfCoups = lcl_Getcoupnum(nNullDate,nSettle,nMat,nFreq);\n"
1350 " double fDur = 0.0;\n"
1351 " double f100 = 100.0;\n"
1352 " fCoup *= f100 / nFreq;\n"
1353 " fYield /= nFreq;\n"
1354 " fYield += 1.0;\n"
1355 " double nDiff = fYearfrac * nFreq - fNumOfCoups;\n"
1356 " int t;\n"
1357 " for( t = 1 ; t < fNumOfCoups ; t++ )\n"
1358 " fDur += ( t + nDiff ) * ( fCoup ) / pow( fYield, t + nDiff );\n"
1359 " fDur += ( fNumOfCoups + nDiff ) * ( fCoup + f100 ) /"
1360 " pow( fYield, fNumOfCoups + nDiff );\n"
1361 " double p = 0.0;\n"
1362 " for( t = 1 ; t < fNumOfCoups ; t++ )\n"
1363 " p += fCoup / pow( fYield, t + nDiff );\n"
1364 " p += ( fCoup + f100 ) / pow( fYield, fNumOfCoups + nDiff );\n"
1365 " fDur /= p;\n"
1366 " fDur /= nFreq;\n"
1367 " return fDur;\n""}\n";
1368 
1370 "double GetDuration_new( \n"
1371 " int nNullDate, int nSettle, int nMat, double fCoup,\n"
1372 " double fYield, int nFreq, int nBase );\n";
1373 
1374 std::string GetDuration_new=
1375 "double GetDuration_new( \n"
1376 " int nNullDate, int nSettle, int nMat, double fCoup,\n"
1377 " double fYield, int nFreq, int nBase )\n"
1378 " {\n"
1379 " double fYearfrac = GetYearFrac(nNullDate,nSettle,nMat,nBase);\n"
1380 " double fNumOfCoups = lcl_Getcoupnum_new(nNullDate,nSettle,nMat,"
1381 "nFreq,nBase);\n"
1382 " double fDur = 0.0;\n"
1383 " fCoup = fCoup * 100.0 * pow(nFreq, -1.0);\n"
1384 " fYield = fYield * pow(nFreq, -1.0);\n"
1385 " fYield += 1.0;\n"
1386 " double nDiff = fYearfrac * nFreq - fNumOfCoups;\n"
1387 " int t;\n"
1388 " double tmp0 = 0, tmp1 = 0, tmp2 = 0;\n"
1389 " for( t = 1 ; t < fNumOfCoups ; t++ ){\n"
1390 " tmp0 = (t + nDiff) * ( fCoup ) ;\n"
1391 " tmp1 = pow( fYield, t + nDiff ) ;\n"
1392 " tmp2 = tmp0 * pow(tmp1, -1);\n"
1393 " fDur += tmp2;\n"
1394 " }\n"
1395 " fDur += (fNumOfCoups + nDiff) * (fCoup + 100.0) * pow(pow(fYield,"
1396 " fNumOfCoups + nDiff ),-1);\n"
1397 " double p = 0.0;\n"
1398 " for( t = 1 ; t < fNumOfCoups ; t++ ){\n"
1399 " tmp0 = pow( fYield, t + nDiff );\n"
1400 " p += fCoup * pow(tmp0, -1);}\n"
1401 " p += (fCoup + 100.0) * pow(pow(fYield, fNumOfCoups + nDiff), -1);\n"
1402 " fDur = fDur * pow(p, -1.0);\n"
1403 " fDur = fDur * pow(nFreq, -1.0);\n"
1404 " return fDur;\n"
1405 " }\n";
1406 
1407 std::string ScGetDDBDecl=
1408 "double ScGetDDB(double fCost, double fSalvage, double fLife, double fPeriod,"
1409 "double fFactor);\n";
1410 
1411 std::string ScGetDDB=
1412 "double ScGetDDB(double fCost, double fSalvage, double fLife, double fPeriod,"
1413 "double fFactor)\n"
1414 "{\n"
1415 " double fDdb, fRate, fOldValue, fNewValue;\n"
1416 " fRate = fFactor / fLife;\n"
1417 " if (fRate >= 1.0)\n"
1418 " {\n"
1419 " fRate = 1.0;\n"
1420 " if (fPeriod == 1.0)\n"
1421 " fOldValue = fCost;\n"
1422 " else\n"
1423 " fOldValue = 0.0;\n"
1424 " }\n"
1425 " else\n"
1426 " fOldValue = fCost * pow(1.0 - fRate, fPeriod - 1.0);\n"
1427 " fNewValue = fCost * pow(1.0 - fRate, fPeriod);\n"
1428 
1429 " if (fNewValue < fSalvage)\n"
1430 " fDdb = fOldValue - fSalvage;\n"
1431 " else\n"
1432 " fDdb = fOldValue - fNewValue;\n"
1433 " if (fDdb < 0.0)\n"
1434 " fDdb = 0.0;\n"
1435 " return fDdb;\n"
1436 "}\n";
1437 
1438 std::string DblMinDecl=
1439 "inline double DblMin( double a, double b );\n";
1440 
1441 std::string DblMin=
1442 "inline double DblMin( double a, double b )\n"
1443 "{\n"
1444 " return (a < b) ? a : b;\n"
1445 "}\n";
1446 
1447 std::string ScInterVDBDecl=
1448 "double ScInterVDB(double fCost, double fSalvage, double fLife, double fLife1,"
1449 "double fPeriod, double fFactor);\n";
1450 
1451 std::string ScInterVDB=
1452 "double ScInterVDB(double fCost, double fSalvage, double fLife, double fLife1,"
1453 "double fPeriod, double fFactor)\n"
1454 "{\n"
1455 " double fVdb=0;\n"
1456 " double fIntEnd = ceil(fPeriod);\n"
1457 " int nLoopEnd = fIntEnd;\n"
1458 
1459 " double fTerm, fSln;\n"
1460 " double fSalvageValue = fCost - fSalvage;\n"
1461 " int nNowSln = 0;\n"
1462 " double fDdb;\n"
1463 " int i;\n"
1464 " fSln=0;\n"
1465 " for ( i = 1; i <= nLoopEnd; i++)\n"
1466 " {\n"
1467 " if(!nNowSln)\n"
1468 " {\n"
1469 " fDdb = ScGetDDB(fCost, fSalvage, fLife, (double) i, fFactor);\n"
1470 " fSln = fSalvageValue/ (fLife1 - (double) (i-1));\n"
1471 " if (fSln > fDdb)\n"
1472 " {\n"
1473 " fTerm = fSln;\n"
1474 " nNowSln = 1;\n"
1475 " }\n"
1476 " else\n"
1477 " {\n"
1478 " fTerm = fDdb;\n"
1479 " fSalvageValue =fSalvageValue- fDdb;\n"
1480 " }\n"
1481 " }\n"
1482 " else\n"
1483 " {\n"
1484 " fTerm = fSln;\n"
1485 " }\n"
1486 
1487 " if ( i == nLoopEnd)\n"
1488 " fTerm *= ( fPeriod + 1.0 - fIntEnd );\n"
1489 
1490 " fVdb += fTerm;\n"
1491 " }\n"
1492 " return fVdb;\n"
1493 "}\n";
1494 
1495 std::string VDBImplementDecl=
1496 "double VDBImplement(double fCost, double fSalvage, double fLife, double fStart"
1497 ", double fEnd, double fFactor, bool bNoSwitch);\n";
1498 
1499 std::string VDBImplement=
1500 "double VDBImplement(double fCost, double fSalvage, double fLife, double fStart"
1501 ", double fEnd, double fFactor, bool bNoSwitch)\n"
1502 "{\n"
1503 " double result=0;\n"
1504 " double fIntStart = floor(fStart);\n"
1505 " double fIntEnd = ceil(fEnd);\n"
1506 " int nLoopStart = (int) fIntStart;\n"
1507 " int nLoopEnd = (int) fIntEnd;\n"
1508 " if (bNoSwitch)\n"
1509 " {\n"
1510 " for (int i = nLoopStart + 1; i <= nLoopEnd; i++)\n"
1511 " {\n"
1512 " double fTerm = ScGetDDB(fCost, fSalvage, fLife, (double) i, fFactor"
1513 ");\n"
1514 " if ( i == nLoopStart+1 )\n"
1515 " fTerm *= ( DblMin( fEnd, fIntStart + 1.0 ) - fStart );\n"
1516 " else if ( i == nLoopEnd )\n"
1517 " fTerm *= ( fEnd + 1.0 - fIntEnd );\n"
1518 " result += fTerm;\n"
1519 " }\n"
1520 " }\n"
1521 " else\n"
1522 " {\n"
1523 " double fLife1=fLife;\n"
1524 " if(!isequal(fStart,floor(fStart)))\n"
1525 " {\n"
1526 " if(fFactor>1)\n"
1527 " {\n"
1528 " if(fStart>fLife/2 || isequal(fStart,fLife/2))\n"
1529 " {\n"
1530 " double fPart=fStart-fLife/2;\n"
1531 " fStart=fLife/2;\n"
1532 " fEnd-=fPart;\n"
1533 " fLife1+=1;\n"
1534 " }\n"
1535 " }\n"
1536 " }\n"
1537 " fCost-=ScInterVDB(fCost, fSalvage, fLife, fLife1, fStart, fFactor);\n"
1538 " result=ScInterVDB(fCost, fSalvage, fLife, fLife-fStart, fEnd-fStart,"
1539 "fFactor);\n"
1540 " }\n"
1541 " return result;\n"
1542 "}\n";
1543 
1544 std::string GetOddlpriceDecl=
1545 "double GetOddlprice( int nNullDate, int nSettle, int nMat, int nLastCoup,\n"
1546 " double fRate, double fYield, double fRedemp, int nFreq, int nBase );\n";
1547 
1548 std::string GetOddlprice=
1549 "double GetOddlprice( int nNullDate, int nSettle, int nMat, int nLastCoup,\n"
1550 " double fRate, double fYield, double fRedemp, int nFreq, int nBase )\n"
1551 "{\n"
1552 " double fFreq = nFreq ;\n"
1553 " double fDCi = GetYearFrac( nNullDate, nLastCoup,"
1554 "nMat, nBase ) * fFreq;\n"
1555 " double fDSCi = GetYearFrac( nNullDate, nSettle,"
1556 "nMat, nBase ) * fFreq;\n"
1557 " double fAi = GetYearFrac( nNullDate, nLastCoup,"
1558 "nSettle, nBase ) * fFreq;\n"
1559 " double p = fRedemp + fDCi * 100.0 * fRate / fFreq;\n"
1560 " p /= fDSCi * fYield / fFreq + 1.0;\n"
1561 " p -= fAi * 100.0 * fRate / fFreq;\n"
1562 " return p;\n"
1563 "}\n";
1564 
1565 std::string GetOddlyieldDecl=
1566 "double GetOddlyield( int nNullDate, int nSettle, int nMat, int nLastCoup,\n"
1567 " double fRate, double fPrice, double fRedemp, int nFreq, int nBase );\n";
1568 
1569 std::string GetOddlyield=
1570 "double GetOddlyield( int nNullDate, int nSettle, int nMat, int nLastCoup,\n"
1571 " double fRate, double fPrice, double fRedemp, int nFreq, int nBase ) \n"
1572 "{\n"
1573 " double fFreq = nFreq ;\n"
1574 " double fDCi= GetYearFrac( nNullDate, nLastCoup, nMat, nBase ) * fFreq;\n"
1575 " double fDSCi= GetYearFrac( nNullDate, nSettle, nMat, nBase ) * fFreq;\n"
1576 " double fAi= GetYearFrac( nNullDate, nLastCoup, nSettle, nBase )*fFreq;\n"
1577 " double y = fRedemp + fDCi * 100.0 * fRate / fFreq;\n"
1578 " y /= fPrice + fAi * 100.0 * fRate / fFreq;\n"
1579 " y -= 1.0;\n"
1580 " y *= fFreq / fDSCi;\n"
1581 " return y;\n"
1582 "}\n";
1583 
1585 "double GetYearFrac_new( int nNullDate, int nStartDate, int nEndDate,"
1586 "int nMode );\n";
1587 
1588 std::string GetYearFrac_new=
1589 "double GetYearFrac_new( int nNullDate, int nStartDate, int nEndDate,"
1590 "int nMode ) \n"
1591 "{\n"
1592 " if( nStartDate == nEndDate )\n"
1593 " return 0.0; \n"
1594 " if( nStartDate > nEndDate )\n"
1595 " {\n"
1596 " int n = nEndDate;\n"
1597 " nEndDate = nStartDate;\n"
1598 " nStartDate = n;\n"
1599 " }\n"
1600 " int nDate1 = nStartDate + nNullDate;\n"
1601 " int nDate2 = nEndDate + nNullDate;\n"
1602 " int nDay1, nDay2;\n"
1603 " int nMonth1, nMonth2;\n"
1604 " int nYear1, nYear2;\n"
1605 " DaysToDate_new( nDate1, &nDay1, &nMonth1, &nYear1 );\n"
1606 " DaysToDate_new( nDate2, &nDay2, &nMonth2, &nYear2 );\n"
1607 " int nDayDiff;\n"
1608 " switch( nMode )\n"
1609 " {\n"
1610 " case 0: \n"
1611 " if ( nDay1 == 31 )\n"
1612 " {\n"
1613 " nDay1--;\n"
1614 " }\n"
1615 " if ( nDay1 == 30 && nDay2 == 31 )\n"
1616 " {\n"
1617 " nDay2--;\n"
1618 " }\n"
1619 " else\n"
1620 " {\n"
1621 " if ( nMonth1 == 2 && nDay1 == "
1622 "( IsLeapYear( nYear1 ) ? 29 : 28 ) )\n"
1623 " {\n"
1624 " nDay1 = 30;\n"
1625 " if ( nMonth2 == 2 && nDay2 == "
1626 "( IsLeapYear( nYear2 ) ? 29 : 28 ) )\n"
1627 " {\n"
1628 " nDay2 = 30;\n"
1629 " }\n"
1630 " }\n"
1631 " }\n"
1632 " nDayDiff = ( nYear2 - nYear1 ) * 360 + "
1633 "( nMonth2 - nMonth1 ) * 30 + ( nDay2 - nDay1 );\n"
1634 " break;\n"
1635 " case 1: \n"
1636 " case 2: \n"
1637 " case 3: \n"
1638 " nDayDiff = nDate2 - nDate1;\n"
1639 " break;\n"
1640 " case 4: \n"
1641 " if ( nDay1 == 31 )\n"
1642 " {\n"
1643 " nDay1--;\n"
1644 " }\n"
1645 " if ( nDay2 == 31 )\n"
1646 " {\n"
1647 " nDay2--;\n"
1648 " }\n"
1649 " nDayDiff = ( nYear2 - nYear1 ) * 360 + "
1650 "( nMonth2 - nMonth1 ) * 30 + ( nDay2 - nDay1 );\n"
1651 " break;\n"
1652 " }\n"
1653 " double nDaysInYear;\n"
1654 " switch( nMode )\n"
1655 " {\n"
1656 " case 0: \n"
1657 " case 2: \n"
1658 " case 4: \n"
1659 " nDaysInYear = 360;\n"
1660 " break;\n"
1661 " case 1: \n"
1662 " {\n"
1663 " bool isYearDifferent = ( nYear1 != nYear2 );\n"
1664 " if ( isYearDifferent &&\n"
1665 " ( ( nYear2 != nYear1 + 1 ) ||\n"
1666 " ( nMonth1 < nMonth2 ) ||\n"
1667 " ( nMonth1 == nMonth2 && nDay1 < nDay2 ) ) )\n"
1668 " {\n"
1669 " int nDayCount = 0;\n"
1670 " for ( int i = nYear1; i <= nYear2; i++ )\n"
1671 " nDayCount += ( IsLeapYear( i ) ? 366 : 365 );\n"
1672 " nDaysInYear = ( double ) nDayCount / "
1673 "( double ) ( nYear2 - nYear1 + 1 );\n"
1674 " }\n"
1675 " else\n"
1676 " {\n"
1677 " if ( isYearDifferent && IsLeapYear( nYear1 ) )\n"
1678 " {\n"
1679 " nDaysInYear = 366;\n"
1680 " }\n"
1681 " else\n"
1682 " {\n"
1683 " if ( ( IsLeapYear( nYear1 ) && nMonth1 <= 2 "
1684 "&& nDay1 <= 29 ) ||\n"
1685 " ( IsLeapYear( nYear2 ) && ( nMonth2 > 3 || "
1686 "( nMonth2 == 2 && nDay1 == 29 ) ) ) )\n"
1687 " {\n"
1688 " nDaysInYear = 366;\n"
1689 " }\n"
1690 " else\n"
1691 " {\n"
1692 " nDaysInYear = 365;\n"
1693 " for ( int i = nYear1; i <= nYear2; i++ )\n"
1694 " {\n"
1695 " if ( IsLeapYear( i ) )\n"
1696 " {\n"
1697 " nDaysInYear = 366;\n"
1698 " break;\n"
1699 " }\n"
1700 " }\n"
1701 " }\n"
1702 " }\n"
1703 " }\n"
1704 " }\n"
1705 " break;\n"
1706 " case 3: \n"
1707 " nDaysInYear = 365;\n"
1708 " break;\n"
1709 " }\n"
1710 " return (double)( nDayDiff ) / (nDaysInYear);\n"
1711 "}\n";
1712 
1713 std::string DaysToDate_newDecl =
1714 "void DaysToDate_new( int nDays, int *rDay, int* rMonth, int* rYear );\n";
1715 
1716 std::string DaysToDate_new =
1717 "void DaysToDate_new( int nDays, int *rDay, int* rMonth, int* rYear )\n"
1718 "{\n"
1719 " int nTempDays;\n"
1720 " int i = 0;\n"
1721 " bool bCalc;\n"
1722 " do\n"
1723 " {\n"
1724 " nTempDays = nDays;\n"
1725 " *rYear = (int)((nTempDays / 365) - i);\n"
1726 " nTempDays -= ((int) *rYear -1) * 365;\n"
1727 " nTempDays -= ((*rYear -1) / 4) - ((*rYear -1) / 100) + ((*rYear -1)"
1728 " / 400);\n"
1729 " bCalc = false;\n"
1730 " if ( nTempDays < 1 )\n"
1731 " {\n"
1732 " i++;\n"
1733 " bCalc = true;\n"
1734 " }\n"
1735 " else\n"
1736 " {\n"
1737 " if ( nTempDays > 365 )\n"
1738 " {\n"
1739 " if ( (nTempDays != 366) || !IsLeapYear( *rYear ) )\n"
1740 " {\n"
1741 " i--;\n"
1742 " bCalc = true;\n"
1743 " }\n"
1744 " }\n"
1745 " }\n"
1746 " }\n"
1747 " while ( bCalc );\n"
1748 " if(nTempDays != 0){\n"
1749 " for (*rMonth = 1; (int)nTempDays > DaysInMonth( *rMonth, *rYear );"
1750 " *rMonth += 1)\n"
1751 " {\n"
1752 " nTempDays -= DaysInMonth( *rMonth, *rYear ); \n"
1753 " }\n"
1754 " *rDay = (int)nTempDays;\n"
1755 " }\n"
1756 "}\n";
1757 
1759 "void DaysToDate( int nDays, int *rDay, int* rMonth, int* rYear );\n";
1760 
1762 "void DaysToDate( int nDays, int *rDay, int* rMonth, int* rYear )\n"
1763 "{\n"
1764 " int nTempDays;\n"
1765 " int i = 0;\n"
1766 " bool bCalc;\n"
1767 " do\n"
1768 " {\n"
1769 " nTempDays = nDays;\n"
1770 " *rYear = (int)((nTempDays / 365) - i);\n"
1771 " nTempDays -= ((int) *rYear -1) * 365;\n"
1772 " nTempDays -= ((*rYear -1) / 4) - ((*rYear -1) / 100) + ((*rYear -1)"
1773 " / 400);\n"
1774 " bCalc = false;\n"
1775 " if ( nTempDays < 1 )\n"
1776 " {\n"
1777 " i++;\n"
1778 " bCalc = true;\n"
1779 " }\n"
1780 " else\n"
1781 " {\n"
1782 " if ( nTempDays > 365 )\n"
1783 " {\n"
1784 " if ( (nTempDays != 366) || !IsLeapYear( *rYear ) )\n"
1785 " {\n"
1786 " i--;\n"
1787 " bCalc = true;\n"
1788 " }\n"
1789 " }\n"
1790 " }\n"
1791 " }\n"
1792 " while ( bCalc );\n"
1793 " barrier(CLK_LOCAL_MEM_FENCE);\n"
1794 " if(nTempDays != 0){\n"
1795 " for (*rMonth = 1; (int)nTempDays > DaysInMonth( *rMonth, *rYear );"
1796 " *rMonth += 1)\n"
1797 " {\n"
1798 " nTempDays -= DaysInMonth( *rMonth, *rYear ); \n"
1799 " }\n"
1800 " *rDay = (int)nTempDays;\n"
1801 " }\n"
1802 "}\n";
1803 
1805 "double GetYearDiff_new( int nNullDate, int nStartDate, int nEndDate,"
1806 "int nMode);\n";
1807 
1808 std::string GetYearDiff_new=
1809 "double GetYearDiff_new( int nNullDate, int nStartDate, int nEndDate,"
1810 "int nMode )\n"
1811 "{\n"
1812 " int nDays1stYear;\n"
1813 " int nTotalDays = GetDiffDate_new( nNullDate, nStartDate, nEndDate,"
1814 "nMode, &"
1815 "nDays1stYear );\n"
1816 " return (double)(nTotalDays)* pow((double)nDays1stYear,-1);\n"
1817 "}\n";
1818 
1820 "int GetDiffDate_new( int nNullDate, int nStartDate, int nEndDate, int nMode,"
1821 " int* pOptDaysIn1stYear );\n";
1822 
1823 std::string GetDiffDate_new=
1824 "int GetDiffDate_new( int nNullDate, int nStartDate, int nEndDate, int nMode,"
1825 " int* pOptDaysIn1stYear )\n"
1826 "{\n"
1827 " bool bNeg = nStartDate > nEndDate;\n"
1828 " if( bNeg )\n"
1829 " {\n"
1830 " int n = nEndDate;\n"
1831 " nEndDate = nStartDate;\n"
1832 " nStartDate = n;\n"
1833 " }\n"
1834 " int nRet;\n"
1835 " switch( nMode )\n"
1836 " {\n"
1837 " case 0: \n"
1838 " case 4: \n"
1839 " {\n"
1840 " int nD1, nM1, nY1, nD2, nM2, nY2;\n"
1841 " nStartDate += nNullDate;\n"
1842 " nEndDate += nNullDate;\n"
1843 " DaysToDate_new( nStartDate, &nD1, &nM1, &nY1 );\n"
1844 " DaysToDate_new( nEndDate, &nD2, &nM2, &nY2 );\n"
1845 " bool bLeap = IsLeapYear( nY1 );\n"
1846 " int nDays, nMonths;\n"
1847 " nMonths = nM2 - nM1;\n"
1848 " nDays = nD2 - nD1;\n"
1849 " nMonths += ( nY2 - nY1 ) * 12;\n"
1850 " nRet = nMonths * 30 + nDays;\n"
1851 " if( nMode == 0 && nM1 == 2 && nM2 != 2 && nY1 == nY2 )\n"
1852 " nRet -= bLeap? 1 : 2;\n"
1853 " if( pOptDaysIn1stYear )\n"
1854 " *pOptDaysIn1stYear = 360;\n"
1855 " }\n"
1856 " break;\n"
1857 " case 1: \n"
1858 " if( pOptDaysIn1stYear )\n"
1859 " {\n"
1860 " int nD, nM, nY;\n"
1861 " DaysToDate_new( nStartDate + nNullDate, &nD, &nM, &nY );\n"
1862 " *pOptDaysIn1stYear = IsLeapYear( nY )? 366 : 365;\n"
1863 " }\n"
1864 " nRet = nEndDate - nStartDate;\n"
1865 " break;\n"
1866 " case 2: \n"
1867 " nRet = nEndDate - nStartDate;\n"
1868 " if( pOptDaysIn1stYear )\n"
1869 " *pOptDaysIn1stYear = 360;\n"
1870 " break;\n"
1871 " case 3: \n"
1872 " nRet = nEndDate - nStartDate;\n"
1873 " if( pOptDaysIn1stYear )\n"
1874 " *pOptDaysIn1stYear = 365;\n"
1875 " break;\n"
1876 " }\n"
1877 " return bNeg? -nRet : nRet;\n"
1878 "}\n";
1879 
1880 #endif
1881 
1882 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::string ScInterVDBDecl
std::string DaysToDate_new
std::string GetOddlpriceDecl
std::string GetNullDate_new
std::string getPrice_new
std::string DateToDaysDecl
std::string coupdaybs
std::string GetYearFrac_newDecl
std::string coupdaysnc_new
std::string GetYearDiffDecl
std::string getDiffDecl
std::string GetFV_new
std::string GetDiffDate360_
std::string GetDaysInYear
std::string GetDiffDate360
std::string coupdaysnc
std::string ScaDateDecl
std::string DaysInMonth_new
std::string IsLeapYearDecl
std::string getPrice_new_Decl
std::string GetDiffDate360_Decl
std::string GetDiffDate360Decl
std::string RoundDecl
std::string GetYieldmatDecl
std::string GetNullDate
std::string GetYearDiff_newDecl
std::string Round
std::string SCdEpsilonDecl
std::string lcl_GetCouppcd
std::string lcl_Getcoupdaybs
std::string setDay
std::string lcl_GetCoupncdDecl
std::string coupdaysnc_newDecl
std::string DblMinDecl
std::string addMonths
std::string DaysToDate_LocalBarrierDecl
std::string IsLeapYear
std::string GetDaysInYearsDecl
std::string coupnum
std::string coupdays_new
std::string lcl_GetcoupdaybsDecl
std::string lcl_Getcoupnum_newDecl
std::string GetDiffDate
std::string coupnumDecl
std::string GetOddlyield
std::string DaysInMonth_newDecl
std::string DateToDays_newDecl
std::string lcl_GetcoupnumDecl
std::string lcl_GetCouppcdDecl
std::string ScaDate
std::string coupdaybs_new
std::string lcl_Getcoupnum
std::string lcl_Getcoupdaybs_newDecl
std::string GetDaysInYearDecl
std::string GetDaysInYears
std::string addMonthsDecl
std::string VDBImplement
std::string lcl_GetCoupncd
std::string DaysToDateDecl
std::string coupdaybs_newDecl
std::string GetOddlprice
std::string getDaysInMonthRange
std::string getDiff
std::string DaysToDate_LocalBarrier
std::string lcl_Getcoupnum_new
std::string GetOddlyieldDecl
std::string coupdays
std::string VDBImplementDecl
std::string GetDuration_newDecl
std::string DblMin
std::string DaysInMonth
std::string GetDuration_new
std::string GetYearDiff
std::string lcl_Getcoupdays_newDecl
std::string DateToDays
std::string coupnum_newDecl
std::string GetFV
std::string getYield_
std::string coupdaysncDecl
std::string GetYearFrac
std::string ScGetDDBDecl
std::string DaysInMonthDecl
std::string GetPMT_newDecl
std::string coupdays_newDecl
std::string DaysToDate
std::string coupdaysDecl
std::string lcl_Getcoupdays_new
std::string GetYieldmat
std::string GetFV_newDecl
std::string getDaysInMonthRangeDecl
std::string getPrice_Decl
std::string GetNullDateDecl
std::string checklessthanDecl
std::string lcl_Getcoupdaybs_new
std::string ScGetDDB
std::string ScInterVDB
std::string getYield_Decl
std::string nCorrValDecl
std::string lcl_GetcoupdaysDecl
std::string coupdaybsDecl
std::string getPrice_
std::string checklessthan
std::string lcl_Getcoupdays
std::string GetDiffDateDecl
std::string GetDuration
std::string GetYearFrac_new
std::string DateToDays_new
std::string GetYearFracDecl
std::string GetPMT_new
std::string GetDiffDate_new
std::string GetFVDecl
std::string GetDurationDecl
std::string getDaysInYearRangeDecl
std::string GetDiffDate_newDecl
std::string GetNullDate_newDecl
std::string getDaysInYearRange
std::string setDayDecl
std::string DaysToDate_newDecl
std::string GetYearDiff_new
std::string coupnum_new