Skip to content

Variance

VAR calculates the statistical variance of a set of values.

Method

tm.ta.var(source, timeperiod, nbdev)

Inputs

ParameterArgument typeDescriptionDefault Value
sourcepd.SeriesInput data series-
timeperiodintNumber of periods for the indicator5
nbdevfloatNumber of deviations for the indicator1

Outputs

OutputType
varnp.ndarray

Example usage

strategy.py
import tradomate as tm
@tm.strategy()
def my_strategy(config: tm.TradomateConfig, data: tm.TradomateData):
# Trying out Variance
var = tm.ta.var(data.close, timeperiod=5, nbdev=1)
# Get the last value and print
last_value = var.iloc[-1]
tm.log(f"Last value of Variance is {last_value}")
# Plot the values of var
tm.plot(var, title="Variance", overlay=False)