[Blotter-commits] r1704 - pkg/blotter/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Oct 29 16:52:23 CET 2015
Author: bodanker
Date: 2015-10-29 16:52:22 +0100 (Thu, 29 Oct 2015)
New Revision: 1704
Modified:
pkg/blotter/R/updatePosPL.R
Log:
Make Dates POSIXct when index(prices) is not
The Dates object is created from the index of the Prices argument (or
the object containing data for the given Symbol) if the user doesn't
supply the Dates argument in the updatePortf call.
We subtract a very small value from the first observation in Dates in
order to get a date range for which position P&L needs to be updated.
If the index of Prices is a 'Date' vector, subtracting a very small
value from Dates causes the startDate to be shifted back an entire day.
This causes the initializing transaction in the txn table to be
included in the P&L calculations.
Avoid this by ensuring Dates (and therefore startDate and endDate) are
always POSIXct with the same timezone as the txn table (the index of
the posPL and txn tables are always POSIXct).
Modified: pkg/blotter/R/updatePosPL.R
===================================================================
--- pkg/blotter/R/updatePosPL.R 2015-10-28 20:40:11 UTC (rev 1703)
+++ pkg/blotter/R/updatePosPL.R 2015-10-29 15:52:22 UTC (rev 1704)
@@ -38,6 +38,11 @@
# if no date is specified, get all available dates
if(is.null(Dates)) {
Dates = index(prices)
+ # Covert to POSIXct w/same TZ as portfolio object
+ if(indexClass(prices) %in% c("Date","yearmon","yearqtr")) {
+ portfTZ <- indexTZ(Portfolio$symbols[[Symbol]]$txn)
+ Dates <- as.POSIXct(as.character(as.Date(Dates)), tz=portfTZ)
+ }
} else if(!is.timeBased(Dates)) {
Dates<- if(is.na(.parseISO8601(Dates)$first.time) ||
.parseISO8601(Dates)$first.time < as.POSIXct(first(index(prices)))){
More information about the Blotter-commits
mailing list