def _get_combined_forecast(system, instrument_code, this_stage ): forecast_weights=this_stage.get_forecast_weights(instrument_code) rule_variation_list=list(forecast_weights.columns) forecasts=[this_stage.get_capped_forecast(instrument_code, rule_variation_name) for rule_variation_name in rule_variation_list] forecast_div_multiplier=this_stage.get_forecast_diversification_multiplier(instrument_code) forecast_cap=this_stage.get_forecast_cap() forecasts=pd.concat(forecasts, axis=1) ## multiply weights by forecasts combined_forecast=multiply_df(forecast_weights, forecasts) ## sum combined_forecast=combined_forecast.sum(axis=1).to_frame("comb_forecast") ## apply fdm ## (note in this simple version we aren't adjusting FDM if forecast_weights change) forecast_div_multiplier=forecast_div_multiplier.reindex(forecasts.index, method="ffill") raw_combined_forecast=multiply_df(combined_forecast,forecast_div_multiplier) combined_forecast=apply_cap(raw_combined_forecast, forecast_cap) return combined_forecast
def _get_combined_forecast(system, instrument_code, this_stage): print(__file__ + ":" + str(inspect.getframeinfo(inspect.currentframe())[:3][1]) + ":" +"Calculating combined forecast for %s" % (instrument_code)) forecast_weights = this_stage.get_forecast_weights(instrument_code) rule_variation_list = list(forecast_weights.columns) forecasts = this_stage.get_all_forecasts(instrument_code, rule_variation_list) forecast_div_multiplier = this_stage.get_forecast_diversification_multiplier( instrument_code) forecast_cap = this_stage.get_forecast_cap() # multiply weights by forecasts #NOT NEEDED: (forecast_weights, forecasts) = forecast_weights.align(forecasts, join="right") combined_forecast = forecast_weights.ffill()* forecasts # sum combined_forecast = combined_forecast.sum( axis=1) # apply fdm # (note in this simple version we aren't adjusting FDM if forecast_weights change) raw_combined_forecast = combined_forecast * forecast_div_multiplier.ffill() combined_forecast = apply_cap(raw_combined_forecast, forecast_cap) return combined_forecast
def _get_combined_forecast(system, instrument_code, this_stage): this_stage.log.msg("Calculating combined forecast for %s" % (instrument_code), instrument_code=instrument_code) forecast_weights = this_stage.get_forecast_weights(instrument_code) rule_variation_list = list(forecast_weights.columns) forecasts = this_stage.get_all_forecasts(instrument_code, rule_variation_list) forecast_div_multiplier = this_stage.get_forecast_diversification_multiplier( instrument_code) forecast_cap = this_stage.get_forecast_cap() # multiply weights by forecasts combined_forecast = multiply_df(forecast_weights, forecasts) # sum combined_forecast = combined_forecast.sum( axis=1).to_frame("comb_forecast") # apply fdm # (note in this simple version we aren't adjusting FDM if forecast_weights change) forecast_div_multiplier = forecast_div_multiplier.reindex( forecasts.index, method="ffill") raw_combined_forecast = multiply_df( combined_forecast, forecast_div_multiplier) combined_forecast = apply_cap(raw_combined_forecast, forecast_cap) return combined_forecast
def _get_combined_forecast(system, instrument_code, this_stage): this_stage.log.msg("Calculating combined forecast for %s" % (instrument_code), instrument_code=instrument_code) forecast_weights = this_stage.get_forecast_weights(instrument_code) rule_variation_list = list(forecast_weights.columns) forecasts = this_stage.get_all_forecasts(instrument_code, rule_variation_list) forecast_div_multiplier = this_stage.get_forecast_diversification_multiplier( instrument_code) forecast_cap = this_stage.get_forecast_cap() # multiply weights by forecasts # NOT NEEDED: (forecast_weights, forecasts) = # forecast_weights.align(forecasts, join="right") combined_forecast = forecast_weights.ffill() * forecasts # sum combined_forecast = combined_forecast.sum(axis=1) # apply fdm # (note in this simple version we aren't adjusting FDM if forecast_weights change) raw_combined_forecast = combined_forecast * forecast_div_multiplier.ffill( ) combined_forecast = apply_cap(raw_combined_forecast, forecast_cap) return combined_forecast
def get_combined_forecast(self, instrument_code): """ Get a combined forecast, linear combination of individual forecasts with FDM applied We forward fill all forecasts. We then adjust forecast weights so that they are 1.0 in every period; after setting to zero when no forecast is available. Finally we multiply up, and apply the FDM. Then we cap. :param instrument_code: :type str: :returns: Tx1 pd.DataFrame KEY OUTPUT >>> from systems.tests.testdata import get_test_object_futures_with_rules_and_capping >>> from systems.basesystem import System >>> (fcs, rules, rawdata, data, config)=get_test_object_futures_with_rules_and_capping() >>> system=System([rawdata, rules, fcs, ForecastCombineFixed()], data, config) >>> >>> system.combForecast.get_combined_forecast("EDOLLAR").tail(2) comb_forecast 2015-12-10 1.619134 2015-12-11 2.462610 >>> >>> config.forecast_div_multiplier=1000.0 >>> system2=System([rawdata, rules, fcs, ForecastCombineFixed()], data, config) >>> system2.combForecast.get_combined_forecast("EDOLLAR").tail(2) comb_forecast 2015-12-10 21 2015-12-11 21 """ self.log.msg("Calculating combined forecast for %s" % (instrument_code), instrument_code=instrument_code) forecast_weights = self.get_forecast_weights(instrument_code) rule_variation_list = list(forecast_weights.columns) forecasts = self.get_all_forecasts( instrument_code, rule_variation_list) forecast_div_multiplier = self.get_forecast_diversification_multiplier( instrument_code) forecast_cap = self.get_forecast_cap() combined_forecast = forecast_weights.ffill() * forecasts # sum combined_forecast = combined_forecast.sum( axis=1) # apply fdm # (note in this simple version we aren't adjusting FDM if forecast_weights change) raw_combined_forecast = combined_forecast * forecast_div_multiplier.ffill() combined_forecast = apply_cap(raw_combined_forecast, forecast_cap) return combined_forecast
def _get_capped_forecast( system, instrument_code, rule_variation_name, this_stage): scaled_forecast = this_stage.get_scaled_forecast( instrument_code, rule_variation_name) cap = this_stage.get_forecast_cap() capped_forecast = apply_cap(scaled_forecast, cap) capped_forecast.columns = scaled_forecast.columns return capped_forecast
def _get_capped_forecast( system, instrument_code, rule_variation_name, this_stage): print(__file__ + ":" + str(inspect.getframeinfo(inspect.currentframe())[:3][1]) + ":" +"Calculating capped forecast for %s %s" % (instrument_code, rule_variation_name)) scaled_forecast = this_stage.get_scaled_forecast( instrument_code, rule_variation_name) cap = this_stage.get_forecast_cap() capped_forecast = apply_cap(scaled_forecast, cap) return capped_forecast
def _get_capped_forecast( system, instrument_code, rule_variation_name, this_stage): this_stage.log.msg("Calculating capped forecast for %s %s" % (instrument_code, rule_variation_name), instrument_code=instrument_code, rule_variation_name=rule_variation_name) scaled_forecast = this_stage.get_scaled_forecast( instrument_code, rule_variation_name) cap = this_stage.get_forecast_cap() capped_forecast = apply_cap(scaled_forecast, cap) return capped_forecast
def _get_capped_forecast(system, instrument_code, rule_variation_name, this_stage): print(__file__ + ":" + str(inspect.getframeinfo(inspect.currentframe())[:3][1]) + ":" + "Calculating capped forecast for %s %s" % (instrument_code, rule_variation_name)) scaled_forecast = this_stage.get_scaled_forecast( instrument_code, rule_variation_name) cap = this_stage.get_forecast_cap() capped_forecast = apply_cap(scaled_forecast, cap) return capped_forecast
def _get_capped_forecast(system, instrument_code, rule_variation_name, this_stage): this_stage.log.msg("Calculating capped forecast for %s %s" % (instrument_code, rule_variation_name), instrument_code=instrument_code, rule_variation_name=rule_variation_name) scaled_forecast = this_stage.get_scaled_forecast( instrument_code, rule_variation_name) cap = this_stage.get_forecast_cap() capped_forecast = apply_cap(scaled_forecast, cap) return capped_forecast
def get_capped_forecast(self, instrument_code, rule_variation_name): """ Return the capped, scaled, forecast KEY OUTPUT :param instrument_code: :type str: :param rule_variation_name: :type str: name of the trading rule variation :returns: Tx1 pd.DataFrame, same size as forecast >>> from systems.tests.testdata import get_test_object_futures_with_rules >>> from systems.basesystem import System >>> (rules, rawdata, data, config)=get_test_object_futures_with_rules() >>> config.forecast_cap=0.2 >>> system=System([rawdata, rules, ForecastScaleCapFixed()], data, config) >>> system.forecastScaleCap.get_capped_forecast("EDOLLAR", "ewmac8").tail(2) ewmac8 2015-12-10 -0.190583 2015-12-11 0.200000 """ self.log.msg( "Calculating capped forecast for %s %s" % (instrument_code, rule_variation_name), instrument_code=instrument_code, rule_variation_name=rule_variation_name) scaled_forecast = self.get_scaled_forecast(instrument_code, rule_variation_name) cap = self.get_forecast_cap() capped_forecast = apply_cap(scaled_forecast, cap) return capped_forecast
def get_capped_forecast(self, instrument_code, rule_variation_name): """ Return the capped, scaled, forecast KEY OUTPUT :param instrument_code: :type str: :param rule_variation_name: :type str: name of the trading rule variation :returns: Tx1 pd.DataFrame, same size as forecast >>> from systems.tests.testdata import get_test_object_futures_with_rules >>> from systems.basesystem import System >>> (rules, rawdata, data, config)=get_test_object_futures_with_rules() >>> config.forecast_cap=0.2 >>> system=System([rawdata, rules, ForecastScaleCapFixed()], data, config) >>> system.forecastScaleCap.get_capped_forecast("EDOLLAR", "ewmac8").tail(2) ewmac8 2015-12-10 -0.190583 2015-12-11 0.200000 """ self.log.msg("Calculating capped forecast for %s %s" % (instrument_code, rule_variation_name), instrument_code=instrument_code, rule_variation_name=rule_variation_name) scaled_forecast = self.get_scaled_forecast(instrument_code, rule_variation_name) cap = self.get_forecast_cap() capped_forecast = apply_cap(scaled_forecast, cap) return capped_forecast
def _cap_forecast(self, raw_multiplied_combined_forecast): forecast_cap = self.get_forecast_cap() combined_forecast = apply_cap(raw_multiplied_combined_forecast, forecast_cap) return combined_forecast