-2

Scenario (using quantstrat, blotter and portfolioanalytics)

  • I have 10k initial equity
  • I have a strategy that i want to backtest over 3000 symbol universe (stocks)
  • Let say the strategy is a simple MA crossover
  • Every time i get a buy crossover I buy 10k worth of stock and close position on the sell crossover
  • For backtest purpose the strategy can trade without any portfolio restriction, therefore i may be holding 100+ positions at any point in time, therefore the initial equity shouldn't be considered.

I want to know the AVERAGE return of this strategy over all trades.

In reality if i only had 10k i would only be able to be in one trade at once, but i would like know statisctally what the average return would be.

I then want to compare this with the stock index benchmark.

  • Do i SUM or MEAN the return stream of each symbol
  • Is it the return of the portfolio, does this take into account the initial equity? - i don't want the return to be as a percentage of the initial equity or consider how may symbols are trading.
GeV 126
  • 351
  • 1
  • 3
  • 14
  • You have to provide a sample of your dataset and what the ideal output would look. If your dataset is sensitive, then try to create some fake data that we can work with and then you can adjust the solution to your real dataset. – AntoniosK Nov 05 '17 at 14:11
  • ok i'll put an example strategy – GeV 126 Nov 06 '17 at 06:07

1 Answers1

0

I'll add an example strategy when i get time, but the solution to the problem is:

#get the portfolio returns
instRets <- PortfReturns(account.st)
#for each column, NA the values where there is no return, because when the values are averaged out, you don't want 0's to be included in the calculation
# if there are no signals in the strategy, you will invest money elsewhere rather than just leaving lying around. Therefore you only calculate the returns #when the strategy is ACTIVE
for (i in 1:ncol(instRets)){
  instRets[,i][instRets[,i] == 0] <- NA
}
#this will give you the average return when the strategy is active, if there are 100 trades on, you want the average return during that period.
portfRets <- xts(rowMeans(instRets, na.rm = T), order.by = index(instRets)) 
portfRets <- portfRets[!is.na(portfRets)] 

Now you can compare the strategy with a benchmark SPY for example. If the strategy has alpha you can use a balancing rule to apply funds to the strategy when signals arise or keep invested in the index when there are no signals.

As far to my knowledge the returns analysis built into blotter uses the initial equity to work out returns, therefor invest the same amount in each trade as you have for initial equity. 10k initial equity, 10k per trade.

GeV 126
  • 351
  • 1
  • 3
  • 14