Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6026673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:28:47+00:00 2026-05-23T04:28:47+00:00

I need to calculate 3-day correlation. A sample matrix is given below. My problem

  • 0

I need to calculate 3-day correlation. A sample matrix is given below. My problem is that IDs may not be in the universe every day. For example, AAPL may always be in universe but a company – CCL may be in my universe for just 2 days. I would appreciate a vectorized solution. I might have to use structs/accumarray etc. here as the correlation-matrix size may vary.

% col1 = tradingDates, col2 = companyID_asInts, col3 = VALUE_forCorrelation

rawdata = [ ...

    734614 1 0.5; 
    734614 2 0.4; 
    734614 3 0.1; 

    734615 1 0.6; 
    734615 2 0.4; 
    734615 3 0.2; 
    734615 4 0.5; 
    734615 5 0.12;

    734618 1 0.11; 
    734618 2 0.9; 
    734618 3 0.2; 
    734618 4 0.1; 
    734618 5 0.33;
    734618 6 0.55; 

    734619 2 0.11; 
    734619 3 0.45; 
    734619 4 0.1; 
    734619 5 0.6; 
    734619 6 0.5;

    734620 5 0.1; 
    734620 6 0.3] ; 

‘3-day correlation’:

% 734614 & 734615 corr is ignored as this is a 3-day corr

% 734618_corr = corrcoef(IDs 1,2,3 values are used. ID 4,5,6 is ignored) -> 3X3 matrix

% 734619_corr = corrcoef(IDs 2,3,4,5 values are used. ID 1,6 is ignored) -> 3X4 matrix

% 734620_corr = corrcoef(IDs 5,6 values are used. ID 1,2,3,4 is ignored) -> 3X2 matrix

Real data covers Russel1000 universe from 1995-2011 and has over 4.1 million rows. The desired correlation is over a 20-day period.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:28:48+00:00Added an answer on May 23, 2026 at 4:28 am

    I wouldn’t try and get a vectorized solution here: the MATLAB JIT compiler means that loops can often be just as fast on recent versions of MATLAB.

    Your matrix looks a lot like a sparse matrix: does it help to convert it into that form, so that you can use array indexing? This probably only works if the data in the third column can never be 0, otherwise you’ll have to keep the current explicit list and use something like this:

    dates = unique(rawdata(:, 1));
    num_comps = max(rawdata(:, 2));
    
    for d = 1:length(dates) - 2;
        days = dates(d:d + 2);
    
        companies = true(1, num_comps);
        for curr_day = days'
            c = false(1, num_comps);
            c(rawdata(rawdata(:, 1) == curr_day, 2)) = true;
            companies = companies & c;
        end
        companies = find(companies);
    
        data = zeros(3, length(companies));
        for curr_day = 1:3
            for company = 1:length(companies)
                data(curr_day, company) = ...
                    rawdata(rawdata(:, 1) == days(curr_day) & ...
                            rawdata(:, 2) == companies(company), 3);
            end
        end
    
        corrcoef(data)
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The problem is that I need to store 1 integer every day (adding new
In order to calculate projected sales for a given day, I need to query
I need to calculate date (year, month, day) which is (for example) 18 working
I need to calculate the distance (in meters and miles) between two coordinates given
I need to calculate a java.util.Date for a beginning of a today day (00:00:00
I need to calculate the date of the first day in a calendar week,
I have rails 3 application and the following problem. I need to calculate a
I need to calculate Math.exp() from java very frequently, is it possible to get
I need to calculate averages, standard deviations, medians etc for a bunch of numerical
I need to calculate the time complexity of the following code: for (i =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.