Skip to content

How to use backtesting.py for forex trading #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sylver opened this issue Jul 13, 2019 · 5 comments · Fixed by #47
Closed

How to use backtesting.py for forex trading #10

sylver opened this issue Jul 13, 2019 · 5 comments · Fixed by #47
Labels
enhancement New feature or request

Comments

@sylver
Copy link

sylver commented Jul 13, 2019

Expected Behavior

Having an example in the documentation on how use this library for Forex trading with lot size, position size, leverage, margin call, multiple positions opening, etc

Actual Behavior

I can't figure out how/if this is possible with this library even if you mention forex and have a sample set of EURUSD.

The methods buy and sell of Strategy mention that they "close any current position and use all available funds" which seems a bit extreme and inflexible when money management recommends to use only 1% of your account on each trade.
Maybe I didn't understand what you mean here but I don't see the point to use all or none of the account and not give a strategy a way to set the account's amount/percent we want per trade and to open several trades on the same pair, moreover for Forex with lots.

If not already coded, would love to help improve that.

Disclaimer: I'm new to trading and forex trading, maybe there's something I didn't understand on this part.

Awesome library btw

@algomaschine
Copy link

algomaschine commented Jul 18, 2019

+1 here. at least it would be helpful to be able to:

  1. simulate 1:100 leverage (there's an example with 1:30, but no formula on how to setup any leverage)
  2. fixed and variable (on demand) position size in trading assuming lots (100k USD is one lot roughly)

@baptisteArno
Copy link

https://kernc.github.io/backtesting.py/doc/backtesting/backtesting.html

in the init function you can specify a margin option

margin is the required margin (ratio) of a leveraged account. No difference is made between initial and maintenance margins. To run the backtest using e.g. 50:1 leverge your broker allows, set margin to 0.02

but for variable position size I'm looking for this option too !

@kernc kernc added the enhancement New feature or request label Aug 2, 2019
@taoxuau
Copy link

taoxuau commented Aug 18, 2019

Hi @kernc ,

I am wondering if the best way to add real forex trading support is to create a subclass of _Broker and implement all method with my real forex trading APIs. Any suggestion is appreciated. BTW, I'm using OANDA v20.

Thanks in advance.

@algomaschine
Copy link

Dear @kernc , is there a possibility to offer you a small job of integrating your lib into my project? I've tried doing it other developer following the guidelines in the questions asked here, but eventually it stops working either in one way or another due to the way signals are generated in my project. Of course, that would be paid. Really it should take no more than one for you to get it done since your know the ins and outs of this projects. If you would help on this one, please drop me a line on the email [email protected] or leave your contact. Thanks.

@kernc
Copy link
Owner

kernc commented Mar 9, 2020

Sorry for not chipping in sooner. I guess order sizing and what came with it required a more serious overhaul.

I pushed PR #47 that adds order sizing (among other things). If anyone is interested to give it a glance, particularly to _Broker._process_orders() method, I'd be delighted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants