简体   繁体   English

在SAS中计算价值加权收益

[英]Calculating value weighted returns in SAS

I have some data in the following format: 我有以下格式的一些数据:

COMPNAME DATA CAP RETURN

I have found some code that will construct and calculate the value-weighted return based on the data. 我发现了一些代码,这些代码将基于数据构造和计算值加权的回报。

This works great and is below: 这很好用,如下所示:

PROC SUMMARY NWAY DATA = Data1 ; CLASS DATE ;

VAR RETURN / WEIGHT = CAP ;

OUTPUT
   OUT = MKTRET
   MEAN (RETURN) = MONTHLYRETURN
RUN;

The extension that I would like to make is in my head a little bit complicated. 我想进行的扩展有点复杂。

I want to make the weights based on the market capitalization in June. 我想根据六月份的市值进行加权。

So this will be a buy and hold portfolios. 因此,这将是一个购买并持有的投资组合。 The actual data has 100's of companies but to give a representative example for two companies with the sole explanation of how the weights will evolve... 实际数据有100家公司,但仅举两个例子说明权重将如何变化......

Say for example I have two companies, A and B. 假设我有两家公司,A和B。

The CAP of A is £100m and B is £100m. A的CAP值为1亿英镑,B的CAP为1亿英镑。

In July of one year, I would invest 50% in A and 50% in B. 在一年的7月,我将对A投资50%,对B投资50%。

The returns in July are 10% and -10%. 7月的回报率分别为10%和-10%。

Therefore I would invest 55% and 45%. 因此,我将投资55%和45%。

It will go on like this until next June when I will re-balance again based on the market capitalisation... 这种情况将一直持续到明年六月,那时我将根据市值再次重新平衡...

10% monthly return is pretty speculative! 10%的月度回报是投机性的!

When the two companies differ by more than 200 you will need to also sell and buy to equalize the companies. 当两家公司相差200多个时,您还需要出售和购买以使两家公司均等。

Presume the rates per month are simulated and stored in a data set. 假设模拟了每个月的费率,并将其存储在数据集中。 You can generate a simulated ledger as follows 您可以按以下方式生成模拟分类帐

  • add returns 增加收益
  • compare balances 比较余额
    • equalize by splitting 200 investment if balances are close enough 如果余额足够接近,则通过拆分200个投资来均衡
    • equalize by investing all 200 in one and selling and buying 通过将全部200个投资于一个并买卖来实现均衡

Of course, a portfolio with more than 2 companies becomes a more complicated balancing act to achieve mathematical balance. 当然,拥有超过2家公司的投资组合成为实现数学平衡的更为复杂的平衡行为。

data simurate(label="Future expectation is not an indicator of past performance :)");
  do month = 1 to 60;
  do company = 1 to 2;
    return = round (sin(company+month/4) / 12, 0.001); %* random return rate for month;
    output; 
  end;
  end;    
run;

data want;
  if 0 then set simurate;

  declare hash lookup (dataset:'simurate');
  lookup.defineKey ('company', 'month');
  lookup.defineData('return');
  lookup.defineDone();


  month = 0;
  bal1 = 0; bal2 = 0;
  output;

  do month = 1 to 60;

    lookup.find(key:1, key:month);  rate1 = return;
    ret1 = round(bal1 * rate1, 0.0001);

    lookup.find(key:2, key:month);  rate2 = return;
    ret2 = round(bal1 * rate2, 0.0001);

    bal1 + ret1;
    bal2 + ret2;

    goal = mean(bal1,bal2) + 100;

    sel1 = 0; buy1 = 0;
    sel2 = 0; buy2 = 0;

    if abs(bal1-bal2) <= 200 then do;
      * difference between balances after returns is < 200;
      * balances can be equalized simple investment split;
      inv1 = goal - bal1;
      inv2 = goal - bal2;
    end;
    else if bal1 < bal2 then do;
      * sell bal2 as needed to equalize;
      inv1 = 200;
      inv2 = 0;
      buy1 = goal - 200 - bal1;
      sel2 = bal2 - goal;
    end;
    else do;
      inv2 = 200;
      inv1 = 0;
      buy2 = goal - 200 - bal2;
      sel1 = bal1 - goal;      
    end;

    bal1 + (buy1 - sel1 + inv1);
    bal2 + (buy2 - sel2 + inv2);

    output;

  end;
  stop;
  drop company return ;
  format bal: 10.4 rate: 5.3;
run;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM