Daily PE Portfolio Value
Beginner Mode

Scenario

You work for a private equity firm and have been given two tables: one containing each firm's shareholdings per company and another containing daily closing prices per company.

Task

Write a Snowflake SQL query that:

  1. Joins {{ ref("portfolio") }} with {{ ref("prices") }} on the company column using INNER JOIN
  2. Computes portfolio_value as CAST(SUM(shares * closing_price) AS INTEGER) grouped by PE firm and date
  3. Returns PE_firm, date, and portfolio_value

Schema

portfolio

Column Type Description
PE_firm String Name of the private equity firm
company String Name of the company
shares Integer Number of shares the firm holds in the company

prices

Column Type Description
date Date The trading date
company String Name of the company
closing_price Double Closing price of the company's equity on that date

Example

portfolio:

PE_firm company shares
Apex TechCo 800
Apex FinCo 1500
Summit TechCo 2000
Summit GreenCo 1200
Crest FinCo 900

prices:

date company closing_price
2024-03-01 TechCo 45.0
2024-03-01 FinCo 32.0
2024-03-01 GreenCo 18.0
2024-03-02 TechCo 47.0
2024-03-02 FinCo 30.0
2024-03-02 GreenCo 19.5

Expected Output:

PE_firm date portfolio_value
Apex 2024-03-01 84000
Apex 2024-03-02 82600
Crest 2024-03-01 28800
Crest 2024-03-02 27000
Summit 2024-03-01 111600
Summit 2024-03-02 117400

Note: Each firm's daily portfolio value is the sum of (shares held times closing price) across all companies in their portfolio. For example, Apex on 2024-03-01 is (800 x 45) + (1500 x 32) = 84000.

Quick Solution

Code Environment

Sign in or try as guest to run your code.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →