You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Having a column that shows the outstanding balance on each candle can be useful. What is the outstanding balance? The sum of the virtual profits of all open trades on each candle, this is a very slow version:
frompandasimportSeries, Timedelta, date_range, DatetimeIndexhloc=kwargs["processed"]
config=kwargs["config"]
timeframe=config["timeframe"]
timedelta=Timedelta(timeframe)
date_index: DatetimeIndexdate_index=date_range(start=min_date, end=max_date, freq=timeframe, normalize=True)
balance= {pair: Series(0.0, index=date_index) forpairinhloc}
balance_total=Series(0.0, index=date_index)
close_time=results["close_time"].valuesopen_time=results["open_time"].valuesforpairinhloc:
hloc[pair].set_index("date", inplace=True)
fordateindate_index.values:
# set the balance for all the opens that are not instantly closedwhere= (open_time==date) & (close_time!=date)
for_, trinresults.loc[where].iterrows():
pair=tr["pair"]
close=hloc[pair].at[date, "close"]
# balance at datebal_at_date=1-tr["open_rate"] /close-slippagebalance[pair][date] +=bal_at_date# set the balance for all the closesfor_, trinresults.loc[close_time==date].iterrows():
pair=tr["pair"]
# balance at date, since it's the close we take the profits minus slippagebal_at_date=tr["profit_percent"] -slippagebalance[tr["pair"]][date] +=bal_at_date# since we are closing, update all the balances since open time# ranges are inclusive:[):exclusiveforopen_datein (
balance[pair]
.loc[tr["open_time"] +timedelta : tr["close_time"]]
.index
).values:
close=hloc[pair].at[open_date, "close"]
balance[pair][open_date] +=1-tr["open_rate"] /close-slippage# settle the balance for all the pairs at current dateforpairinbalance:
balance_total[date] +=balance[pair][date]
I am trying to come up with a vectorized one, also not sure how much would this calculation impact performance if it was applied on the main backtest loop
The text was updated successfully, but these errors were encountered:
You should look at btanalysis.py - this should be very similar to the function analyze_trade_parallelism() we have to test max_open_trades is respected - but using sum() instead of count().
But let me ask- what for / why would you need this?
I'm not certain in which usecase this should be used ... - knowing how many trades are open at any given time is usually enough ... ?
you can't do it with the sum, you have to match the close price at each candle for every non closed trade
But let me ask- what for / why would you need this?
It is probably in the same vein as disable_max_market_positions and enable_position_stacking since it gives you a clearer picture with less data.
If you for example try to run objectives like sortino/sharpe in a mono trend timerange it will optimize always for bigger stoplosses (if market is bull) or smaller stoplosses (if market is bear) akin to future knowledge
Having a column that shows the outstanding balance on each candle can be useful. What is the outstanding balance? The sum of the virtual profits of all open trades on each candle, this is a very slow version:
I am trying to come up with a vectorized one, also not sure how much would this calculation impact performance if it was applied on the main backtest loop
The text was updated successfully, but these errors were encountered: