trendmanagement / Tmqr-framework-2

3 stars 0 forks source link

Alex V2 Alpha Bug - all alphas without passive index fail - source of ES smartcampaign error #100

Closed spickering-git closed 6 years ago

spickering-git commented 6 years ago

@alexveden The source of the ES_smartcampaign error https://10.0.1.2:8888/notebooks/smart_campaign_generation/ES_SmartCampaign_RelStrength_V5_dashboard.ipynb

v2 alpha errors image image

It looks like all alphas that don't have a passive index throw an error

check this for example: https://10.0.1.2:8889/notebooks/alphas/Alpha%20Testing.ipynb image

We have been using a notebook like this to create the smartcampaigns https://10.0.1.2:8889/notebooks/alphas/V4%20alphas/Alpha%20V4%20generation-smart-campaign-Dec19-2017.ipynb image

spickering-git commented 6 years ago

@alexveden thanks for fixing that error. we still need help with S&P There is still an open tail in the S&P position. https://10.0.1.2:8888/notebooks/smart_campaign_generation/ES_SmartCampaign_RelStrength_V5_dashboard.ipynb?dashboard image

from looking at the V1 alpha logs and the watchdog, it looks like the ES alphas calculated ~12:46 and the V2 alphas calculated at 12:47

Here are the EXO logs US.ES_EXO_Active_leg_Short_Call_For_Bearish_CallSpread.log US.ES_EXOWeekly_Calendar_putspread.log US.ES_EXOWeekly_Calendar_risk_restriction_longs.log US.ES_EXOWeekly_Calendar_risk_restriction_shorts.log

Here are the Alpha logs US_ES_Longside_Active_Weekly_Calendar_putspread_AlpV1Exp_AtvPsv_ES_ContFut_Long_Strategy_DSP_LowPass__Bullish_2_Sept_5_Nov_14_2017.log US_ES_Longside_Active_Weekly_Calendar_putspread_AlpV1Exp_AtvPsv_ES_ContFut_Long_Strategy_DSP_LowPass__Bullish_Sept_5_Nov_14_2017.log US_ES_Longside_Passive_Risk_Restriction_AlpV1Exp_AtvPsv_ES_ContFut_Long_Strategy_DSP_LowPass__Bullish_Sept2_5_Nov_14_2017.log US_ES_Shortside_Passive_Risk_Restriction_AlpV1Exp_AtvPsv_ES_ContFut_Short_Strategy_DSP_LowPass__Bearish_2_Sept_5_Nov_14_2017.log

alexveden commented 6 years ago
  1. My investigation showed that index/alpha order is correct

  2. The position of v1+v2 stack are correct:

    • ES_ContFut_Long_Strategy_DSP_LowPass__Bullish_2_Sept_5_custom
    • !NEW_US_ES_Longside_Active_Weekly_Calendar_putspread_AlpV1Exp_AtvPsv_ES_ContFut_Long_Strategy_DSP_LowPass__Bullish_2_Sept_5_Nov_14_2017
  3. The position of v1+v2 stack is zero, because the underlying v1 alpha out of the market:

    • 'ES_ContFut_Long_Strategy_DSP_LowPass__Bullish_Sept_5_custom':1.0,
    • !NEW_US_ES_Longside_Active_Weekly_Calendar_putspread_AlpV1Exp_AtvPsv_ES_ContFut_Long_Strategy_DSP_LowPass__Bullish_Sept_5_Nov_14_2017'
  4. Both of v1 alphas for passive legs are out of the market, BUT the V2 alphas have passive legs and holding the following positions (without adjustments of alpha QTY of the campaign): US_ES_Shortside_Passive_Risk_Restriction_AlpV1Exp_AtvPsv_ES_ContFut_Short_Strategy_DSP_LowPass__Bearish_2_Sept_5_Nov_14_2017

2017-12-20 12:47:12,165 [strategy_base.py:542 - run() ] INFO - Last alpha position: Position last date: 2017-12-20 12:45:00-08:00 Asset DecisionPx ExecPx Qty US.C.F-ES-H18-180316.171222.EW4@2670.0 16.849 16.652 0.0 US.P.F-ES-H18-180316.180105.EW1@2500.0 1.092 1.099 0.0 US.C.F-ES-H18-180316.171229.EW@2710.0 2.638 2.593 2.0 US.P.F-ES-H18-180316.180105.EW1@2605.0 3.227 3.253 -1.0


**US_ES_Longside_Passive_Risk_Restriction_AlpV1Exp_AtvPsv_ES_ContFut_Long_Strategy_DSP_LowPass__Bullish_Sept2_5_Nov_14_2017**

2017-12-20 12:47:07,518 [strategy_base.py:542 - run() ] INFO - Last alpha position: Position last date: 2017-12-20 12:45:00-08:00 Asset DecisionPx ExecPx Qty US.C.F-ES-H18-180316.171222.EW4@2670.0 16.849 16.652 0.0 US.P.F-ES-H18-180316.180105.EW1@2500.0 1.092 1.099 0.0 US.C.F-ES-H18-180316.180112.EW2@2730.0 3.720 3.679 2.0 US.P.F-ES-H18-180316.180105.EW1@2605.0 3.227 3.253 1.0


