It is possible to code the beta(cov(x,,y)/var(y))? variance and covariance

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #152990 quote
    babula
    Participant
    New

    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

    #153090 quote
    Nicolas
    Keymaster
    Master

    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
    #153092 quote
    Nicolas
    Keymaster
    Master

    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
    
    
    #219339 quote
    LucasBest
    Participant
    Average

    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
    #219340 quote
    LucasBest
    Participant
    Average

    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

    #219342 quote
    LucasBest
    Participant
    Average

    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 ?

    #219344 quote
    JS
    Participant
    Senior

    Hi,

    That’s right, the variance can be found by squaring the standard deviation…

    Variance= Square(Std[x](Close))

    LucasBest thanked this post
Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.

It is possible to code the beta(cov(x,,y)/var(y))? variance and covariance


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
babula @babula Participant
Summary

This topic contains 6 replies,
has 4 voices, and was last updated by JS
2 years, 5 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 12/08/2020
Status: Active
Attachments: No files
Logo Logo
Loading...