[Pnl-commits] r6 - in pkg: . tests

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Mar 25 17:54:54 CET 2010


Author: mark
Date: 2010-03-25 17:54:54 +0100 (Thu, 25 Mar 2010)
New Revision: 6

Added:
   pkg/tests/
   pkg/tests/pnlTest.R
Log:


Added: pkg/tests/pnlTest.R
===================================================================
--- pkg/tests/pnlTest.R	                        (rev 0)
+++ pkg/tests/pnlTest.R	2010-03-25 16:54:54 UTC (rev 6)
@@ -0,0 +1,21 @@
+library(xts)
+library(pnl)
+
+Sys.setenv(TZ="GMT")
+
+prices = c(23.07, 23.05, 23.06, 23.09, 23.28, 23.36)
+pseries = xts(prices, as.POSIXct(strptime(paste("2009-01-", seq(1:length(prices)), sep=""),"%Y-%m-%d")))
+colnames(pseries) = "Close"
+
+txn = addTxn(NULL, date='2009-01-02', size=36, price=23.05, fees=-1.0)
+txn = addTxn(txn, date='2009-01-04', size=-36, price=23.09, fees=-1.0)
+
+res = pnl(pseries, txn=txn)
+
+checkEquals(matrix(res["2009-01-01",]), matrix(c(0,0,0,0,0,0,0,0,0,0)))
+checkEquals(matrix(res["2009-01-02",]), matrix(c(36,23.05,-1,36,0,0,0,0,-1,0)))
+checkEquals(matrix(res["2009-01-03",]), matrix(c(0,0,0,36,0,0,0,0.36,-0.64,0)))
+checkEquals(matrix(res["2009-01-04",]), matrix(c(-36,23.09,-1,0,0,0,0,1.08,0,-0.56)))
+checkEquals(matrix(res["2009-01-05",]), matrix(c(0,0,0,0,0,0,0,0,0,0)))
+checkEquals(matrix(res["2009-01-06",]), matrix(c(0,0,0,0,0,0,0,0,0,0)))
+



More information about the pnl-commits mailing list