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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:06:05+00:00 2026-05-13T15:06:05+00:00

Thanks for the answers, I have not used StackOverflow before so I was suprised

  • 0

Thanks for the answers, I have not used StackOverflow before so I was suprised by the number of answers and the speed of them – its fantastic.

I have not been through the answers properly yet, but thought I should add some information to the problem specification. See the image below.

I can’t post an image in this because i don’t have enough points but you can see an image
at http://journal.acquitane.com/2010-01-20/image003.jpg

This image may describe more closely what I’m trying to achieve. So you can see on the horizontal lines across the page are price points on the chart. Now where you get a clustering of lines within 0.5% of each, this is considered to be a good thing and why I want to identify those clusters automatically. You can see on the chart that there is a cluster at S2 & MR1, R2 & WPP1.

So everyday I produce these price points and then I can identify manually those that are within 0.5%. – but the purpose of this question is how to do it with a python routine.

I have reproduced the list again (see below) with labels. Just be aware that the list price points don’t match the price points in the image because they are from two different days.

[YR3,175.24,8]
[SR3,147.85,6]
[YR2,144.13,8]
[SR2,130.44,6]
[YR1,127.79,8]
[QR3,127.42,5]
[SR1,120.94,6]
[QR2,120.22,5]
[MR3,118.10,3]
[WR3,116.73,2]
[DR3,116.23,1]
[WR2,115.93,2]
[QR1,115.83,5]
[MR2,115.56,3]
[DR2,115.53,1]
[WR1,114.79,2]
[DR1,114.59,1]
[WPP,113.99,2]
[DPP,113.89,1]
[MR1,113.50,3]
[DS1,112.95,1]
[WS1,112.85,2]
[DS2,112.25,1]
[WS2,112.05,2]
[DS3,111.31,1]
[MPP,110.97,3]
[WS3,110.91,2]
[50MA,110.87,4]
[MS1,108.91,3]
[QPP,108.64,5]
[MS2,106.37,3]
[MS3,104.31,3]
[QS1,104.25,5]
[SPP,103.53,6]
[200MA,99.42,7]
[QS2,97.05,5]
[YPP,96.68,8]
[SS1,94.03,6]
[QS3,92.66,5]
[YS1,80.34,8]
[SS2,76.62,6]
[SS3,67.12,6]
[YS2,49.23,8]
[YS3,32.89,8]

I did make a mistake with the original list in that Group C is wrong and should not be included. Thanks for pointing that out.

Also the 0.5% is not fixed this value will change from day to day, but I have just used 0.5% as an example for spec’ing the problem.

Thanks Again.
Mark

PS. I will get cracking on checking the answers now now.

Hi:

I need to do some manipulation of stock prices. I have just started using Python, (but I think I would have trouble implementing this in any language). I’m looking for some ideas on how to implement this nicely in python.

Thanks
Mark

Problem:
I have a list of lists (FloorLevels (see below)) where the sublist has two items (stockprice, weight). I want to put the stockprices into groups when they are within 0.5% of each other. A groups strength will be determined by its total weight. For example:

Group-A
115.93,2
115.83,5
115.56,3
115.53,1
-------------
TotalWeight:12
-------------
Group-B
113.50,3
112.95,1
112.85,2
-------------
TotalWeight:6
-------------    

FloorLevels[   
[175.24,8]
[147.85,6]
[144.13,8]
[130.44,6]
[127.79,8]
[127.42,5]
[120.94,6]
[120.22,5]
[118.10,3]
[116.73,2]
[116.23,1]
[115.93,2]
[115.83,5]
[115.56,3]
[115.53,1]
[114.79,2]
[114.59,1]
[113.99,2]
[113.89,1]
[113.50,3]
[112.95,1]
[112.85,2]
[112.25,1]
[112.05,2]
[111.31,1]
[110.97,3]
[110.91,2]
[110.87,4]
[108.91,3]
[108.64,5]
[106.37,3]
[104.31,3]
[104.25,5]
[103.53,6]
[99.42,7]
[97.05,5]
[96.68,8]
[94.03,6]
[92.66,5]
[80.34,8]
[76.62,6]
[67.12,6]
[49.23,8]
[32.89,8]
]
  • 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-13T15:06:06+00:00Added an answer on May 13, 2026 at 3:06 pm

    I suggest a repeated use of k-means clustering — let’s call it KMC for short. KMC is a simple and powerful clustering algorithm… but it needs to “be told” how many clusters, k, you’re aiming for. You don’t know that in advance (if I understand you correctly) — you just want the smallest k such that no two items “clustered together” are more than X% apart from each other. So, start with k equal 1 — everything bunched together, no clustering pass needed;-) — and check the diameter of the cluster (a cluster’s “diameter”, from the use of the term in geometry, is the largest distance between any two members of a cluster).

    If the diameter is > X%, set k += 1, perform KMC with k as the number of clusters, and repeat the check, iteratively.

    In pseudo-code:

    def markCluster(items, threshold):
        k = 1
        clusters = [items]
        maxdist = diameter(items)
        while maxdist > threshold:
            k += 1
            clusters = Kmc(items, k)
            maxdist = max(diameter(c) for c in clusters)
        return clusters
    

    assuming of course we have suitable diameter and Kmc Python functions.

    Does this sound like the kind of thing you want? If so, then we can move on to show you how to write diameter and Kmc (in pure Python if you have a relatively limited number of items to deal with, otherwise maybe by exploiting powerful third-party add-on frameworks such as numpy) — but it’s not worthwhile to go to such trouble if you actually want something pretty different, whence this check!-)

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

Sidebar

Related Questions

I have not used PackedArray before, but just started looking at using them from
This post on SO answers most of the questions I have (much thanks to
Can anyone help me with this? I have not been able to find anything
EDIT: I'm still waiting for more answers. Thanks! In SQL 2000 days, I used
I have a difficult problem. Difficult means I searched through the net and StackOverflow
Thanks for your answers to my previous question about GUI in java . I
SOLVED I misspelled the property department -> Department. Thanks for the answers and a
Why new()/delete() is slower than malloc()/free()? EDIT: Thanks for the answers so far. Please
Thanks for looking, all helpful answers are voted up. This is my markup. I'm
Thanks for looking. All sincerely helpful answers are voted up. I use a password

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.