UBS question about the outperform S&P500

Do we have the certain form for the input data of our pay-out function, just like ‘‘emaCrossSelect’’ function’s? If we need ‘’‘OHLC’’ prices of stocks to create our strategies not like ‘‘emaCrossSelect’’ , how could we use ‘‘alphien.portfolio.Portfolio’’ to backtest our strategies? Moreover, we need one more Dataframe as input data of pay-out function to find out whether those stocks are in S&P500. So under the circumstances, can we still use ‘‘alphien.portfolio.Portfolio’’ to backtest? If we can’t, how can we backtest our strategies?

Hi there and thanks for your question.

Whatever times series you use you have to pass as the first argument of the payout function, regardless of whether it is only adjusted close (we call this ‘bb_live’) or OHLC (non adjusted). In the example given in the notebook, the dataframe containing time series is implicit (not declared in payout() ); when this is the case, Portfolio considers you are only using the time series of adjusted prices from the assets that compose your portfolio. In your case, you want to use more data. Just pass them in as the first argument of your payout. If your payout is called “myPayout” and looks like this:

def myPayout(data, filter):
pass

The variable “data” above can contain any time series (OHLC included) provided it is a pandas data frame with a datetime index. Then you can add a parameter “filter” to pass in your matrix of inclusion in the S&P.


If you have a portfolio “pf”, the payout would be declared explicitly as:

pf.payout(myPayout, myDataWithOHLC, mySPFilter)


You can also pass the first data parameter implicitly. Use the method dataFeatures for this. You can add all time series you use to generate your weights in the portfolio object. E.g.

pf = alphien.portfolio.Portfolio([‘AAPL.US Equity’, ‘MSFT.US Equity’, ‘NFLX.US Equity’])
pf.addFeatures([‘AAPL.US Equity’, ‘MSFT.US Equity’, ‘NFLX.US Equity’] + alphien.data.getTickersSP500Data().ticker.tolist())
print(pf.features)

“Features” is automatically used as the “data” argument in the function “myPayout” if you leave it empty when you call payout().

pf.payout(myPayout, mySPFilter)


Hope this helps. Please let us know if you have further questions