Could someone explain the pctdev() function?

Hi,

Could someone give a numerical example of how the pctdev() function is used? I cannot follow the example in the Help files. I am familiar with how volatility is calculated and how standard deviation is calculated. Any help would be appreciated.

Thanks,

hoosierboy:D

The PctDev function returns a number between 0 and 1.

Ex: PctDev(50,1) >=.08 and PctDev(50,1) <=.1 will pass all issues with deviations of the daily percentage moves greaterthan or equal to 8% and lessthan or equal to 10% as calulated for the last 50 days.

EX: Frank(“PctDev(50,1)”,1,0) > 99 will pass only those top Franked issues with a rank above 99.

Test this in screener, you will find 33 issues pass the above Frank.

Hope this helps

Thanks J for your good example.

So PctDev(50,1) is essentially the daily percentage volatility looking back 50 days.

hoosierboy.

[quote]
The PctDev function returns a number between 0 and 1.
Ex: PctDev(50,1) >=.08 and PctDev(50,1) <=.1 will pass all issues with deviations of the daily percentage moves greaterthan or equal to 8% and lessthan or equal to 10% as calulated for the last 50 days.
[/quote]I share Hoosierboy’s bewilderment. What is a “deviation of a daily percentage move?”

This confusion is another fine example of inadequate documentation. First off, PctDev is stated as being expressed as a number of percentage points, not as a fraction between 0 and 1.0. But it gets worse.

Let’s consider two cases for (say) a 5 day period:
A. Closing price change is constant at +2.00% per 5-day period. (we wish!)
B. Varies back & forth, +2%, then -2%, then repeats.

If PctDev(5,n) is actually the standard deviation of % moves as advertised, then the value is 0.00 for Case A, and 2.00 for Case B. This is because standard deviation always refers to deviations from the mean, which is 2.0 in Case A and 0.0 in Case B.

On the other hand, PctDev(5,n) might actually be the root-mean-square (RMS) of percentage moves, ignoring the mean. If so, both cases have the value 2.00.

The same definitional problem applies to PctAvg. The Help page says that it’s “the average of the percentage moves
of the closing prices.” This would be 2.00 for Case A, and 0.00 for Case B. However, I suspect that it really means average of absolute values of percentage moves, which means a value of 2.00 for either case.

Marco, please clear this up by stating definitively what PctAvg and PctDev would be for my two hypothetical cases. Thanks.

Hi,

What a timely and good question! Guess what? I can’t seem to able to come up with a numeric example either! Chances are no one will come up with a specific numeric example either! I believe the ball is in the court of the person who constructed this “PctDev(m,n)” function for P123!

Only the author of this “PctDev(m,n)” knows the true definition of it, but I’d like to believe m is NOT the “number of percent moves”, but rather "the total number of bars for which we calculate the standard deviation… and n is NOT the “length in bars for the pct move”, but rather “the number of most recent bars for which we average out our standard deviation calculations”.

There’s a strong possibility this “PctDev(m,n)” function has never worked on P123’s site before, because in the last two to four weeks I’ve run hundreds of sims at this web site, trying to design a practical example of how this “PctDev(m,n)” function might work, but the more I try it, the more wildly differing results I get, and the more time I seem to waste.

Definitely, we need better documentation! If the documentation of P123 was better, perhaps, we members, would use the server of P123 a lot less often, and this would result in a fewer number of sims, which, in itself, could solve P123’s server problems!

I hope this helps.

Robert

Hello,

I’m new to P123, so please be gentle. :slight_smile:

I’ve spent (wasted) a fair amount of time trying to figure this issue out today. Given that this thread is “only” 8 years old, odds are that this has been addressed elsewhere already, but I’m tired of hunting.

So I’d like to try to answer this to see if I’ve got this right, and also to close with a question.

The only conclusion that I can see is that neither function (PctDev or PctAvg) is meant to give a true Standard Deviation of the price itself.

Other than having the average of this type of price change, I can’t see much use for it, in and of itself, since averages can hide all manner of sins.

But PctDev could be useful as a measure of how volatile prices (measured as price changes) are over any given time period of “m” moves of “n” bars (where “bar” is a day). So, in the PctDev(5,2) example given here…

https://www.portfolio123.com/doc/doc_detail.jsp?factor=PctDev&popUpFullDesc=1

We see the example of five 2-day moves, which yielded these percent changes from the price of the day that occurred 2 days earlier…

0.67, 1.64, 0.94, -2.53, -1.55

The 0.67, for example, is derived from (75.99-75.48)/75.48, which equals 0.67%. Same thing for the rest of the sequence – it’s the pct change from 2 days earlier, over a total of five 2-day “moves.” That gives us…

0.67,1.64,0.94,-2.53,-1.55

And that averages out to -0.165, as we see in the same example where PctAvg(5,2) is used, too…

