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é