Simple Standard Deviation Command

0 126 Views No Comments 2 months ago
  • This command is used to calculate a standard deviation for a given data set.

    Note: Its a bit slow but works well enough

    • This topic was modified 1 month, 3 weeks ago by r4stl1n.
    HaasScript Code
    -- [r4stl1n] Simple Standard Deviation Command
    -- Very simple standard deviation. Pretty sure its correct
    -- Note: This is rather slow we should probably bring this to a 
    -- local command call rather than interpret it from a script
    -- You are on your own with this script
    -- ~Bored and programming series~
    DefineCommand("GetSTDev","Get the standard deviation for input array")
    local dataSetArray = DefineParameter(ListNumberType, "DataSetArray", "The dataset to calculate", true, 0)
    local currentSum = ArraySum(dataSetArray)
    local meanValue = Div(currentSum, Count(dataSetArray))
    local newArray = {}
    for i = 1, Count(dataSetArray)
        local numberToAdd = Sub(dataSetArray[i], meanValue)
        numberToAdd = Mul(numberToAdd, numberToAdd)
        newArray[i] = numberToAdd
    local newWorkingTotal = ArraySum(newArray)
    local newMeanValue = Div(newWorkingTotal, Count(newArray))
    local finalValue = Sqrt(newMeanValue)
    DefineOutput(NumberType, finalValue, "StdDev for the input array", "NumberType")
Login or Register to Comment

Unlock your crypto trading potential

Create a free account and enjoy everything we have to offer.

Join for Free