当前位置: 首页>>代码示例>>Python>>正文


Python objects.resolve_function函数代码示例

本文整理汇总了Python中syscore.objects.resolve_function函数的典型用法代码示例。如果您正苦于以下问题:Python resolve_function函数的具体用法?Python resolve_function怎么用?Python resolve_function使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了resolve_function函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self, optimise_params):
        """
        Create an object which estimates the moments for a single period of data, according to the parameters

        The parameters we need are popped from the config dict
        
        :param optimise_params: Parameters for optimisation
        :type optimise_params: dict
    
        """
        
        corr_estimate_params=copy(optimise_params["correlation_estimate"])
        mean_estimate_params=copy(optimise_params["mean_estimate"])
        vol_estimate_params=copy(optimise_params["vol_estimate"])

        corr_estimate_func=resolve_function(corr_estimate_params.pop("func"))
        mean_estimate_func=resolve_function(mean_estimate_params.pop("func"))
        vol_estimate_func=resolve_function(vol_estimate_params.pop("func"))

        setattr(self, "corr_estimate_params", corr_estimate_params)
        setattr(self, "mean_estimate_params", mean_estimate_params)
        setattr(self, "vol_estimate_params", vol_estimate_params)
        
        setattr(self, "corr_estimate_func", corr_estimate_func)
        setattr(self, "mean_estimate_func", mean_estimate_func)
        setattr(self, "vol_estimate_func", vol_estimate_func)
开发者ID:MortenMunck,项目名称:pysystemtrade,代码行数:26,代码来源:optimisation.py

示例2: __init__

    def __init__(self,
                 optimise_params,
                 annualisation=BUSINESS_DAYS_IN_YEAR,
                 ann_target_SR=.5):
        """
        Create an object which estimates the moments for a single period of data, according to the parameters

        The parameters we need are popped from the config dict

        :param optimise_params: Parameters for optimisation
        :type optimise_params: dict

        """

        corr_estimate_params = copy(optimise_params["correlation_estimate"])
        mean_estimate_params = copy(optimise_params["mean_estimate"])
        vol_estimate_params = copy(optimise_params["vol_estimate"])

        corr_estimate_func = resolve_function(corr_estimate_params.pop("func"))
        mean_estimate_func = resolve_function(mean_estimate_params.pop("func"))
        vol_estimate_func = resolve_function(vol_estimate_params.pop("func"))

        setattr(self, "corr_estimate_params", corr_estimate_params)
        setattr(self, "mean_estimate_params", mean_estimate_params)
        setattr(self, "vol_estimate_params", vol_estimate_params)

        setattr(self, "corr_estimate_func", corr_estimate_func)
        setattr(self, "mean_estimate_func", mean_estimate_func)
        setattr(self, "vol_estimate_func", vol_estimate_func)

        period_target_SR = ann_target_SR / (annualisation**.5)

        setattr(self, "annualisation", annualisation)
        setattr(self, "period_target_SR", period_target_SR)
        setattr(self, "ann_target_SR", ann_target_SR)
开发者ID:kohehir,项目名称:pysystemtrade,代码行数:35,代码来源:optimisation.py

