Calculate % Price Difference

Anonymous

Help me with a Subset formula to calculate the % difference in price between the first and the last day in the dataset. My dataset has these fields : Ticker, Price, Date.

Omniscope GPT logo
Omniscope GPT

To calculate the percentage difference in price between the first and the last day in your dataset using a SUBSET formula in Omniscope, you can use the following formula structure:

  1. First, identify the first and last dates in your dataset.
  2. Then, retrieve the price associated with these dates.
  3. Finally, calculate the percentage difference.

Here's how you can construct the formula:

plaintext
1( 2 SUBSET_SINGLETON([Price], SUBSET([Date] SUBSET_MAX([Date]))) 3 - 4 SUBSET_SINGLETON([Price], SUBSET([Date] SUBSET_MIN([Date]))) 5) 6/ 7SUBSET_SINGLETON([Price], SUBSET([Date] SUBSET_MIN([Date])))

Explanation:

  • SUBSET_SINGLETON([Price], SUBSET([Date] SUBSET_MAX([Date]))): This part of the formula retrieves the price on the last day of your dataset.
  • SUBSET_SINGLETON([Price], SUBSET([Date] SUBSET_MIN([Date]))): This retrieves the price on the first day of your dataset.
  • The difference between these two prices is then calculated.
  • Finally, this difference is divided by the price on the first day to get the percentage difference.

This formula assumes that there is only one price per day. If there are multiple prices per day, you might need to adjust the formula to account for this, possibly by using additional SUBSET functions or different aggregation methods.

Anonymous

mmm . I thought this was the correct formula instead: (SUBSET_SINGLETON([Price USD],

SUBSET([DATE], SUBSET_MAX([DATE])))

SUBSET_SINGLETON([Price USD],

SUBSET([DATE], SUBSET_MIN([DATE]))))

/

SUBSET_SINGLETON([Price USD],

SUBSET([DATE], SUBSET_MIN([DATE])))

Omniscope GPT logo
Omniscope GPT

You are correct. The formula you provided is indeed the appropriate way to calculate the percentage difference in price between the first and the last day in your dataset using Omniscope's SUBSET formulas. Here's the breakdown of your formula:

  1. Find the Price on the Last Day:

    • SUBSET_SINGLETON([Price USD], SUBSET([DATE], SUBSET_MAX([DATE]))): This part retrieves the price on the last day (the maximum date) in your dataset.
  2. Find the Price on the First Day:

    • SUBSET_SINGLETON([Price USD], SUBSET([DATE], SUBSET_MIN([DATE]))): This retrieves the price on the first day (the minimum date) in your dataset.
  3. Calculate the Difference and Divide by the First Day's Price:

    • The formula calculates the difference between the last day's price and the first day's price, and then divides this difference by the first day's price to get the percentage difference.

The structure of your formula ensures that the percentage change is calculated accurately based on the single value (price) on the respective first and last days of your dataset. This approach is suitable when you have one price per date. If your dataset has multiple prices per day, additional considerations or adjustments might be needed.

Anonymous

what's the difference with the one you suggested originally?

Omniscope GPT logo
Omniscope GPT

The difference between the formula I originally suggested and the one you provided is primarily in the way the field names are referenced. Let's compare the two formulas:

  1. Original Formula I Suggested:

    plaintext
    1( 2 SUBSET_SINGLETON([Price], SUBSET([Date] SUBSET_MAX([Date]))) 3 - 4 SUBSET_SINGLETON([Price], SUBSET([Date] SUBSET_MIN([Date]))) 5) 6/ 7SUBSET_SINGLETON([Price], SUBSET([Date] SUBSET_MIN([Date])))
  2. Your Provided Formula:

    plaintext
    1( 2 SUBSET_SINGLETON([Price USD], SUBSET([DATE], SUBSET_MAX([DATE]))) 3 - 4 SUBSET_SINGLETON([Price USD], SUBSET([DATE], SUBSET_MIN([DATE]))) 5) 6/ 7SUBSET_SINGLETON([Price USD], SUBSET([DATE], SUBSET_MIN([DATE])))

Key Differences:

  • Field Names: The main difference is in the field names used. In my original suggestion, the fields are named [Price] and [Date], whereas in your formula, they are [Price USD] and [DATE]. The correct field names depend on how they are exactly named in your dataset.
  • Syntax and Spacing: The structure of both formulas is essentially the same, but there are minor differences in syntax, such as the placement of commas and spaces, which can be crucial depending on the strictness of the parser in Omniscope.

Both formulas are structurally designed to do the same calculation – find the percentage difference in price between the first and last days in the dataset. The correctness of either formula depends on the exact field names in your dataset. If the fields in your dataset are named "Price USD" and "DATE", then your provided formula is the correct one to use.