+ Reply to Thread
Results 1 to 2 of 2

Creating a rolling window Variance Covariance Matrix

  1. #1
    Registered User
    Join Date
    08-13-2018
    Location
    brighton, england
    MS-Off Ver
    2007
    Posts
    1

    Question Creating a rolling window Variance Covariance Matrix

    Hello

    I am having problems creating loops for varcovar matrix as I want it to move through a daily rolling window given: (1:1001) , (2:1002) and so on.

    I want to do the same for the linest function as well in order for it to use data in a rolling window

    This is in order to create function that uses such rolling windows to forecast day-ahead Variance which is brought by multiplying the vector output from linest by the VarCovar matrix. Could someone please help me build such code?

    I have coded the var covar matrix on VBA and the code is below:


    Function VarCovar(rng As Range) As Variant
    Dim i As Integer
    Dim j As Integer
    Dim numcols As Integer
    numcols = rng.Columns.Count
    numrows = rng.Rows.Count
    Dim matrix() As Double
    ReDim matrix(numcols - 1, numcols - 1)

    For i = 1 To numcols
    For j = 1 To numcols
    matrix(i - 1, j - 1) = Application.WorksheetFunction.Covar(rng.Columns(i), rng.Columns(j)) _
    * numrows / (numrows - 1)
    Next j
    Next i
    VarCovar = matrix
    End Function

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Creating a rolling window Variance Covariance Matrix

    I have no idea what a varcovar matrix is, but whenever I hear "rolling windows" or similar terms I think of named dynamic ranges.

    See if this wiki can help you out without having to use VBA: http://www.utteraccess.com/wiki/Offs...Dynamic_Ranges.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

+ 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. Covariance matrix from worksheet
    By uncina in forum Excel Programming / VBA / Macros
    Replies: 28
    Last Post: 01-22-2014, 12:17 PM
  2. Covariance-Variance Stock Prices - VBA code
    By Bana in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-07-2012, 06:26 PM
  3. Covariance Matrix
    By andrewc in forum Excel General
    Replies: 1
    Last Post: 09-14-2011, 09:53 AM
  4. COVARIANCE.S to build a covariance matrix
    By steve.lorimer in forum Excel General
    Replies: 6
    Last Post: 06-05-2011, 09:37 AM
  5. variance covariance matrix
    By ctallen23 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-18-2011, 01:34 AM
  6. Custom Variance and Covariance Functions
    By qwe789123 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-31-2009, 06:07 AM
  7. [SOLVED] CORRELATION / COVARIANCE MATRIX
    By Walker in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-30-2005, 02:06 AM

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