[R-SIG-Finance] Blotter example by kafka from R-bloggers

Brian G. Peterson brian at braverock.com
Tue Dec 28 11:56:59 CET 2010


On Tue, 28 Dec 2010 18:14:09 +1100, Stephen Choularton
<stephen at organicfoodmarkets.com.au> wrote:
> I'm still not winning with this.   


Really, does the script fail?  
No: these are warnings.

Alternately: Does it produce incorrect results?  Does it replicate the
charts on his blog?  It does when I run it (warnings aside).


> I  installed blotter again from 
> https://r-forge.r-project.org/R/?group_id=316 but now I am getting  this

> inside the loop:


Please at least attempt to read the documentation before posting.  

Failing that, please try to figure out what a given *Warning* (these are
not Errors!) is telling you.


I've trimmed the following to keep only unique warnings. 


> There were 50 or more warnings (use warnings() to see the first 50)
>  > warnings()
> Warning messages:
> 1: In getInstrument(symbol) : Instrument SPY  not found, please create 
> it first.
> 2: In getInstrument(Symbol) : Instrument SPY  not found, please create 
> it first.
> 3: In .updatePosPL(Portfolio = pname, Symbol = as.character(symbol), 
... :
>    Instrument SPY  not found, things may break


getInstrument is called by all sorts of things.  The warning is saying
that you don't have an instrument definition, and things may be wonky.  Per
the documentation, we'll *attempt* to assume USD for the currency, and a
multiplier of 1, but this may not work everywhere, and per one comment in
the documentation which you apparently haven't read and Warnings
3,11,15,19, etc. from your output, "things may break".

adding this somewhere near the beginning of the script (after loading
blotter) should eliminate all of the warnings related to the lack of an
instrument:

currency("USD")
stock("SPY",currency="USD",multiplier=1)

but they are Warnings, and are there to inform you that something unhappy
might be going on.  Errors actually stop R in most cases, because it can't
continue.

<...>

> 8: In updatePortf(ltportfolio, Dates = currentDate) :
>    Incompatible methods ("Ops.Date", "Ops.POSIXt") for ">="


I've never seen this one before in blotter, even when running the script
you are using to test this, which works for me.  It may have something to
do with the script, as I know it has a loop on Dates with an updatePortf
after every day in order to do position sizing (which is a lot of heavy
lifting for the computer to do, and you likely won't want to do something
like this for most strategies when backtesting, though obviously running
once a day or even once an hour on real portfolios wouldn't be a problem.)


<...>

> 50: In addTxn(ltportfolio, Symbol = symbols[1], TxnDate = currentDate,  
> ... :
>    Instrument SPY  not found, using contract multiplier of 1


See my earlier comments about assuming a multiplier of 1 ...  your
computer told you that before I re-highlighted it.

 
> getInstrument doesn't even appear in the code so I'm not sure where this

> is going wrong.

.../blotter/R$ grep -c getInstrument *.R | grep -v 0
addTxn.R:3
chart.Spread.R:1
updateAcct.R:1
updatePortf.R:1
updatePosPL.R:2

The code you're running calls every file/function in the output above
except for chart.Spread, so getInstrument does 'appear in the code' (which
you have always had available to you for inspection)

  - Brian

-- 
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock



More information about the R-SIG-Finance mailing list