Announcement

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

  • cumulative returns

    I'm using stata 13 with windows 10 OS.

    I want to calculate cumulative returns by firm in a certain period of time. I thought about calculate the sum of ln(1+ret), but as I have negatives, I don't think this is the way to go.
    Does anyone have any idea about how to do this?
    My date variable represents the date for the last earnings announcement. I want to calculate the cumulative returns for this date.
    Following is a example of my data


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long permno float(abn_ret date_ea)
    10001 .0009003075 20528
    10001  -.01267928 20528
    10001  .006637205 20528
    10001 -.007484646 20528
    10001  -.02332831 20528
    10001  .011132848 20528
    10001   .02164412 20528
    10001  -.01230608 20528
    10001   .01596631 20401
    10001 -.027130686 20401
    10001  .004668585 20401
    end
    format %td date_ea

  • #2
    What kind of returns are they? Percentages? Log returns? How come you have multiple returns for the same day?

    Comment


    • #3
      They are percentages.

      date_ea refers to the date of the next earnings announcement. I want to calculate the cumulative returns until this date, therefore I created this variable that gives the same date for all the returns I want to put together.

      Comment


      • #4
        Code:
        gen cumReturn_a = 1
        gen cumReturn_b = 1
        
        bysort permno (date_ea): replace cumReturn_a = cumReturn_a[_n-1] * (1+abn_ret) if _n > 1
        bysort permno date_ea  : replace cumReturn_b = cumReturn_b[_n-1] * (1+abn_ret) if _n > 1
        
        bysort permno (date_ea): gen totalReturn_a = cumReturn_a[_N] - 1
        bysort permno date_ea  : gen totalReturn_b = cumReturn_b[_N] - 1
        I'm not entirely sure what you want, so I coded two options.

        _a simply calculates the total return for this permno
        _b calculates the total return per permno per date_ea

        cumReturn_* can best be seen as a stock variable, normalized to one. I.e. it shows your stock now relative to what you started with.
        totalReturn_* is the actual percentage change between start and end. I think this might actually be an incorrect way to do it and it should in fact be a division of some sorts, but you probably know that better than I do (I'm not a finance guy)?

        Does that help?

        Comment


        • #5
          it does, but can you explain what the if option does?

          Comment


          • #6
            Originally posted by Felipe Damasceno View Post
            it does, but can you explain what the if option does?
            The if qualifier prevents all the observations from being set to missing.

            When within a <by: statement>, _n provides the number of the observation within the group. Hence, if _n>1 stops the command from doing anything on the very first observation within a group. This is necessary because *Return_*[_n-1] doesn't exist if _n == 1.

            Does that make sense? You can try it without the _n > 1 and you'll see the difference, specifying _n == 1 will show you what's going wrong.

            EDIT: Changed option to qualifier as the third word as per #7
            Last edited by Jesse Wursten; 14 Jul 2016, 11:24.

            Comment


            • #7
              Note if is not an option; here it's a qualifier.

              Comment


              • #8
                Jesse,

                Here is the thing. With this code I´m getting the cumulative result at that point. I´d like to get the cumulative result for all observation of the same firm with the same date_ea.

                Comment


                • #9
                  Originally posted by Felipe Damasceno View Post
                  Jesse,

                  Here is the thing. With this code I´m getting the cumulative result at that point. I´d like to get the cumulative result for all observation of the same firm with the same date_ea.
                  Isn't that what you get in totalReturn_b? If not I don't really understand what you're asking for... Can you perhaps include a simple example?

                  Comment


                  • #10
                    For what I understood, the totalReturn is the percentual difference between two observations. But, I don't got price to calculate returns. I have returns for each day and want to calculate the cumulative return for the period. What I did is to create a new variable called date_ea that gives the same date to every return I want to accumulate together.
                    Here is a better example of my data. I'd like to calculate all returns together that have the same data_ea and. if it's possible, get the value in the EPS date.



                    Code:
                    * Example generated by -dataex-. To install: ssc install dataex
                    clear
                    input long permno float(abn_ret anndats date_ea EPS)
                    11691    .012172948 17465 17465 1.14
                    11691  -.0089746155 17468 17567    .
                    11691   -.013763692 17469 17567    .
                    11691     .02741313 17470 17567    .
                    11691    .011868282 17471 17567    .
                    11691    .006654933 17472 17567    .
                    11691    .003023942 17475 17567    .
                    11691   .0031912194 17476 17567    .
                    11691     .00923176 17477 17567    .
                    11691   .0034949144 17478 17567    .
                    11691   -.014358364 17479 17567    .
                    11691   -.006314079 17482 17567    .
                    11691   -.008196113 17483 17567    .
                    11691  -.0008487114 17484 17567    .
                    11691  -.0008843668 17485 17567    .
                    11691   -.009579462 17486 17567    .
                    11691  -.0009021742 17489 17567    .
                    11691   -.013464108 17490 17567    .
                    11691    .007748195 17491 17567    .
                    11691   -.008166206 17493 17567    .
                    11691    .009179472 17496 17567    .
                    11691   -.000940704 17497 17567    .
                    11691    .019943254 17498 17567    .
                    11691  -.0020121557 17499 17567    .
                    11691    .024047587 17500 17567    .
                    11691   -.004227172 17503 17567    .
                    11691    .007689217 17504 17567    .
                    11691    .000648663 17505 17567    .
                    11691 -.00044146396 17506 17567    .
                    11691      .0148687 17507 17567    .
                    11691     .00501804 17510 17567    .
                    11691    .004268157 17511 17567    .
                    11691   .0021716324 17512 17567    .
                    11691    .005686784 17513 17567    .
                    11691   -.004705402 17514 17567    .
                    11691   -.005461689 17517 17567    .
                    11691   .0008598414 17518 17567    .
                    11691    .006586414 17519 17567    .
                    11691   .0022872891 17520 17567    .
                    11691   -.013708348 17521 17567    .
                    11691   .0013388155 17524 17567    .
                    11691   -.016903091 17526 17567    .
                    11691    .016134791 17527 17567    .
                    11691     .01082256 17528 17567    .
                    11691   -.022595154 17531 17567    .
                    11691   -.014054383 17533 17567    .
                    11691    -.01058653 17534 17567    .
                    11691    -.01157745 17535 17567    .
                    11691      -.014192 17538 17567    .
                    11691   -.008841429 17539 17567    .
                    11691    -.02037946 17540 17567    .
                    11691   -.013391983 17541 17567    .
                    11691   -.014078217 17542 17567    .
                    11691    .024091717 17545 17567    .
                    11691   -.016190942 17546 17567    .
                    11691   -.015647493 17547 17567    .
                    11691    .004940304 17548 17567    .
                    11691    .012980293 17549 17567    .
                    11691   -.018685527 17553 17567    .
                    11691    .004865461 17554 17567    .
                    11691    .008396044 17555 17567    .
                    11691    .011103337 17556 17567    .
                    11691   -.015268028 17559 17567    .
                    11691     .01705285 17560 17567    .
                    11691    .011386285 17561 17567    .
                    11691   -.013333277 17562 17567    .
                    11691   -.013327525 17563 17567    .
                    11691   -.012675485 17566 17567    .
                    11691     .04067366 17567 17567  .85
                    end
                    format %td anndats
                    format %td date_ea

                    Comment


                    • #11
                      I'm sorry but I still have no idea what it is you need. Can you give a simple example? E.g. two date_ea's with three returns each and then your manual calculation (with intermediary steps) on how to get the cumulative returns you want.

                      Comment

                      Working...
                      X