oanda-backtest is a python library for backtest with oanda rest api on Python 3.6 and above.
Project description
oanda-backtest
oanda-backtest is a python library for backtest with oanda 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 -344.000
total trades 193.000
win rate 29.534
profit factor 0.966
maximum drawdown 2781.000
recovery factor -0.124
riskreward ratio 2.289
sharpe ratio -0.011
average return -1.748
stop loss 1.000
take profit 1.000
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.2.0.tar.gz
(5.5 kB
view hashes)
Built Distribution
Close
Hashes for oanda_backtest-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b80dce434244178ef84f9a45cb3bc2170ab0b63eb2e57ed4152f2ca1313b135a |
|
MD5 | ba9fc688e08d32f31557d772c9d4052f |
|
BLAKE2b-256 | 622e04d0fa7729cc2a1a0b1da52e537f5f456947dac540066f5fd4d19abeccad |