Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
sb_user
Regular Visitor

Model Approach for creating a stock index

I am trying to create a value weighted index across the positions in a portfolio

 

I have the below Inputs from excel which I load into seperate tables in the model

- Prices for each security for each day over the last two years. Dates along the left column

- Trades comprimising the portfolio

 

To create the Index I need to do the following

- Use the Trades to find the size of each position on each day

- Multiply each position by the respective price for each day to get the value of each position on each day

-  Divide the value of each position by the total value of the portfolio to get the weighting of each portfolio

- create the the Index value by combing all Prices combing with their value weighting

 

I currently have two tables (Prices, Trades) as well as a date table. I am struggling with the approach in terms of creating new tables to perform the steps above, or store the calculations in measures. Any tips greatly appreciated

3 REPLIES 3
lbendlin
Super User
Super User

Please provide sanitized sample data that fully covers your issue. If you paste the data into a table in your post or use one of the file services it will be easier to work with. Avoid posting screenshots of your source data if possible.

Please show the expected outcome based on the sample data you provided. Screenshots of the expected outcome are ok.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

littlemojopuppy
Community Champion
Community Champion

Hi @sb_user 

 

This doesn't seem terribly difficult at first glance...can you provide some sample data to play with?

Hi - Sure,

 

I have created some dummy date which hopefully makes it easier.

 

Inputs 1 = Prices

 

Price     
      
 Stock AStock BStock CStock DStock E
01/01/202223.656.5215.124.826.35
02/01/2022247.3815.725.5528.15
03/01/202224.16.9114.7825.628.55
04/01/202224.756.6115.8426.729.8
05/01/202225.56.1916.624.630.55
06/01/202225.556.41724.830.95
07/01/202225.356.517.0824.830.8
08/01/2022256.417.4424.530.3
09/01/202225.156.5516.5823.7531.75
10/01/202225.66.7116.924.2531.5
11/01/202225.66.7917.32529.9
12/01/202225.36.7817.1224.6529.35
13/01/202224.556.7217.2624.2529.15
14/01/202225.26.8518.124.128.1
15/01/202225.656.8219.4623.828.15
16/01/202224.76.732023.1526.6
17/01/202224.76.732023.1526.6
18/01/202224.76.732023.1526.6
19/01/202224.76.732023.1526.6
20/01/202225.056.3219.7223.1526.8

 

Inputs 2 = Trades

 

Trades  
   
01/01/2022Stock A100
01/01/2022Stock B400
03/01/2022Stock C550
04/01/2022Stock A-3
05/01/2022Stock C-2
08/01/2022Stock A-4
08/01/2022Stock B-10
08/01/2022Stock C-13
11/01/2022Stock A-20
11/01/2022Stock C-10
11/01/2022Stock E140
13/01/2022Stock A-20
13/01/2022Stock C-5
13/01/2022Stock B-1
13/01/2022Stock D40
15/01/2022Stock C-12
15/01/2022Stock D-3
15/01/2022Stock B-4
17/01/2022Stock D-1
17/01/2022Stock B-6
17/01/2022Stock C-9

 

