0

I am trying to calculate weighted portfolio allocation in R from a dataset containing information about an ETF holding.

I will print the head down so data structure is apparent.

 Ticker     `Security Name`                                 Sector                 Industry       Price Weight Return Contr…¹ Country
  <chr>      <chr>                                           <chr>                  <chr>          <chr>  <dbl> <chr>  <chr>   <chr>  
1 ZENITHBANK Zenith Bank Plc                                 Financials             Banks          19.55   0.95 -9.59% -9.35   Nigeria
2 WLCON      Wilcon Depot Inc.                               Consumer Discretionary Specialty Ret… 27.40   0.07 -20.9… -1.72   Philip…
3 VRE        Vincom Retail Joint Stock Company               Real Estate            Real Estate M… 2540…   0.92 -12.8… -12.60  Vietnam
4 VPI        Van Phu - Invest Investment Joint Stock Company Real Estate            Real Estate M… 5960…   0.21 65.78% 7.73    Vietnam
5 VNM        Vietnam Dairy Products Joint Stock Company      Consumer Staples       Food Products  7050…   1.94 -17.2… -37.47  Vietnam
6 VND        VNDIRECT Securities Joint Stock Company         Financials             Capital Marke… 1465…   0.5  -7.58% -3.80   Vietnam

Price is of no interest here as it is shown in local currency. You will see there is a variable weight (dbl) which contains the portfolio percentage allocation weight of that specific company.

Now I would like to calculate statistics such as:

  • Portfolio weight by country
  • Portfolio weight by country and sector

What would be the best way to go about that? I am relatively clear on what I want out of the data, but I am not quite sure how to go about calculating it. Will appreciate any help.

Best,

  • Which statistics do you want ? You need `summarise()` : https://dplyr.tidyverse.org/reference/summarise.html – Basti Oct 12 '22 at 07:42

0 Answers0