Merge branch 'develop' into backtest_live_models
This commit is contained in:
@@ -284,7 +284,7 @@ def load_backtest_data(filename: Union[Path, str], strategy: Optional[str] = Non
|
||||
df['enter_tag'] = df['buy_tag']
|
||||
df = df.drop(['buy_tag'], axis=1)
|
||||
if 'orders' not in df.columns:
|
||||
df.loc[:, 'orders'] = None
|
||||
df['orders'] = None
|
||||
|
||||
else:
|
||||
# old format - only with lists.
|
||||
@@ -341,9 +341,9 @@ def trade_list_to_dataframe(trades: List[LocalTrade]) -> pd.DataFrame:
|
||||
"""
|
||||
df = pd.DataFrame.from_records([t.to_json(True) for t in trades], columns=BT_DATA_COLUMNS)
|
||||
if len(df) > 0:
|
||||
df.loc[:, 'close_date'] = pd.to_datetime(df['close_date'], utc=True)
|
||||
df.loc[:, 'open_date'] = pd.to_datetime(df['open_date'], utc=True)
|
||||
df.loc[:, 'close_rate'] = df['close_rate'].astype('float64')
|
||||
df['close_date'] = pd.to_datetime(df['close_date'], utc=True)
|
||||
df['open_date'] = pd.to_datetime(df['open_date'], utc=True)
|
||||
df['close_rate'] = df['close_rate'].astype('float64')
|
||||
return df
|
||||
|
||||
|
||||
|
@@ -272,7 +272,7 @@ class IDataHandler(ABC):
|
||||
return res
|
||||
|
||||
def ohlcv_load(self, pair, timeframe: str,
|
||||
candle_type: CandleType,
|
||||
candle_type: CandleType, *,
|
||||
timerange: Optional[TimeRange] = None,
|
||||
fill_missing: bool = True,
|
||||
drop_incomplete: bool = True,
|
||||
|
@@ -4485,6 +4485,120 @@
|
||||
}
|
||||
}
|
||||
],
|
||||
"BTCUSDT_221230": [
|
||||
{
|
||||
"tier": 1.0,
|
||||
"currency": "USDT",
|
||||
"minNotional": 0.0,
|
||||
"maxNotional": 375000.0,
|
||||
"maintenanceMarginRate": 0.02,
|
||||
"maxLeverage": 25.0,
|
||||
"info": {
|
||||
"bracket": "1",
|
||||
"initialLeverage": "25",
|
||||
"notionalCap": "375000",
|
||||
"notionalFloor": "0",
|
||||
"maintMarginRatio": "0.02",
|
||||
"cum": "0.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"tier": 2.0,
|
||||
"currency": "USDT",
|
||||
"minNotional": 375000.0,
|
||||
"maxNotional": 2000000.0,
|
||||
"maintenanceMarginRate": 0.05,
|
||||
"maxLeverage": 10.0,
|
||||
"info": {
|
||||
"bracket": "2",
|
||||
"initialLeverage": "10",
|
||||
"notionalCap": "2000000",
|
||||
"notionalFloor": "375000",
|
||||
"maintMarginRatio": "0.05",
|
||||
"cum": "11250.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"tier": 3.0,
|
||||
"currency": "USDT",
|
||||
"minNotional": 2000000.0,
|
||||
"maxNotional": 4000000.0,
|
||||
"maintenanceMarginRate": 0.1,
|
||||
"maxLeverage": 5.0,
|
||||
"info": {
|
||||
"bracket": "3",
|
||||
"initialLeverage": "5",
|
||||
"notionalCap": "4000000",
|
||||
"notionalFloor": "2000000",
|
||||
"maintMarginRatio": "0.1",
|
||||
"cum": "111250.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"tier": 4.0,
|
||||
"currency": "USDT",
|
||||
"minNotional": 4000000.0,
|
||||
"maxNotional": 10000000.0,
|
||||
"maintenanceMarginRate": 0.125,
|
||||
"maxLeverage": 4.0,
|
||||
"info": {
|
||||
"bracket": "4",
|
||||
"initialLeverage": "4",
|
||||
"notionalCap": "10000000",
|
||||
"notionalFloor": "4000000",
|
||||
"maintMarginRatio": "0.125",
|
||||
"cum": "211250.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"tier": 5.0,
|
||||
"currency": "USDT",
|
||||
"minNotional": 10000000.0,
|
||||
"maxNotional": 20000000.0,
|
||||
"maintenanceMarginRate": 0.15,
|
||||
"maxLeverage": 3.0,
|
||||
"info": {
|
||||
"bracket": "5",
|
||||
"initialLeverage": "3",
|
||||
"notionalCap": "20000000",
|
||||
"notionalFloor": "10000000",
|
||||
"maintMarginRatio": "0.15",
|
||||
"cum": "461250.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"tier": 6.0,
|
||||
"currency": "USDT",
|
||||
"minNotional": 20000000.0,
|
||||
"maxNotional": 40000000.0,
|
||||
"maintenanceMarginRate": 0.25,
|
||||
"maxLeverage": 2.0,
|
||||
"info": {
|
||||
"bracket": "6",
|
||||
"initialLeverage": "2",
|
||||
"notionalCap": "40000000",
|
||||
"notionalFloor": "20000000",
|
||||
"maintMarginRatio": "0.25",
|
||||
"cum": "2461250.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"tier": 7.0,
|
||||
"currency": "USDT",
|
||||
"minNotional": 40000000.0,
|
||||
"maxNotional": 400000000.0,
|
||||
"maintenanceMarginRate": 0.5,
|
||||
"maxLeverage": 1.0,
|
||||
"info": {
|
||||
"bracket": "7",
|
||||
"initialLeverage": "1",
|
||||
"notionalCap": "400000000",
|
||||
"notionalFloor": "40000000",
|
||||
"maintMarginRatio": "0.5",
|
||||
"cum": "1.246125E7"
|
||||
}
|
||||
}
|
||||
],
|
||||
"BTS/USDT": [
|
||||
{
|
||||
"tier": 1.0,
|
||||
@@ -5759,6 +5873,104 @@
|
||||
}
|
||||
}
|
||||
],
|
||||
"CVX/USDT": [
|
||||
{
|
||||
"tier": 1.0,
|
||||
"currency": "USDT",
|
||||
"minNotional": 0.0,
|
||||
"maxNotional": 5000.0,
|
||||
"maintenanceMarginRate": 0.01,
|
||||
"maxLeverage": 25.0,
|
||||
"info": {
|
||||
"bracket": "1",
|
||||
"initialLeverage": "25",
|
||||
"notionalCap": "5000",
|
||||
"notionalFloor": "0",
|
||||
"maintMarginRatio": "0.01",
|
||||
"cum": "0.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"tier": 2.0,
|
||||
"currency": "USDT",
|
||||
"minNotional": 5000.0,
|
||||
"maxNotional": 25000.0,
|
||||
"maintenanceMarginRate": 0.025,
|
||||
"maxLeverage": 20.0,
|
||||
"info": {
|
||||
"bracket": "2",
|
||||
"initialLeverage": "20",
|
||||
"notionalCap": "25000",
|
||||
"notionalFloor": "5000",
|
||||
"maintMarginRatio": "0.025",
|
||||
"cum": "75.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"tier": 3.0,
|
||||
"currency": "USDT",
|
||||
"minNotional": 25000.0,
|
||||
"maxNotional": 100000.0,
|
||||
"maintenanceMarginRate": 0.05,
|
||||
"maxLeverage": 10.0,
|
||||
"info": {
|
||||
"bracket": "3",
|
||||
"initialLeverage": "10",
|
||||
"notionalCap": "100000",
|
||||
"notionalFloor": "25000",
|
||||
"maintMarginRatio": "0.05",
|
||||
"cum": "700.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"tier": 4.0,
|
||||
"currency": "USDT",
|
||||
"minNotional": 100000.0,
|
||||
"maxNotional": 250000.0,
|
||||
"maintenanceMarginRate": 0.1,
|
||||
"maxLeverage": 5.0,
|
||||
"info": {
|
||||
"bracket": "4",
|
||||
"initialLeverage": "5",
|
||||
"notionalCap": "250000",
|
||||
"notionalFloor": "100000",
|
||||
"maintMarginRatio": "0.1",
|
||||
"cum": "5700.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"tier": 5.0,
|
||||
"currency": "USDT",
|
||||
"minNotional": 250000.0,
|
||||
"maxNotional": 1000000.0,
|
||||
"maintenanceMarginRate": 0.125,
|
||||
"maxLeverage": 2.0,
|
||||
"info": {
|
||||
"bracket": "5",
|
||||
"initialLeverage": "2",
|
||||
"notionalCap": "1000000",
|
||||
"notionalFloor": "250000",
|
||||
"maintMarginRatio": "0.125",
|
||||
"cum": "11950.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"tier": 6.0,
|
||||
"currency": "USDT",
|
||||
"minNotional": 1000000.0,
|
||||
"maxNotional": 5000000.0,
|
||||
"maintenanceMarginRate": 0.5,
|
||||
"maxLeverage": 1.0,
|
||||
"info": {
|
||||
"bracket": "6",
|
||||
"initialLeverage": "1",
|
||||
"notionalCap": "5000000",
|
||||
"notionalFloor": "1000000",
|
||||
"maintMarginRatio": "0.5",
|
||||
"cum": "386950.0"
|
||||
}
|
||||
}
|
||||
],
|
||||
"DAR/USDT": [
|
||||
{
|
||||
"tier": 1.0,
|
||||
@@ -8105,6 +8317,120 @@
|
||||
}
|
||||
}
|
||||
],
|
||||
"ETHUSDT_221230": [
|
||||
{
|
||||
"tier": 1.0,
|
||||
"currency": "USDT",
|
||||
"minNotional": 0.0,
|
||||
"maxNotional": 375000.0,
|
||||
"maintenanceMarginRate": 0.02,
|
||||
"maxLeverage": 25.0,
|
||||
"info": {
|
||||
"bracket": "1",
|
||||
"initialLeverage": "25",
|
||||
"notionalCap": "375000",
|
||||
"notionalFloor": "0",
|
||||
"maintMarginRatio": "0.02",
|
||||
"cum": "0.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"tier": 2.0,
|
||||
"currency": "USDT",
|
||||
"minNotional": 375000.0,
|
||||
"maxNotional": 2000000.0,
|
||||
"maintenanceMarginRate": 0.05,
|
||||
"maxLeverage": 10.0,
|
||||
"info": {
|
||||
"bracket": "2",
|
||||
"initialLeverage": "10",
|
||||
"notionalCap": "2000000",
|
||||
"notionalFloor": "375000",
|
||||
"maintMarginRatio": "0.05",
|
||||
"cum": "11250.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"tier": 3.0,
|
||||
"currency": "USDT",
|
||||
"minNotional": 2000000.0,
|
||||
"maxNotional": 4000000.0,
|
||||
"maintenanceMarginRate": 0.1,
|
||||
"maxLeverage": 5.0,
|
||||
"info": {
|
||||
"bracket": "3",
|
||||
"initialLeverage": "5",
|
||||
"notionalCap": "4000000",
|
||||
"notionalFloor": "2000000",
|
||||
"maintMarginRatio": "0.1",
|
||||
"cum": "111250.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"tier": 4.0,
|
||||
"currency": "USDT",
|
||||
"minNotional": 4000000.0,
|
||||
"maxNotional": 10000000.0,
|
||||
"maintenanceMarginRate": 0.125,
|
||||
"maxLeverage": 4.0,
|
||||
"info": {
|
||||
"bracket": "4",
|
||||
"initialLeverage": "4",
|
||||
"notionalCap": "10000000",
|
||||
"notionalFloor": "4000000",
|
||||
"maintMarginRatio": "0.125",
|
||||
"cum": "211250.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"tier": 5.0,
|
||||
"currency": "USDT",
|
||||
"minNotional": 10000000.0,
|
||||
"maxNotional": 20000000.0,
|
||||
"maintenanceMarginRate": 0.15,
|
||||
"maxLeverage": 3.0,
|
||||
"info": {
|
||||
"bracket": "5",
|
||||
"initialLeverage": "3",
|
||||
"notionalCap": "20000000",
|
||||
"notionalFloor": "10000000",
|
||||
"maintMarginRatio": "0.15",
|
||||
"cum": "461250.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"tier": 6.0,
|
||||
"currency": "USDT",
|
||||
"minNotional": 20000000.0,
|
||||
"maxNotional": 40000000.0,
|
||||
"maintenanceMarginRate": 0.25,
|
||||
"maxLeverage": 2.0,
|
||||
"info": {
|
||||
"bracket": "6",
|
||||
"initialLeverage": "2",
|
||||
"notionalCap": "40000000",
|
||||
"notionalFloor": "20000000",
|
||||
"maintMarginRatio": "0.25",
|
||||
"cum": "2461250.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"tier": 7.0,
|
||||
"currency": "USDT",
|
||||
"minNotional": 40000000.0,
|
||||
"maxNotional": 400000000.0,
|
||||
"maintenanceMarginRate": 0.5,
|
||||
"maxLeverage": 1.0,
|
||||
"info": {
|
||||
"bracket": "7",
|
||||
"initialLeverage": "1",
|
||||
"notionalCap": "400000000",
|
||||
"notionalFloor": "40000000",
|
||||
"maintMarginRatio": "0.5",
|
||||
"cum": "1.246125E7"
|
||||
}
|
||||
}
|
||||
],
|
||||
"FIL/BUSD": [
|
||||
{
|
||||
"tier": 1.0,
|
||||
@@ -10138,10 +10464,10 @@
|
||||
"minNotional": 0.0,
|
||||
"maxNotional": 5000.0,
|
||||
"maintenanceMarginRate": 0.01,
|
||||
"maxLeverage": 50.0,
|
||||
"maxLeverage": 25.0,
|
||||
"info": {
|
||||
"bracket": "1",
|
||||
"initialLeverage": "50",
|
||||
"initialLeverage": "25",
|
||||
"notionalCap": "5000",
|
||||
"notionalFloor": "0",
|
||||
"maintMarginRatio": "0.01",
|
||||
@@ -10216,13 +10542,13 @@
|
||||
"tier": 6.0,
|
||||
"currency": "USDT",
|
||||
"minNotional": 1000000.0,
|
||||
"maxNotional": 30000000.0,
|
||||
"maxNotional": 5000000.0,
|
||||
"maintenanceMarginRate": 0.5,
|
||||
"maxLeverage": 1.0,
|
||||
"info": {
|
||||
"bracket": "6",
|
||||
"initialLeverage": "1",
|
||||
"notionalCap": "30000000",
|
||||
"notionalCap": "5000000",
|
||||
"notionalFloor": "1000000",
|
||||
"maintMarginRatio": "0.5",
|
||||
"cum": "386950.0"
|
||||
@@ -11389,6 +11715,104 @@
|
||||
}
|
||||
}
|
||||
],
|
||||
"LDO/USDT": [
|
||||
{
|
||||
"tier": 1.0,
|
||||
"currency": "USDT",
|
||||
"minNotional": 0.0,
|
||||
"maxNotional": 5000.0,
|
||||
"maintenanceMarginRate": 0.01,
|
||||
"maxLeverage": 25.0,
|
||||
"info": {
|
||||
"bracket": "1",
|
||||
"initialLeverage": "25",
|
||||
"notionalCap": "5000",
|
||||
"notionalFloor": "0",
|
||||
"maintMarginRatio": "0.01",
|
||||
"cum": "0.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"tier": 2.0,
|
||||
"currency": "USDT",
|
||||
"minNotional": 5000.0,
|
||||
"maxNotional": 25000.0,
|
||||
"maintenanceMarginRate": 0.025,
|
||||
"maxLeverage": 20.0,
|
||||
"info": {
|
||||
"bracket": "2",
|
||||
"initialLeverage": "20",
|
||||
"notionalCap": "25000",
|
||||
"notionalFloor": "5000",
|
||||
"maintMarginRatio": "0.025",
|
||||
"cum": "75.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"tier": 3.0,
|
||||
"currency": "USDT",
|
||||
"minNotional": 25000.0,
|
||||
"maxNotional": 100000.0,
|
||||
"maintenanceMarginRate": 0.05,
|
||||
"maxLeverage": 10.0,
|
||||
"info": {
|
||||
"bracket": "3",
|
||||
"initialLeverage": "10",
|
||||
"notionalCap": "100000",
|
||||
"notionalFloor": "25000",
|
||||
"maintMarginRatio": "0.05",
|
||||
"cum": "700.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"tier": 4.0,
|
||||
"currency": "USDT",
|
||||
"minNotional": 100000.0,
|
||||
"maxNotional": 250000.0,
|
||||
"maintenanceMarginRate": 0.1,
|
||||
"maxLeverage": 5.0,
|
||||
"info": {
|
||||
"bracket": "4",
|
||||
"initialLeverage": "5",
|
||||
"notionalCap": "250000",
|
||||
"notionalFloor": "100000",
|
||||
"maintMarginRatio": "0.1",
|
||||
"cum": "5700.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"tier": 5.0,
|
||||
"currency": "USDT",
|
||||
"minNotional": 250000.0,
|
||||
"maxNotional": 1000000.0,
|
||||
"maintenanceMarginRate": 0.125,
|
||||
"maxLeverage": 2.0,
|
||||
"info": {
|
||||
"bracket": "5",
|
||||
"initialLeverage": "2",
|
||||
"notionalCap": "1000000",
|
||||
"notionalFloor": "250000",
|
||||
"maintMarginRatio": "0.125",
|
||||
"cum": "11950.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"tier": 6.0,
|
||||
"currency": "USDT",
|
||||
"minNotional": 1000000.0,
|
||||
"maxNotional": 5000000.0,
|
||||
"maintenanceMarginRate": 0.5,
|
||||
"maxLeverage": 1.0,
|
||||
"info": {
|
||||
"bracket": "6",
|
||||
"initialLeverage": "1",
|
||||
"notionalCap": "5000000",
|
||||
"notionalFloor": "1000000",
|
||||
"maintMarginRatio": "0.5",
|
||||
"cum": "386950.0"
|
||||
}
|
||||
}
|
||||
],
|
||||
"LEVER/BUSD": [
|
||||
{
|
||||
"tier": 1.0,
|
||||
|
@@ -377,10 +377,10 @@ class Backtesting:
|
||||
for col in HEADERS[5:]:
|
||||
tag_col = col in ('enter_tag', 'exit_tag')
|
||||
if col in df_analyzed.columns:
|
||||
df_analyzed.loc[:, col] = df_analyzed.loc[:, col].replace(
|
||||
df_analyzed[col] = df_analyzed.loc[:, col].replace(
|
||||
[nan], [0 if not tag_col else None]).shift(1)
|
||||
elif not df_analyzed.empty:
|
||||
df_analyzed.loc[:, col] = 0 if not tag_col else None
|
||||
df_analyzed[col] = 0 if not tag_col else None
|
||||
|
||||
df_analyzed = df_analyzed.drop(df_analyzed.head(1).index)
|
||||
|
||||
|
@@ -173,7 +173,7 @@ def generate_tag_metrics(tag_type: str,
|
||||
tabular_data = []
|
||||
|
||||
if tag_type in results.columns:
|
||||
for tag, count in results[tag_type].value_counts().iteritems():
|
||||
for tag, count in results[tag_type].value_counts().items():
|
||||
result = results[results[tag_type] == tag]
|
||||
if skip_nan and result['profit_abs'].isnull().all():
|
||||
continue
|
||||
@@ -199,7 +199,7 @@ def generate_exit_reason_stats(max_open_trades: int, results: DataFrame) -> List
|
||||
"""
|
||||
tabular_data = []
|
||||
|
||||
for reason, count in results['exit_reason'].value_counts().iteritems():
|
||||
for reason, count in results['exit_reason'].value_counts().items():
|
||||
result = results.loc[results['exit_reason'] == reason]
|
||||
|
||||
profit_mean = result['profit_ratio'].mean()
|
||||
@@ -361,7 +361,7 @@ def generate_daily_stats(results: DataFrame) -> Dict[str, Any]:
|
||||
winning_days = sum(daily_profit > 0)
|
||||
draw_days = sum(daily_profit == 0)
|
||||
losing_days = sum(daily_profit < 0)
|
||||
daily_profit_list = [(str(idx.date()), val) for idx, val in daily_profit.iteritems()]
|
||||
daily_profit_list = [(str(idx.date()), val) for idx, val in daily_profit.items()]
|
||||
|
||||
return {
|
||||
'backtest_best_day': best_rel,
|
||||
|
Reference in New Issue
Block a user