[R-SIG-Finance] ABS value calculation for ATR use
Jeff Ryan
jeff.a.ryan at gmail.com
Thu Sep 20 18:23:55 CEST 2012
Seconded.
> library(quantmod) # requires TTR
> getSymbols("INFY.BO")
[1] "INFY.BO"
> head(ATR(INFY.BO))
tr atr trueHigh trueLow
2007-01-02 NA NA NA NA
2007-01-03 43.95 NA 2280 2236.05
2007-01-04 43.90 NA 2320 2276.10
2007-01-05 15.00 NA 2290 2275.00
2007-01-08 19.50 NA 2280 2260.50
2007-01-09 16.70 NA 2208 2191.30
HTH
Jeff
On Thu, Sep 20, 2012 at 10:47 AM, Zachary Mayer <zach.mayer at gmail.com> wrote:
> Why not use the ATR indicator in the TTR package?
>
> On Thu, Sep 20, 2012 at 11:39 AM, sean fallon <sf99167 at yahoo.com> wrote:
>
>> I am trying to calculate the Absolute value to append in file so I can
>> build ATR indicator. I am stuck at the first part wherein I am trying to
>> calculate the ABS for High - Close Price. However when I run the
>> "head(data)" to see what the results are, the AbsHC shows me the same
>> number i.e. 61.2, whether I put the "data$AbsHC=abs(x)" inside the for loop
>> or outside. I am only trying it for the first 10 rows of data. Enclosed
>> below is the code
>>
>> #Get data fro Yahoo finance for Infosys (INFY.BO)
>> data <- read.csv("
>> http://ichart.finance.yahoo.com/table.csv?s=INFY.BO&a=08&b=16&c=2008&d=08&e=20&f=2012&g=d&ignore=.csv",
>> stringsAsFactors=F)
>>
>> #view data
>> head(data)
>>
>> #compute high-close
>> h=data[,3]
>> c=data[,4]
>> hcdif=h-c
>> data$HminusC=hcdif
>>
>> #check data
>> data[30:40,]
>>
>> #compute absolute value
>> j=2
>> for (i in 1:10)
>> {
>> ab1= data[i,5]
>> ab2= data[j,3]
>> x=ab1-ab2
>> #data$AbsHC=abs(x), I have commented this as I have out it outside the
>> loop.
>> j = j+1
>> }
>>
>> data$AbsHC=abs(x)
>> head(data)
>>
>> What am I doing wrong here???
>>
>> regards
>>
>> Sean
>> [[alternative HTML version deleted]]
>>
>>
>> _______________________________________________
>> R-SIG-Finance at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>> -- Subscriber-posting only. If you want to post, subscribe first.
>> -- Also note that this is not the r-help list where general R questions
>> should go.
>>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.
--
Jeffrey Ryan
jeffrey.ryan at lemnica.com
www.lemnica.com
More information about the R-SIG-Finance
mailing list