https://www.portfolio123.com/doc/doc_detail.jsp?factor=PctAvg&popUpFullDesc=1

I actually get that to be -0.166, so I’ll use that number, instead, for the rest of this.

So we get the difference between the above 5 numbers and -0.166 (the mean of the 2-day price changes)…

0.836 1.806 1.106 -2.364 -1.384

And summing up their squares…

0.698896 + 3.261636 + 1.223236 + 5.588496 + 1.915456

= 12.68772

The sum of the squares is, finally, divided by n-1 (using Excel’s formula STDEV.S which assumes that this is a sample of the population).

So 12.68772/4 = 3.17193

And phew! The square root of that is 1.78%.

This gives us an indication of how volatile prices are from day to day, or 2 day period to 2 days, or week to week, or whatever.

So it does have some usefulness.

But, and this is my question, what would have been wrong to also have a function that gave us the Standard Deviation of, say the last 10 numbers (+ the 11th), which would be the equivalent (using the same example) of this function in Excel…

stdev(75.99,74.86,75.48,76.07,74.26,73.70,73.57,74.24,75.48,76.47)

That gives us a Standard Deviation of 1.03% for the last 10 daily numbers, where the SD of the prices from the mean are more directly tied to the price itself.

This could be a stupid question, but then again, I gave the newbie warning up top. :slight_smile:

But isn’t this latter the convention? I mean, if you want to talk to others in the literature (I don’t, but I’m just saying), which is conventional?

All the best,
Ken

Ken you can calculate standard deviation, volatility etc in P123. Just use the Sttdev function. Because a field is limited to 250 character you might have to create custom formulas that give you day to day log returns for the last n days. Something like
$lnreturn1 = ln(close(0))-ln(close(1))

$lnreturn10= ln(close(9))-ln(close(20))

and then in your field
stddev($lnreturn1,…,$lnreturn10)

Be careful in your last excel example you are inputting closing prices and not returns. It doesn’t have much meaning.

Thanks very much, Aurel. Good to know that it’s there.

Does this mean that PctDev does something different? Or is it just an easy-to-set method to determine Standard Deviation, with the ability to vary time spans and number of moves?

I guess I’m asking if PctDev gives the Standard Deviation of price differences for a defined number of moves, each move measured over a defined time period.

