Results 1 to 2 of 2
  1. #1
    Join Date
    May 2012
    Posts
    3

    Unanswered: Daily Change in price

    If i have a data in a temporary data set which looks like this:

    Stock Date Price
    AAPL 01/02 565
    AAPL 01/03 567
    AAPL 01/04 545
    AAPL 01/05 550
    AAPL 01/06 552
    BOA 01/02 5.65
    BOA 01/03 6
    BOA 01/04 6.45
    BOA 01/05 6.0
    BOA 01/06 6.5

    How do I calcuate percentage change in price for a stock for each pricing date?

    So for appl I would want the % change in price for each pricing date starting from 01/03 till 01/06?

    Also if possible I would want it to be dynamic so that I don't need to mention the dates.

    Appreciate all your help

  2. #2
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Code:
    select stock, 
           "DATE", 
           price, 
           100 - ((price / lag(price) over (partition by stock order by "DATE")) * 100) as diff_pct
    from the_table_with_no_name
    where trunc("DATE") between to_date('2012-01-03', 'YYYY-MM-DD') 
                            and to_date('2012-01-06', 'YYYY-MM-DD')
    order by stock, "DATE";
    You should not use column names that are reserved words ("DATE").

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •