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)

            combined_forecast[combined_forecast > 0.0] = 10.0
            combined_forecast[combined_forecast < 0.0] = 10.0

            return combined_forecast
示例#2
0
        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)

            combined_forecast[combined_forecast > 0.0] = 10.0
            combined_forecast[combined_forecast < 0.0] = 10.0

            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)

            def map_forecast_value(x):
                x = float(x)
                if x < -20.0:
                    return -30.0
                if x >= -20.0 and x < -10.0:
                    return -(abs(x) - 10.0) * 3
                if x >= -10.0 and x <= 10.0:
                    return 0.0
                if x > 10.0 and x <= 20.0:
                    return (abs(x) - 10.0) * 3
                return 30.0

            combined_forecast = pd.DataFrame(
                [map_forecast_value(x) for x in combined_forecast.values],
                combined_forecast.index)

            return combined_forecast
示例#4
0
        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)

            def map_forecast_value(x):
                x = float(x)
                if x < -20.0:
                    return -30.0
                if x >= -20.0 and x < -10.0:
                    return -(abs(x) - 10.0) * 3
                if x >= -10.0 and x <= 10.0:
                    return 0.0
                if x > 10.0 and x <= 20.0:
                    return (abs(x) - 10.0) * 3
                return 30.0

            combined_forecast = pd.DataFrame(
                [map_forecast_value(x)
                 for x in combined_forecast.values], combined_forecast.index)

            return combined_forecast