Does this function become the same thing as StdDev if the time period used is 1 day (ex., is PctDev(20,1) the 20 day daily volatility? I wasn’t sure how to use the “in” function that you described and could not find it in the A-Z guide, but I found it at this thread, which addresses StdDev more completely…

http://www.portfolio123.com/mvnforum/viewthread_thread,6995 (You helped with that one, too, so thank you again).

Do these two dovetail to be the same thing if the interval used in PctDev is set to 1 day?

Man, it’s painful pulling out high school math after all these years! Sorry, I know these are dumb, but I’m not grasping the point of PctDev and if/how/when it relates to actual SD.

All the best,
Ken

The intent of,

$lnreturn1 = ln(close(0))-ln(close(1))

looks nicer to me written as;

$lnreturn1 = ln(close(0)/close(1))

Just sayin’.

Some functional languages has a “take” function what will return the next X items in a series. I wish P123 had something like that so I could write;

take(“ln(Close(0)/Close(1)”,10) to return the %changes over the last 10 days. Of course, data items like Close(0) would need to be interpreted as occurring at some point-in-time X days back.

Then I we could write;

stddev(take(“ln(Close(0)/Close(1)”,10))

PctDev returns the standard deviation of a number of samples set in the first parameter. The second parameter is the number of day’s change in each sample.

The full description gives an example with IBM in 2006, but here’s the raw data from today, 04/17/2013, for IBM. In addition, I calculated the 2-day percentage price changes and then the standard deviation of those changes:

Date	        Close    2-Day Changes	Standard Deviation
04/16/14	196.4 	-0.6927238712	1.8641224877
04/15/14	197.02		
04/14/14	197.77	1.0680703189	
04/11/14	195.19		
04/10/14	195.68	1.2364840395	
04/09/14	196.64		
04/08/14	193.29	0.7926161548	
04/07/14	194.52		
04/04/14	191.77	-0.9196590028	
04/03/14	192.69		
04/02/14	193.55	0.5506779573	
04/01/14	194.5		
03/31/14	192.49	1.4012537534	
03/28/14	190.45		
03/27/14	189.83	-2.6712469237	
03/26/14	192.62		
03/25/14	195.04	4.4838485027	
03/24/14	188.25		
03/21/14	186.67	1.0611228412	
03/20/14	187.9		
03/19/14	184.71

The output from PctDev(10,2) for IBM is, indeed, 1.8641 today.

Ken,

You said: [quote]
I wasn’t sure how to use the “in” function that you described and could not find it in the A-Z guide.
[/quote] It is not “in”, it is the function Ln(); the natural log function.

You can use the screener to test all kinds of things that you have a question about. To compare PctDev(xx) to StdDev(xx) create a screen using the Set Variable function; SetVar() to define your variables like; SetVar(@PctDev,PctDev(20,1)) and SetVar(@StdDev,StdDev(20.1)). Then you can create a custom report for the screen, and when you run the screen the custom report will give you the value of your Set Variables.

Denny :sunglasses:

Thanks very much to wwasilev, Paul, and Denny.

PctDev is now firmly understood and reinforced. I kind of understood it, had read the Full Description help page, but was searching these forums for examples of how to use it.

Instead, I found this old thread which had never been resolved.

I finally figured it out (nothing new to y’all, though, obviously :slight_smile: ), so thought I’d answer it in greater detail than was provided in the Full Description…

http://www.portfolio123.com/mvnforum/viewthread_thread,1341_offset,0#37776

It’s still not really clear how to use it, but (if I’ve got it right), it basically measures the Standard Deviation (using the Excel-type calc of SD) of a series of price changes.

I did not see much value in PctAVG, although I’m sure others would, but PctDEV could be useful as a measure of how volatile price CHANGES are during a series of “m” moves of “n” bars.

Then I broke it down as to how the Full Description got to where it did, since prior questions seemed not to get it (it took me quite a while to get there).

For some of us just starting out, there’s a certain assumption of a knowledge level that may not be there, so some jumps may be non-obvious. I get that, not complaining – this is a sophisticated place on the Web.

I was hoping that my post added the extra explanation that previous questions may have been missing, to help future “me’s” if they hit the same snag. Adding the extra steps let me “test” my understanding with you.

I’m pretty sure I’ve got that part. And Paul, thank you for reinforcing that here.

What I couldn’t figure out is where was Standard Deviation? Aurel pointed that out, but then I got all mixed up as to whether PctDev could have any relationship with StdDev.

THAT was when I realized that I was way out of the ballpark. It’s funny how you can understand the concept of the financial use of the therm “volatility” without realizing that it’s not the standard deviation of the prices. Thanks much to Aurel for that.

Denny, you pointed out that it’s “ln” that Aurel was referencing. I can’t find that in the A-Z Guide, either. I’ve “got it” now that it’s returns and not prices that volatility calculates in the financial world, but I don’t understand why “ln” is used as opposed to square root.

By the way, that’s a great point about using the Screener and Custom Reports. That’s invaluable!

Right now, I"m settling down and working through the A-Z Guide from start to finish, instead of on an “as needed” basis, to find out more about gems I won’t discover otherwise.

Regarding “SetVar,” I could not find anything on it in the A-Z Guide, either. But the in-box help says…

Does this mean that we can create unlimited number of variables that we expect to use repeatedly? So, in the above example, do I understand that…

  1. there is no such pre-set option as “1wkRet”

  2. we can use SetVar to create “@1wkRet” which I define as being the formula you see above, AND

  3. thereafter, I can use “@1wkRet” instead of repeating that formula over and over.

Do I have this right? And can that variable also be used in other formulas, too (does omission of that from help mean “no”)? I know that formulas can’t be used within other formulas, but what about variables?

And are variables stored anywhere or do we keep a log of them somewhere else for easy reference?

This software is amazing, but I haven’t scratched the surface yet. Time to stop tinkering and just sit down and read.

Thanks very much to all for your patient help.

All the best,
Ken

Ken, you are getting there, but I will clear up a few things.

The LN() function is found in the index by selecting the “L” list. it is about 2/3 of the way down; LN() Natural Log Returns the natural log of val(ue).

you can’t “save” the SetVar(@1wkRet, 100*(Close(0)-Close(5))/Close(5)) to be used in other areas. For that you would create a Custom Formula. Go to Tools in the top line and select Custom Formula in the second line. Select New in the third line. There you can create a formula that you can use in other areas without having to re-write it over and over. The 1 week gain you referenced above could be created like this:

Name; $1WkGain, Formula; (Close(0)/Close(5) - 1) * 100

Hang in there! You are coming up to speed fast for being a member for only 2 months,
Denny :sunglasses:

Thanks very much for the encouragement, Denny.

I managed to find Ln in the “Math” listing under “Misc” in the Formula Reference area. Is that what you meant? I’m not sure what or where the “L” list is.

And now I understand SetVar (I think). You use it to set a variable that can be used in rules later in a screen. But it is not saved for re-use elsewhere. To do that, I’d save it as a Custom Formula. Do I have that right?

I understand what Ln does (straining my high school math, though). But why is it used in the instance below instead of the square root?

Thank you, again, for all the help and especially the encouragement. Quite a learning curve.

All the best,
Ken