<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Daily IRR in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Daily-IRR/m-p/597887#M16217</link>
    <description>&lt;P&gt;That is called a function root problem.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp; wrote many blog about it by IML .&lt;/P&gt;
&lt;P&gt;Also you could try Generic Algorithm :&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2019/3099-2019.pdf" target="_blank" rel="noopener"&gt;https://www.&lt;WBR /&gt;sas.com/cont&lt;WBR /&gt;ent/dam/SAS/&lt;WBR /&gt;support/en/s&lt;WBR /&gt;as-global-fo&lt;WBR /&gt;rum-proceedi&lt;WBR /&gt;ngs/2019/309&lt;WBR /&gt;9-2019.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And the best choice is using FINANCE() or IRR() function .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 19 Oct 2019 11:59:56 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2019-10-19T11:59:56Z</dc:date>
    <item>
      <title>Daily IRR</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Daily-IRR/m-p/597817#M16198</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to calculate a daily IRR. In theory I could use FINANCE XIRR to calculate the annual IRR and then get the daily IRR, but when the IRR is too high or too close to -100% it fails to converge, even if I set a guess value close to the solution&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What is the best option for this? PROC NLIN, PROC MODEL or PROC IML?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you're not familiar with IRR, I have a set of dates and cashflows. I need to find an interest rate that makes the sum of the present values equal to zero. In other words, I need to find a value for daily_irr that satisfies the following equation&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SUM ( cashflow[i] / ((1 + daily_irr) ** ndays[i])&amp;nbsp; &amp;nbsp;) = 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Where ** is the power operator and ndays[i] is the amount of days elapsed between the first cashflow and cashflow[i]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is a sample dataset below. The daily_irr for that dataset would be 2.11%&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA irr;
input day :ddmmyy8. cashflow;
format day date9.;
fomat cashflow dollarx12.2;
datalines;
	31-03-19 30
	09-04-19 10
	08-05-19 10
	13-06-19 10
	30-06-19 -300
;
run;

DATA irr;
	SET irr;
	RETAIN first_day;
	FORMAT first_day date9.;
	if _N_ = 1 THEN first_day = day;
	ndays = day - first_day;
	keep ndays cashflow;
	RUN;

proc print data=irr; run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2019 19:17:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Daily-IRR/m-p/597817#M16198</guid>
      <dc:creator>HGimenez</dc:creator>
      <dc:date>2019-10-18T19:17:18Z</dc:date>
    </item>
    <item>
      <title>Re: Daily IRR</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Daily-IRR/m-p/597829#M16202</link>
      <description>&lt;P&gt;Not that I understand the this financial function, or most of them, but it might be a good idea to show how you attempted to use the Finance IRR function. Especially one of the examples that fails to converge. Someone with more expertise might have an 'Aha!' with an example.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2019 20:53:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Daily-IRR/m-p/597829#M16202</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-10-18T20:53:17Z</dc:date>
    </item>
    <item>
      <title>Re: Daily IRR</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Daily-IRR/m-p/597838#M16203</link>
      <description>&lt;P&gt;Can you give us some data that fails to converge using the finance('XIRR',...) function?&amp;nbsp; Using that function on the data you provide generates results as you suggest.&amp;nbsp; I get&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; annual_rate=2024.7843291&lt;/P&gt;