From the Tables I need to find the Total number of shares for each day. I have tried creating a cumulative measure for this in Power BI, but unsure how this should be stored. (I have a large data set with 40 + Stocks, and over 2 years of prices. But ideally, I need something like the below, Either implicitly or explicitly in the model

 

Running Sharecount

Shares     
 Stock AStock BStock CStock DStock E
01/01/2022100400000
02/01/2022100400000
03/01/202210040055000
04/01/20229740055000
05/01/20229740054800
06/01/20229740054800
07/01/20229740054800
08/01/20229339053500
09/01/20229339053500
10/01/20229339053500
11/01/2022733905250140
12/01/2022733905250140
13/01/20225338952040140
14/01/20225338952040140
15/01/20225338550837140
16/01/20225338550837140
17/01/20225337949936140
18/01/20225337949936140
19/01/20225337949936140
20/01/20225337949936140

 

Then from this I need to times the Price for each stock * the shares held for each stock. For each day, again unsure how this should be stored in the model, but the values would be below

 

Shares     
 Stock AStock BStock CStock DStock E
01/01/2022100400000
02/01/2022100400000
03/01/202210040055000
04/01/20229740055000
05/01/20229740054800
06/01/20229740054800
07/01/20229740054800
08/01/20229339053500
09/01/20229339053500
10/01/20229339053500
11/01/2022733905250140
12/01/2022733905250140
13/01/20225338952040140
14/01/20225338952040140
15/01/20225338550837140
16/01/20225338550837140
17/01/20225337949936140
18/01/20225337949936140
19/01/20225337949936140
20/01/20225337949936140

 

 

Mkt Value      
 Stock AStock BStock CStock DStock ETotal
01/01/2022   2,365.00   2,608.00                  -                 -                  -       4,973.00
02/01/2022   2,400.00   2,952.00                  -                 -                  -       5,352.00
03/01/2022   2,410.00   2,764.00     8,129.00               -                  -     13,303.00
04/01/2022   2,400.75   2,644.00     8,712.00               -                  -     13,756.75
05/01/2022   2,473.50   2,476.00     9,096.80               -                  -     14,046.30
06/01/2022   2,478.35   2,560.00     9,316.00               -                  -     14,354.35
07/01/2022   2,458.95   2,600.00     9,359.84               -                  -     14,418.79
08/01/2022   2,325.00   2,496.00     9,330.40               -                  -     14,151.40
09/01/2022   2,338.95   2,554.50     8,870.30               -                  -     13,763.75
10/01/2022   2,380.80   2,616.90     9,041.50               -                  -     14,039.20
11/01/2022   1,868.80   2,648.10     9,082.50               -     4,186.00   17,785.40
12/01/2022   1,846.90   2,644.20     8,988.00               -     4,109.00   17,588.10
13/01/2022   1,301.15   2,614.08     8,975.20      970.00   4,081.00   17,941.43
14/01/2022   1,335.60   2,664.65     9,412.00      964.00   3,934.00   18,310.25
15/01/2022   1,359.45   2,625.70     9,885.68      880.60   3,941.00   18,692.43
16/01/2022   1,309.10   2,591.05   10,160.00      856.55   3,724.00   18,640.70
17/01/2022   1,309.10   2,550.67     9,980.00      833.40   3,724.00   18,397.17
18/01/2022   1,309.10   2,550.67     9,980.00      833.40   3,724.00   18,397.17
19/01/2022   1,309.10   2,550.67     9,980.00      833.40   3,724.00   18,397.17
20/01/2022   1,327.65   2,395.28     9,840.28      833.40   3,752.00   18,148.61

 

From this I can create the index value by a Summing (for all equity),  Equity Price * ( Equity Mkt Value / Total Mkt Value ). e.g. =(EqPrice1*EqMv1/MktValTotal) For 1 to N

 

Which gets me the below

 

Index Value 
  
01/01/202214.666481
02/01/202214.8329148
03/01/202214.8332602
04/01/202215.6209484
05/01/202216.3322419
06/01/202216.5857627
07/01/202216.58256
08/01/202216.7348514
09/01/202216.1748173
10/01/202216.4759551
11/01/202219.5728254
12/01/202219.2816709
13/01/202219.3354405
14/01/202219.445118
15/01/202220.1712634
16/01/202219.9488254
17/01/202219.9733105
18/01/202219.9733105
19/01/202219.9733105
20/01/202219.962572

 

Then as a final stage I index this the initial Index to 100

 

Index Base 
  
01/01/2022100
02/01/2022101.13479028
03/01/2022101.13714510
04/01/2022106.50781497
05/01/2022111.35760477
06/01/2022113.08617712
07/01/2022113.06434012
08/01/2022114.10270395
09/01/2022110.28424129
10/01/2022112.33747969
11/01/2022133.45277174
12/01/2022131.46760226
13/01/2022131.83421773
14/01/2022132.58202863
15/01/2022137.53308250
16/01/2022136.01644027
17/01/2022136.18338662
18/01/2022136.18338662
19/01/2022136.18338662
20/01/2022136.11016846

 

Any help very much appreciated! In reality my data set is a little more complicated, but its mainly the model concept I am struggling with (how many tables I need). Once I have this i will be able to figure out the nuances

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.