Results 1 to 7 of 7

Math Help - Create whole numbers within array

  1. #1
    Newbie
    Joined
    Oct 2010
    Posts
    4

    Create whole numbers within array

    Hi friends,

    I have an array of numbers, each number of which represents quantities of a financial instrument I must either buy or sell to create a statically hedged portfolio. Some of the numbers are not whole numbers, but rather contain values extending beyond the decimal point.

    E.g.:

    1) 102.56
    2) -79.35
    3) 34.1

    The decimal values create a problem, as one cannot buy and sell fractions of shares or contracts. Is there an equation for generating the lowest possible number by which an array could be multiplied whereby all the numbers of the array would be whole numbers? I say "lowest possible number" because it may be impractical to multiply the array by a large value, as the resulting outputs may call for higher performance bond requirements (margin). Thus, a lower multiple is preferable, all else being equal.

    Thank you very much for your consideration of this challenge. I appreciate any insights you may have to share.

    Steven
    Follow Math Help Forum on Facebook and Google+

  2. #2
    A Plied Mathematician
    Joined
    Jun 2010
    From
    CT, USA
    Posts
    6,318
    Thanks
    5
    Awards
    2
    I'm assuming, by the phrasing "array could be multiplied", that you must multiply all numbers in the array by the same factor in order to achieve integers everywhere.

    Here's one algorithm:

    Code:
    For each entry in the array:
       count the number of decimal places, 
    
    
    
    
    n, that are present
       Let 
    
    
    
    
    x be the numbers beyond the decimal place, expressed as an integer
       let 
    
    
    
    
    y_{n} = 10^n / \gcd(10^n, x)
    Let 
    
    
    
    
    y = \text{lcm}(y_1, y_2, ... , y_n)
    Then y is the number you're after.

    Here's your three numbers as an example:

    For 102.56, n=2. Let x=56. Then y_{1}=10^{2}/\gcd(10^{2},56)=100/4=25. (Check: 102.56\times 25=2564, an integer.)

    For -79.35, n=2. Let x=35. Then y_{2}=10^{2}/\gcd(10^{2},35)=100/5=20. (Check: -79.35\times 20=-1587, an integer.)

    For 34.1, n=1. Let x=1. Then y_{3}=10^{1}/\gcd(10^{1},1)=10/1=10. (Check: 34.1\times 10=341, an integer.)

    Finally, let y=\text{lcm}(y_{1},y_{2},y_{3})=\text{lcm}(25,20,1  0)=100, which certainly works for your situation. You could dream up an example where the final factor is less than that, but your numbers beyond the decimals would have to have more factors in common than your example.

    Does this make sense?
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Oct 2010
    Posts
    4
    Thank you so much, Dr. Keister! Your solution makes perfect sense. I'm so impressed that you were able to dream this up. I wish I knew enough about math to think of such ideas.

    I think I could extend the numbers a few more decimal places out, which would perhaps create higher GCDs, resulting in a lower LCM.

    Thanks again,

    Steven
    Follow Math Help Forum on Facebook and Google+

  4. #4
    A Plied Mathematician
    Joined
    Jun 2010
    From
    CT, USA
    Posts
    6,318
    Thanks
    5
    Awards
    2
    You're welcome. Have a good one!
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Newbie
    Joined
    Oct 2010
    Posts
    4
    Hi again Ackbeet,

    I had meant to ask what should be done if the first number(s) beyond the decimal point are zeros. Should I just omit the zero(s) in expressing the fractions as integers? If I do omit the zero(s), does n correspond to the number of decimal places with or without the zero? For example, if I were using the number 102.056, and assuming I should just omit the zero, would I solve for y_1 by: = 10^3/GCD(10^3, 56) , or would it be: =10^2/GCD(10^2, 56) ?

    Thanks again for your philanthropy in being of assistance to others in need in this forum.

    Steven
    Follow Math Help Forum on Facebook and Google+

  6. #6
    A Plied Mathematician
    Joined
    Jun 2010
    From
    CT, USA
    Posts
    6,318
    Thanks
    5
    Awards
    2
    For example, if I were using the number 102.056, and assuming I should just omit the zero, would I solve for y_1 by: = 10^3/GCD(10^3, 56) , or would it be: =10^2/GCD(10^2, 56) ?
    You should do the first one.

    You're very welcome for any help I can provide.
    Follow Math Help Forum on Facebook and Google+

  7. #7
    Newbie
    Joined
    Oct 2010
    Posts
    4
    OK, great, Dr. Keister. I now know just how to proceed, thanks to you.

    Steven
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Array Help
    Posted in the LaTeX Help Forum
    Replies: 1
    Last Post: January 31st 2011, 07:42 AM
  2. Replies: 1
    Last Post: November 20th 2009, 11:46 PM
  3. array help
    Posted in the LaTeX Help Forum
    Replies: 1
    Last Post: October 12th 2008, 05:42 PM
  4. array
    Posted in the LaTeX Help Forum
    Replies: 3
    Last Post: October 8th 2008, 01:43 PM
  5. Array of Numbers
    Posted in the Discrete Math Forum
    Replies: 0
    Last Post: November 24th 2006, 08:33 PM

Search Tags


/mathhelpforum @mathhelpforum