Announcement

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

  • Calculate volatility within specific window

    I have the information on monthly return volatility (vol) for a given firm(permno). What I need is to calculate annual volatility. To do so, I need to take an average of 12 months and multiply by sqrt(12). The problem is in the following. Can anyone advise me how to calculate annual volatility for each month? E.g. for date – Dec 2001 I will calcúlate mean of all volatility from Jan2001 till Dec2001; for Nov2001 – from Dec2000 till Nov2001. (There can be some firms with data on volatility of less then 12 months)
    Please, help me with this issue.




    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double permno float fdate double vol
    10001 656  .06403224492662121
    10001 657   .0642184858910423
    10001 658  .06422293091889109
    10001 659  .06132661265416173
    10001 660  .06325274408781455
    10001 661  .06336734126650605
    10001 662  .06334452424597348
    10001 663 .061410578170574714
    10001 664  .06142662684393377
    10001 665  .06120134826671392
    10001 666  .06036999156637595
    10001 667 .060382959605466795
    10001 668  .05961408212357318
    10001 669  .05947813840800326
    10001 670  .05737425895618173
    10001 671  .05961166276158599
    10001 672  .06137658319431642
    10001 673  .06175224810125758
    10001 674  .06103207202876633
    10001 675  .06124932503246213
    10001 676 .061186831629557986
    10001 677 .061221379018593904
    10001 678 .061237467261545234
    10001 679  .06141052037132038
    10001 680 .061654409880222805
    10001 681  .10103402858270005
    10001 682  .10101437100408721
    10001 683  .10086884591971629
    10002 468                   .
    10002 469                   .
    10002 470                   .
    10002 471                   .
    10002 472                   .
    10002 473                   .
    10002 474                   .
    10002 475                   .
    10002 476                   .
    10002 477                   .
    10002 478                   .
    10002 479  .08124466376706692
    10002 480  .07786064589159718
    10002 481  .08472920546846713
    10002 482  .08282250023633123
    10002 483   .0804557907478288
    10002 484  .07791106099170318
    10002 485  .07693039621264686
    10002 486  .07476862319449326
    10002 487  .07277652243600559
    10002 488  .08771336831915962
    10002 489  .09533083416391132
    10002 490  .09344931646986948
    10002 491  .09264975458064945
    10002 492  .09297027105879481
    10002 493  .09218288073280059
    10002 494  .12241523137180942
    10002 495  .12911082345176922
    10002 496  .12693690068241129
    10002 497  .12492512147287697
    10002 498  .12300040559183043
    10002 499  .12130545927364728
    10002 500  .11965037361851862
    10002 501    .117921171507891
    10002 502    .116676154403075
    10002 503  .11499823134497376
    10002 504  .11339146052002329
    10002 505  .11275577706162246
    10002 506  .11186827640760627
    10002 507  .11628907093724404
    10002 508  .11482628926079243
    10002 509  .11342146559084368
    10002 510  .11306319433245644
    10002 511  .11178677461860578
    10002 512  .11067921047876796
    10002 513  .10944957877664027
    10002 514   .1082881659546003
    10002 515  .10745300195270781
    10002 516  .10669552402947205
    10002 517  .10692611602355384
    10002 518  .10661494319387681
    10002 519  .10641468048133089
    10002 520   .1054745331694984
    10002 521  .10456807219056466
    10002 522  .10360396815957336
    10002 523  .10266161560482454
    10002 524  .10207658996879733
    10002 525  .10119379108590142
    10002 526   .1003354836705227
    10002 527  .09950052873409242
    10002 528   .0994960310969487
    10002 529  .09955330090836216
    end
    format %tm fdate

  • #2
    You're presuming that we know how you define volatility. Either way, search the forum for mentions of rangestat (SSC).

    Comment


    • #3
      Thank you for the reply. THere is no need to define volatility it is already defined - "vol". Simply, it is need to be taken as an average over created period (e.g. Jan2001 till Dec2001) and multiplied by sqrt(12). THe problem is how to set this period. Thank you for the suggested command.

      Comment


      • #4
        You're right. rangestat does most of what you want and the rest is easy.

        Code:
        rangestat (mean) vol (count) vol, int(fdate -11 0) by(permno)
        gives the mean of this and the previous 11 months and also counts how many values are available (so that you can ignore or adjust incomplete results if you wish). Then you can multiply up.

        Comment

        Working...
        X