同步回测与tqsdk
This commit is contained in:
@@ -51,9 +51,14 @@ def calculate_metrics(
|
||||
|
||||
total_days = (df_values.index.max() - df_values.index.min()).days
|
||||
if total_days > 0:
|
||||
annualized_return = (1 + total_return) ** (252 / total_days) - 1
|
||||
if total_return > -1:
|
||||
annualized_return = (1 + total_return) ** (252 / total_days) - 1
|
||||
else:
|
||||
annualized_return = -9999999
|
||||
else:
|
||||
annualized_return = 0.0
|
||||
print(f'total_return: {total_return}, annualized_return:{annualized_return}, 252 / total_days:{252 / total_days}')
|
||||
|
||||
|
||||
rolling_max = df_values["total_value"].cummax()
|
||||
daily_drawdown = (rolling_max - df_values["total_value"]) / rolling_max
|
||||
@@ -63,7 +68,10 @@ def calculate_metrics(
|
||||
daily_volatility = excess_daily_returns.std()
|
||||
|
||||
if daily_volatility > 0:
|
||||
sharpe_ratio = np.sqrt(252) * (excess_daily_returns.mean() / daily_volatility)
|
||||
if total_return > -1:
|
||||
sharpe_ratio = np.sqrt(252) * (excess_daily_returns.mean() / daily_volatility)
|
||||
else:
|
||||
sharpe_ratio = -10
|
||||
else:
|
||||
sharpe_ratio = 0.0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user