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
Bookmarks