Commit adbb221f authored by jichao's avatar jichao

增加危机1信号判断逻辑

parent 2021b48e
......@@ -42,6 +42,7 @@ py-jftech:
crisis_one: rebalance.signals.crisis_signal.LastRateCrisisOneSignal
date-curve: rebalance.drift_solver.DateCurve
curve-drift: rebalance.signals.curve_drift.CurveDrift
market-right: rebalance.signals.right_side.MarketRight
email:
server: smtphz.qiye.163.com
user: jft-ra@thizgroup.com
......
......@@ -36,10 +36,18 @@ class MarketRight(BaseRebalanceSignal):
def cvar_min_volume(self):
return self._config['cvar-min-volume']
@property
def include_last_type(self):
return [
SignalType.CRISIS_ONE,
SignalType.CRISIS_TWO,
SignalType.INIT,
SignalType.MARKET_RIGHT
]
def is_trigger(self, day, risk: PortfoliosRisk) -> bool:
last_re = rrs.get_last_one(risk=risk, max_date=day, effective=True)
if last_re is not None and SignalType(last_re['type']) in [SignalType.CRISIS_ONE, SignalType.CRISIS_TWO,
SignalType.MARKET_RIGHT, SignalType.INIT]:
if last_re is not None and SignalType(last_re['type']) in self.include_last_type:
return False
spx = self.load_spx_close_rtns(day)
......@@ -51,16 +59,6 @@ class MarketRight(BaseRebalanceSignal):
cvar = self.get_cvar(day, risk, spx=spx)
return cvar is not None and spx[-1]['rtn'] < cvar
def is_fall(self, day, risk: PortfoliosRisk, spx=None):
if spx is None:
spx = self.load_spx_close_rtns(day)
start_date = self.find_cvar_start_date(day, risk, spx=spx)
if start_date:
spx = pd.DataFrame(spx)
spx = spx[(spx.date >= start_date) & (spx.date <= day)]
return spx.iloc[-1].close < spx.iloc[0].close
return False
def get_cvar(self, day, risk: PortfoliosRisk, spx=None):
if spx is None:
spx = self.load_spx_close_rtns(day)
......@@ -97,3 +95,31 @@ class MarketRight(BaseRebalanceSignal):
spx.dropna(inplace=True)
spx = spx[['date', 'close', 'rtn']]
return spx.to_dict('records')
@component(bean_name='market-right')
class FallMarketRight(MarketRight):
def is_fall(self, day, risk: PortfoliosRisk, spx=None):
if spx is None:
spx = self.load_spx_close_rtns(day)
start_date = self.find_cvar_start_date(day, risk, spx=spx)
if start_date:
spx = pd.DataFrame(spx)
spx = spx[(spx.date >= start_date) & (spx.date <= day)]
return spx.iloc[-1].close < spx.iloc[0].close
return False
def is_trigger(self, day, risk: PortfoliosRisk) -> bool:
last_re = rrs.get_last_one(risk=risk, max_date=day, effective=True)
if last_re is not None and SignalType(last_re['type']) in self.include_last_type:
return False
spx = self.load_spx_close_rtns(day)
if self.is_fall(day, risk, spx=spx):
return True
if spx[-1]['rtn'] > self.min_threshold:
return False
cvar = self.get_cvar(day, risk, spx=spx)
return cvar is not None and spx[-1]['rtn'] < cvar
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment