- Take in Start date-End date, and stock tickers, eg. TSLA, AAPL, BND from yahoo finance and fetch adjusted price data f
- take in portfolio weights% for these stock e.g. 25%, 25%, and 50% (target allocation)
- take in rebalancing frequency, e.g. daily, monthly, annual rebalancing
- take in threshold %, e.g. if I specify 5% then rebalance this portfolio monthly, only if the portfolio deviates more than 5% up or down from the target % allocation so as to avoid excessive rebalancing even for minute changes in allocation %
- show the backtested portfolio return chart, volatility, and other common metrics.
- number of times the portfolio that was rebalanced during the backtested period
- commission assumption $0.5 per transaction
Attached code does all the above except factoring in the threshold condition. You can add threshold function on top of it instead of writing from scratch.