mirror of
https://github.com/webclinic017/drift.git
synced 2026-08-02 05:37:47 +00:00
feat(Evaluate): increase transactions costs, to get a more realistic view on performance (#137)
This commit is contained in:
committed by
GitHub
parent
fc5eba4e2d
commit
22b3167cb9
@@ -55,6 +55,15 @@ def __load_data(assets: DataCollection,
|
||||
narrow_format=narrow_format,
|
||||
) for data_source in target_file]
|
||||
target_asset_df = ray.get(target_asset_future)
|
||||
|
||||
target_asset_only_returns_future = __load_df.remote(
|
||||
data_source=target_file[0],
|
||||
prefix=target_file[0][1],
|
||||
returns='returns',
|
||||
feature_extractors=[],
|
||||
narrow_format=narrow_format,
|
||||
)
|
||||
df_target_asset_only_returns = ray.get(target_asset_only_returns_future)
|
||||
|
||||
asset_futures = [__load_df.remote(
|
||||
data_source=data_source,
|
||||
@@ -86,14 +95,16 @@ def __load_data(assets: DataCollection,
|
||||
|
||||
if index_column == 'int':
|
||||
dfs.reset_index(drop=True, inplace=True)
|
||||
df_target_asset_only_returns.reset_index(drop=True, inplace=True)
|
||||
|
||||
if narrow_format:
|
||||
dfs = dfs.drop(index=dfs.index[0], axis=0)
|
||||
df_target_asset_only_returns = df_target_asset_only_returns.drop(index=dfs.index[0], axis=0)
|
||||
|
||||
## Create target
|
||||
target_col = 'target'
|
||||
returns_col = target_asset[1] + '_returns'
|
||||
forward_returns = __create_target_cum_forward_returns(dfs, returns_col, forecasting_horizon)
|
||||
forward_returns = __create_target_cum_forward_returns(df_target_asset_only_returns, returns_col, forecasting_horizon)
|
||||
if method == 'regression':
|
||||
dfs[target_col] = forward_returns
|
||||
elif method == 'classification':
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ from utils.helpers import get_first_valid_return_index
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
|
||||
def backtest(returns: pd.Series, signal: pd.Series, transaction_cost = 0.002) -> pd.Series:
|
||||
def backtest(returns: pd.Series, signal: pd.Series, transaction_cost = 0.008) -> pd.Series:
|
||||
delta_pos = signal.diff(1).abs().fillna(0.)
|
||||
costs = transaction_cost * delta_pos
|
||||
return (signal * returns) - costs
|
||||
|
||||
Reference in New Issue
Block a user