簡體   English   中英

在SAS中計算價值加權收益

[英]Calculating value weighted returns in SAS

我有以下格式的一些數據:

COMPNAME DATA CAP RETURN

我發現了一些代碼,這些代碼將基於數據構造和計算值加權的回報。

這很好用,如下所示:

PROC SUMMARY NWAY DATA = Data1 ; CLASS DATE ;

VAR RETURN / WEIGHT = CAP ;

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

我想進行的擴展有點復雜。

我想根據六月份的市值進行加權。

因此,這將是一個購買並持有的投資組合。 實際數據有100家公司,但僅舉兩個例子說明權重將如何變化......

假設我有兩家公司,A和B。

A的CAP值為1億英鎊,B的CAP為1億英鎊。

在一年的7月,我將對A投資50%,對B投資50%。

7月的回報率分別為10%和-10%。

因此,我將投資55%和45%。

這種情況將一直持續到明年六月,那時我將根據市值再次重新平衡...

10%的月度回報是投機性的!

當兩家公司相差200多個時,您還需要出售和購買以使兩家公司均等。

假設模擬了每個月的費率,並將其存儲在數據集中。 您可以按以下方式生成模擬分類帳

  • 增加收益
  • 比較余額
    • 如果余額足夠接近,則通過拆分200個投資來均衡
    • 通過將全部200個投資於一個並買賣來實現均衡

當然,擁有超過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