[R-SIG-Finance] Error in addTxn - Quantstrat

Joshua Ulrich josh.m.ulrich at gmail.com
Wed May 24 22:30:49 CEST 2017


On Wed, May 24, 2017 at 1:10 PM, Daniel Cegiełka
<daniel.cegielka at gmail.com> wrote:
> 2017-05-24 19:45 GMT+02:00 Joshua Ulrich <josh.m.ulrich at gmail.com>:
>>
>> This is a bug that was introduced here:
>> https://github.com/braverock/blotter/commit/24b578628415111885d29ef97d5ab0eed1c7bb75
>
>
> https://github.com/braverock/blotter/commit/24b578628415111885d29ef97d5ab0eed1c7bb75#diff-7347fe5a0f184f79ef064e92e3beb297R69
>
> https://github.com/braverock/blotter/blob/master/R/addTxn.R#L85
>
> why end() from stats?
>
Because stats::end is the generic.

> https://github.com/braverock/blotter/blob/master/R/addTxn.R#L154
>
> Should be end.xts(), eg:
>
end.xts() is not exported from the xts namespace.  And it's generally
a bad idea to call methods directly, because you do not know if that
method will be able to handle objects of different classes.

> end.xts <- function (x, ...)
> {
>     if (!length(x)) {
>         index(x[length(.index(x)), ])
>     } else
>         index(x[NROW(x), ])
> }
>
> If I understood the problem correctly...
>
> Best,
> Daniel
>
>
>>
>>
>>
>> Here's a *minimal* reproducible example:
>> require(blotter)
>> currency("USD")
>> initPortf("test", symbols="AAPL", currency="USD")
>>
>> addTxn("test", "AAPL", as.Date("2017-01-01"),  1, 10)
>> addTxn("test", "AAPL", as.Date("2017-01-02"), -1, 10)
>>
>> Thanks for the report!  I'll work on a fix.
>>
>> Best,
>> Josh
>>



-- 
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com
R/Finance 2017 | www.rinfinance.com



More information about the R-SIG-Finance mailing list