I think it would be great if the backtest engine allowed you to enter a portfolio of more than one currency type. For instance, if I am testing a strategy that trades the BTC/USD pair I would like to enter an amount of funds onhand for both BTC and USD. I keep getting an insufficient funds error on the one that I don't specify as the starting currency.
For instance, if I say I have $1,000 and the first trade comes up with a signal to sell BTC then I don't have the funds to execute and I get an error. Thanks for thinking about it.
I handle funds error like this:
PAIR = info.primary_pair
price = float(data[PAIR].price)
holding_usd = holding_btc = False
if portfolio.usd > 0.1*price:
holding_usd = True
if portfolio.btc > 0.1
holding_btc = True
if you want to hold 50% assets on the first tick start with BTC, then:
PAIR = info.primary_pair
if info.tick == 0:
holding_half = float(portfolio.btc) / 2
This would have you half bought in at the closing price of the candle prior to the first tick.
check "strategy api help" / "orders" for more tools.
Though @litepresence code work in this instance, I think this feature makes sense for backtesting.
I am thinking a better way would be to allow code to override parameters inside
initialize method. For e.g. say you set parameters of starting portfolio to
$10,000on the UI, which you can override in the code
data[PRIMARY_PAIR].starting_portfolio = 15000
data[SECODARY_PAIR].starting_portfolio = 20000
#we can override any predefined parameters
#somewhere in the code
Does this make sense to you guys?
Yes, I see how this would work. Seems like a great idea to me.
Sorry for the slow response. I was away at training.
would be sweet if we could over ride the start and stop date too with epoch time stamp
Sorry didn't get this one. Every time you run a backtest, you can change the dates. So how would this help other than change the code and run? I am concerned it might trip users with two places to change the dates.
On a different note, it would be cool to create a set of dates (tuple of start, end dates) and let the backtest run for each value. The backtest can then plot the graph from multiple runs and collate the data from all the runs. Its a major change but I think it goes back to our conversation on parameter optimization.
would be nice to be able to collate gox and btce btcusd data all the way to the beginning too.
You are limited by the data available in the shortest of the exchange/pair selected. The other dates are "greyed out" and you can't select them.
see the issue raised here: