Exemple #1
0
    def pandl_for_trading_rule_unweighted(self,
                                          rule_variation_name: str,
                                          delayfill: bool = True) \
                                        -> accountCurveGroup:

        list_of_instruments = self.get_instrument_list()
        dict_of_pandl_by_instrument = dict([
            (instrument_code,
             self.pandl_for_instrument_forecast(
                 instrument_code=instrument_code,
                 rule_variation_name=rule_variation_name,
                 delayfill=delayfill))
            for instrument_code in list_of_instruments
        ])

        dict_of_pandl_by_instrument = dictOfAccountCurves(
            dict_of_pandl_by_instrument)

        capital = self.get_notional_capital()

        account_curve = accountCurveGroup(dict_of_pandl_by_instrument,
                                          capital=capital,
                                          weighted=False)

        return account_curve
Exemple #2
0
    def pandl_for_trading_rule(self,
                               rule_variation_name: str,
                               delayfill: bool = True) \
                            -> accountCurveGroup:

        #  If I want the performance of a given trading rule across individual
        #  instruments in isolation, then I need to take pandl_for_trading_rule_weighted
        #  and normalise it so that the returns are as a proportion of the sum of
        #  all the relevant
        #  forecast weight * FDM * instrument weight * IDM;
        #  this is equivalent to the rules risk contribution within the system

        # flag as weighted but actually semi-weighted
        list_of_instruments = self.get_instrument_list()
        dict_of_pandl_by_instrument = dict([
            (instrument_code,
             self.pandl_for_instrument_forecast_weighted_within_trading_rule(
                 instrument_code,
                 rule_variation_name=rule_variation_name,
                 delayfill=delayfill))
            for instrument_code in list_of_instruments
        ])

        dict_of_pandl_by_instrument = dictOfAccountCurves(
            dict_of_pandl_by_instrument)

        capital = self.get_notional_capital()

        account_curve = accountCurveGroup(dict_of_pandl_by_instrument,
                                          capital=capital,
                                          weighted=True)

        return account_curve
Exemple #3
0
    def pandl_for_instrument_rules_unweighted(
            self,
            instrument_code: str,
            trading_rule_list=arg_not_supplied,
            delayfill: bool = True) -> accountCurveGroup:

        # (unweighted group - elements are pandl_for_instrument_forecast across trading rules)
        if trading_rule_list is arg_not_supplied:
            trading_rule_list = self.list_of_rules_for_code(instrument_code)
        dict_of_pandl_by_rule = dict([
            (rule_variation_name,
             self.pandl_for_instrument_forecast(
                 instrument_code=instrument_code,
                 rule_variation_name=rule_variation_name,
                 delayfill=delayfill))
            for rule_variation_name in trading_rule_list
        ])

        dict_of_pandl_by_rule = dictOfAccountCurves(dict_of_pandl_by_rule)

        capital = self.get_notional_capital()

        account_curve = accountCurveGroup(dict_of_pandl_by_rule,
                                          capital=capital,
                                          weighted=False)

        return account_curve
    def pandl_for_instrument_rules(
            self,
            instrument_code: str,
            delayfill: bool = True) -> accountCurveGroup:

        # how all trading rules have done for a particular instrument, weighted
        list_of_rules = self.list_of_rules_for_code(instrument_code)
        dict_of_pandl_by_rule = dict([(
            rule_variation_name,
            self.pandl_for_instrument_forecast_weighted(
                instrument_code=instrument_code,
                rule_variation_name=rule_variation_name,
                delayfill=delayfill,
            ),
        ) for rule_variation_name in list_of_rules])

        dict_of_pandl_by_rule = dictOfAccountCurves(dict_of_pandl_by_rule)

        capital = self.get_notional_capital()

        account_curve = accountCurveGroup(dict_of_pandl_by_rule,
                                          capital=capital,
                                          weighted=True)

        return account_curve
    def portfolio(self, delayfill=True, roundpositions=True):
        """
        Get the p&l for entire portfolio

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

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

        :returns: accountCurve

        >>> from systems.basesystem import System
        >>> from systems.tests.testdata import get_test_object_futures_with_portfolios
        >>> (portfolio, posobject, combobject, capobject, rules, rawdata, data, config)=get_test_object_futures_with_portfolios()
        >>> system=System([portfolio, posobject, combobject, capobject, rules, rawdata, Account()], data, config)
        >>>
        >>> system.accounts.portfolio().ann_std()
        0.2638225179274214
        """

        self.log.terse("Calculating pandl for portfolio")
        capital = self.get_notional_capital()
        instruments = self.get_instrument_list()
        dict_of_pandl_by_instrument = dict(
            [
                (
                    instrument_code,
                    self.pandl_for_instrument(
                        instrument_code,
                        delayfill=delayfill,
                        roundpositions=roundpositions,
                    ),
                )
                for instrument_code in instruments
            ]
        )

        dict_of_pandl_by_instrument = dictOfAccountCurves(dict_of_pandl_by_instrument)

        account_curve = accountCurveGroup(
            dict_of_pandl_by_instrument, capital=capital, weighted=True
        )

        return account_curve
    def optimised_portfolio(self, delayfill=True):

        self.log.terse("Calculating pandl for portfolio")
        capital = self.get_notional_capital()
        instruments = self.get_instrument_list()
        dict_of_pandl_by_instrument = dict([(
            instrument_code,
            self.pandl_for_optimised_instrument(instrument_code,
                                                delayfill=delayfill),
        ) for instrument_code in instruments])

        dict_of_pandl_by_instrument = dictOfAccountCurves(
            dict_of_pandl_by_instrument)

        account_curve = accountCurveGroup(dict_of_pandl_by_instrument,
                                          capital=capital,
                                          weighted=True)

        return account_curve
Exemple #7
0
    def portfolio_with_multiplier(self, delayfill=True, roundpositions=True):

        self.log.terse("Calculating pandl for portfolio with multiplier")
        capital = self.get_actual_capital()
        instruments = self.get_instrument_list()
        port_pandl = [(instrument_code,
                       self.pandl_for_instrument_with_multiplier(
                           instrument_code,
                           delayfill=delayfill,
                           roundpositions=roundpositions))
                      for instrument_code in instruments]

        port_pandl = dictOfAccountCurves(port_pandl)

        port_pandl = accountCurveGroup(port_pandl,
                                       capital=capital,
                                       weighted=True)

        return port_pandl
    def pandl_across_subsystems(self,
                                delayfill=True,
                                roundpositions=False) -> accountCurveGroup:

        dict_of_pandl_across_subsystems = dict([
            (instrument_code,
             self.pandl_for_subsystem(instrument_code,
                                      delayfill=delayfill,
                                      roundpositions=roundpositions))
            for instrument_code in self.get_instrument_list()
        ])

        dict_of_pandl_across_subsystems = dictOfAccountCurves(
            dict_of_pandl_across_subsystems)

        capital = self.get_notional_capital()

        pandl_across_subsystems = accountCurveGroup(
            dict_of_pandl_across_subsystems, capital=capital, weighted=False)

        return pandl_across_subsystems