oanda-backtest
oanda-backtest is a python library for backtest with oanda fx trade rest api on Python 3.6 and above.
Installation
$ pip install oanda-backtest
Usage
basic
from oanda_backtest import Backtest
bt = Backtest(access_token='<your access token>', environment='practice')
bt.candles("EUR_USD")
fast_ma = bt.sma(period=5)
slow_ma = bt.sma(period=25)
bt.sell_exit = bt.buy_entry = (fast_ma > slow_ma) & (fast_ma.shift() <= slow_ma.shift())
bt.buy_exit = bt.sell_entry = (fast_ma < slow_ma) & (fast_ma.shift() >= slow_ma.shift())
bt.run()
bt.plot()
advanced
from oanda_backtest import Backtest
bt = Backtest(access_token='<your access token>', environment='practice')
filepath='usd-jpy-h1.csv'
if bt.exists(filepath):
bt.read_csv(filepath)
else:
params = {
"granularity": "H1", # 1 hour candlesticks (default=S5)
"count": 5000 # 5000 candlesticks (default=500, maximum=5000)
}
bt.candles("USD_JPY", params)
bt.to_csv(filepath)
fast_ma = bt.sma(period=10)
slow_ma = bt.sma(period=30)
exit_ma = bt.sma(period=5)
bt.buy_entry = (fast_ma > slow_ma) & (fast_ma.shift() <= slow_ma.shift())
bt.sell_entry = (fast_ma < slow_ma) & (fast_ma.shift() >= slow_ma.shift())
bt.buy_exit = (bt.C < exit_ma) & (bt.C.shift() >= exit_ma.shift())
bt.sell_exit = (bt.C > exit_ma) & (bt.C.shift() <= exit_ma.shift())
bt.initial_deposit = 100000 # default=0
bt.units = 1000 # currency unit (default=10000)
bt.stop_loss = 50 # stop loss pips (default=0)
bt.take_profit = 100 # take profit pips (default=0)
print(bt.run())
bt.plot("backtest.png")
total profit 1989.000
total trades 171.000
win rate 35.088
profit factor 1.198
maximum drawdown 2745.000
recovery factor 0.725
riskreward ratio 2.236
sharpe ratio 0.050
average return 10.666
stop loss 5.000
take profit 5.000
Supported indicators
- Simple Moving Average 'sma'
- Exponential Moving Average 'ema'
- Moving Average Convergence Divergence 'macd'
- Relative Strenght Index 'rsi'
- Bollinger Bands 'bband'
- Stochastic Oscillator 'stoch'
- Market Momentum 'mom'
Getting started
For help getting started with OANDA REST API, view our online documentation.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request
Metadata
Release files for oanda-backtest 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| oanda-backtest-0.2.2.tar.gz | 6.9 kB | Without provenance | Details for oanda-backtest-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| oanda_backtest-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for oanda_backtest-0.2.2-py3-none-any.whl |
Total release size: 14.1 kB
Release files / oanda-backtest-0.2.2.tar.gz
| Download URL | oanda-backtest-0.2.2.tar.gz |
|---|---|
| Size | 6.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cfe397f2cda1f6d01e4582765c01ef7874e12dc2810bd829b2bcad7904c825ea
|
|
BLAKE2b-256 checksum How to use checksums |
03b7069d0b494b68b5868801653ed79555c0a8d664687ed580b6112d558d9dea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.2
|
Release files / oanda_backtest-0.2.2-py3-none-any.whl
| Download URL | oanda_backtest-0.2.2-py3-none-any.whl |
|---|---|
| Size | 7.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5f0fd6bddcc19d061d579e4b5e5f2da74e28666952264932e8a1ffb57087f00b
|
|
BLAKE2b-256 checksum How to use checksums |
a998dcaa02482e6bcb3b589795e67a4a7169ba8816ec52d92adbfa37b505b3be
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.2
|
Security for oanda-backtest 0.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.