Download software Tutorial videos
Subscription & data-feed pricing Class schedule


New account application Trading resources
Margin rates Stock & option commissions

Attention: Discussion forums are read-only for extended maintenance until further notice.
Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

Coefficient of Variation Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
WenzelAnalytics
Posted : Thursday, June 13, 2013 11:28:09 AM
Registered User
Joined: 2/1/2005
Posts: 9

I would like to write a PCF that would calculate the average return (percent change) for the last x periods, i.e. 30.  I would like to divide that average into the standard deviation of the returns of the last x perioeds, i.e. 30.  Is it feasible to do this with a PCF?   If so, can someone point me down the path to doing so?   

Bruce_L
Posted : Thursday, June 13, 2013 12:23:36 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

The 30-period mean of a 1-period percent change could be written as:

100 * ((C / C1 + C1 / C2 + C2 / C3 + C3 / C4 + C4 / C5 + C5 / C6 + C6 / C7 + C7 / C8 + C8 / C9 + C9 / C10 + C10 / C11 + C11 / C12 + C12 / C13 + C13 / C14 + C14 / C15 + C15 / C16 + C16 / C17 + C17 / C18 + C18 / C19 + C19 / C20 + C20 / C21 + C21 / C22 + C22 / C23 + C23 / C24 + C24 / C25 + C25 / C26 + C26 / C27 + C27 / C28 + C28 / C29 + C29 / C30) / 30 - 1)

The 30-period standard deviation of 1-period percent change could be written as:

100 * SQR(ABS((C / C1) ^ 2 + (C1 / C2) ^ 2 + (C2 / C3) ^ 2 + (C3 / C4) ^ 2 + (C4 / C5) ^ 2 + (C5 / C6) ^ 2 + (C6 / C7) ^ 2 + (C7 / C8) ^ 2 + (C8 / C9) ^ 2 + (C9 / C10) ^ 2 + (C10 / C11) ^ 2 + (C11 / C12) ^ 2 + (C12 / C13) ^ 2 + (C13 / C14) ^ 2 + (C14 / C15) ^ 2 + (C15 / C16) ^ 2 + (C16 / C17) ^ 2 + (C17 / C18) ^ 2 + (C18 / C19) ^ 2 + (C19 / C20) ^ 2 + (C20 / C21) ^ 2 + (C21 / C22) ^ 2 + (C22 / C23) ^ 2 + (C23 / C24) ^ 2 + (C24 / C25) ^ 2 + (C25 / C26) ^ 2 + (C26 / C27) ^ 2 + (C27 / C28) ^ 2 + (C28 / C29) ^ 2 + (C29 / C30) ^ 2 - (C / C1 + C1 / C2 + C2 / C3 + C3 / C4 + C4 / C5 + C5 / C6 + C6 / C7 + C7 / C8 + C8 / C9 + C9 / C10 + C10 / C11 + C11 / C12 + C12 / C13 + C13 / C14 + C14 / C15 + C15 / C16 + C16 / C17 + C17 / C18 + C18 / C19 + C19 / C20 + C20 / C21 + C21 / C22 + C22 / C23 + C23 / C24 + C24 / C25 + C25 / C26 + C26 / C27 + C27 / C28 + C28 / C29 + C29 / C30) ^ 2 / 30) / 30)

The ratio of the 30-period standard devation to the 30-period mean of the a 1-period percent change could be written as:

SQR(ABS((C / C1) ^ 2 + (C1 / C2) ^ 2 + (C2 / C3) ^ 2 + (C3 / C4) ^ 2 + (C4 / C5) ^ 2 + (C5 / C6) ^ 2 + (C6 / C7) ^ 2 + (C7 / C8) ^ 2 + (C8 / C9) ^ 2 + (C9 / C10) ^ 2 + (C10 / C11) ^ 2 + (C11 / C12) ^ 2 + (C12 / C13) ^ 2 + (C13 / C14) ^ 2 + (C14 / C15) ^ 2 + (C15 / C16) ^ 2 + (C16 / C17) ^ 2 + (C17 / C18) ^ 2 + (C18 / C19) ^ 2 + (C19 / C20) ^ 2 + (C20 / C21) ^ 2 + (C21 / C22) ^ 2 + (C22 / C23) ^ 2 + (C23 / C24) ^ 2 + (C24 / C25) ^ 2 + (C25 / C26) ^ 2 + (C26 / C27) ^ 2 + (C27 / C28) ^ 2 + (C28 / C29) ^ 2 + (C29 / C30) ^ 2 - (C / C1 + C1 / C2 + C2 / C3 + C3 / C4 + C4 / C5 + C5 / C6 + C6 / C7 + C7 / C8 + C8 / C9 + C9 / C10 + C10 / C11 + C11 / C12 + C12 / C13 + C13 / C14 + C14 / C15 + C15 / C16 + C16 / C17 + C17 / C18 + C18 / C19 + C19 / C20 + C20 / C21 + C21 / C22 + C22 / C23 + C23 / C24 + C24 / C25 + C25 / C26 + C26 / C27 + C27 / C28 + C28 / C29 + C29 / C30) ^ 2 / 30) / 30) / ((C / C1 + C1 / C2 + C2 / C3 + C3 / C4 + C4 / C5 + C5 / C6 + C6 / C7 + C7 / C8 + C8 / C9 + C9 / C10 + C10 / C11 + C11 / C12 + C12 / C13 + C13 / C14 + C14 / C15 + C15 / C16 + C16 / C17 + C17 / C18 + C18 / C19 + C19 / C20 + C20 / C21 + C21 / C22 + C22 / C23 + C23 / C24 + C24 / C25 + C25 / C26 + C26 / C27 + C27 / C28 + C28 / C29 + C29 / C30) / 30 - 1)

