[R-SIG-Finance] Question regarding PerformanceAnalytics - "endof" and "lastof" in to.weekly(..) function

Brian G. Peterson brian at braverock.com
Sun Nov 4 13:32:20 CET 2012


On 11/04/2012 01:20 AM, Pie T wrote:
> Hi,
> What is the difference between "endof" and "lastof" keywords in to.weekly()
> and to.monthly functions?

to.period (and the wrappers to.weekly and to.monthly) are provided by 
xts, not PerformanceAnalytics.

While 'startof' and 'endof' are discussed at the beginning of to.period, 
it looks from the code like only 'firstof' and 'lastof' are actually 
*used*.  So, until we sort out the discrepancy, just use 'firstof' and 
'lastof' if you absolutely need to pass a value here (but it's not clear 
that you do, see below).

> example: SPY = to.weekly(SPY, indexAt='endof', drop.time=FALSE)
>
> Context:
> I was getting duplicate index values in blotter account object for summary
> i.e., getAccount(..)$summary. The source of the error finally turned out to
> be  usage of "lastof" in to.weekly(..) function in PerformanceAnalytics. If
> I use "endof" that seems to take care of the problem.

to.period, by default, will take the last observation in the period, so 
these extra options shouldn't be necessary in most cases anyway.  That 
is, you shouldn't have to pass an indexAt argument at all for the 
application you're describing.

> On another note, currently to simulate equal asset weighting,  I track the
> account capital and compute the quantity for each transaction in my program
> before adding to portfolio. I am  wondering is there any API in
> blotter/performance analytics where I can just provide weights for each
> asset, initial capital and list of  transactions with quantity as 1 and the
> rest is taken care automatically by an R package?

You're kind of mixing two paradigms.

If you're dealing with weights and returns, then the 
PerformanceAnalytics function Return.portfolio can do periodic 
rebalancing, skipping the 'transactions' and 'prices' steps entirely. 
If all you want to do is sort out the net return of a periodically 
rebalanced equal weight portfolio (or any periodically rebalanced 
portfolio), then using Return.portfolio will be the simplest thing.

If you want to deal with transactions in blotter and get cash results by 
performing rebalancing trades to adjust the portfolio, then there is 
currently no function for doing this in blotter (which deals with 
transaction accounting).  If you've already written code to extract 
weights from blotter and generate difference transactions to get to a 
new target weight, it would be nice if you would contribute that code to 
the dev team.  It's been on my list, but hasn't gotten anywhere near the 
top of that list.

Regards,

   - Brian

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



More information about the R-SIG-Finance mailing list