&lt;P&gt;and&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; daily_rate=0.0210785653 &amp;nbsp; (using 365 days compounding per year).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tmp;
   v1=30; d1=mdy(3, 31, 2019);
   v2=10; d2=mdy(4, 9, 2019);  
   v3=10; d3=mdy(5, 8, 2019);
   v4=10; d4=mdy(6, 13, 2019);
   v5=-300; d5=mdy(6, 30, 2019);
   format d: date9. ;
   ann_r=finance('xirr', v1, v2, v3, v4, v5, d1, d2, d3, d4, d5, 0.9);
   put ann_r=;
        
   presval1=exp(log(v1)+ log(1+ann_r)*((d5-d1)/365));
   presval2=exp(log(v2)+ log(1+ann_r)*((d5-d2)/365));
   presval3=exp(log(v3)+ log(1+ann_r)*((d5-d3)/365));
   presval4=exp(log(v4)+ log(1+ann_r)*((d5-d4)/365));
   presval5=v5;
   array _v {5} v1-v5; array _d {5} d1-d5; array _p {5} presval1-presval5;
   do i=1 to 5;
     put i= _v{i}= _d{i}=  _p{i}=;
   end;
   presval_sum=sum(of presval:);
   put presval_sum=;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edited addition:&amp;nbsp; I suspect (but I haven't done a mathematical proof so I don't know it is absolutely true) that you could discount all your values by a compounded daily rate of, say 1%&amp;nbsp; (i.e. NewV = V * .99**n) where n is the number of elapsed days.&amp;nbsp; Then perhaps XIRR convergence for the NewV series could be more computationally stable.&amp;nbsp; And I think you could then take that IRR and de-adjust it to get the corresponding IRR for the original values.&amp;nbsp; Of course all this would be needed only if your real problem is in unstable numeric convergence.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2019 21:56:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Daily-IRR/m-p/597838#M16203</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-10-18T21:56:57Z</dc:date>
    </item>
    <item>
      <title>Re: Daily IRR</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Daily-IRR/m-p/597887#M16217</link>
      <description>&lt;P&gt;That is called a function root problem.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp; wrote many blog about it by IML .&lt;/P&gt;
&lt;P&gt;Also you could try Generic Algorithm :&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2019/3099-2019.pdf" target="_blank" rel="noopener"&gt;https://www.&lt;WBR /&gt;sas.com/cont&lt;WBR /&gt;ent/dam/SAS/&lt;WBR /&gt;support/en/s&lt;WBR /&gt;as-global-fo&lt;WBR /&gt;rum-proceedi&lt;WBR /&gt;ngs/2019/309&lt;WBR /&gt;9-2019.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And the best choice is using FINANCE() or IRR() function .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 19 Oct 2019 11:59:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Daily-IRR/m-p/597887#M16217</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-10-19T11:59:56Z</dc:date>
    </item>
    <item>
      <title>Re: Daily IRR</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Daily-IRR/m-p/598011#M16233</link>
      <description>&lt;P&gt;I finally managed to solve this using the finance function&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem was that I had some cashflows missing. I usually completed missing values with an amount=0 and date=0. Date=0 is 01JAN1960. This works in most of the cases, but when the IRR is too high or too close to -100%, it fails to converge.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Workaround: complete missing values with a date closer to other cashflows.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is a simplified version of my code. The two calls to finance() only differ in the date used.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data irr;
	format d1-d3 d4_v1 d4_v2 DATE9.;
	v1 = 44.77;
	v2 = -1080.59;
	v3 = -151.61;
	v4 = 0;
	d1 = '31Mar2019'd;
	d2 = '12Jun2019'd;
	d3 = '30Jun2019'd;
	d4_v1 = 0;
	d4_v2 = '31Mar2019'd;
	irr_doesnt_converge = finance('xirr', v1, v2, v3, v4, d1, d2, d3, d4_v1);
	irr_converges = finance('xirr', v1, v2, v3, v4, d1, d2, d3, d4_v2);
	run;

proc print data=irr; run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Note that if v1 changes to, for instance, 1444.7, in both cases the finance() call converges:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data irr;
	format d1-d3 d4_v1 d4_v2 DATE9.;
	v1 = 1444.77;
	v2 = -1080.59;
	v3 = -151.61;
	v4 = 0;
	d1 = '31Mar2019'd;
	d2 = '12Jun2019'd;
	d3 = '30Jun2019'd;
	d4_v1 = 0;
	d4_v2 = '31Mar2019'd;
	irr_converges_v1 = finance('xirr', v1, v2, v3, v4, d1, d2, d3, d4_v1);
	irr_converges_v2 = finance('xirr', v1, v2, v3, v4, d1, d2, d3, d4_v2);
	run;

proc print data=irr; run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks everybody for your comments!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Oct 2019 02:12:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Daily-IRR/m-p/598011#M16233</guid>
      <dc:creator>HGimenez</dc:creator>
      <dc:date>2019-10-21T02:12:00Z</dc:date>
    </item>
  </channel>
</rss>

