File size: 1,197 Bytes
1cd56b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import sys, os
import pandas as pd

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../strategies')))

from backtesting.engines.v30_causal_engine import load_data, V30_PARAMS
from backtesting.strategies.v68_tranche_engines import run_v68_soft_tranche

STRATEGY_NAME = "V68_SOFT_TRANCHE"
ACTIVE_STRATEGY_FN = run_v68_soft_tranche
ACTIVE_PARAMS = V30_PARAMS.copy()

ACTIVE_PARAMS['txn_bps'] = 20
ACTIVE_PARAMS['rebal_days'] = 10 # Effective rebalance for the framework offset/monkey tests
ACTIVE_PARAMS['consistency_window'] = 63
ACTIVE_PARAMS['top_n'] = 15

TXN_PARAM_NAME = 'txn_bps'
REBAL_PARAM_NAME = 'rebal_days'

def signal_fn(dc, spy, vf):
    mom_long = ACTIVE_PARAMS.get('mom_long', 175)
    mom_short = ACTIVE_PARAMS.get('mom_short', 21)
    consistency_window = ACTIVE_PARAMS.get('consistency_window', 63)
    
    price_mom = (dc[vf].shift(mom_short) / dc[vf].shift(mom_long)) - 1
    daily_ret = dc[vf].pct_change()
    rolling_ret = daily_ret.gt(0).where(daily_ret.notna()).rolling(consistency_window).mean()
    return price_mom * rolling_ret

ACTIVE_SIGNAL_FN = signal_fn