[Blotter-commits] r1579 - pkg/quantstrat/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Dec 15 03:11:40 CET 2013
Author: efmrforge
Date: 2013-12-15 03:11:38 +0100 (Sun, 15 Dec 2013)
New Revision: 1579
Modified:
pkg/quantstrat/R/chart.forward.R
Log:
fixed as.environment(NULL) error NEEDS TESTING
[17:05] <efm> i'm doing some code review of quantstrat
[17:06] <efm> this may be a very old error (2006ish?)
[17:06] <efm> the relevant lines are
[17:06] <efm> .audit <- NULL
[17:06] <efm> portfolios.st = ls(name=.audit, pattern='portfolio.*.[0-9]+')
[17:07] <efm> which, when I run just those lines throws an error:
[17:07] <efm> Error in as.environment(pos) : using 'as.environment(NULL)' is defunct
[17:07] <efm> which looks to be a change from 2006: http://tolstoy.newcastle.edu.au/R/e2/devel/06/09/0012.html
[17:09] <efm> as this is the first I've seen the .audit environment (I haven't done any walkforwards yet), I was wondering if the fix from that post to set the package:quantstrat would make sense, or if the change would be better to .audit <- new.env()
17:49] <braverock_hm> well, if we need .audit to be an environment, then yes, I's say setting it to new.env() would make sense
[17:50] <braverock_hm> but I'd also expect that it would be created during the walk-forward process, not inside a chart function, because then it would only have function-scope
[18:00] --> meretrix has joined this channel (meretrix at unaffiliated/meretrix).
[18:03] <efm> braverock_hm: I'll check that, thanks
[18:05] <efm> walkforward also does .audit <- NULL but creates the .audit evironment
[18:05] <efm> .audit <- NULL
[18:05] <efm> if(!is.null(audit.prefix))
[18:05] <efm> .audit <- new.env()
[18:05] <efm> that's likely the correct behavior for chart.forward, which loads the .audit environment from the audit.file
[18:09] <-- top4o has left this server (Read error: Connection reset by peer).
[18:11] <braverock_hm> rifght, creating it if it doesn't exist makes sense. obviously if there is no data available to chart, it would be nice to bail out gracefully
Modified: pkg/quantstrat/R/chart.forward.R
===================================================================
--- pkg/quantstrat/R/chart.forward.R 2013-12-13 01:23:35 UTC (rev 1578)
+++ pkg/quantstrat/R/chart.forward.R 2013-12-15 02:11:38 UTC (rev 1579)
@@ -8,10 +8,14 @@
{
if(!require(xtsExtra, quietly=TRUE)) stop('The "xtsExtra" package is required to use this function')
- .audit <- NULL
+ #.audit <- NULL
+ if(is.null(.audit)) stop ('You need to run a walk forward test first to create the .audit environment')
+
+ if(!is.null(audit.filename))
+ load(audit.filename)
+ else
+ stop('You need to provide an audit.filename.')
- load(audit.filename)
-
# extract all portfolio names from the audit environment, except wfa portfolio
portfolios.st = ls(name=.audit, pattern='portfolio.*.[0-9]+')
n <- length(portfolios.st)
More information about the Blotter-commits
mailing list