Registered User Joined: 9/1/2009 Posts: 14
|
Are you able to scan via Historical Volatility in Stockfinder. I like to look for stocks that have a high Statistical Volatily percentile rating of above 70 etc.
|
|
Registered User Joined: 4/20/2009 Posts: 188
|
if the formula i posted is correct, or we can get some others to verify, then we should be able to scan for HV at a given value
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You could create a Daily Historical Volatility using the following RealCode Indicator:
'# Period = UserInput.integer = 100
Static sumofsqr As Single
If CurrentIndex >= Period + 1 Then
sumofsqr += System.Math.Log(Price.Last / Price.Last(1)) ^ 2 - _
System.Math.Log(Price.Last(Period) / Price.Last(Period + 1)) ^ 2
Else If isFirstBar Then
sumofsqr = 0
Else
sumofsqr += System.Math.Log(Price.Last / Price.Last(1)) ^ 2
End If
If CurrentIndex >= Period Then
Plot = 1600 * ((sumofsqr - _
(System.Math.Log(Price.Last / Price.Last(Period)) ^ 2) / Period) / Period) ^ .5
Else
Plot = Single.NaN
End If
You could create a Daily Historical Volatility Ratio using the following RealCode Indicator:
'# ShortHV = UserInput.Integer = 6
'# LongHV = UserInput.Integer = 100
Static Sum(1) As Single
If isFirstBar Then
Sum(0) = 0
Sum(1) = 0
Else
Sum(0) += System.Math.Log(Price.Last / Price.Last(1)) ^ 2
Sum(1) += System.Math.Log(Price.Last / Price.Last(1)) ^ 2
End If
If CurrentIndex > ShortHV Then Sum(0) -= System.Math.Log(Price.Last(ShortHV) / _
Price.Last(ShortHV + 1)) ^ 2
If CurrentIndex > LongHV Then Sum(1) -= System.Math.Log(Price.Last(LongHV) / _
Price.Last(LongHV + 1)) ^ 2
If CurrentIndex >= 100 Then
Plot = ((Sum(0) - (System.Math.Log(Price.Last / Price.Last(ShortHV)) ^ 2) / _
ShortHV) / ShortHV) ^ .5 / _
((Sum(1) - (System.Math.Log(Price.Last / Price.Last(LongHV)) ^ 2) / _
LongHV) / LongHV) ^ .5
Else
Plot = Single.NaN
End If
You should be able to right-click on the Indicator and select Create Rule to create a Rule that could be Dragged and Dropped to the Watchlist to create a Scan.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 12/31/2005 Posts: 2,499
|
QUOTE (Bruce_L) You could create a Daily Historical Volatility using the following RealCode Indicator:
'# Period = UserInput.integer = 100
Static sumofsqr As Single
If CurrentIndex >= Period + 1 Then
sumofsqr += System.Math.Log(Price.Last / Price.Last(1)) ^ 2 - _
System.Math.Log(Price.Last(Period) / Price.Last(Period + 1)) ^ 2
Else If isFirstBar Then
sumofsqr = 0
Else
sumofsqr += System.Math.Log(Price.Last / Price.Last(1)) ^ 2
End If
If CurrentIndex >= Period Then
Plot = 1600 * ((sumofsqr - _
(System.Math.Log(Price.Last / Price.Last(Period)) ^ 2) / Period) / Period) ^ .5
Else
Plot = Single.NaN
End If
You could create a Daily Historical Volatility Ratio using the following RealCode Indicator:
'# ShortHV = UserInput.Integer = 6
'# LongHV = UserInput.Integer = 100
Static Sum(1) As Single
If isFirstBar Then
Sum(0) = 0
Sum(1) = 0
Else
Sum(0) += System.Math.Log(Price.Last / Price.Last(1)) ^ 2
Sum(1) += System.Math.Log(Price.Last / Price.Last(1)) ^ 2
End If
If CurrentIndex > ShortHV Then Sum(0) -= System.Math.Log(Price.Last(ShortHV) / _
Price.Last(ShortHV + 1)) ^ 2
If CurrentIndex > LongHV Then Sum(1) -= System.Math.Log(Price.Last(LongHV) / _
Price.Last(LongHV + 1)) ^ 2
If CurrentIndex >= 100 Then
Plot = ((Sum(0) - (System.Math.Log(Price.Last / Price.Last(ShortHV)) ^ 2) / _
ShortHV) / ShortHV) ^ .5 / _
((Sum(1) - (System.Math.Log(Price.Last / Price.Last(LongHV)) ^ 2) / _
LongHV) / LongHV) ^ .5
Else
Plot = Single.NaN
End If
You should be able to right-click on the Indicator and select Create Rule to create a Rule that could be Dragged and Dropped to the Watchlist to create a Scan.
Minor correction
'# ShortHV = UserInput.Integer = 6
'# LongHV = UserInput.Integer = 100
Static Sum(1) As Single
If isFirstBar Then
Sum(0) = 0
Sum(1) = 0
Else
Sum(0) += System.Math.Log(Price.Last / Price.Last(1)) ^ 2
Sum(1) += System.Math.Log(Price.Last / Price.Last(1)) ^ 2
End If
If CurrentIndex > ShortHV Then
Sum(0) -= System.Math.Log(Price.Last(ShortHV) / Price.Last(ShortHV + 1)) ^ 2
End If
If CurrentIndex > LongHV Then
Sum(1) -= System.Math.Log(Price.Last(LongHV) / Price.Last(LongHV + 1)) ^ 2
end if
If CurrentIndex >= LongHV Then
Plot = ((Sum(0) - (System.Math.Log(Price.Last / Price.Last(ShortHV)) ^ 2) / _
ShortHV) / ShortHV) ^ .5 / _
((Sum(1) - (System.Math.Log(Price.Last / Price.Last(LongHV)) ^ 2) / _
LongHV) / LongHV) ^ .5
Else
Plot = Single.NaN
End If
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
jas0501,
Thanks. We probably shouldn't assume that the person using the formula will have a longer LongHV than ShortHV however (of course I'm already making the assumption that Periods and Prices are always going to be positive...).
'# ShortHV = UserInput.Integer = 6
'# LongHV = UserInput.Integer = 100
Static Sum(1) As Single
Static Start As Integer
If isFirstBar Then
Sum(0) = 0
Sum(1) = 0
Start = System.Math.Max(ShortHV, LongHV)
Else
Sum(0) += System.Math.Log(Price.Last / Price.Last(1)) ^ 2
Sum(1) += System.Math.Log(Price.Last / Price.Last(1)) ^ 2
End If
If CurrentIndex > ShortHV Then Sum(0) -= System.Math.Log(Price.Last(ShortHV) / _
Price.Last(ShortHV + 1)) ^ 2
If CurrentIndex > LongHV Then Sum(1) -= System.Math.Log(Price.Last(LongHV) / _
Price.Last(LongHV + 1)) ^ 2
If CurrentIndex >= Start Then
Plot = ((Sum(0) - (System.Math.Log(Price.Last / Price.Last(ShortHV)) ^ 2) / _
ShortHV) / ShortHV) ^ .5 / _
((Sum(1) - (System.Math.Log(Price.Last / Price.Last(LongHV)) ^ 2) / _
LongHV) / LongHV) ^ .5
Else
Plot = Single.NaN
End If
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 9/1/2009 Posts: 14
|
Thanks guys however even though you have given me the codes/formulae etc I am brand new to stockfinder & just dont have a clue how to use the info you have given me?????
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
paul.meneghel,
To create the Daily Historical Volatility Indicator:
- Select Add Indicator | Create in RealCode.
- Give the Indicator a name and select OK.
- Replace everything the Code tab with the RealCode for Daily Historical Volatility.
- Select Apply | OK.
To create a Rule based on the Daily Historical Volatility Indicator, right-click on the Indicator and select Create Rule and set up the Rule parameters as desired. In your example of HV being above 70, you would right-click on the Indicator and select Create Rule | Greater Than Value: 70 | Apply | OK.
Rule Basics
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 9/1/2009 Posts: 14
|
it said there were some compiler errors when I pasted your formulae in
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
paul.meneghel,
What are the error messages?
Are you just pasting the following into the Code tab of a RealCode Indicator?
'# Period = UserInput.integer = 100
Static sumofsqr As Single
If CurrentIndex >= Period + 1 Then
sumofsqr += System.Math.Log(Price.Last / Price.Last(1)) ^ 2 - _
System.Math.Log(Price.Last(Period) / Price.Last(Period + 1)) ^ 2
Else If isFirstBar Then
sumofsqr = 0
Else
sumofsqr += System.Math.Log(Price.Last / Price.Last(1)) ^ 2
End If
If CurrentIndex >= Period Then
Plot = 1600 * ((sumofsqr - _
(System.Math.Log(Price.Last / Price.Last(Period)) ^ 2) / Period) / Period) ^ .5
Else
Plot = Single.NaN
End If
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 9/1/2009 Posts: 14
|
I thin I have got it, you supplied two codes so I have been able to set up 2 rules. Can you please advise me what each rule iscanning for in layman terms, is it HV above 70 or is HV in its 70th percentile
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
paul.meneghel,
The Daily Historical Volatility Indicator is returning the actual Value of the Historical Volatility. It is not a Rank based Indicator, so a Drag and Drop Rule checking for the the Indicator to be Greater Than Value: 70 would be checking for the actual Value of Historical Volatility to be above 70.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 9/1/2009 Posts: 14
|
Sorry, it was getting late & I had an early start in the morning. Is it possible to scan via a ranking, what I am looking for is a scan on HV over a minimum of 1 year & a max of 3 years ( differant scans ok). What I am trying to identify is stocks which today have a HV which is within the 70% to 100% range of the volatility to which it has operated in the last period as defined above (1 year, 3 years etc). I am an option trader & what this scan alerts me to is a sharp drop in price which bumps up the HV, IV normally also heads up & it presents me with an opportunity to sell the IV at a high price.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
paul.meneghel,
Add a Stochastic with a long enough Period to cover the desired Time Frame to the Daily Historical Volatility Indicator and check for the Stochastic being greater than 70 instead of checking for the Daily Historical Volatility Indicator being greater than 70.
Working with Stochastics
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 9/1/2009 Posts: 14
|
Bruce, thanks very much I had a look at the Stochastics video. It was very informative & I will give it a go. Jas0501 thankyou as well. The program seem great & able to do an amazing amount of things. This real code writing however is currently way over my head. Who know, I might get the hang of it as I progree. Once again thanks to you both for your efforts.
Paul
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You're welcome. Our pleasure.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 9/1/2009 Posts: 14
|
Bruce,
I tried to load the code you supplied on 7/10 as relates to the 2nd HV code which was a Daily HV Ratio. In came up with an error on line 16 & 21 which stated that the name plot is not declared. Any ideas?
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
paul.meneghel,
It reads as if you attempting to use the RealCode in a RealCode Rule instead of using it in the Code tab of a RealCode Indicator (we discussed this earlier in the topic and I was under the impression that you had figured it out).
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Guest-1 |