For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

Commission Scheme that accesses data feed(s)?

  • How can a commission scheme access strategy data feeds?

    I'm writing a strategy that trades the 28 major pairs (combos of major currencies) in FOREX. One of the issues is coding a replication of the fixed spread commission scheme - like the one referenced here - but one that can handle currency pairs that do not include the trading account's currency.

    For instance: my trading account currency is USD - and I'd like to calculate commission based on a fixed spread scheme for a trade on EUR/JPY. I'd use the formula:

    (Spread)(Pip Cost)(Number of Lots Traded) = Commission

    Determining "Pip Cost" requires me to know the exchange rate between the account and counter currency - in this case the rate of USDJPY. Because my strategy is running with 28 data feeds - and looping during next with enumerate - I have access to USDJPY from inside my strategy, and I frequently must reference alternate exchange rates to size my positions. Is there a way that I can do this from inside a commission scheme? This is how I reference a needed exchange rate for an account currency/counter currency pair in my position sizing method:

            pair = d._name
            base = pair[0:3]
            counter = pair[3:]
            if counter == self.accn_currency:
                method = 0
            elif base == self.accn_currency:
                method = 1
            elif base != self.accn_currency and counter != self.accn_currency:
                method = 2
                exchange_pair = self.accn_currency+counter
                # Check if Exchange Pair Exists
                if exchange_pair in list(self.data_dict.keys()):
                    exchange_rate = self.closes[self.data_dict[exchange_pair]][0]
                # Check if Reverse of Exchange Pair Exists
                elif counter+self.accn_currency in list(self.data_dict.keys()):
                    exchange_rate = self.closes[self.data_dict[counter+self.accn_currency]][0]
                    exchange_rate = 1/exchange_rate

    In order to interpret this easier, note that d is a datafeed being passed to the function through an enumerate loop in next - similar to the example given here. I've also stored the closing prices of all 28 pairs in the dictionary named self.closes and a dictionary with the all datafeeds called self.data_dict for my convenience.

  • administrators

    Commission Schemes are supposed to be agnostic. Nothing prevents you from creating one and giving it the data feeds before adding it to cerebro. It would already have the data feeds in itself.

Log in to reply