楼主: yingxin0824
3616 13

SAS XIRR计算收益率 重谢!! [推广有奖]

  • 1关注
  • 0粉丝

硕士生

21%

还不是VIP/贵宾

-

威望
0
论坛币
29630 个
通用积分
1.3500
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
426 点
帖子
37
精华
0
在线时间
229 小时
注册时间
2012-2-13
最后登录
2024-4-25

楼主
yingxin0824 在职认证  发表于 2015-1-15 17:04:44 |AI写论文
100论坛币
数据格式是这样的:


id                number               amount             payday                 rate           month       receiveday
1                   1001                    80                2012/3/1                10%           6                 2012/5/1
1                   1002                   150               2012/3/25              16%           4                 2012/5/20

那个id为1的投资者它的现金流是这样的:

2012/3/1      -80
2012/5/1     13.72        excel中这样算的pmt(10%/12, 6, -80)
2012/6/1     13.72
2012/7/1     13.72
2012/8/1     13.72
2012/9/1     13.72
2012/10/1   13.72
2012/3/25    -150
2012/5/20   38.76
2012/6/20   38.76
2012/7/20   38.76
2012/8/20   38.76

然后求XIRR  

因为有很多id 以及很多一个id很多条贷款,所以没有办法手工,所以求教大家怎么解决这个问题!

谢谢大家了!





关键词:IRR 收益率 received receive amount number amount payday 收益率

沙发
ermutuxia 发表于 2015-1-15 20:42:08
建议使用循环语句来解决。在SAS里面,例如使用do while循环语句的语法如下:
使用DO…WHILE 循环计算1+2+3+…+100的结果
data;
s=0;
i=1;
do while (i<=100);
s=s+i;
i=i+1;
end;
put "The sum of 1 to 100 is " s;
run;

藤椅
yingxin0824 在职认证  发表于 2015-1-15 22:05:15
ermutuxia 发表于 2015-1-15 20:42
建议使用循环语句来解决。在SAS里面,例如使用do while循环语句的语法如下:
使用DO…WHILE 循环计算1+2+3 ...
希望您能具体一点

板凳
yingxin0824 在职认证  发表于 2015-1-16 11:38:49
没有人回答吗??希望大家帮帮忙啦,实在不知道应该怎么解决。

报纸
jingju11 发表于 2015-1-17 02:38:38
You can calculate PMT in SAS too. To compute PMT value, you can either define your own function or include the formula in data step (because here PMT has a closed form and can be calculated from PV, rate and number of payments directly).
For details, You can read my blog
JingJu
http://blog.sina.com.cn/s/blog_a3a926360102vbff.html

地板
jingju11 发表于 2015-1-17 05:29:49
jingju11 发表于 2015-1-17 02:38
You can calculate PMT in SAS too. To compute PMT value, you can either define your own function or i ...
I also propose an algorithm ti calculate XIRR in sas.
JingJu
http://blog.sina.com.cn/s/blog_a3a926360102vbfj.html

7
yingxin0824 在职认证  发表于 2015-1-19 11:29:15
jingju11 发表于 2015-1-17 02:38
You can calculate PMT in SAS too. To compute PMT value, you can either define your own function or i ...
用的就是您帖子上的程序:

proc fcmp outlib=sasuser.funcs.trial;
  function annuity(pv,rate,nper,pmt,type,fv);
      if rate ^=0 then formula =pv*(1+rate)**nper+pmt(1+rate*type)*(((1+rate)**nper-1)/rate)+fv;
      else formula =(pmt * nper) + pv + fv;
      return(formula);
  endsub;
  function pmtx(pv,rate,nper);
  pmt=solve("annuity", {.}, 0, pv,rate,nper,.,0,0);
  return(pmt);
  endsub;
  run;
  quit;


但是sas显示
ERROR: The function PMT requires at least 3 arguments. There are too few arguments for the function PMT at 行 454 列
  
请问这怎么解决?

8
jingju11 发表于 2015-1-19 11:39:15
yingxin0824 发表于 2015-1-19 11:29
用的就是您帖子上的程序:

proc fcmp outlib=sasuser.funcs.trial;
++pmt(1+rate*type)*(((1+rate)**nper-1)/rate)+fv;
you had a typo above. it should be ...+pmt * (1+rate*type)*(((1+rate)**nper-1)/rate)+fv;

because * is missing, sas treats it a function pmt and thus cauases error.

by the way, one of my previous colleagues (working on bank now) points out that:
SAS/base has a function call FINANCE(). we can use that function directly to compute PMT and IRRS. Please refer to SAS documentation for this function.--非常抱歉。我有些孤陋寡闻了。
JingJu

9
yingxin0824 在职认证  发表于 2015-1-19 17:59:52
jingju11 发表于 2015-1-19 11:39
you had a typo above. it should be ...+pmt * (1+rate*type)*(((1+rate)**nper-1)/rate)+fv;

beca ...
您好,下面是您的博客中的计算xirr的程序,我是初学者,真的是看不懂,您的程序简直太高大上了!!
我现在日期那一列的变量名为day,  现金流那一列的变量名为pmt,请问下面的程序怎么修改啊?
还有就是我需要计算每个id的xirr, by id类似的应该加在哪里呢?

真的是对您感激不尽!!


data have2;
     set have end=Eof;
     array pi[&n] _temporary_;
     array dd[&n] _temporary_;
     retain t0;
     if _n_=1 then t0=dt;
     pi[_n_] =p; dd[_n_]=(dt-t0)/365;
     if Eof then do;
               array fn[&n] _temporary_; array  fd[&n] _temporary_;
                   r0=0.01;
                   r=r0;tan=1;
                   do i =1 to 100 by 1 until(abs(tan)<1e-8);
                        do k=1 to &n;
                                fn[k]=pi[k]/((1+r)**dd[k]);
                                fd[k]=-pi[k]*dd[k]/((1+r)**dd[k]+1));
                                end;
                                tan=sum(of fn
  • )/sum(of fd
  • );
                                    r + -tan;
                                    output;
            end;
      end;
      keep r0 r tan;
    run;
  • 10
    yingxin0824 在职认证  发表于 2015-1-20 18:48:58 来自手机
    jingju11 发表于 2015-1-19 11:39
    you had a typo above. it should be ...+pmt * (1+rate*type)*(((1+rate)**nper-1)/rate)+fv;

    beca ...
    您好,计算xirr对我来说非常关键,下面的工作都需要先计算这一步,所以真的很希望您能帮助我,非常抱歉打扰您,谢谢您!!

    您需要登录后才可以回帖 登录 | 我要注册

    本版微信群
    加好友,备注cda
    拉您进交流群
    GMT+8, 2025-12-29 16:55