Results 1 to 4 of 4

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

Threaded 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.

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