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
    babulababula
    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
    NicolasNicolas
    Keymaster
    Legend
    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
    NicolasNicolas
    Keymaster
    Legend
    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
    LucasBestLucasBest
    Participant
    Senior
    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
    LucasBestLucasBest
    Participant
    Senior
    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
    LucasBestLucasBest
    Participant
    Senior
    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
    JSJS
    Participant
    Master

    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.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

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 JSJS
3 years, 2 months ago.

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