Commit 6ec07856 authored by jichao's avatar jichao

同步汇率

parent b2f4f7b7
......@@ -41,11 +41,25 @@ class MarketRight(BaseRebalanceSignal):
if last_re is not None and SignalType(last_re['type']) in [SignalType.CRISIS_ONE, SignalType.CRISIS_TWO, SignalType.MARKET_RIGHT, SignalType.INIT]:
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
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)
......@@ -65,7 +79,7 @@ class MarketRight(BaseRebalanceSignal):
spx = self.load_spx_close_rtns(day)
spx = pd.DataFrame(spx)
last_right = rrs.get_last_one(type=(SignalType.MARKET_RIGHT, SignalType.INIT), max_date=day, risk=risk, effective=True)
last_buy = rrs.get_last_one(type=(SignalType.LOW_BUY, SignalType.HIGH_BUY), max_date=day, risk=risk, effective=True)
last_buy = rrs.get_first_after(type=(SignalType.LOW_BUY, SignalType.HIGH_BUY), risk=risk, effective=True, min_date=last_right['date'])
if not last_buy or not last_right or last_buy['date'] <= last_right['date']:
return None
spx = spx[(spx['date'] >= last_right['date']) & (spx['date'] <= last_buy['date'])]
......
......@@ -33,7 +33,7 @@ class RebalanceTest(unittest.TestCase):
@autowired(names={'builder': 'market-right'})
def test_market_right(self, builder: RebalanceSignal = None):
signal = builder.get_signal(parse_date('2022-10-13'), PortfoliosRisk.FT9)
signal = builder.get_signal(parse_date('2022-02-22'), PortfoliosRisk.FT9)
logger.info(signal)
@autowired(names={'builder': 'curve-drift'})
......
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