I can´t how to create the beta indicator cause within the indicator i don´t know how to get the var of the marekt and also how to get the cov (stock,market).
Thx
You are talking about Covariance and Variance of a data serie:
length = 10
srca = open
srcb = close
a = ((srca-srca[1])/srca[1]*100)
b = ((srcb-srcb[1])/srcb[1]*100)
aavg = average[length](a)
bavg = average[length](b)
sum = 0
for i = length downto 0 do
sum=sum+((a[i]-aavg)*(b[i]-bavg))
next
covariance = sum/(length-1)
return covariance
Variance indicator formula:
t = 10 //Lookback
k = 2 //Single VRT Sampling Period
src = customclose
x = log(src/src[1])
xk = log(src/src[k])
mean = average[t](x)
sum = 0
for i = 0 to t-1-k do
sum=sum+(square(xk[i]-mean*k))
next
m = k * (t - k + 1) * (1 - (k/t))
variance = sum/m
return variance
How is it possible to translate this instruction from Pine script, as there is only one period (length) and not 2 like in the above script for Variance ?
"ta.variance(source,length)"
Also, as standard deviation equal the square root of the variance.
Is it possible to calculate more quickly and simply the Variance with std squared ?
Variance(src,length)=STD[length](src)*STD[length](src)
Thanks
standard deviation is simply obtained by calculating the square root of the variance, is it possible to calculate more quickly and simply the Variance with std squared
Thanks
Sorry, i don”t understand why my reply appears like they did…
As STD is simply obtained by calculating the square root of the variance, is it possible to calculate more quickly and simply the Variance with std squared ?
JSParticipant
Senior
Hi,
That’s right, the variance can be found by squaring the standard deviation…
Variance= Square(Std[x](Close))