oanda-backtest is a python library for backtest with oanda rest api on Python 3.5 and above.
Project description
oanda-backtest
oanda-backtest is a python library for backtest with oanda rest api on Python 3.5 and above.
Installation
$ pip install oanda-backtest
Usage
#
# basic
#
from oanda_backtest import Backtest
bt = Backtest(token='XXXXXXXXXX')
bt.get("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())).values
bt.buy_exit = bt.sell_entry = ((fast_ma < slow_ma) & (fast_ma.shift() >= slow_ma.shift())).values
bt.run()
bt.plot()
#
# advanced
#
from oanda_backtest import Backtest
import os
bt = Backtest(token='XXXXXXXXXX')
filepath='usd-jpy-h1.csv'
if os.path.exists(filepath):
df = bt.read_csv(filepath)
else:
params = {
"granularity": "H1", # 1 hour candlesticks
"count": 5000 # 5000 candlesticks (default=500, maximum=5000)
}
df = bt.get("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())).values
bt.sell_entry = ((fast_ma < slow_ma) & (fast_ma.shift() >= slow_ma.shift())).values
bt.buy_exit = ((bt.C < exit_ma) & (bt.C.shift() >= exit_ma.shift())).values
bt.sell_exit = ((bt.C > exit_ma) & (bt.C.shift() <= exit_ma.shift())).values
bt.initial_deposit = 100000 # default=0
bt.point = 0.01 # 1pips (default=0.0001)
bt.lots = 1000 # currency unit (default=10000)
bt.loss_cut = 50 # loss cut pips (default=0)
bt.profit_taking = 100 # profit taking pips (default=0)
print(bt.run())
bt.plot("backtest.png")
total profit 72.00
total trades 188.00
win rate 29.79
profit factor 1.01
maximum drawdown 2781.00
recovery factor 0.03
riskreward ratio 2.36
sharpe ratio 0.00
average return 0.17
loss cut rate 0.53
profit taking rate 0.53
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
oanda-backtest-0.1.0.tar.gz
(5.6 kB
view hashes)
Built Distribution
Close
Hashes for oanda_backtest-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b439c4f7eb89ad4afa3e0892feeeca9dac179a5ed0e2f2dcb99bc8335e47fd21 |
|
MD5 | 80dbea3d2ab6b1f854e813c817bafb66 |
|
BLAKE2b-256 | a2316e29038a42e703f42acf902d201187ac652bd1748c70cd8e0f3dcdec2a91 |