示例3: calculation_of_raw_instrument_weights

    def calculation_of_raw_instrument_weights(self):
        """
        Estimate the instrument weights

        Done like this to expose calculations

        :returns: TxK pd.DataFrame containing weights, columns are instrument names, T covers all

        """

        def _calculation_of_raw_instrument_weights(system, NotUsed1, this_stage,
                                                   weighting_func, **weighting_params):

            this_stage.log.terse("Calculating raw instrument weights")

            instrument_codes = system.get_instrument_list()

            weight_func = weighting_func(
                log=this_stage.log.setup(
                    call="weighting"),
                **weighting_params)
            if weight_func.need_data():

                if hasattr(system, "accounts"):
                    pandl = this_stage.pandl_across_subsystems()
                    (pandl_gross, pandl_costs) = decompose_group_pandl([pandl])

                    weight_func.set_up_data(
                        data_gross=pandl_gross, data_costs=pandl_costs)

                else:
                    error_msg = "You need an accounts stage in the system to estimate instrument weights"
                    this_stage.log.critical(error_msg)

            else:
                # equal weights doesn't need data

                positions = this_stage._get_all_subsystem_positions()
                weight_func.set_up_data(weight_matrix=positions)

            SR_cost_list = [this_stage.get_instrument_subsystem_SR_cost(
                instr_code) for instr_code in instrument_codes]

            weight_func.optimise(ann_SR_costs=SR_cost_list)

            return weight_func

        # Get some useful stuff from the config
        weighting_params = copy(self.parent.config.instrument_weight_estimate)

        # which function to use for calculation
        weighting_func = resolve_function(weighting_params.pop("func"))

        calcs_of_instrument_weights = self.parent.calc_or_cache(
            'calculation_of_raw_instrument_weights', ALL_KEYNAME,
            _calculation_of_raw_instrument_weights,
            self, weighting_func, **weighting_params)

        return calcs_of_instrument_weights
开发者ID:bmaher74,项目名称:pysystemtrade,代码行数:59,代码来源:portfolio.py

示例4: daily_returns_volatility

    def daily_returns_volatility(self, instrument_code):
        """
        Gets volatility of daily returns (not % returns)

        This is done using a user defined function

        We get this from:
          the configuration object
          or if not found, system.defaults.py

        The dict must contain func key; anything else is optional

        :param instrument_code: Instrument to get prices for
        :type trading_rules: str

        :returns: Tx1 pd.DataFrame

        >>> from systems.tests.testdata import get_test_object
        >>> from systems.basesystem import System
        >>>
        >>> (rawdata, data, config)=get_test_object()
        >>> system=System([rawdata], data)
        >>> ## uses defaults
        >>> system.rawdata.daily_returns_volatility("EDOLLAR").tail(2)
                         vol
        2015-12-10  0.054145
        2015-12-11  0.058522
        >>>
        >>> from sysdata.configdata import Config
        >>> config=Config("systems.provided.example.exampleconfig.yaml")
        >>> system=System([rawdata], data, config)
        >>> system.rawdata.daily_returns_volatility("EDOLLAR").tail(2)
                         vol
        2015-12-10  0.054145
        2015-12-11  0.058522
        >>>
        >>> config=Config(dict(volatility_calculation=dict(func="syscore.algos.robust_vol_calc", days=200)))
        >>> system2=System([rawdata], data, config)
        >>> system2.rawdata.daily_returns_volatility("EDOLLAR").tail(2)
                         vol
        2015-12-10  0.057946
        2015-12-11  0.058626

        """
        self.log.msg(
            "Calculating daily volatility for %s" % instrument_code,
            instrument_code=instrument_code)

        system = self.parent
        dailyreturns = self.daily_returns(instrument_code)
        volconfig = copy(system.config.volatility_calculation)

        # volconfig contains 'func' and some other arguments
        # we turn func which could be a string into a function, and then
        # call it with the other ags
        volfunction = resolve_function(volconfig.pop('func'))
        vol = volfunction(dailyreturns, **volconfig)

        return vol
开发者ID:ChrisAllisonMalta,项目名称:pysystemtrade,代码行数:59,代码来源:rawdata.py

