Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Continuously compounded returns

    Hello Statalist
    I've been trying to calculate a Continuously compounded returns on S&P500 index, daily data
    as follows:
    (1+r[1])+(1+r[2])+.....+(1+r[n])
    So I think it should be in a loop

    any help is highly appreciated

  • #2
    First, your formula is incorrect. Those plus signs should be multiplication signs. Otherwise after 5 working days with 0 return on each of the days, your compounded return would be 500%.

    Second, it need not be in a loop. The general principle is, assuming a variable r containing the daily return, is
    Code:
    generate cr = (1+r)
    replace cr = cr*cr[_n-1] if _n>1
    replace cr = cr-1

    Comment


    • #3
      William showed one way of doing it.

      There is also the user contributed -egen, prod-, which calculates products.

      net describe dm71, from(http://www.stata.com/stb/stb51)

      Comment


      • #4
        Thank you so much

        Comment


        • #5
          I tried that code, it generated a vector of [.]

          Comment


          • #6
            Show a sample of your data, using -dataex-, and say what you want to calculate from your data.

            Originally posted by Sarah Hussein View Post
            I tried that code, it generated a vector of [.]

            Comment


            • #7
              Works for me. Did you forget the if clause in the first replace command?
              Code:
              . generate cr = (1+r)
              
              . replace cr = cr*cr[_n-1] if _n>1
              (9 real changes made)
              
              . replace cr = cr-1
              (10 real changes made)
              
              . list
              
                   +------------------+
                   |    r          cr |
                   |------------------|
                1. |  .02         .02 |
                2. | -.03      -.0106 |
                3. |  .02    .0091881 |
                4. | -.01   -.0009038 |
                5. | -.03   -.0308766 |
                   |------------------|
                6. | -.01   -.0405679 |
                7. | -.02   -.0597565 |
                8. | -.05   -.1067687 |
                9. |  .00   -.1067687 |
               10. |  .04   -.0710395 |
                   +------------------+
              Last edited by William Lisowski; 26 Mar 2021, 12:59.

              Comment

              Working...
              X