您现在的位置:程序化交易>> 期货公式>> 金字塔等>> 其他期货软件知识>>正文内容

求助:转化代码 [金字塔]

  • 咨询内容:  

    这是一个HURET指数的代码,请求您:

    1、能不能转化成金字塔中能够计算和运行的代码吗?

    2、这个是VB代码,这个和金字塔语言的转换的关键是什么呢?

     

    'This program calculates an estimate of the Hurst coefficient.

    'Written by Martin Sewell <martin@martinsewell.com>


    Sub Hurst()


        Dim Data()

        Dim Array1()

        Dim Array2()

        Dim Mean

        Dim Result()

       

        Dim NoOfDataPoints As Integer

       

        Dim NoOfPlottedPoints As Integer

        Dim PlottedPointNo As Integer

       

        Dim NoOfPeriods As Integer

        Dim PeriodNo As Integer

       

        Dim N As Integer

        Dim i As Integer

        Dim m As Integer

        Dim logten

        Dim R

        Dim S

        Dim RS

        Dim SumSquared

       

        logten = Log(10)

       

        'Delete any previous results

        Worksheets("Data").Range("C3").Value = Null

        Worksheets("Data").Range("D:D").Value = Null

        Worksheets("Data").Range("E:E").Value = Null

       

        'Get total number of data points

        NoOfDataPoints = Worksheets("Data").Range("C1").Value

       

        ReDim Data(NoOfDataPoints)

       

        'Get data, ignoring any spaces

        i = 1

        counter = 1

        Do While counter <= NoOfDataPoints

            Set curCell = Worksheets("Data").Cells(i, 1)

            If Application.WorksheetFunction.IsNumber(curCell.Value) Then

                Data(counter) = curCell.Value

                counter = counter + 1

            End If

            i = i + 1

        Loop

       

        NoOfPlottedPoints = NoOfDataPoints - 2

        ReDim Result(NoOfPlottedPoints, 2)

       

        'Begin main loop

        For N = 3 To NoOfDataPoints

           

            totalR = 0

            totalS = 0

           

            NoOfPeriods = NoOfDataPoints - N + 1

           

            For PeriodNo = 1 To NoOfPeriods

                ReDim Array1(N)

                ReDim Array2(N)

               

                For i = 1 To N

                    Array1(i) = Data((PeriodNo - 1) + i)

                    Array2(i) = 0

                Next i


                Summ = 0

                SumSquared = 0

                For i = 1 To N

                    Summ = Summ + Array1(i)

                    SumSquared = SumSquared + ((Array1(i)) * (Array1(i)))

                   

                Next i

                Mean = Summ / N


                'STDEV

                'S = Sqr((SumSquared - (Summ * Summ) / N) / (N - 1))

                

                'STDEVP

                S = Sqr((SumSquared - (Summ * Summ) / N) / N)

               

                For i = 1 To N

                    Array1(i) = Array1(i) - Mean

                Next i

               

                For i = 1 To N

                    For j = 1 To i

                        Array2(i) = Array2(i) + Array1(j)

                    Next j

                Next i

               

                Maxi = Array2(1)

                Mini = Array2(1)

                For i = 1 To N

                    If Array2(i) > Maxi Then Maxi = Array2(i)

                    If Array2(i) < Mini Then Mini = Array2(i)

                Next i

               

                R = Maxi - Mini

                totalR = totalR + R

                totalS = totalS + S

               

            Next PeriodNo

         

            R = totalR / NoOfPeriods

            S = totalS / NoOfPeriods

            RS = R / S

         

          PlottedPointNo = N - 2

            Result(PlottedPointNo, 1) = (Log(N)) / logten

            Result(PlottedPointNo, 2) = (Log(RS)) / logten

             

        Next N

           

        Sumx = 0

        Sumy = 0

        Sumxy = 0

        Sumxx = 0

       

        For i = 1 To NoOfPlottedPoints

            Worksheets("Data").Cells(i + 6, 4).Value = Result(i, 1)

            Worksheets("Data").Cells(i + 6, 5).Value = Result(i, 2)

            Sumx = Sumx + Result(i, 1)

            Sumy = Sumy + Result(i, 2)

            Sumxy = Sumxy + (Result(i, 1)) * (Result(i, 2))

            Sumxx = Sumxx + (Result(i, 1)) * (Result(i, 1))

        Next i

       

        'Calculate Hurst coefficient

        H = (Sumxy - ((Sumx * Sumy) / NoOfPlottedPoints)) / (Sumxx - ((Sumx * Sumx) / NoOfPlottedPoints))

        Worksheets("Data").Range("C3").Value = H

       

    End Sub

     

  • 金字塔客服: 能不能把思路写出来?

 

如果以上指标公式不适用于您常用的行情软件

或者您想改编成选股公式,以便快速选出某种形态个股的话,

可以联系我们相关技术人员 QQ: 262069696  点击在线交流进行 有偿 改编!

 


【字体: 】【打印文章】【查看评论

相关文章

    没有相关内容