switch to using itertuples instead of iterrows as it's a lot faster
This commit is contained in:
		| @@ -53,18 +53,14 @@ def backtest(conf, pairs, mocker): | |||||||
|             mocker.patch('arrow.utcnow', return_value=arrow.get('2017-08-20T14:50:00')) |             mocker.patch('arrow.utcnow', return_value=arrow.get('2017-08-20T14:50:00')) | ||||||
|             ticker = analyze_ticker(pair)[['close', 'date', 'buy']].copy() |             ticker = analyze_ticker(pair)[['close', 'date', 'buy']].copy() | ||||||
|             # for each buy point |             # for each buy point | ||||||
|             for index, row in ticker[ticker.buy == 1].iterrows(): |             for row in ticker[ticker.buy == 1].itertuples(index=True): | ||||||
|                 trade = Trade( |                 trade = Trade(open_rate=row.close, open_date=row.date, amount=1) | ||||||
|                     open_rate=row['close'], |  | ||||||
|                     open_date=row['date'], |  | ||||||
|                     amount=1, |  | ||||||
|                 ) |  | ||||||
|                 # calculate win/lose forwards from buy point |                 # calculate win/lose forwards from buy point | ||||||
|                 for index2, row2 in ticker[index:].iterrows(): |                 for row2 in ticker[row.Index:].itertuples(index=True): | ||||||
|                     if should_sell(trade, row2['close'], row2['date']): |                     if should_sell(trade, row2.close, row2.date): | ||||||
|                         current_profit = (row2['close'] - trade.open_rate) / trade.open_rate |                         current_profit = (row2.close - trade.open_rate) / trade.open_rate | ||||||
|  |  | ||||||
|                         trades.append((pair, current_profit, index2 - index)) |                         trades.append((pair, current_profit, row2.Index - row.Index)) | ||||||
|                         break |                         break | ||||||
|     labels = ['currency', 'profit', 'duration'] |     labels = ['currency', 'profit', 'duration'] | ||||||
|     results = DataFrame.from_records(trades, columns=labels) |     results = DataFrame.from_records(trades, columns=labels) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user