Sharpe Ratio is Different when Position Size % is Different
-
The Sharpe ratio is supposed to be the same regardless of how much cash % is in the portfolio (ex: 90% vs 5%). However, I am getting two different sharpe ratios for the same strategy but with a different cash position. Here is the code:
class MaCrossStrategy(bt.Strategy): def __init__(self): pass ma_fast = bt.ind.SMA(period= 50) ma_slow = bt.ind.SMA(period = 200) self.crossover = bt.ind.CrossOver(ma_fast, ma_slow) def next(self): if not self.position: if self.crossover > 0: self.buy() elif self.crossover < 0: self.close() cerebro = bt.Cerebro() data = bt.feeds.YahooFinanceData( dataname = 'SPY', fromdate = datetime.datetime(2000, 1, 1), todate = datetime.datetime(2021, 4, 4) ) cerebro.adddata(data) cerebro.addstrategy(MaCrossStrategy) cerebro.broker.setcash(1000000) cerebro.addsizer(bt.sizers.PercentSizer, percents = 10) cerebro.addanalyzer(btanalyzers.SharpeRatio, _name = "sharpe") cerebro.addanalyzer(btanalyzers.Transactions, _name = "trans") cerebro.addanalyzer(btanalyzers.TradeAnalyzer, _name = "trades") back = cerebro.run() print('Ending portfolio value: {:,.0f}'.format(cerebro.broker.getvalue())) print(back[0].analyzers.sharpe.get_analysis()) print(back[0].analyzers.trans.get_analysis()) profit = cerebro.broker.getvalue() - 1000000 print('total profit: {:,.0f}'.format(profit)) cerebro.plot()
The Sharpe ratio I get for sizer = 10 (cerebro.addsizer(bt.sizers.PercentSizer, percents = 10) is -0.212 but the Sharpe ratio I get for sizer = 95 is 0.67.
What is the reason for this and how can I solve it?
-
@riskfreealpha said in Sharpe Ratio is Different when Position Size % is Different:
The Sharpe ratio is supposed to be the same regardless of how much cash % is in the portfolio (ex: 90% vs 5%).
What do you base this assumption on?
-
@run-out if you start out with a portfolio with no cash and then increase it to 50% cash, the expected return and standard deviation are also halved, thereby leaving the Sharpe ratio unchanged.