Skip to content
Prev 10970 / 15274 Next

Question regarding PerformanceAnalytics - "endof" and "lastof" in to.weekly(..) function

On 11/04/2012 01:20 AM, Pie T wrote:
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).
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.
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