+ Reply to Thread
Results 1 to 4 of 4

Correlation of the last 1250days, but starting after 750 days of non missing data

  1. #1
    Registered User
    Join Date
    06-30-2017
    Location
    Germany
    MS-Off Ver
    2016
    Posts
    2

    Post Correlation of the last 1250days, but starting after 750 days of non missing data

    Hello,

    I´ve got a quite specific problem. In order to calculate the beta of the Capital Asset Pricing Model (CAPM), I need to calculate the volatility of stock returns as well as their correlation with the S&P 500.
    Thereby I follow the approach of a specific paper ("Betting against Beta"). The volatility is calculated for the last 250 trading days and the correlation for the last 1250 days. Until this point, there is no problem.

    But: The authors start calculating the volatility/correlation as 120/750 days of non-missing data are reached.
    That means: Starting with the 120th,121th,122th,.../750th,751th,752th,... day of non-missing data, I need the volatility/correlation for the last 120,121,122,.../750,751,752,...days. The used days should rise until the "normal" 250/1250 days are reached.

    Doing it manually is almost impossible, because I use >1000 stocks, which have different dates of IPO´s/delistings. I literally have no idea how to implement the approach. Maybe a nested if- and count-if function within the volatility/correlation-function?

    I appreciate every kind of help!
    (Please excuse, that the syntax of my question might be wrong at some point. I'm not a native english speaker)

    Best Regards

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,980

    Re: Correlation of the last 1250days, but starting after 750 days of non missing data

    You can filter the data that is passed to any Array-Entered formula using nested conditionals, like =MEDIAN(IF(DateRange>IPODate+120,DataRange)) entered using Ctrl-Shift-Enter. SUMPRODUCT also allows filtering of data. How you would do that specifically depends on your data structures and what functions you want to use.

    You could also use a VBA solution - a custom User-Defined-Function that checks the values for existence (and counts) before beginning the actual calculation. How that would be done depends on how your data is arranged, and what indicates the start of the valid period of data, etc...
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    06-30-2017
    Location
    Germany
    MS-Off Ver
    2016
    Posts
    2

    Re: Correlation of the last 1250days, but starting after 750 days of non missing data

    Thank you Bernie,

    The data are structured as follows:

    I have daily price data for ~1500 stocks from 1980 to 2015. Out of those I calculate daily stock returns and index returns (value weighted by their market value). I have no specific data on the date of the IPO, it´s just the first day when prices are available. All days before and all days after delisting are marked as "#VALUE!".
    So I have to determine the IPO date with sth. like "first day unequal #VALUE!" (or if I mark them as "999", first day with data less than 999).

    The volatility of returns is calculated for the stocks itself, the correlation is calculated using the stock- and index-returns.

    Another problem would be: How can I make Excel know, when it should calculate the correlation for 120,121,....,249 and finally 250 days? When facing other problems I use auxiliary numbers, which are filled into the formula, if you know what I mean..

    What I forgot to mention: I calculate a rolling volatility/correlation, which means that I have volatility/correlation data for each day after 250/1250 (respectively 120+n/750+n) listed days.
    I hope you understand me, it's somewhat hard for me to explain it in English.

    Best regards

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,980

    Re: Correlation of the last 1250days, but starting after 750 days of non missing data

    Is an individual stock's price in a row, or in a column? Is newer at the top, or at the bottom?

    Anyway, if your prices are in a column, headers in row 1, with older at the top, then an array formula like this (entered using Ctrl-Shift-Enter):

    =XXXX(OFFSET($L$1,SMALL(IF(NOT(ISERROR($L$2:$L$30000)),ROW($L$2:$L$30000)),1)-1,0,120))

    will pass the first 120 cells after the #VALUE! entries in column L to the function XXXX.

    So, if you need to use CORREL with, say, 120 values of A and L based on values in L (again, entered using Ctrl-Shift-Enter):

    =CORREL(OFFSET($A$1,SMALL(IF(NOT(ISERROR($L$2:$L$30000)),ROW($L$2:$L$30000)),1)-1,0,120),OFFSET($L$1,SMALL(IF(NOT(ISERROR($L$2:$L$30000)),ROW($L$2:$L$30000)),1)-1,0,120))

    You could also Parameterize the formulas so that it isn't repeated - for example, put this part into cell AAA1:

    =SMALL(IF(NOT(ISERROR($L$2:$L$30000)),ROW($L$2:$L$30000)),1)

    and use

    =CORREL(OFFSET($A$1,AAA1-1,0,120),OFFSET($L$1,AAA1-1,0,120))

    You could reduce the calculational load by using that formula in a row to find all the first data points, then copying and pasting values so that it is only calculated once.
    Last edited by Bernie Deitrick; 06-30-2017 at 01:10 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Correlation analysis with missing values
    By hsapir in forum Excel General
    Replies: 7
    Last Post: 08-07-2023, 10:41 PM
  2. [SOLVED] Find days between days, but including the starting date.
    By Jocamo in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-25-2015, 10:37 PM
  3. [SOLVED] Calculate days between 2 dates and returning a blank cell if there is missing data
    By j_dinh in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-14-2013, 01:53 AM
  4. data saved for the last 10 days is missing
    By shakeer1978 in forum Excel General
    Replies: 0
    Last Post: 01-11-2013, 09:31 AM
  5. Correlation input range missing
    By leeto in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-20-2012, 10:18 AM
  6. Replies: 3
    Last Post: 07-01-2009, 11:47 PM
  7. [SOLVED] Missing Menu Bar When Starting Excel
    By MattB in forum Excel General
    Replies: 4
    Last Post: 07-07-2006, 10:10 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1