示例5: _get_forecast_scalar_estimated_from_instrument_list

    def _get_forecast_scalar_estimated_from_instrument_list(
            self, instrument_code, rule_variation_name,
            forecast_scalar_config):
        """
        Get the scalar to apply to raw forecasts

        If not cached, these are estimated from past forecasts


        :param instrument_code: instrument code, or ALL_KEYNAME if pooling
        :type str:

        :param rule_variation_name:
        :type str: name of the trading rule variation

        :param forecast_scalar_config:
        :type dict: relevant part of the config

        :returns: float

        """

        # The config contains 'func' and some other arguments
        # we turn func which could be a string into a function, and then
        # call it with the other ags
        scalar_function = resolve_function(forecast_scalar_config.pop('func'))
        """
        instrument_list contains multiple things, might pool everything across
          all instruments
        """

        if instrument_code == ALL_KEYNAME:
            # pooled, same for all instruments
            instrument_list = self.parent.get_instrument_list()

        else:
            ## not pooled
            instrument_list = [instrument_code]

        self.log.msg(
            "Getting forecast scalar for %s over %s" %
            (rule_variation_name, ", ".join(instrument_list)),
            rule_variation_name=rule_variation_name)

        # Get forecasts for each instrument
        forecast_list = [
            self.get_raw_forecast(instrument_code, rule_variation_name)
            for instrument_code in instrument_list
        ]

        cs_forecasts = pd.concat(forecast_list, axis=1)

        # an example of a scaling function is syscore.algos.forecast_scalar
        # must return thing the same size as cs_forecasts
        scaling_factor = scalar_function(cs_forecasts,
                                         **forecast_scalar_config)

        return scaling_factor
开发者ID:kohehir,项目名称:pysystemtrade,代码行数:58,代码来源:forecast_scale_cap.py

示例6: __init__

 def __init__(self, optimise_params, annualisation=BUSINESS_DAYS_IN_YEAR, 
              ann_target_SR=.5):        
     corr_estimate_params=copy(optimise_params["correlation_estimate"])
     mean_estimate_params=copy(optimise_params["mean_estimate"])
     vol_estimate_params=copy(optimise_params["vol_estimate"])
     corr_estimate_func=resolve_function(corr_estimate_params.pop("func"))
     mean_estimate_func=resolve_function(mean_estimate_params.pop("func"))
     vol_estimate_func=resolve_function(vol_estimate_params.pop("func"))
     setattr(self, "corr_estimate_params", corr_estimate_params)
     setattr(self, "mean_estimate_params", mean_estimate_params)
     setattr(self, "vol_estimate_params", vol_estimate_params)        
     setattr(self, "corr_estimate_func", corr_estimate_func)
     setattr(self, "mean_estimate_func", mean_estimate_func)
     setattr(self, "vol_estimate_func", vol_estimate_func)
     period_target_SR = ann_target_SR / (annualisation**.5)        
     setattr(self, "annualisation", annualisation)
     setattr(self, "period_target_SR", period_target_SR)
     setattr(self, "ann_target_SR", ann_target_SR)
开发者ID:caitouwh,项目名称:kod,代码行数:18,代码来源:tw2.py

示例7: get_instrument_correlation_matrix

    def get_instrument_correlation_matrix(self):
        """
        Returns a correlationList object which contains a history of correlation matricies

        :returns: correlation_list object

        >>> from systems.tests.testdata import get_test_object_futures_with_pos_sizing_estimates
        >>> from systems.basesystem import System
        >>> (account, posobject, combobject, capobject, rules, rawdata, data, config)=get_test_object_futures_with_pos_sizing_estimates()
        >>> system=System([rawdata, rules, posobject, combobject, capobject,PortfoliosEstimated(), account], data, config)
        >>> system.config.forecast_weight_estimate["method"]="shrinkage" ## speed things up
        >>> system.config.forecast_weight_estimate["date_method"]="in_sample" ## speed things up
        >>> system.config.instrument_weight_estimate["date_method"]="in_sample" ## speed things up
        >>> system.config.instrument_weight_estimate["method"]="shrinkage" ## speed things up
        >>> ans=system.portfolio.get_instrument_correlation_matrix()
        >>> ans.corr_list[-1]
        array([[ 1.        ,  0.56981346,  0.62458477],
               [ 0.56981346,  1.        ,  0.88087893],
               [ 0.62458477,  0.88087893,  1.        ]])
        >>> print(ans.corr_list[0])
        [[ 1.    0.99  0.99]
         [ 0.99  1.    0.99]
         [ 0.99  0.99  1.  ]]
        >>> print(ans.corr_list[10])
        [[ 1.          0.99        0.99      ]
         [ 0.99        1.          0.78858156]
         [ 0.99        0.78858156  1.        ]]
        """

        self.log.terse("Calculating instrument correlations")

        system = self.parent

        # Get some useful stuff from the config
        corr_params = copy(system.config.instrument_correlation_estimate)

        # which function to use for calculation
        corr_func = resolve_function(corr_params.pop("func"))

        if hasattr(system, "accounts"):
            pandl = self.pandl_across_subsystems().to_frame()
        else:
            error_msg = "You need an accounts stage in the system to estimate instrument correlations"
            self.log.critical(error_msg)

        # Need to resample here, because the correlation function won't do
        # it properly (doesn't know it's dealing with returns data)
        frequency = corr_params['frequency']
        pandl = pandl.cumsum().resample(frequency).last().diff()

        # The subsequent resample inside the correlation function will have no effect

        return corr_func(pandl, **corr_params)
