返回列表 上一主題 發帖

[發問] 如何使用巨集自動計算股價漲跌停價?

大大應該先舉例說一下
哪一日的值計算有錯誤
而正確的值應該又是多少

TOP

大大我照你公式翻譯而已

Public Function 漲跌停價(昨收,  漲or跌 As Long)

漲跌停價 = ""
If 昨收 = "" Then Exit Function

   Price_Sample = Array(0, 10, 50, 100, 500, 1000)
interval_Sample = Array(0.01, 0.05, 0.1, 0.5, 1, 5)

interval = Application.WorksheetFunction.Lookup(昨收, Price_Sample, interval_Sample)

If 漲or跌 > 0 Then 漲跌停價 = Application.WorksheetFunction.Floor(昨收 * 1.1, interval)
If 漲or跌 < 0 Then 漲跌停價 = Application.WorksheetFunction.Ceiling(昨收 * 0.9, interval)

End Function

TOP

本帖最後由 jackyq 於 2016-4-25 09:15 編輯

回復 5# shuasa

我有理解錯歐     

應該這樣才對

Public Function 漲跌停價(昨收,  漲or跌 As Long)

漲跌停價 = ""
If 昨收 = "" Then Exit Function
if 漲or跌 = 0 Then Exit Function

   Price_Sample = Array(0, 10, 50, 100, 500, 1000)
interval_Sample = Array(0.01, 0.05, 0.1, 0.5, 1, 5)

漲跌停價 = 昨收 * ( 1 + sgn( 漲or跌 )   )  * 0.1
interval = Application.WorksheetFunction.Lookup(漲跌停價, Price_Sample, interval_Sample)

If 漲or跌 > 0 Then 漲跌停價 = Application.WorksheetFunction.Floor(漲跌停價 , interval)
If 漲or跌 < 0 Then 漲跌停價 = Application.WorksheetFunction.Ceiling(漲跌停價 , interval)

End Function

TOP

跌停一定要用 Ceiling 不能用 floor

TOP

回復 8# jackyq

挖哩勒 !!!!  0.1 放錯位置

再更正一次

Public Function 漲跌停價(昨收,  漲or跌 As Long)

漲跌停價 = ""
If 昨收 = "" Then Exit Function
if 漲or跌 = 0 Then Exit Function

   Price_Sample = Array(0, 10, 50, 100, 500, 1000)
interval_Sample = Array(0.01, 0.05, 0.1, 0.5, 1, 5)

漲跌停價 = 昨收 * ( 1 + sgn( 漲or跌 )  * 0.1  )  
interval = Application.WorksheetFunction.Lookup(漲跌停價, Price_Sample, interval_Sample)

If 漲or跌 > 0 Then 漲跌停價 = Application.WorksheetFunction.Floor(漲跌停價 , interval)
If 漲or跌 < 0 Then 漲跌停價 = Application.WorksheetFunction.Ceiling(漲跌停價 , interval)

End Function

TOP

        靜思自在 : 做該做的事是智慧,做不該做的事是愚癡。
返回列表 上一主題