Inputs for Payout Function

I had a question about the payout function, which is supposed to generate the portfolio weights. In the asset allocation template, it says the input to this function is “rets: a .xts matrix of portfolio returns (generated by evaluate())”. But because the alphathon comes with external data, my impression was that the payout function will input both building block returns, and external data (PMI, gov bond yields, etc) and return a timeseries of portfolio weights? So just wanted to clarify if that is the case?


Majid

Actually, never mind. The second tutorial on alphathon seems to answer that question. So I guess we can have external data and any parameters as inputs to the payout function.

Hi Majid,

Thanks for your question. Let me clarify how portfolio() works so that it clearer.


If you use the class portfolio(), you will create a portfolio object that can invest in a collection of underlying building blocks. For e.g.

> myPort = portfolio(list(‘TYa’, ‘USHYa’, ‘BNKa’))

creates a portfolio that can invest in TYa, USHYa, and BNKa. At this stage, there is no logic for allocating weights between underlying assets. This is what your payout function does. To create a payout that applies to portfolio(), the payout function has to take as input the returns of the portfolio’s underlying assets as an xts. This is the first argument of your payout function; you can add any other arguments afterwards. Example for a payout function that we call “myPayoutFunction”:

> myPayoutFunction = function(returnMatrix, …) {…}

If you use the piping syntax that we show in notebook tutorials (the %>% operator), your portfolio will deduce the returns automatically when you call evaluate(). For instance:

> myPort %>% payout(myPayoutFunction) %>% evaluate() -> myPort

> tail(myPort@returnsMatrix)

shows portfolio’s asset returns were created and stored in myPort when we use portfolio() %>% payout() %>% evaluate().


Independently, if you want to use extra data in your payout, you can directly call them from within your payout body:

> myPayoutFunction = function(returnMatrix, …) {

extraData = getAlphathonData(asPrice=TRUE)

}

Or you can pass them on as an argument:

> myPayoutFunction = function(returnMatrix, extraData = getAlphathonData(asPrice=TRUE), …) {…}


Hope this clarifies things.

Thanks,


Hervé

Great, thank you!