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

FX trading base currency problem



  • This might be a newbie only problem, but I am not quite sure when I backtest my strategy, how can I set base currency and product currency to manage my PnL to have all them in a single base currency. Can anyone give me some hit or any crafted code to use for this?

    (eg, USD.JPY trade in JPY amount per 1 USD, after the closing of a holding position, my profit or loss result is in JPY. I want to have it in USD.)



  • Hi Jimmy,
    You can just take the last JPYUSD close price and perform a currency conversion at that price.

    For example, if the last close was 100 JPY to 1 USD and your profit was 500 JPY, then you made 5 USD profit.

    It gets more complex if your account currency is in USD and you were trading GBPEUR or something without USD. In that case, you would need to add another currency feed to the system and then do a conversion from the feed with the USD pair.



  • @thatblokedave

    Hey, thatblokedave!
    Many thanks for your reply!

    I understand that I need to e.g usd.jpy divide the profit by the price when close out the position to get profit in usd, but I wonder if there are any built-in functions or parameters that I could use or adjust to achieve this? If so, could you please hit me which file I should change or looking at? Or I need to create my own profit & loss function?

    Another thing is that, I load data from IB and store in Ib.store, and use it for my backtest directly from the store. I noticed that the plot after the backtests that have been done this way doesn’t really plot out the buy and sell points which the code that provided in the QuickStart does. Is there any solution for that? Or I need to load data to a cav file first and then feed it to backtrader? Do you have any idea?

    Thanks a lot Dave.



  • Hi Jimmyliu,

    I have the same problem and have also not yet found an easy solution for that. Would be great if someone in the community that has solved this issue could share his/her approach.

    I first thought about just adding two trades that would (in your example) basically convert the "base currency" exposure from USD to JPY. However, in this approach one would have twice as much invested capital per position, portfolio composition gets really messy, etc.

    So I am still trying to find a practical solution as well :-)

    Best JF