开发者ID:ChrisAllisonMalta,项目名称:pysystemtrade,代码行数:53,代码来源:portfolio.py

示例8: _daily_returns_volatility

        def _daily_returns_volatility(system, instrument_code, this_stage):
            this_stage.log.msg("Calculating daily volatility for %s" % instrument_code, instrument_code=instrument_code)

            dailyreturns = this_stage.daily_returns(instrument_code)

            volconfig=copy(system.config.volatility_calculation)

            # volconfig contains 'func' and some other arguments
            # we turn func which could be a string into a function, and then
            # call it with the other ags
            volfunction = resolve_function(volconfig.pop('func'))
            vol = volfunction(dailyreturns, **volconfig)

            return vol
开发者ID:Sayan-Paul,项目名称:kod,代码行数:14,代码来源:rawdata.py

示例9: _daily_returns_volatility

        def _daily_returns_volatility(system, instrument_code, this_stage):
            print(__file__ + ":" + str(inspect.getframeinfo(inspect.currentframe())[:3][1]) + ":" +"Calculating daily volatility for %s" % instrument_code)

            dailyreturns = this_stage.daily_returns(instrument_code)

            volconfig=copy(system.config.volatility_calculation)

            # volconfig contains 'func' and some other arguments
            # we turn func which could be a string into a function, and then
            # call it with the other ags
            volfunction = resolve_function(volconfig.pop('func'))
            vol = volfunction(dailyreturns, **volconfig)

            return vol
开发者ID:caitouwh,项目名称:kod,代码行数:14,代码来源:rawdata.py

示例10: _get_instrument_div_multiplier

        def _get_instrument_div_multiplier(system,  NotUsed, this_stage):

            this_stage.log.terse("Calculating instrument div. multiplier")
            
            ## Get some useful stuff from the config
            div_mult_params=copy(system.config.instrument_div_mult_estimate)
            
            idm_func=resolve_function(div_mult_params.pop("func"))
            
            correlation_list_object=this_stage.get_instrument_correlation_matrix()
            weight_df=this_stage.get_instrument_weights()

            ts_idm=idm_func(correlation_list_object, weight_df, **div_mult_params)

            return ts_idm
开发者ID:SkippyHo,项目名称:pysystemtrade,代码行数:15,代码来源:portfolio.py

示例11: _get_forecast_div_multiplier

        def _get_forecast_div_multiplier(system, instrument_code, this_stage):

            print(__file__ + ":" + str(inspect.getframeinfo(inspect.currentframe())[:3][1]) + ":" +"Calculating forecast div multiplier for %s" % instrument_code)
            
            ## Get some useful stuff from the config
            div_mult_params=copy(system.config.forecast_div_mult_estimate)
            
            idm_func=resolve_function(div_mult_params.pop("func"))
            
            correlation_list_object=this_stage.get_forecast_correlation_matrices(instrument_code)
            weight_df=this_stage.get_forecast_weights(instrument_code)

            ts_fdm=idm_func(correlation_list_object, weight_df, **div_mult_params)

            return ts_fdm
开发者ID:caitouwh,项目名称:kod,代码行数:15,代码来源:forecast_combine.py

