2019-10-02: The community is currently in read-only mode
Commission Scheme that accesses data feed(s)?
Brandon Johnson last edited by
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
strategyis running with 28 data feeds - and looping during
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]] # 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]] exchange_rate = 1/exchange_rate
In order to interpret this easier, note that
dis a datafeed being passed to the function through an
next- similar to the example given here. I've also stored the closing prices of all 28 pairs in the dictionary named
self.closesand a dictionary with the all datafeeds called
self.data_dictfor my convenience.
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.