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

  • Home
  • SEARCH
  • 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 195435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:40:55+00:00 2026-05-11T16:40:55+00:00

I am sure it’s an obvious error with my logic, but I can’t seem

  • 0

I am sure it’s an obvious error with my logic, but I can’t seem to work out what I am doing wrong. Quite simply I have an array list of security codes, I want to compute the correlation between each combination of security codes. My code is as follows:

private void crossCorr(ArrayList<String> codes, HashMap<String, Stock> stockMap){

    // iterate through the codes list and get all the cross correlations:

    Iterator<String> itr1 = codes.iterator();
    while(itr1.hasNext()){
        String code1 = itr1.next();
System.out.println("  -----  " +code1);
        Iterator<String> itr2 = codes.iterator();
        ArrayList<Double> corrs = new ArrayList<Double>();
        HashMap<String, Double> codeCorr = new HashMap<String, Double>();
        String code2="";
        double corr=-2;
        while(itr2.hasNext()){
            code2 = itr2.next();
            Maths calcs = new Maths();      
            corr = calcs.getCorrelation(stockMap.get(code1).getRorHistory(), stockMap.get(code2).getRorHistory());
            corrs.add(corr);    // we order this list and then use this ordered list
                                // to find the codes for the stocks with the highest
                                // correlation for any given stock
            codeCorr.put(code2, corr);
            System.out.println(code1+" - "+code2+" - Correlation is "+corr);
        }
        orderCorrs(6, codeCorr, corrs, code1);
    }

}

The output I get is —

—– GOOG
GOOG – GOOG – Correlation is 1.0000000000000002
GOOG – YHOO – Correlation is 0.6986623807707519
GOOG – MSFT – Correlation is 0.7275411317567286
GOOG – CSCO – Correlation is 0.8122979333663799
GOOG – AAPL – Correlation is 0.8217785260604609
GOOG – ADBE – Correlation is 0.6102679356472099
GOOG – DISH – Correlation is 0.644852624453125
GOOG – NSOL – Correlation is 0.11600387177879072
GOOG – SBUX – Correlation is 0.6694306410719489
GOOG – PSFT – Correlation is -0.09921822861087544
GOOG – XOM – Correlation is 0.6728272039489009
GOOG – WMT – Correlation is 0.4004364090315347
GOOG – IBM – Correlation is 0.7559988282095168
GOOG – JPM – Correlation is 0.7085525367336528
GOOG – DNA – Correlation is 0.13628949379947575
GOOG – HPQ – Correlation is 0.7819350018750656
GOOG – KO – Correlation is 0.5700932682157461
GOOG – VZ – Correlation is 0.737881573641585
GOOG – INTC – Correlation is 0.7654127298771953
GOOG – SPY – Correlation is 0.8042488406758052
GOOG – PEP – Correlation is 0.6297924741882344
GOOG – WFC – Correlation is 0.5064491351161948
GOOG – ABT – Correlation is 0.238752389446595
GOOG – QCOM – Correlation is 0.726356709262025
GOOG – COP – Correlation is 0.570604981251932
GOOG – MCD – Correlation is 0.5434872575410538

But I never get

YHOO – GOOG – Correlation is …. etc. etc.

I am sure this is a simple error and for some reason I am not picking it up.

I know I am doing the correlation calculations twice, I will fix this once I get this part working as intended.

Please let me know if I need to provide more info.

  • 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-11T16:40:56+00:00Added an answer on May 11, 2026 at 4:40 pm

    A quick test application having removed references to code we don’t know about works fine for me.

    Is it possible that something’s throwing an unchecked exception which you’re not handling? If you could post a short but complete program demonstrating the problem, that would help immensely. Take a copy of your full project, and just remove bits (e.g. hard-coding data and return values) until you can’t take anything else away without the problem going away too. At that point you may well have found the problem for yourself, of course.

    By the way, if you’re using Java 1.5 or greater, it’s simpler to use an extended for loop than explicitly using an iterator. You’d do:

    for (String code1 : codes) {
        // ...
        for (String code2 : codes) {
            // ...
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 274k
  • Answers 274k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would check out the UIStringDrawing Category for NSStrings which… May 13, 2026 at 2:21 pm
  • Editorial Team
    Editorial Team added an answer As far as I know there is now way to… May 13, 2026 at 2:21 pm
  • Editorial Team
    Editorial Team added an answer Standard operating procedure for consistent cross-browser Website design involves always… May 13, 2026 at 2:21 pm

Related Questions

I have a JSP page retrieving data and when single or double quotes are
I am sure it's possible to be able to drag files onto a Flash
I am sure it's an obvious error with my logic, but I can't seem
I am sure it is a piece of cake, but I can't find it
I am sure it already exists somewhere, just can't find it.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.