Note that the Coefficient of Variation will not be valid if the scale of the variable for which it is being calculated can be negative. You may be better calculating this on the ratio of one price to the next than on the percent change values themselves since it will always be positive (as they are different ways to express the same relationship).



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
WenzelAnalytics
Posted : Thursday, June 13, 2013 4:12:07 PM
Registered User
Joined: 2/1/2005
Posts: 9

I'm most impressed with your work!  I'm still trying to figure out how it all works, since PDFs are relatively foreign to me. 1. When I load the indicator into a chart it appears that the C1, C2 etc. refer to the period of the chart.  So if the chart is weekly, the calculations are over the past 30 weeks.  Is there a way to get that data into a watchlist column?  The watchlist column appears to only bring in daily calculations.  I presume I could rewrite the PCF with C/C5 + C5/C10 etc. if that is the necessary way to get there.  2. Regarding the negatives, I presume you are saying that the way it is written is not a valid COV.  However, might it be more useful for trying to identify smooth momentum if I take the values starting > 0 ?  That would eliminate an overall negative value, but I'm not sure of the effect of negatives within specific periods.  Do you have thoughts on that?  Thanks again.   Lee 

Bruce_L
Posted : Thursday, June 13, 2013 4:26:57 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

You can right-click on the WatchList Column Header and select Edit Columns to adjust the Time Frame setting of a WatchList Column.

The PCF Formula Descriptions topic has a comprehensive list of the syntax which is valid in the Personal Criteria Formula Language and the Handy PCF example formulas to help you learn the syntax of PCFs! topic has basic example of this syntax in use. The Modelling Bollinger Bands (& Standard Deviation) in a TC PCF topic explores the creation of standard deviation in PCFs.

I would not suggest ignoring the negative values completely. My suggestion was to use the ratio of consecutive bars instead of percent change between consecutive bars in the calculations.

The fact that it is not a statistically valid coefficient of variation does not mean you won't find it useful. You could try using it as is. What you do is up to you.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
WenzelAnalytics
Posted : Friday, June 14, 2013 10:37:05 PM
Registered User
Joined: 2/1/2005
Posts: 9

The code supplied above has the general right format, but does not produce a standard deviation or coefficient of variation.  The adapted code below has been tested against Excel formulas.  It uses the StDev.p rather than the sample version of N-1. 

SQR((ABS((C / C1-1) ^ 2 + (C1 / C2 - 1) ^ 2 + (C2 / C3 - 1) ^ 2 + (C3 / C4 - 1) ^ 2 + (C4 / C5 - 1) ^ 2 + (C5 / C6 - 1) ^ 2 + (C6 / C7 - 1) ^ 2 + (C7 / C8 - 1) ^ 2 + (C8 / C9 - 1) ^ 2 + (C9 / C10 - 1) ^ 2 + (C10 / C11 - 1) ^ 2 + (C11 / C12 - 1) ^ 2 + (C12 / C13 - 1) ^ 2 + (C13 / C14 - 1) ^ 2 + (C14 / C15 - 1) ^ 2 + (C15 / C16 - 1) ^ 2 + (C16 / C17 - 1) ^ 2 + (C17 / C18 - 1) ^ 2 + (C18 / C19 - 1) ^ 2 + (C19 / C20 - 1) ^ 2 + (C20 / C21 - 1) ^ 2 + (C21 / C22 - 1) ^ 2 + (C22 / C23 - 1) ^ 2 + (C23 / C24 - 1) ^ 2 + (C24 / C25 - 1) ^ 2 + (C25 / C26 - 1) ^ 2 + (C26 / C27 - 1) ^ 2 + (C27 / C28 - 1) ^ 2 + (C28 / C29 - 1) ^ 2 + (C29 / C30 - 1) ^ 2)

- ((((C / C1 + C1 / C2 + C2 / C3 + C3 / C4 + C4 / C5 + C5 / C6 + C6 / C7 + C7 / C8 + C8 / C9 + C9 / C10 + C10 / C11 + C11 / C12 + C12 / C13 + C13 / C14 + C14 / C15 + C15 / C16 + C16 / C17 + C17 / C18 + C18 / C19 + C19 / C20 + C20 / C21 + C21 / C22 + C22 / C23 + C23 / C24 + C24 / C25 + C25 / C26 + C26 / C27 + C27 / C28 + C28 / C29 + C29 / C30) /30) -1) ^ 2 * 30)) /30)

 / (((C / C1 + C1 / C2 + C2 / C3 + C3 / C4 + C4 / C5 + C5 / C6 + C6 / C7 + C7 / C8 + C8 / C9 + C9 / C10 + C10 / C11 + C11 / C12 + C12 / C13 + C13 / C14 + C14 / C15 + C15 / C16 + C16 / C17 + C17 / C18 + C18 / C19 + C19 / C20 + C20 / C21 + C21 / C22 + C22 / C23 + C23 / C24 + C24 / C25 + C25 / C26 + C26 / C27 + C27 / C28 + C28 / C29 + C29 / C30) / 30) - 1)

Bruce_L
Posted : Monday, June 17, 2013 11:07:30 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

I have made significant adjustments to the formulas in my Thursday, June 13, 2013 12:23:36 PM ET post. Please try the newer formulas posted above.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Users browsing this topic
Guest-1

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.