[R-SIG-Finance] (TTR) chaikinVolatility problems

Mark Knecht markknecht at gmail.com
Mon Sep 14 22:59:36 CEST 2009


That's great input Josh. Thanks.

I'm now wondering if there's a simple function to call that will tell
me the date range that is valid to use for a function's that require
high and low data? I suppose I could construct something that look for
Hi-Lo==0, but maybe it's already in one of these packages somewhere?

Thanks,
Mark

On Mon, Sep 14, 2009 at 1:50 PM, Joshua Ulrich <josh.m.ulrich at gmail.com> wrote:
> Mark,
>
> It's because the daily data is used to create the weekly data.  You'll
> notice that the weekly high / low is the daily maximum / minimum
> within each week.  You can use to.weekly (from xts) to replicate TS's
> weekly OHLC data from their daily data.
>
> I've generally found that HL data is sparse before 1980-ish, so don't
> look for it too hard (and let me know if you find it). ;-)
>
> Best,
> Josh
> --
> http://www.fosstrading.com
>
>
>
> On Mon, Sep 14, 2009 at 3:44 PM, Mark Knecht <markknecht at gmail.com> wrote:
>> Josh,
>>   I don't know why I didn't see that. I'll have to investigate why
>> the TS weekly data has OHLC values but the Daily does not.
>>
>>   Thanks for pointing that out and sorry for wasting bandwidth.
>>
>> Cheers,
>> Mark
>>
>> Weekly:
>>
>> "Date","Time","Open","High","Low","Close","Vol","OI"
>> 01/08/1960,1300,59.91,60.39,59.50,59.50,18028,0
>> 01/15/1960,1300,58.77,58.77,58.08,58.38,17680,0
>> 01/22/1960,1300,57.89,57.89,57.07,57.38,14219,0
>> 01/29/1960,1300,56.78,56.86,55.61,55.61,14006,0
>> 02/05/1960,1300,55.96,56.82,55.96,55.98,14076,0
>> 02/12/1960,1300,55.32,55.84,55.18,55.46,13483,0
>>
>> Daily for same time period:
>>
>> "Date","Time","Open","High","Low","Close","Vol","OI","FastAvg","SlowAvg"
>> 01/04/1960,1300,59.91,59.91,59.91,59.91,3988,0,0.00,0.00
>> 01/05/1960,1300,60.39,60.39,60.39,60.39,3712,0,0.00,0.00
>> 01/06/1960,1300,60.13,60.13,60.13,60.13,3730,0,0.00,0.00
>> 01/07/1960,1300,59.69,59.69,59.69,59.69,3311,0,0.00,0.00
>> 01/08/1960,1300,59.50,59.50,59.50,59.50,3287,0,0.00,0.00
>> 01/11/1960,1300,58.77,58.77,58.77,58.77,3466,0,0.00,0.00
>> 01/12/1960,1300,58.41,58.41,58.41,58.41,3764,0,0.00,0.00
>> 01/13/1960,1300,58.08,58.08,58.08,58.08,3468,0,0.00,0.00
>> 01/14/1960,1300,58.40,58.40,58.40,58.40,3560,0,0.00,0.00
>> 01/15/1960,1300,58.38,58.38,58.38,58.38,3422,0,0.00,0.00
>> 01/18/1960,1300,57.89,57.89,57.89,57.89,3019,0,0.00,0.00
>> 01/19/1960,1300,57.27,57.27,57.27,57.27,3096,0,0.00,0.00
>> 01/20/1960,1300,57.07,57.07,57.07,57.07,2717,0,0.00,0.00
>> 01/21/1960,1300,57.21,57.21,57.21,57.21,2697,0,0.00,0.00
>> 01/22/1960,1300,57.38,57.38,57.38,57.38,2690,0,0.00,0.00
>> 01/25/1960,1300,56.78,56.78,56.78,56.78,2793,0,0.00,0.00
>> 01/26/1960,1300,56.86,56.86,56.86,56.86,3062,0,0.00,0.00
>> 01/27/1960,1300,56.72,56.72,56.72,56.72,2463,0,0.00,0.00
>> 01/28/1960,1300,56.13,56.13,56.13,56.13,2627,0,0.00,0.00
>> 01/29/1960,1300,55.61,55.61,55.61,55.61,3061,0,0.00,0.00
>> 02/01/1960,1300,55.96,55.96,55.96,55.96,2825,0,0.00,0.00
>> 02/02/1960,1300,56.82,56.82,56.82,56.82,3077,0,0.00,0.00
>> 02/03/1960,1300,56.32,56.32,56.32,56.32,3022,0,0.00,0.00
>> 02/04/1960,1300,56.27,56.27,56.27,56.27,2617,0,0.00,0.00
>> 02/05/1960,1300,55.98,55.98,55.98,55.98,2535,0,0.00,0.00
>> 02/08/1960,1300,55.32,55.32,55.32,55.32,3348,0,0.00,0.00
>> 02/09/1960,1300,55.84,55.84,55.84,55.84,2859,0,0.00,0.00
>> 02/10/1960,1300,55.49,55.49,55.49,55.49,2441,0,0.00,0.00
>> 02/11/1960,1300,55.18,55.18,55.18,55.18,2606,0,0.00,0.00
>> 02/12/1960,1300,55.46,55.46,55.46,55.46,2229,0,0.00,0.00
>>
>> On Mon, Sep 14, 2009 at 1:25 PM, Joshua Ulrich <josh.m.ulrich at gmail.com> wrote:
>>> Hi Mark,
>>>
>>> The limitation is in the way the indicator is constructed.  It
>>> measures the rate of change of the trading range.  It's failing
>>> because, at least for the observations you've shown, the trading range
>>> is *zero*.  Please report back if you still have issues if you apply
>>> the indicator over values with non-zero differences.
>>>
>>> HTH,
>>> Josh
>>> --
>>> http://www.fosstrading.com
>>>
>>>
>>>
>>> On Mon, Sep 14, 2009 at 3:11 PM, Mark Knecht <markknecht at gmail.com> wrote:
>>>> Hi,
>>>>   I'm wondering if there are any know limitations with the TTR
>>>> chaikinVolatility function I should be aware of. I've got a small
>>>> application I've been writing in R that uses it. I debugged the app
>>>> using weekly data for the SPX, DJI, Nasdaq and Russell going back as
>>>> far as TradeStation would give me data. Everything worked great.
>>>> However when I switched to SPX daily data the indicator fails for the
>>>> first 1/3 to 1/2 of the data. (Roughly 12400 days) Looking into the
>>>> data output of the indicator I see this:
>>>>
>>>>  [4465]  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
>>>> 0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
>>>>  [4483]  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
>>>> 0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
>>>>  [4501]  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
>>>> 0.00   Inf   Inf   Inf   Inf   Inf   Inf   Inf
>>>>  [4519]   Inf   Inf   Inf   Inf   Inf   Inf  3.83  1.75  0.78  0.46
>>>> 0.35  0.20  0.15  0.12  0.12  0.12  0.09  0.03
>>>>  [4537]  0.01  0.05  0.03  0.02  0.00 -0.04 -0.03 -0.06 -0.07 -0.09
>>>> -0.13 -0.12 -0.07 -0.02 -0.02 -0.01 -0.02  0.01
>>>>  [4555] -0.01 -0.01 -0.01 -0.01  0.04  0.08  0.11  0.09  0.04  0.06
>>>> 0.06  0.10  0.08  0.07  0.05  0.07  0.04 -0.03
>>>>
>>>>   After the indicator starts working it continues to work, but it's
>>>> all 0.00 back to the beginning except for these few Inf's in the
>>>> middle.
>>>>
>>>>   When I broke the code out to try to debug it before I wrote this
>>>> email I got somewhat different results with NaN's:
>>>>
>>>>> head(TradeSystem, n=40)
>>>>         Date Time  Open  High   Low Close  Vol OI FastAvg SlowAvg
>>>> MyDate ChVol
>>>> 1  01/04/1960 1300 59.91 59.91 59.91 59.91 3988  0       0       0
>>>> 1960-01-04    NA
>>>> 2  01/05/1960 1300 60.39 60.39 60.39 60.39 3712  0       0       0
>>>> 1960-01-05    NA
>>>> 3  01/06/1960 1300 60.13 60.13 60.13 60.13 3730  0       0       0
>>>> 1960-01-06    NA
>>>> 4  01/07/1960 1300 59.69 59.69 59.69 59.69 3311  0       0       0
>>>> 1960-01-07    NA
>>>> 5  01/08/1960 1300 59.50 59.50 59.50 59.50 3287  0       0       0
>>>> 1960-01-08    NA
>>>> 6  01/11/1960 1300 58.77 58.77 58.77 58.77 3466  0       0       0
>>>> 1960-01-11    NA
>>>> 7  01/12/1960 1300 58.41 58.41 58.41 58.41 3764  0       0       0
>>>> 1960-01-12    NA
>>>> 8  01/13/1960 1300 58.08 58.08 58.08 58.08 3468  0       0       0
>>>> 1960-01-13    NA
>>>> 9  01/14/1960 1300 58.40 58.40 58.40 58.40 3560  0       0       0
>>>> 1960-01-14    NA
>>>> 10 01/15/1960 1300 58.38 58.38 58.38 58.38 3422  0       0       0
>>>> 1960-01-15    NA
>>>> 11 01/18/1960 1300 57.89 57.89 57.89 57.89 3019  0       0       0
>>>> 1960-01-18    NA
>>>> 12 01/19/1960 1300 57.27 57.27 57.27 57.27 3096  0       0       0
>>>> 1960-01-19    NA
>>>> 13 01/20/1960 1300 57.07 57.07 57.07 57.07 2717  0       0       0
>>>> 1960-01-20    NA
>>>> 14 01/21/1960 1300 57.21 57.21 57.21 57.21 2697  0       0       0
>>>> 1960-01-21    NA
>>>> 15 01/22/1960 1300 57.38 57.38 57.38 57.38 2690  0       0       0
>>>> 1960-01-22    NA
>>>> 16 01/25/1960 1300 56.78 56.78 56.78 56.78 2793  0       0       0
>>>> 1960-01-25    NA
>>>> 17 01/26/1960 1300 56.86 56.86 56.86 56.86 3062  0       0       0
>>>> 1960-01-26    NA
>>>> 18 01/27/1960 1300 56.72 56.72 56.72 56.72 2463  0       0       0
>>>> 1960-01-27    NA
>>>> 19 01/28/1960 1300 56.13 56.13 56.13 56.13 2627  0       0       0
>>>> 1960-01-28    NA
>>>> 20 01/29/1960 1300 55.61 55.61 55.61 55.61 3061  0       0       0
>>>> 1960-01-29    NA
>>>> 21 02/01/1960 1300 55.96 55.96 55.96 55.96 2825  0       0       0
>>>> 1960-02-01    NA
>>>> 22 02/02/1960 1300 56.82 56.82 56.82 56.82 3077  0       0       0
>>>> 1960-02-02    NA
>>>> 23 02/03/1960 1300 56.32 56.32 56.32 56.32 3022  0       0       0
>>>> 1960-02-03    NA
>>>> 24 02/04/1960 1300 56.27 56.27 56.27 56.27 2617  0       0       0
>>>> 1960-02-04    NA
>>>> 25 02/05/1960 1300 55.98 55.98 55.98 55.98 2535  0       0       0
>>>> 1960-02-05    NA
>>>> 26 02/08/1960 1300 55.32 55.32 55.32 55.32 3348  0       0       0
>>>> 1960-02-08   NaN
>>>> 27 02/09/1960 1300 55.84 55.84 55.84 55.84 2859  0       0       0
>>>> 1960-02-09   NaN
>>>> 28 02/10/1960 1300 55.49 55.49 55.49 55.49 2441  0       0       0
>>>> 1960-02-10   NaN
>>>> 29 02/11/1960 1300 55.18 55.18 55.18 55.18 2606  0       0       0
>>>> 1960-02-11   NaN
>>>> 30 02/12/1960 1300 55.46 55.46 55.46 55.46 2229  0       0       0
>>>> 1960-02-12   NaN
>>>> 31 02/15/1960 1300 55.17 55.17 55.17 55.17 2772  0       0       0
>>>> 1960-02-15   NaN
>>>> 32 02/16/1960 1300 54.73 54.73 54.73 54.73 3278  0       0       0
>>>> 1960-02-16   NaN
>>>> 33 02/17/1960 1300 55.03 55.03 55.03 55.03 4208  0       0       0
>>>> 1960-02-17   NaN
>>>> 34 02/18/1960 1300 55.80 55.80 55.80 55.80 3798  0       0       0
>>>> 1960-02-18   NaN
>>>> 35 02/19/1960 1300 56.24 56.24 56.24 56.24 3234  0       0       0
>>>> 1960-02-19   NaN
>>>> 36 02/23/1960 1300 55.94 55.94 55.94 55.94 2960  0       0       0
>>>> 1960-02-23   NaN
>>>> 37 02/24/1960 1300 55.74 55.74 55.74 55.74 2744  0       0       0
>>>> 1960-02-24   NaN
>>>> 38 02/25/1960 1300 55.93 55.93 55.93 55.93 3601  0       0       0
>>>> 1960-02-25   NaN
>>>> 39 02/26/1960 1300 56.16 56.16 56.16 56.16 3384  0       0       0
>>>> 1960-02-26   NaN
>>>> 40 02/29/1960 1300 56.12 56.12 56.12 56.12 2994  0       0       0
>>>> 1960-02-29   NaN
>>>>>
>>>>
>>>>   The data came from TradeStation. It looks OK to me visually. The
>>>> code stub I'm using follows. I could possibly post the data somewhere
>>>> if necessary.
>>>>
>>>> Thanks,
>>>> Mark
>>>>
>>>>
>>>> require(chron)
>>>> require(ggplot2)
>>>> require(quantmod)
>>>> require(reshape)
>>>> require(TTR)
>>>>
>>>> AbsLookback = 13
>>>>
>>>> TradeSystem = read.csv("C:\\MiningData\\SPX_Daily.txt",header=TRUE)
>>>> #TradeSystem = read.csv("C:\\MiningData\\SPX_Weekly.txt",header=TRUE)
>>>> #TradeSystem = read.csv("C:\\MiningData\\INDU_Weekly.txt",header=TRUE)
>>>> #TradeSystem = read.csv("C:\\MiningData\\NDX_Weekly.txt",header=TRUE)
>>>> #TradeSystem = read.csv("C:\\MiningData\\RUT_Weekly.txt",header=TRUE)
>>>>
>>>> TradeSystem$MyDate = as.Date(TradeSystem$Date, "%m/%d/%Y")
>>>>
>>>> CVol = data.frame(chaikinVolatility(TradeSystem[,c("High","Low")],
>>>> n=AbsLookback))
>>>> names(CVol)[1]="ChVol"
>>>>
>>>> TradeSystem$ChVol = round(CVol$ChVol, 2)
>>>>
>>>> _______________________________________________
>>>> R-SIG-Finance at stat.math.ethz.ch mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>>>> -- Subscriber-posting only.
>>>> -- If you want to post, subscribe first.
>>>>
>>>
>>
>



More information about the R-SIG-Finance mailing list