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 7046569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:39:58+00:00 2026-05-28T02:39:58+00:00

I have a database with 101 simulations for, lets say, 5 different asset classes

  • 0

I have a database with 101 simulations for, lets say, 5 different asset classes returns.

I need to write a query that will calculate the respective correlations between each of the 5 classes. Table will look something like this:

AssetClass_ID | Simulation | AssetClass_Value

Any ideas? I am struggling to get even close.

(Depending on difficulty I may end up having to tell the end user to just download all the simulations and do the stats using inbuilt EXCEL functions, but I am unlikely to be popular for doing so)

  • 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-28T02:39:59+00:00Added an answer on May 28, 2026 at 2:39 am

    Ok, with some google and some work I came up with:

    SELECT  
            AssetID_1, AssetID_2,
            ((psum - (sum1 * sum2 / n)) / sqrt((sum1sq - sum1*sum1 / n) * (sum2sq - sum2*sum2 / n))) AS [Correlation Coefficient],
            n
    FROM
            (SELECT 
                    n1.AssetClass_ID AS AssetID_1,
                    n2.AssetClass_ID AS AssetID_2,
                    SUM(n1.RunResults_Value) AS sum1,
                    SUM(n2.RunResults_Value) AS sum2,
                    SUM(n1.RunResults_Value * n1.RunResults_Value) AS sum1sq,
                    SUM(n2.RunResults_Value * n2.RunResults_Value) AS sum2sq,
                    SUM(n1.RunResults_Value * n2.RunResults_Value) AS psum,
                    COUNT(*) AS n
            FROM
                    dbo.tbl_RunResults AS n1
                    LEFT JOIN dbo.tbl_RunResults AS n2 ON n1.Simulation_ID = n2.Simulation_ID
            WHERE   
    
                    n1.AssetClass_ID  < n2.AssetClass_ID AND
                    n1.series_ID = 2332 AND
                    n2.series_ID = 2332
    
        GROUP BY
            n1.AssetClass_ID, n2.AssetClass_ID) AS step1
    ORDER BY
            AssetID_1
    

    Answers match Excel inbuilt functions so far, so good.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a database that has a bunch of stock quotes TableQuotes
I have a monster query that I'm running against a SQL SERVER 2005 database
I have a database that contains a date and we are using the MaskedEditExtender
I have a MySQL database that I have performed a couple dumps on. I
I have an existing database that was setup (for whatever reason??) to store a
Supposed that we have classes Person, Character, and PersonCharacter and their corresponding structure in
I have a ruby daemon that selects 100 records from database and do a
I'm building a Windows application that will go against a SQL 2008 database. Some
i have a database that has a list of employees of an organziation. There
Right now I am working on a new database that will show changes to

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.