+ Reply to Thread
Results 1 to 4 of 4

this function only works for 2 out of 3 of my stocks

Hybrid View

  1. #1
    Registered User
    Join Date
    05-28-2022
    Location
    Sydney
    MS-Off Ver
    microsoft 365
    Posts
    1

    this function only works for 2 out of 3 of my stocks

    Function Bubble_Finder_Exp(StockPrices, Dates, StepSize, nobubbles)
    
    'check the speed of these stocks
    Dim var1 As Integer
    var1 = StockPrices.Cells.Count
    Dim var2 As Integer
    var2 = var1 - 1
    Dim Momentum() As Double
    ReDim Momentum(1 To var2, 1 To 1)
    For i = 1 To var2
    Momentum(i, 1) = StockPrices.Cells(i + 1, 1) / StockPrices.Cells(i, 1) - 1
    Next i
    'Here's the memory core, make sure you remember it!
    Dim small_lil_nums() As Double
    ReDim small_lil_nums(1 To nobubbles, 1 To 2)
    'Take that BIG step, i ain't got time to waste with these little stpes
    big_step = StepSize
    For i = 1 To var2 Step big_step
    'which one small? find out on the next episode of YU-Gi-OH!!!
    If Momentum(i, 1) < small_lil_nums(2, 1) Then
    'WOwee! If its smaller than the smallest one as well we better remember that
    If Momentum(i, 1) < small_lil_nums(1, 1) Then
    'Commence remember.exe of LIL NUMBERS
    small_lil_nums(2, 1) = small_lil_nums(1, 1)
    small_lil_nums(2, 2) = small_lil_nums(1, 2)
    'Smol number still loading...
    small_lil_nums(1, 1) = Momentum(i, 1)
    small_lil_nums(1, 2) = i
    Else
    ' That numbers not quite super small but it is still pretty small so I guess ill remember it
    small_lil_nums(2, 1) = Momentum(i, 1)
    small_lil_nums(2, 2) = Dates(i, 1)
    End If
    End If
    Next i
    'check the little numbers to see if we can find an even littler number
    Dim The_real_small() As Double
    ReDim The_real_small(1 To 2, 1 To 2)
    Dim small_set As Integer
    small_set = 3
    For j = 1 To 2
    For i = (small_lil_nums(j, 2) - small_set) To (small_lil_nums(j, 2) + small_set)
    If Momentum(i, 1) < The_real_small(j, 1) Then
    The_real_small(j, 1) = Momentum(i, 1)
    The_real_small(j, 2) = i
    End If
    Next i
    Next j
    'who be blowing bubbles, lets find out as a team
    Dim deviation As Double
    Dim how_much_difference As Double
    how_much_difference = 0
    Dim walk_sum As Double
    For i = 1 To var2
    walk_sum = walk_sum + Momentum(i, 1)
    Next i
    Dim X_Bar As Double
    X_Bar = walk_sum / var2
    For i = 1 To var2
    how_much_difference = how_much_difference + (Momentum(i, 1) - X_Bar) ^ 2
    Next i
    deviation = (how_much_difference / (var2 - 1)) ^ 0.5
    Dim Fast_burst As Integer
    Dim Slow_burst As Integer
    Dim bubble_go_boom() As Variant
    ReDim bubble_go_boom(1 To 2, 1 To 1)
    For j = 1 To 2
    'is there a bubble to pop? see here for more!
    For i = (The_real_small(j, 2) - 3) To (The_real_small(j, 2) + 3)
    If Momentum(i, 1) < (X_Bar - 4 * deviation) Then
    Fast_burst = Fast_burst + 1
    ElseIf Momentum(i, 1) < (X_Bar - deviation) Then
    Slow_burst = Slow_burst + 1
    End If
    Next i
    'how_much_difference bubble points
    Bubble_burst = 2 * Fast_burst + Slow_burst
    'define bubble type
    If Bubble_burst > WorksheetFunction.Floor(small_set * 1.5, 1) Then
    bubble_go_boom(j, 1) = "Large Bubble Burst"
    ElseIf Bubble_burst > small_set Then
    bubble_go_boom(j, 1) = "Standard Bubble Burst"
    ElseIf Bubble_burst > WorksheetFunction.Floor(small_set * 0.5, 1) Then
    bubble_go_boom(j, 1) = "Partial Bubble Burst"
    Else
    bubble_go_boom(j, 1) = "No Bubble/No Burst"
    End If
    Fast_burst = 0
    Slow_burst = 0
    Next j
    'Scream what we found to the world
    Dim results() As String
    ReDim results(1 To 2 + 1, 1 To 5)
    results(1, 1) = "Average Momentum"
    results(2, 1) = Format(X_Bar, "0.000000000")
    results(3, 1) = ""
    results(1, 2) = "Momentum Std Dev"
    results(2, 2) = Format(deviation, "0.000000000")
    results(3, 2) = ""
    For i = 3 To 2 + 1
    results(i, 1) = ""
    results(i, 2) = ""
    Next i
    results(1, 3) = "Local Min Momentum"
    results(1, 4) = "Local Min Location"
    results(1, 5) = "Bubble Burst Found"
    For i = 1 To 2
    results(i + 1, 3) = Format(The_real_small(i, 1), "0.000000000")
    results(i + 1, 4) = Dates(The_real_small(i, 2) + 1, 1)
    results(i + 1, 5) = bubble_go_boom(i, 1)
    Next i
    Bubble_Finder_Exp = results()
    
    End Function
    Last edited by AliGW; 05-28-2022 at 04:20 AM. Reason: Code tags added.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,448

    Re: this function only works for 2 out of 3 of my stocks

    Welcome to the forum.

    Please don't just dump a whole load of code into a post and expect someone to be able to help you without a clear explanation of the issue.

    Administrative Note:

    You need to include code tags around your code.

    Please take a moment to add the tags. Posting code between [code] [/code] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. As you are new here I have done it for you this time.)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,869

    Re: this function only works for 2 out of 3 of my stocks

    I will agree with AliGW, we cannot help debug this without some detail about what "works" and "does not work" mean.

    I will add, though, that a big part (half??) of programming is debugging. Are you familiar with VBA's debugging tools (quick tutorial here: http://www.cpearson.com/excel/DebuggingVBA.aspx?em_x=22 )? I find that one of the first things I will do with something like this (whether my own code or someone else's) is to put a Stop statement or breakpoint at the top of the function (and, as debugging goes on, elsewhere in the function procedure) so VBA can enter debug mode and I can debug the procedure. The basic idea of debugging is to execute the procedure one statement at a time and identify which statements are doing something unexpected. Then figure out why the logic of that statement is incorrect and come up with a new statement that is correct.

    Hopefully that will help get you started debugging on your own.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  4. #4
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,331

    Re: this function only works for 2 out of 3 of my stocks

    I suggest uploading a sample file and explaining in step by step detail...ignoring your code...what it is you are wanting to achieve...Showing a before | after scenario...
    99% of the time, a simplified solution can be offered...
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Index function works in the first row but not the others
    By mehmetics in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-26-2018, 12:39 PM
  2. Why this function not works
    By gargigargi in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-14-2016, 09:47 AM
  3. Replies: 13
    Last Post: 04-08-2014, 05:46 AM
  4. Function works in one worksheet but not another
    By KCFractal in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-09-2012, 08:20 PM
  5. .Find sub works but not function
    By mattflow in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-15-2010, 03:07 PM
  6. Function for top 10 list, Mode function works for first and then?
    By Imiel in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 05-31-2007, 06:50 AM
  7. [SOLVED] Creating a Macros function but co9ntent of function only works in a sub plz help
    By Alexandre Brisebois (www.pointnetsolutions.com) in forum Excel General
    Replies: 6
    Last Post: 07-20-2005, 04:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1