{"id":111,"date":"2014-02-25T13:05:22","date_gmt":"2014-02-25T04:05:22","guid":{"rendered":"http:\/\/www.fsquare.co.kr\/?p=111"},"modified":"2014-03-14T09:42:31","modified_gmt":"2014-03-14T00:42:31","slug":"%ec%b1%84%ea%b6%8c%ea%b0%80%ea%b2%a9%ea%b3%84%ec%82%b0-library-%ea%b0%9c%eb%b0%9c-2","status":"publish","type":"post","link":"https:\/\/www.fsquare.co.kr\/?p=111","title":{"rendered":"\ucc44\uad8c\uac00\uaca9\uacc4\uc0b0 library \uac1c\ubc1c-2"},"content":{"rendered":"<p>\uc5bc\ub9c8\uc804 \ucc44\uad8c\ud3c9\uac00\uc0ac \uc911 \ud55c \uacf3\uc5d0\uc11c c++\uc744 \uc774\uc6a9\ud558\uc5ec \uc5d4\uc9c4\uc744 \uac1c\ubc1c\ud588\ub2e4\uace0 \ud55c\ub2e4. \uae30\uc874\uc758 c\uc5d4\uc9c4\ubcf4\ub2e4 \uc18d\ub3c4\ub098 \uc720\uc5f0\uc131, \ud655\uc7a5\uc131\uc744 \ub192\uc774\uae30 \uc704\ud574\uc11c\ub77c\uace0 \uadf8 \uc774\uc720\ub97c \ubc1d\ud614\uc5c8\ub294\ub370 \uc5b8\uc5b4\uc758 \ud655\uc7a5\uc131\uc740 \uc0ac\uc2e4 \uc911\uc694\ud55c \uc694\uc18c\uc774\uae34 \ud558\ub2e4. \ud2b9\ud788 \uae08\uc735\uc0c1\ud488\ub4e4\uc744 \ubd84\uc11d\ud558\ub2e4\ubcf4\uba74 \ube44\uc2b7\ud55c \ud328\ud134\uc758 \uc18d\uc131(\uc608\ub97c\ub4e4\uba74 cashflow\ub97c \uc774\uc6a9\ud55c \ud560\uc778\ubc95\uc774\ub098 \uc774\uc790\uc728 \ucd94\uc815 \ubc29\ubc95 \ub4f1)\ub4e4\uc774 \ubc18\ubcf5\ub418\ubbc0\ub85c c++\uc5b8\uc5b4 \uc790\uccb4\uc758 \uc0c1\uc18d\uc131\uacfc \ucea1\uc290\ud654 \ub4f1\uc774 \uc720\uc6a9\ud560 \uc218 \uc788\ub2e4. \ud2b9\ud788 \uc774\ubbf8 \uc798 \uc9dc\uc5ec\uc9c4 c++\uc758 \ud15c\ud50c\ub9bf\uc744 \ud1b5\ud55c \uc5f0\uc0b0\uc18d\ub3c4\uc758 \ud5a5\uc0c1\uc740 \ubc18\ubcf5\uacc4\uc0b0\uc2dc \uc5b4\ub290\uc815\ub3c4 \uc131\ub2a5\ucc28\uc774\ub97c \ubd88\ub7ec\uc62c \uc218\ub3c4 \uc788\ub2e4.<br \/>\n\uadf8\ub7ec\ub098, \uc5b8\uc5b4 \uc790\uccb4\uc758 \ucc28\uc774\ub3c4 \uc911\uc694\ud558\uc9c0\ub9cc \uc5b8\uc5b4\ub97c \uc798 \uc0ac\uc6a9\ud558\ub294 \uac83\ub3c4 \uc544\uc8fc \uc911\uc694\ud55c \uc694\uc18c \uc911 \ud558\ub098\uc774\ub2e4. c++\uc640 c \ub458 \uc911\uc5d0\uc11c \uc5b4\ub290 \ucabd\uc5d0 \ub354 \ub0ab\ub2e4\ub77c\uace0 \ub9d0\ud558\uae30\ub294 \uc560\ub9e4\ud55c \uc0c1\ud669\uc774\ub77c\uc11c \uc544\ubb34\ub798\ub3c4 \uac1c\ubc1c\uc774 \uc26c\uc6b4 c\ub97c \uc120\ud0dd\ud588\ub2e4(\uc5b8\uc820\uac00 java\ub85c\ub3c4 \ud3ec\ud305\ud574 \ubcfc \uc608\uc815\uc774\ub2e4).<\/p>\n<p>\ucc44\uad8c \uac00\uaca9 \uacc4\uc0b0\uc744 \uc704\ud574 \uc81c\uc77c \uba3c\uc800 \ub364\ubcbc\ub4e0 \ubd80\ubd84\uc740 \uc77c\ubc18\ucc44\uad8c(SB : straight bond)\uc774\ub2e4. \uc77c\ubc18 \ucc44\uad8c \uc911\uc5d0\uc11c\ub3c4 \uc774\ud45c\ucc44(Coupon Bond)\ub97c \uba3c\uc800 \uc18c\uac1c\ud55c\ub2e4. \uc5ec\uae30\uc11c\ub294 \ucc44\uad8c\uc758 \uae30\ubcf8\uc778 \uac00\uaca9 \uacc4\uc0b0\uacfc duration, convexity\ub97c \ud568\uaed8 \uacc4\uc0b0\ud560 \uc218 \uc788\ub3c4\ub85d \uc791\uc131\uc744 \ud588\ub2e4. \ucc44\uad8c\uc218\uc775\ub960\uc740 ytm \ud558\ub098\ub97c \uc0ac\uc6a9\ud560 \uc218\ub3c4 \uc788\uace0 spot rate\ub97c \uc0ac\uc6a9\ud560 \uc218\ub3c4 \uc788\ub2e4.<\/p>\n<p><strong>\uac00\uaca9 \uacc4\uc0b0\uc5d0\uc11c\uc758 YTM\uacfc SPOT<\/strong><br \/>\nYTM(Yield to Maturity)\uc740 \uc77c\ubc18\uc801\uc73c\ub85c \ub9cc\uae30\uae4c\uc9c0\uc758 \uc218\uc775\ub960\ub85c \uc774\ud574\ud560 \uc218 \uc788\uc9c0\ub9cc \uac00\uaca9 \uacc4\uc0b0\uc801\uc778 \uce21\uba74\uc5d0\uc11c \ubcfc \ub54c\ub294 \ub9cc\uae30\uc5d0 \ub530\ub77c \uc11c\ub85c \ub2e4\ub978 spot rate\uc744 \ub2e4 \uc801\uc6a9\uc548 \uac83\uacfc \ub3d9\uc77c\ud55c \uc5ed\ud560\uc744 \ud558\ub294 \ud558\ub098\uc758 \uc218\uc775\ub960\uc774\ub2e4.<br \/>\n\uc989, 1M -&gt; 3.45, 3M -&gt; 3.47, 6M -&gt; 3.49, 9M -&gt; 3.50\uc640 \uac19\uc774 \uc11c\ub85c \ub2e4\ub978 spot rate(\ud560\uc778\uc728)\uc744 \uc801\uc6a9\ud574\uc11c \uacc4\uc0b0\ud574\uc57c \ud558\ub294\ub370 \uadf8\ub0e5 3.48\ub85c \uacc4\uc0b0\ud588\uc744 \ub54c \ub3d9\uc77c\ud55c \uacb0\uacfc\uac00 \ub098\uc624\uac8c \ud574 \uc8fc\ub294 \uc218\uc775\ub960\uc774 YTM\uc774\ub2e4.<\/p>\n<p>\ub2e4\uc74c\uc740 \uc544\uc9c1 \ubbf8\uacb0\uc0ac\ud56d\uc774 \uc870\uae08 \ub0a8\uc544 \uc788\ub294 \uc18c\uc2a4\uc774\ub2e4. \uc120\ub9e4\ucd9c\uacfc \uacbd\uacfc\uc774\uc790\uc5d0 \ub300\ud55c \uacc4\uc0b0\uc740 \ud3ec\ud568\ud558\uc9c0 \uc54a\ub294\ub2e4.<\/p>\n<pre>\/*-----------------------------------------------------------------------------\r\n * bond_sb.c\r\n * \t\t\t: SB ( Straight Bond )\ub97c \uacc4\uc0b0\ud558\uae30 \uc704\ud55c \ud568\uc218\r\n * \t\t\t\uac00\uaca9\uacc4\uc0b0\uc2dc duration, convexity\ub97c \uacc4\uc0b0\ud568\r\n *\r\n *---------------------------------------------------------------------------*\/\r\n#ifndef _BOND_SB_C_\r\n#define _BOND_SB_C_\r\n\r\n#include &lt;stdio.h&gt;\r\n#include &lt;math.h&gt;\r\n#include &lt;string.h&gt;\r\n#include &lt;stdlib.h&gt;\r\n#include \"define.h\"\r\n#include \"util.h\"\r\n#include \"bond_lib.h\"\r\n#include \"math_util.h\"\r\n#include \"date_lib.h\"\r\n\r\n\/*-----------------------------------------------------------------------------\r\n * fnSBCouponBond : \uc774\ud45c\ucc44\uc5d0 \ub300\ud55c \uac00\uaca9 \uacc4\uc0b0 \ud568\uc218\r\n *\t\tSpot\/YTM \ubaa8\ub450 \uc0ac\uc6a9\uac00\ub2a5\r\n *\t\tYTM\uc758 \uac2f\uc218\ub97c 1\uac1c\ub9cc \uc9c0\uc815\ud558\ub294 \uacbd\uc6b0 \ud574\ub2f9 YTM\uc744 \uc0ac\uc6a9\ud560 \uc218 \uc788\uc73c\uba70,\r\n *\t\tYTM\uc758 \uac2f\uc218\uac00 \uc5ec\ub7ec\uac1c\uc778 \uacbd\uc6b0 \ubcf4\uac04 \ud558\uc5ec \ud574\ub2f9 YTM \uc0ac\uc6a9\r\n *\r\n * \ubbf8\uacb0\uc0ac\ud56d :\r\n *---------------------------------------------------------------------------*\/\r\nUINT fnSBCouponBond( DATETYPE  dtPriceDay,     \/* \uacc4\uc0b0\uc77c                           *\/\r\n                     BONDINFO  *pBondInfo,   \/* Bond Info Structure              *\/\r\n                     CURVE     *pCurve,      \/* ytm\/sport curve                  *\/\r\n                     BONDPRICE *pBondPrice,  \/* Price Info Structure             *\/\r\n                     INT       *error_code )\r\n{\r\n\tDATETYPE\tnextCouponDate;\r\n\tDATETYPE\tprevCouponDate;\r\n\tDATETYPE\tnextDate;\r\n\tDATETYPE\tprevDate;\r\n\tDATETYPE\tdtBaseDate;\r\n\tCASHFACTOR\t*pCashFactor;\r\n\tUINT \t\tnTotalCoupon;\r\n\tDOUBLE\t\tnCashIn;\r\n\tDOUBLE\t\tnDuration;\r\n\tDOUBLE\t\tnMD;\r\n\tDOUBLE\t\tnConvexity;\r\n        DOUBLE          nBondPrice;\r\n\tDOUBLE\t\tnInterest;\r\n\tDOUBLE\t\tnFace;\r\n\tDOUBLE\t\tnDiscountToday;\r\n        UINT            nIntPayType;\r\n\tUINT\t\tnCouponPerYear;\r\n\tUINT\t\tnNextCouponRemDay;\r\n\tUINT\t\tnCouponTermDay;\r\n\tint\t\tidx;\r\n\tint\t\tnCouponIdx;\r\n...\r\n\uc911\ub7b5\r\n...\r\n\/\/\ucd08\uae30\ud654\r\n\tnFace = 10000.0;\r\n\tnCouponPerYear = 12.0 \/ pBondInfo-&gt;nIntMonth;\r\n\tnInterest = nFace * pBondInfo-&gt;nCouponRate \/ nCouponPerYear;\r\n\tnFace = nFace * pBondInfo-&gt;nReturnRate \/ 100.0;\r\n\tnTotalCoupon = fnCountDate( dtPriceDay, pBondInfo-&gt;dtDueDay, MONTH ) \/ pBondInfo-&gt;nIntMonth + 3;\r\n...\r\n\/\/ \ub9cc\uae30\uac00 \uc9c0\ub098\uac70\ub098 \ubc1c\ud589\uc815\ubcf4\uac00 \uc798\ubabb\ub418\uc5c8\ub294\uc9c0 \uccb4\ud06c\ud558\uace0 \uc798\ubabb\ub418\uc5c8\uc744\ub550 \ub9ac\ud134\ud558\ub3c4\ub85d \ud558\ub294 \ubd80\ubd84 \ud3ec\ud568\r\n...\r\n\/\/\r\n\/\/ \uc774\uc790\ub97c \uc9c0\uae09\ud558\ub294 \uae30\uc900\uc774 \ubc1c\ud589\uc77c \ub9d0\uc77c \uae30\uc900\uc778\uc9c0, \ub9cc\uae30\uc77c \ub9d0\uc77c \uae30\uc900\uc778\uc9c0, \ubc1c\ud589\uc77c \uae30\uc900\uc778\uc9c0, \ub9cc\uae30\uc77c \uae30\uc900\uc778\uc9c0\ub97c \ud310\ub2e8\ud55c\ub2e4.\r\n\tpCashFactor = (CASHFACTOR*)calloc( nTotalCoupon, sizeof( CASHFACTOR ) );\r\n\r\n\tnIntPayType = pBondInfo-&gt;nIntPayType;\r\n\r\n\tif ( nIntPayType == ENGINE_SELECT ) {\r\n\t\tif ( fnIsDate( pBondInfo-&gt;dtFirstIntDay ) &amp;&amp; fnIsLastDay( pBondInfo-&gt;dtFirstIntDay ) &amp;&amp; pBondInfo-&gt;bEndOfMonth )\r\n\t\t\tnIntPayType = ISSUE_MONTH_LAST_DAY;\r\n\t\telse if ( fnIsDate( pBondInfo-&gt;dtFirstIntDay ) &amp;&amp; \r\n\t\t\tfnDatetoInt( pBondInfo-&gt;dtFirstIntDay ) == fnDatetoInt( fnAddDateInt( pBondInfo-&gt;dtIssueDay, MONTH, pBondInfo-&gt;nIntMonth ) ) )\r\n\t\t\tnIntPayType = ISSUE_DAY;\r\n\t\telse if ( fnIsDate( pBondInfo-&gt;dtFirstIntDay ) )\r\n\t\t\tnIntPayType = IRREGULAR_FIRST;\r\n\t\telse if ( fnIsDate( pBondInfo-&gt;dtLastIntDay ) &amp;&amp; fnIsLastDay( pBondInfo-&gt;dtLastIntDay ) )\r\n\t\t\tnIntPayType = MATURE_MONTH_LAST_DAY;\r\n\t\telse if ( fnIsDate( pBondInfo-&gt;dtLastIntDay ) &amp;&amp;\r\n\t\t\tfnDatetoInt( pBondInfo-&gt;dtLastIntDay ) == fnDatetoInt( fnAddDateInt( pBondInfo-&gt;dtLastIntDay, MONTH, -pBondInfo-&gt;nIntMonth ) ) )\r\n\t\t\tnIntPayType = MATURITY_DAY;\r\n\t\telse if ( !fnIsDate( pBondInfo-&gt;dtFirstIntDay ) &amp;&amp; !fnIsDate( pBondInfo-&gt;dtLastIntDay ) ) {\r\n\t\t\tif ( fnIsLastDay( pBondInfo-&gt;dtIssueDay ) &amp;&amp; pBondInfo-&gt;bEndOfMonth )\r\n\t\t\t\tnIntPayType = ISSUE_MONTH_LAST_DAY;\r\n\t\t\telse\r\n\t\t\t\tnIntPayType = ISSUE_DAY;\r\n\t\t}\r\n\t\telse if ( fnIsDate( pBondInfo-&gt;dtLastIntDay ) )\r\n\t\t\tnIntPayType = IRREGULAR_LAST;\r\n\t}\r\n\r\n\t\/* \ubc1c\ud589\uc77c \uae30\uc900 \uc774\uc790\uc9c0\uae09 \ucc44\uad8c\t\t\t\t\t\t\t*\/\r\n\tif ( nIntPayType == ISSUE_DAY || nIntPayType == IRREGULAR_FIRST ) {\r\n\t\tif ( nIntPayType == ISSUE_DAY )\r\n                         \/\/ \uac00\uaca9 \uacc4\uc0b0\uc77c\uc774 \ubc1c\ud589\uc77c\ubcf4\ub2e4 \uc774\uc804\uc778 \uacbd\uc6b0(\ubc1c\ud589\ub3c4 \uc548\ub41c \ucc44\uad8c\uc744 \uc0ac\ub294 \uac83\uc774\ub2e4!)\r\n\t\t\tif ( fnDatetoInt( pBondInfo-&gt;dtIssueDay ) &gt; fnDatetoInt( dtPriceDay ) ) {\r\n\t\t\t\tprevCouponDate = dtPriceDay;\r\n                                \/\/ \ub2e4\uc74c \uc774\uc790\uc9c0\uae09\uc77c\uc740 \ubc1c\ud589\uc77c\uc5d0 \uc774\uc790\uc9c0\uae09 \uc8fc\uae30\ub97c \uadf8\ub0e5 \ub354\ud55c\ub2e4.\r\n\t\t\t\tnextCouponDate = fnAddDateInt( pBondInfo-&gt;dtIssueDay, MONTH, pBondInfo-&gt;nIntMonth );\r\n\t\t\t}\r\n                        \/\/ \uc774\ubbf8 \ubc1c\ud589\ub41c \ucc44\uad8c\uc774\ub77c\uba74 \ub2e4\uc74c \uc774\uc790\uc9c0\uae09\uc77c\uc740 \ubc1c\ud589\uc77c\uc744 \uae30\uc810\uc73c\ub85c \ub354\ud574\ub098\uac00\uc57c \ud55c\ub2e4.\r\n                        \/\/ (\ub2e8 prevCouponDate == nextCoupondate\ub97c \ud574 \ub193\uace0 \uc544\ub798\uc5d0\uc11c loop \ub3cc\uba74\uc11c \ucc3e\ub294\ub2e4.)\r\n\t\t\telse {\r\n\t\t\t\tnextCouponDate = pBondInfo-&gt;dtIssueDay;\r\n\t\t\t\tprevCouponDate = nextCouponDate;\r\n\t\t\t}\r\n\t\telse {\r\n\t\t\tnextCouponDate = pBondInfo-&gt;dtFirstIntDay;\r\n\t\t\tprevCouponDate = nextCouponDate;\r\n\t\t}\r\n\r\n\t\tdtBaseDate = nextCouponDate;\r\n                \/\/ \uac00\uaca9 \uacc4\uc0b0\uc77c\uc774 \ub2e4\uc74c \uc774\uc790\uc9c0\uae09\uc77c \uc9c1\uc804 \uad6c\uac04\uc5d0 \uc624\ub3c4\ub85d \ub0a0\uc9dc\ub97c \ub354\ud574\uac04\ub2e4\r\n                \/\/ \uc0ac\uc2e4 \uac04\ub2e8\ud55c \ub85c\uc9c1\uc73c\ub85c \ud55c\ubc88\uc5d0 \uad6c\ud560 \uc218\ub3c4 \uc788\ub2e4.( \ubc1c\ud589\uc77c + floor((\uac00\uaca9\uacc4\uc0b0\uc77c - \ubc1c\ud589\uc77c ) \/ \uc774\uc790\uc9c0\uae09\uc8fc\uae30 ) * \uc774\uc790\uc9c0\uae09\uc8fc\uae30 ) \uadf8\ub7ec\ub098 \ud504\ub85c\uadf8\ub7a8\uc744 Copy and paste \uc27d\uac8c \ud558\uae30 \uc704\ud574 \ud480\uc5b4\uc37c\ub2e4. ^^;;\r\n\t\twhile ( fnDatetoInt( nextCouponDate ) &lt; fnDatetoInt( dtPriceDay ) ) { \t\t\tprevCouponDate = nextCouponDate; \t\t\tnextCouponDate = fnAddDateInt( dtBaseDate, MONTH, pBondInfo-&gt;nIntMonth * nCouponIdx++ );\r\n\t\t}\r\n\t}\r\n\r\n\/\/ \ub2e4\uc74c\ubd80\ud130\ub294 \ubc1c\ud589\uc77c \ub9d0\uc77c\uc774\ub4e0, \ub9cc\uae30\uc77c \ub9d0\uc77c\uc774\ub4e0, \ub85c\uc9c1\uc774 \ud070 \ucc28\uc774\ub294 \uc5c6\uace0 \ub0a0\uc9dc\ub9cc \uccb4\ud06c\ud558\uba74 \ub41c\ub2e4.\r\n...\r\n\uc911\ub7b5\r\n...\r\n\/\/\r\n\t\/*-------------------------------------------------------------------------\r\n\t * YTM \/ SPOT\uc5d0 \ub530\ub978 cashflow \ud560\uc778 \uacc4\uc0b0 -&gt;\uac00\uaca9\uacc4\uc0b0\r\n\t *-----------------------------------------------------------------------*\/\r\n\tif ( pCurve-&gt;nCurveType == YTM ) \r\n\t{\r\n\t\tpBondPrice-&gt;nYtm = 0.0;\r\n\r\n\t\tif ( pCurve-&gt;nYieldCount == 1 )\r\n\t\t{\r\n\t\t\tpBondPrice-&gt;nYtm = pCurve-&gt;nYield[ 0 ];\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\t\/* \ud574\ub2f9 \uc794\uc874\ub9cc\uae30\uc758 \uc218\uc775\ub960\uc744 \uc120\ud615\ubcf4\uac04\uc73c\ub85c \uac00\uc838\uc634  *\/\r\n\t\t\tUINT\tnRemDay;\r\n\r\n\t\t\tnRemDay = pCashFactor[ nTotalCoupon - 1 ].nRemDay;\r\n\t\t\tpBondPrice-&gt;nYtm = fnGetRate( pCurve, nRemDay, LINEAR );\r\n\t\t}\r\n\r\n\t\tidx = 0;\r\n\t\tnextDate = nextCouponDate;\r\n\t\tprevDate = prevCouponDate;\r\n                \/\/ \ub0a0\uc9dc\ub97c loop \ub3cc\uba74\uc11c discount factor\ub97c \uad6c\ud574\uc8fc\uae30 \uc2dc\uc791\ud55c\ub2e4.\r\n                \/\/ discount factor\ub780 \uac01 \uc774\uc790\uc9c0\uae09\uc77c\uc758 1\uc6d0\uc774 \ud604\uc7ac \uac00\uce58\ub85c \uc5bc\ub9c8\uac00 \ub420 \uac83\uc778\uc9c0 \ud560\uc778\ube44\uc728\uc744 \uacc4\uc0b0\ud55c \uac12\uc774\ub2e4.\r\n\t\twhile ( fnDatetoInt( nextDate ) &lt;= fnDatetoInt( pBondInfo-&gt;dtDueDay ) )\r\n\t\t{\r\n\t\t\tpCashFactor[ idx ].nRemDay = fnCountDate( dtPriceDay, nextDate, DAY );\r\n\t\t\tpCashFactor[ idx ].nCash = nInterest;\r\n\t\t\tpCashFactor[ idx ].nDF = 1 \/ pow( 1.0 + pBondPrice-&gt;nYtm \/ nCouponPerYear, idx );\r\n\t\t\tprevDate = nextDate;\r\n\t\t\tif ( nIntPayType == MATURE_MONTH_LAST_DAY || nIntPayType == ISSUE_MONTH_LAST_DAY )\r\n\t\t\t\tnextDate = fnSetLastDay( fnAddDateInt( dtBaseDate, MONTH, pBondInfo-&gt;nIntMonth * nCouponIdx ) );\r\n\t\t\telse\r\n\t\t\t\tnextDate = fnAddDateInt( dtBaseDate, MONTH, pBondInfo-&gt;nIntMonth * nCouponIdx );\r\n\t\t\tidx++;\r\n\t\t\tnCouponIdx++;\r\n\t\t}\r\n\t\t\tpCashFactor[ idx ].nRemDay = fnCountDate( dtPriceDay, pBondInfo-&gt;dtDueDay, DAY );\r\n\t\t\tpCashFactor[ idx ].nCash = nInterest;\r\n\t\t\tpCashFactor[ idx ].nCash = nInterest * ( fnDatetoInt( pBondInfo-&gt;dtDueDay ) - fnDatetoInt( prevDate ) ) \/ ( fnDatetoInt( nextDate ) - fnDatetoInt( prevDate ) );\r\n\t\t\tpCashFactor[ idx ].nCash += nFace;\r\n\t\t\tif ( idx &gt; 0 )\r\n\t\t\t\tpCashFactor[ idx ].nDF = 1.0 \/ ( pow( 1.0 + pBondPrice-&gt;nYtm \/ nCouponPerYear, idx - 1) ) ;\r\n\t\t\telse \r\n\t\t\t\tpCashFactor[ idx ].nDF = 1.0;\r\n\r\n\t\t\tpCashFactor[ idx ].nDF \/= ( 1.0 + pBondPrice-&gt;nYtm \/ nCouponPerYear * (DOUBLE)( fnDatetoInt( pBondInfo-&gt;dtDueDay ) - fnDatetoInt( prevDate ) ) \/ (DOUBLE)( fnDatetoInt( nextDate ) - fnDatetoInt( prevDate ) ) );\r\n\t\t\tidx++;\r\n\t\t}\r\n\t\telse pCashFactor[ idx - 1].nCash += nFace;\r\n\r\n\t\tnTotalCoupon = idx;\r\n\r\n                \/\/ \ucc44\uad8c\uac00\uaca9\uc744 \uacc4\uc0b0\ud55c\ub2e4.\r\n                \/\/ \uac01 \uc774\uc790\uc9c0\uae09\uc77c\uc758 discount factor\uc640 \uc774\uc790 \ub610\ub294 \uc6d0\uae08\uc744 \uacf1\ud574\uc11c \ud604\uc7ac\uac00\uce58\uc5d0 \ub204\uc801\ud574\uc11c \ub354\ud55c\ub2e4.\r\n\t\tnBondPrice = 0.0;\r\n\t\tnNextCouponRemDay = fnCountDate( dtPriceDay, nextCouponDate, DAY );\r\n\t\tnCouponTermDay    = fnCountDate( prevCouponDate, nextCouponDate, DAY ) ;\r\n\t\tnDiscountToday = (DOUBLE) nNextCouponRemDay \/ (DOUBLE) nCouponTermDay;\r\n\r\n\t\tfor ( idx = 0; idx &lt;  nTotalCoupon; idx++ ) \t\t{ \t\t\tif ( pCashFactor[ idx ].nRemDay == 0 ) continue;                         \/\/ \uac01 \uc774\uc790\uc758 \ud604\uc7ac\uac00\uce58(\ud560\uc778\uae08\uc561)\ub294 \ub2e4\uc74c \uc774\uc790 \uc9c0\uae09\uc77c\uae4c\uc9c0\uc758 \ud560\uc778\uc728\uc744 \uacf1\ud55c\ub2e4 \t\t\tnCashIn = pCashFactor[ idx ].nCash * pCashFactor[ idx ].nDF;                        \/\/ \ub2e4\uc74c \uc774\uc790\uc9c0\uae09\uc77c\uae4c\uc9c0 \ud560\uc778\ub41c \uae08\uc561\uc744 \ub2e4\uc2dc \ud604\uc7ac\uae4c\uc9c0\ub85c \ud560\uc778\ud55c\ub2e4. \ub450\uac1c\uc758 \uc0b0\uc2dd\uc744 \ud569\ud574\uc11c \ud558\ub098\ub85c \ud574\ub3c4 \ubb34\ubc29\ud558\ub2e4. \t\t\tnCashIn \/= ( 1.0 + ( pBondPrice-&gt;nYtm \/ nCouponPerYear * nDiscountToday ) );\r\n                        \/\/ \ub4c0\ub808\uc774\uc158\uc744 \uac19\uc774 \uacf1\ud55c\ub2e4.\r\n\t\t\tnDuration += ( nCashIn * pCashFactor[ idx ].nRemDay \/ 365.0 ) ;\r\n\t\t\tnConvexity += ( nCashIn * pow( pCashFactor[ idx ].nRemDay\/ 365.0, 2 ) * pCashFactor[ idx ].nRemDay \/ 365.0 );\r\n\t\t\tnBondPrice += nCashIn;\r\n\t\t}\r\n                \/\/ \ub4c0\ub808\uc774\uc158\uacfc \ucee8\ubca1\uc11c\ud2f0\ub3c4 \uacc4\uc0b0\ud55c\ub2e4.\r\n\t\tnDuration \/= nBondPrice;\r\n\t\tnMD = Math_Round( nDuration \/ ( 1 + pBondPrice-&gt;nYtm * pBondInfo-&gt;nIntMonth \/ 12.0 ), 5 );\r\n\t\tnConvexity = Math_Round( nConvexity \/ ( pow( 1 + pBondPrice-&gt;nYtm * pBondInfo-&gt;nIntMonth \/ 12.0, 2 ) * nBondPrice ), 5 ) ;\r\n\t}\r\n\r\n\/\/ \ub9cc\uc57d YTM\uc774 \uc544\ub2c8\ub77c\uba74 spot rate\ub97c \uc120\ud615\ubcf4\uac04\ud574\uc11c \ud574\ub2f9 \ub0a0\uc9dc\uc758 \ud560\uc778\uc728\uc744 \uad6c\ud574\uc11c discount factor\ub85c \uc0ac\uc6a9\ud55c\ub2e4.\r\n        else {\r\n...\r\n        }\r\n\/\/ \uac00\uaca9\uacfc \ub4c0\ub808\uc774\uc158, \ucee8\ubca1\uc11c\ud2f0\ub97c \ub9ac\ud134\ud55c\ub2e4.\r\n\r\n\tpBondPrice-&gt;nPrice = nBondPrice;\r\n\tpBondPrice-&gt;nDuration = Math_Round( nDuration, 5 );\r\n\tpBondPrice-&gt;nMD = nMD;\r\n\tpBondPrice-&gt;nConvexity = nConvexity;\r\n\r\n        free(pCashFactor);\r\n\r\n        return SUCCESS;\r\n}<\/pre>\n<p>\uace0\ubbfc\ud558\uc9c0 \uc54a\uace0 \ub85c\uc9c1 \uad6c\ud604\uc5d0\ub9cc \uc2e0\uacbd\uc744 \uc368\uc11c \uc791\uc131\ud55c \ucf54\ub4dc\ub77c \ud45c\ud604\uc774 \uac70\uce60\uace0 \uc815\uad50\ud654\ub418\uc9c0 \uc54a\uc740 \ubd80\ubd84\uc774 \uc788\uaca0\uc9c0\ub9cc \uc804\uccb4\uc801\uc778 \ub85c\uc9c1 \uc774\ud574\uc5d0\ub294 \ud070 \ubb34\ub9ac\uac00 \uc5c6\uc744 \uac83 \uac19\ub2e4.<br \/>\n\uac00\uaca9 \uacc4\uc0b0 \ub85c\uc9c1\uc758 \ud575\uc2ec\uc740 \uac01 \uc774\uc790\uc9c0\uae09\uc77c\uc744 \uc815\ud655\ud788 \uacc4\uc0b0\ud558\ub294 \uac83\uacfc \ud574\ub2f9\uc77c\uc758 discount factor, \uc989 \ud560\uc778\ub960\uc744 \uacc4\uc0b0\ud574\uc11c \uc9c0\uae09\ud558\ub294 \uc774\uc790 \ubc0f \uc6d0\uae08(cashflow)\uc744 \ud604\uc7ac\uac00\uce58\ub85c \uacc4\uc0b0\ud558\ub294 \uac83\uc774\ub2e4.<\/p>\n<p><center><a href=\"https:\/\/www.fsquare.co.kr\/wp-content\/uploads\/2014\/02\/df.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-162\" alt=\"df\" src=\"https:\/\/www.fsquare.co.kr\/wp-content\/uploads\/2014\/02\/df.jpg\" width=\"166\" height=\"82\" \/><\/a><\/center><br \/>\n\uadf8\ub9ac\uace0 \uc774\ubbf8 \uc124\uba85\ud55c \ubc14\uc640 \uac19\uc774 \ub0a0\uc9dc \uacc4\uc0b0 \ud568\uc218\ub4e4\uc774 \ud544\uc218\uc774\ub2e4.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\uc5bc\ub9c8\uc804 \ucc44\uad8c\ud3c9\uac00\uc0ac \uc911 \ud55c \uacf3\uc5d0\uc11c c++\uc744 \uc774\uc6a9\ud558\uc5ec \uc5d4\uc9c4\uc744 \uac1c\ubc1c\ud588\ub2e4\uace0 \ud55c\ub2e4. \uae30\uc874\uc758 c\uc5d4\uc9c4\ubcf4\ub2e4 \uc18d\ub3c4\ub098 \uc720\uc5f0\uc131, \ud655\uc7a5\uc131\uc744 \ub192\uc774\uae30 \uc704\ud574\uc11c\ub77c\uace0 \uadf8 \uc774\uc720\ub97c \ubc1d\ud614\uc5c8\ub294\ub370 \uc5b8\uc5b4\uc758 \ud655\uc7a5\uc131\uc740 \uc0ac\uc2e4 \uc911\uc694\ud55c \uc694\uc18c\uc774\uae34 \ud558\ub2e4. \ud2b9\ud788 \uae08\uc735\uc0c1\ud488\ub4e4\uc744 \ubd84\uc11d\ud558\ub2e4\ubcf4\uba74 \ube44\uc2b7\ud55c \ud328\ud134\uc758 \uc18d\uc131(\uc608\ub97c\ub4e4\uba74 cashflow\ub97c \uc774\uc6a9\ud55c \ud560\uc778\ubc95\uc774\ub098 \uc774\uc790\uc728 \ucd94\uc815 \ubc29\ubc95 \ub4f1)\ub4e4\uc774 \ubc18\ubcf5\ub418\ubbc0\ub85c c++\uc5b8\uc5b4 \uc790\uccb4\uc758 \uc0c1\uc18d\uc131\uacfc \ucea1\uc290\ud654 \ub4f1\uc774 \uc720\uc6a9\ud560 \uc218 \uc788\ub2e4. \ud2b9\ud788 \uc774\ubbf8 \uc798 \uc9dc\uc5ec\uc9c4 c++\uc758 \ud15c\ud50c\ub9bf\uc744 \ud1b5\ud55c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-111","post","type-post","status-publish","format-standard","hentry","category-asset-pricing"],"_links":{"self":[{"href":"https:\/\/www.fsquare.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/111","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fsquare.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fsquare.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fsquare.co.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fsquare.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=111"}],"version-history":[{"count":9,"href":"https:\/\/www.fsquare.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/111\/revisions"}],"predecessor-version":[{"id":163,"href":"https:\/\/www.fsquare.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/111\/revisions\/163"}],"wp:attachment":[{"href":"https:\/\/www.fsquare.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fsquare.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fsquare.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}