示例12: _get_forecast_div_multiplier

        def _get_forecast_div_multiplier(system, instrument_code, this_stage):

            this_stage.log.terse("Calculating forecast div multiplier for %s" % instrument_code,
                                 instrument_code=instrument_code)
            
            ## Get some useful stuff from the config
            div_mult_params=copy(system.config.forecast_div_mult_estimate)
            
            idm_func=resolve_function(div_mult_params.pop("func"))
            
            correlation_list_object=this_stage.get_forecast_correlation_matrices(instrument_code)
            weight_df=this_stage.get_forecast_weights(instrument_code)

            ts_fdm=idm_func(correlation_list_object, weight_df, **div_mult_params)

            return ts_fdm
开发者ID:yowtzu,项目名称:pysystemtrade,代码行数:16,代码来源:forecast_combine.py

示例13: calculation_of_raw_instrument_weights

    def calculation_of_raw_instrument_weights(self):
        """
        Estimate the instrument weights
        
        Done like this to expose calculations

        :returns: TxK pd.DataFrame containing weights, columns are instrument names, T covers all

        """

        def _calculation_of_raw_instrument_weights(system, NotUsed1, this_stage, 
                                      weighting_func, **weighting_params):
            
            this_stage.log.terse("Calculating raw instrument weights")

            instrument_codes=system.get_instrument_list()
            if hasattr(system, "accounts"):
                pandl_subsystems=[this_stage.pandl_for_subsystem(code)
                        for code in instrument_codes]
            else:
                error_msg="You need an accounts stage in the system to estimate instrument weights"
                this_stage.log.critical(error_msg)

            pandl=pd.concat(pandl_subsystems, axis=1)
            pandl.columns=instrument_codes

            instrument_weight_results=weighting_func(pandl,  log=self.log.setup(call="weighting"), **weighting_params)
        
            return instrument_weight_results


        ## Get some useful stuff from the config
        weighting_params=copy(self.parent.config.instrument_weight_estimate)

        ## which function to use for calculation
        weighting_func=resolve_function(weighting_params.pop("func"))
        
        calcs_of_instrument_weights = self.parent.calc_or_cache(
            'calculation_of_raw_instrument_weights', ALL_KEYNAME, 
            _calculation_of_raw_instrument_weights,
             self, weighting_func, **weighting_params)
        
        return calcs_of_instrument_weights
开发者ID:Sayan-Paul,项目名称:kod,代码行数:43,代码来源:portfolio.py

示例14: capital_multiplier

    def capital_multiplier(self, delayfill=True, roundpositions=False):
        """
        Get a capital multiplier

        :param delayfill: Lag fills by one day
        :type delayfill: bool

        :param roundpositions: Round positions to whole contracts
        :type roundpositions: bool

        :returns: pd.Series

        """
        system = self.parent
        capmult_params = copy(system.config.capital_multiplier)
        capmult_func = resolve_function(capmult_params.pop("func"))

        capmult = capmult_func(system, **capmult_params)

        capmult = capmult.reindex(self.portfolio().index).ffill()

        return capmult
开发者ID:kohehir,项目名称:pysystemtrade,代码行数:22,代码来源:account.py

示例15: _daily_returns_volatility

        def _daily_returns_volatility(system, instrument_code, this_stage):
            dailyreturns = this_stage.daily_returns(instrument_code)

            try:
                volconfig = copy(system.config.volatility_calculation)
                identify_error = "inherited from config object"
            except:
                volconfig = copy(system_defaults['volatility_calculation'])
                identify_error = "found in system.defaults.py"

            if "func" not in volconfig:

                raise Exception(
                    "The volconfig dict (%s) needs to have a 'func' key" % identify_error)

            # volconfig contains 'func' and some other arguments
            # we turn func which could be a string into a function, and then
            # call it with the other ags
            volfunction = resolve_function(volconfig.pop('func'))
            vol = volfunction(dailyreturns, **volconfig)

            return vol
开发者ID:as4724,项目名称:pysystemtrade,代码行数:22,代码来源:rawdata.py


注:本文中的syscore.objects.resolve_function函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。