**!NEW_US_ES_Longside_Active_Weekly_Calendar_putspread_AlpV1Exp_AtvPsv_ES_ContFut_Long_Strategy_DSP_LowPass__Bullish_2_Sept_5_Nov_14_2017**

2017-12-20 12:47:16,434 [strategy_base.py:542 - run() ] INFO - Last alpha position: Position last date: 2017-12-20 12:45:00-08:00 Asset DecisionPx ExecPx Qty US.P.F-ES-H18-180316.180112.EW2@2550.0 3.018 3.035 0.0 US.P.F-ES-H18-180316.180105.EW1@2620.0 4.037 4.070 0.0 US.P.F-ES-H18-180316.171222.EW4@2565.0 0.013 0.013 0.0 US.P.F-ES-H18-180316.180112.EW2@2630.0 7.494 7.543 1.0 US.P.F-ES-H18-180316.180105.EW1@2675.0 12.740 12.839 -3.0 US.P.F-ES-H18-180316.180126.EW4@2590.0 7.914 7.952 2.0

alexveden commented 6 years ago

So that, let's calculate the position of the campaign:

Here is the position in the report: image

Qtys of alphas in the campaign:


{'!NEW_US_ES_Longside_Active_Weekly_Calendar_putspread_AlpV1Exp_AtvPsv_ES_ContFut_Long_Strategy_DSP_LowPass__Bullish_2_Sept_5_Nov_14_2017': {'qty': 2.892190016036732},
 '!NEW_US_ES_Longside_Active_Weekly_Calendar_putspread_AlpV1Exp_AtvPsv_ES_ContFut_Long_Strategy_DSP_LowPass__Bullish_Sept_5_Nov_14_2017': {'qty': 1.0152628174038916},
 '!NEW_US_ES_Longside_Passive_Risk_Restriction_AlpV1Exp_AtvPsv_ES_ContFut_Long_Strategy_DSP_LowPass__Bullish_Sept2_5_Nov_14_2017': {'qty': 1.875},
 '!NEW_US_ES_Shortside_Passive_Risk_Restriction_AlpV1Exp_AtvPsv_ES_ContFut_Short_Strategy_DSP_LowPass__Bearish_2_Sept_5_Nov_14_2017': {'qty': 3.75},
 'ES_ContFut_Long_Strategy_DSP_LowPass__Bullish_2_Sept_5_custom': {'qty': 2.892190016036732},
 'ES_ContFut_Long_Strategy_DSP_LowPass__Bullish_Sept2_5_custom': {'qty': 1.875},
 'ES_ContFut_Long_Strategy_DSP_LowPass__Bullish_Sept_5_custom': {'qty': 1.0152628174038916},
 'ES_ContFut_Short_Strategy_DSP_LowPass__Bearish_2_Sept_5_custom': {'qty': 3.75}}

Total position of the campaign


US.C.F-ES-H18-180316.180112.EW2@2730.0       3.720     3.679       2.0 * 1.875 = 3.75
US.C.F-ES-H18-180316.171229.EW@2710.0        2.638     2.593       2.0 * 3.75 = 7.5
US.P.F-ES-H18-180316.180105.EW1@2605.0       3.227     3.253       1.0 * 1.875 - 1.0 * 3.75 = -1.875
US.P.F-ES-H18-180316.180105.EW1@2675.0      12.740    12.839      -3.0 * 2.8921 = 8.67
US.P.F-ES-H18-180316.180112.EW2@2630.0       7.494     7.543       1.0 * 2.8921  =  2.8921
US.P.F-ES-H18-180316.180126.EW4@2590.0       7.914     7.952       2.0 * 2.8921 = 5.78

Exact match

alexveden commented 6 years ago

Position payoff: image

alexveden commented 6 years ago

However, I've implemented some fixes for Campaign Report and payoff diagrams:

  1. Some positions due to floating point operations remain very small, for example, 4 * 10e-16 (it's about 0.0000000000000004) Fixed
  2. Passive leg exposures of alphas were not highlighted in the CampaigReport alpha exposure section. Probably this is a source of misunderstanding. After next v2 run, the passive exposures should be available in the report. Fixed

image

alexveden commented 6 years ago

Also, I would like to notice that exposure concept is not applicable to v2 alphas by design. Because v2 alphas might have many target products for opening of the position, and they are not limited at all. So, consider alpha exposure section as an indicator of that v2 alphas are engaged in the market. And do not use these numbers to calculate the final position of the alpha, use position QTYs from the logs and alpha coefficients from the campaign.

spickering-git commented 6 years ago

We think we have figured out the problem with ES. It was stacking a put spread with a long futures position, which was a mistake in building the campaign. What is the process to follow when a correction like this goes on? Do we need to run the script that runs on Saturday night (smart_campaign_weekly.py)?

This was wrong image

Corrected image

alexveden commented 6 years ago

Do we need to run the script that runs on Saturday night (smart_campaign_weekly.py)?

No this is unnecessary, just use this snippet from the notebook https://10.0.1.2:8888/notebooks/smart_campaigns/SmartCampaign_Deployment_test.ipynb

image

This code recalculates smart campaign and risk params, so this is what smart_campaign_weekly.py does but in application to a single smart campaign.