Announcement

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

  • Estimating annual volatility from daily stock returns

    Hi,

    I am new to Stata and am trying to create annualized volatilities from daily stock returns. Through CRSP I obtained stock price and daily return data on 106 companies for the period of January 2000 till dec 2014. Using this return data I want to create an annualized volatility of each of the 106 companies in my sample (I will later use this annualized volatility as input for the black & Scholes option pricing formula).

    The CRSP data contains the following variables: CompanyID, Date, logreturn.

    Up until now I have defined the data as panel data by using companyID as the panelvar and Date as the timevar.

    'xtset CompanyID Date'

    My goal is to determine an annualized volatility for each company individually by taking the sd of all the daily return observations in a specific year (so for 2000, 2001....etc) and multiplying it by the sqrt of the number of observations in that specific year. The problem I am facing here is that the number of observations differ per year (from about 245 till 252) and that the first day and final day of each year do not always fall on the same day. i.e. sometimes the first day of observations falls on the 2nd of January and sometimes on the 3rd of January. The last day of observations of each years differs between the 29th,30th or 31st of December.

    Does anyone know how to use this data in order to obtain the annualized volatility for each company in each specific year with a simple code? The data in total includes more than 280.000 return observations so manually calculating will require a lot of work.

    To clarify, Below is a graphic example display of my data
    CompanyID Date Log return
    10138 20000103 -.0078
    10138 20000104 -.009
    10138 20000105 -.045
    10138 20000106 .0249
    10138 20000107 .0015
    10138 20000110 .006
    ............ ........... ..............
    ........... ........... ..............
    10138 20001227 3
    10138 20001228 3
    10138 20001229 3
    ................ ......... ..............
    10138 20010102 .025
    10138 20010103 .004
    10138 20010104 -.003
    10138 20010105 -.0045
    10138 20010108 .01
    .......... ........... ............

  • #2
    This was posted yesterday and no-one answered. Repeating posts is allowed, but my advice is that if no-one bites, sorry but there is.

    You would improve your chances a bit by presenting an example using dataex (SSC) as recommended.

    People who answer frequently still filter questions rapidly and drastically. One filter is clearly whether the title appeals or we understand the question; another is whether it requires too much work with the poster's data even to get started. The second may be one reason you didn't get answers.

    Comment


    • #3
      Try something like
      Code:
      gen year=year(Date)
      bys id year: egen vol=sd(log_return)
      Regards
      --------------------------------------------------
      Attaullah Shah, PhD.
      Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
      FinTechProfessor.com
      https://asdocx.com
      Check out my asdoc program, which sends outputs to MS Word.
      For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

      Comment


      • #4
        I thought I posted a comment on this, but it apparently did not appear. Given that Willem seems to be a beginner with Stata, let me note that first you have to get Stata to recognize Date as a date. Then Attaullah's approach with egen will give you counts, and whatever else you need. You can then use generate to do the arithmetic.

        However, your data example is troubling. You label something log returns, but what does this do to negative returns? You also have log returns of 3 in three consecutive days which is almost impossible.

        Comment

        Working...
        X