[R-SIG-Finance] Potential bug in quantstrat in how it handles "F" symbol
Brian G. Peterson
brian at braverock.com
Thu Mar 1 15:04:00 CET 2012
On Wed, 2012-02-29 at 23:53 -0800, rex wrote:
> Sergey Pisarenko <drseergio at gmail.com> [2012-02-29 22:29]:
> >
> >The issue here is that get('F') will return FALSE because F is defined
> >as FALSE in R. This will obviously cause a failure down the road where
> >market data is read and manipulated.
>
> Hello Sergey,
>
> Easy fix:
>
> > if (F == FALSE) print('F == FALSE')
> [1] "F == FALSE"
> > F <- 'F'
> > if (F == FALSE) print('F == FALSE')
> >
According to the R FAQ[1]:
"In R, T and F are just variables being set to TRUE and FALSE,
respectively, but are not reserved words as in S and hence can be
overwritten by the user. (This helps e.g. when you have factors with
levels "T" or "F".) Hence, when writing code you should always use TRUE
and FALSE."
I think you'll find that blotter, quantstrat, FinancialInstrument all
use TRUE and FALSE correctly.
If you are trying to load data for Ford, you would already have locally
overwritten the F variable with your data for Ford.
> require(quantmod, quietly=TRUE)
> getSymbols('F')
[1] "F"
> head(F)
F.Open F.High F.Low F.Close F.Volume F.Adjusted
2007-01-03 7.56 7.67 7.44 7.51 78652200 7.48
2007-01-04 7.56 7.72 7.43 7.70 63454900 7.67
2007-01-05 7.72 7.75 7.57 7.62 40562100 7.59
2007-01-08 7.63 7.75 7.62 7.73 48938500 7.70
2007-01-09 7.75 7.86 7.73 7.79 56732200 7.76
2007-01-10 7.79 7.79 7.67 7.73 42397100 7.70
> head(get('F'))
F.Open F.High F.Low F.Close F.Volume F.Adjusted
2007-01-03 7.56 7.67 7.44 7.51 78652200 7.48
2007-01-04 7.56 7.72 7.43 7.70 63454900 7.67
2007-01-05 7.72 7.75 7.57 7.62 40562100 7.59
2007-01-08 7.63 7.75 7.62 7.73 48938500 7.70
2007-01-09 7.75 7.86 7.73 7.79 56732200 7.76
2007-01-10 7.79 7.79 7.67 7.73 42397100 7.70
so, get('F') will only return FALSE if you don't have any data loaded.
That is a problem on your end, I think, and not a problem in the
package.
Regards,
- Brian
Ref:
[1]
http://sites.stat.psu.edu/~dhunter/R/doc/manual/R-FAQ.html#What-are-the-differences-between-R-and-S_003f
(see section 3.3.3)
--
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock
More information about the R-SIG-Finance
mailing list