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