Comments (11)
This is an interesting error. I am testing your code locally and it performs the backtest correctly. I'm checking if this is because of platform or python version (using 3.7 on MacOS). It could also be an error with the account quoting system under pairs outside of -USD
or generic currency endings but it will require a bit more analysis.
These types of bugs are extremely hard to identify by us, so thanks for creating an issue!
from blankly.
I believe the issue is that there is no generic USD
account allowed under the binance com
ending. I can't create an international account so there is no way to verify this.
I have pushed a new version - v1.6.1-beta
to pypi which doesn't make an implicit assumption that a USD
account exists in the backtest. This may fix your issue. You can run pip install blankly --upgrade
.
from blankly.
You are a very hardworking team. You are making great progress. Thank you very much for your reply and interest.
I have not yet achieved sufficient results to complete my strategy. I know I've come a long way. I am looking forward to getting better results and to meet and communicate with you.
By the way, unfortunately the backtest did not work and I will continue my experiments by installing a linux.
The graphic produced was very nice :)
Including: ETH-USDT,1546290000,1630270800,300.0.csv in backtest.
Including: ETH-USDT,1546290000,1630270800,900.0.csv in backtest.
Including: ETH-USDT,1546290000,1630270800,1800.0.csv in backtest.
Including: ETH-USDT,1546290000,1630270800,3600.0.csv in backtest.
Including: ETH-USDT,1546290000,1630270800,14400.0.csv in backtest.
Including: ETH-USDT,1546290000,1630270800,21600.0.csv in backtest.
Including: ETH-USDT,1546290000,1630270800,86400.0.csv in backtest.
Including: ETH-USDT,1627776000.0,1630108800.0,3600.0.csv in backtest.
Initializing...
1630098000.0
Backtesting...
Progress: [----------] 0.02% Traceback (most recent call last):
File "c:\python39\lib\site-packages\blankly\exchanges\interfaces\paper_trade\backtest_controller.py", line 452, in run
raise e
File "c:\python39\lib\site-packages\blankly\exchanges\interfaces\paper_trade\backtest_controller.py", line 445, in run
self.price_events[0]['function'](self.interface.get_price(self.price_events[0]['asset_id']),
File "C:\Blankly\RSI-strategy.py", line 11, in price_event
state.interface.market_order(symbol, side='buy', funds=10)
File "c:\python39\lib\site-packages\blankly\exchanges\interfaces\paper_trade\paper_trade_interface.py", line 341, in market_order
trade_local.test_trade(symbol, side, qty, price, quote_decimals, quantity_decimals)
File "c:\python39\lib\site-packages\blankly\exchanges\interfaces\paper_trade\local_account\trade_local.py", line 87, in test_trade
raise InvalidOrder("Insufficient funds. Available:" +
blankly.utils.exceptions.InvalidOrder: Insufficient funds. Available:0.0 hold: 0 requested: 0.0749.
c:\python39\lib\site-packages\blankly\metrics\portfolio.py:29: RuntimeWarning: divide by zero encountered in double_scalars
return (end_value / start_value) ** (1 / years) - 1
from blankly.
Hi! I'm glad you like our graphical output!
I believe all the output you showed is expected behavior. The insufficient funds error is caused by running out of USDT
. The loss in account value is caused by ETH devaluing over that period of time.
There is a warning caused by the portfolio valuation because the timeframe is over less than a year (so its a divide by zero). I will work to remove this warning but I want to give speedy responses.
If you want to continue the backtest even with errors you can toggle ignore_user_exceptions
to true
in backtest.json
. A live strategy will also persist through user errors so in some ways this increases accuracy.
You can also check your cash value by doing interface.cash
which can be used to prevent errors from potential overdraft purchases.
from blankly.
Hi, I am still getting this error when I try to backtest Binance. Was the fix reverted?
from blankly.
This should be patched, can you show your console output @rohsat?
from blankly.
Hi Emerson,
I am running through Google Colab. Running the bot.py for Binance.
Code
import blankly
def price_event(price, symbol, state: blankly.StrategyState):
""" This function will give an updated price every 15 seconds from our definition below """
state.variables['history'].append(price)
rsi = blankly.indicators.rsi(state.variables['history'])
if rsi[-1] < 30 and not state.variables['owns_position']:
# Dollar cost average buy
buy = blankly.trunc(state.interface.cash/price, 2)
state.interface.market_order(symbol, side='buy', size=buy)
state.variables['owns_position'] = True
elif rsi[-1] > 70 and state.variables['owns_position']:
# Dollar cost average sell
curr_value = blankly.trunc(state.interface.account[state.base_asset].available, 2)
state.interface.market_order(symbol, side='sell', size=curr_value)
state.variables['owns_position'] = False
def init(symbol, state: blankly.StrategyState):
# Download price data to give context to the algo
state.variables['history'] = state.interface.history(symbol, to=150, return_as='deque',
resolution=state.resolution)['close']
state.variables['owns_position'] = False
if name == "main":
# Authenticate coinbase pro strategy
exchange = blankly.Binance()
# Use our strategy helper on coinbase pro
strategy = blankly.Strategy(exchange)
# Run the price event function every time we check for a new price - by default that is 15 seconds
strategy.add_price_event(price_event, symbol='BTC-USDT', resolution='1d', init=init)
# Start the strategy. This will begin each of the price event ticks
# strategy.start()
# Or backtest using this
results = strategy.backtest(to='1y', initial_values={'USDT': 10000})
print(results)
from blankly.
Error:
INFO: No portfolio name to load specified, defaulting to the first in the file: (another cool portfolio). This is fine if there is only one portfolio in use.
Initializing...
KeyError Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/blankly/exchanges/interfaces/paper_trade/paper_trade_interface.py in get_account(self, symbol)
337 try:
--> 338 return self.local_account.get_account(symbol)
339 except KeyError:
6 frames
/usr/local/lib/python3.7/dist-packages/blankly/exchanges/interfaces/paper_trade/local_account/trade_local.py in get_account(self, asset_id)
210 """
--> 211 return copy.deepcopy(utils.AttributeDict(self.local_account[asset_id]))
212
KeyError: 'USD'
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call last)
in ()
38 # strategy.start()
39 # Or backtest using this
---> 40 results = strategy.backtest(to='1y', initial_values={'USDT': 10000})
41 print(results)
/usr/local/lib/python3.7/dist-packages/blankly/frameworks/strategy/strategy.py in backtest(self, to, initial_values, start_date, end_date, save, settings_path, callbacks, **kwargs)
168
169 # Run the backtest & return results
--> 170 results = self.backtesting_controller.run()
171
172 blankly.reporter.export_backtest_result(results)
/usr/local/lib/python3.7/dist-packages/blankly/exchanges/interfaces/paper_trade/backtest_controller.py in run(self)
716 # Add an initial account row here
717 if self.preferences['settings']['save_initial_account_value']:
--> 718 available_dict, no_trade_dict = self.format_account_data(self.initial_time)
719 price_data.append(available_dict)
720 no_trade.append(no_trade_dict)
/usr/local/lib/python3.7/dist-packages/blankly/exchanges/interfaces/paper_trade/backtest_controller.py in format_account_data(self, local_time)
499 for i in assets:
500 # Grab the account status
--> 501 true_account[i] = self.interface.get_account(i)
502
503 # Create an account total value
/usr/local/lib/python3.7/dist-packages/blankly/utils/utils.py in wrapper(self, symbol)
788 if symbol is not None:
789 symbol = get_base_asset(symbol)
--> 790 return func(self, symbol=symbol)
791 return wrapper
792
/usr/local/lib/python3.7/dist-packages/blankly/exchanges/interfaces/paper_trade/paper_trade_interface.py in get_account(self, symbol)
339 except KeyError:
340 if self.backtesting:
--> 341 raise KeyError("Symbol not found. This can be caused by an invalid quote currency "
342 "in backtest.json.")
343 else:
KeyError: 'Symbol not found. This can be caused by an invalid quote currency in backtest.json.'
from blankly.
I have set USDT in backtest.json.
{
"price_data": {
"assets": []
},
"settings": {
"use_price": "close",
"smooth_prices": false,
"GUI_output": true,
"show_tickers_with_zero_delta": false,
"save_initial_account_value": true,
"show_progress_during_backtest": true,
"cache_location": "./price_caches",
"continuous_caching": true,
"resample_account_value_for_metrics": "1d",
"quote_account_value_in": "USDT",
"ignore_user_exceptions": true,
"risk_free_return_rate": 0.0,
"benchmark_symbol": null
}
}
from blankly.
Additional details - My Binance tld is .com but I have created the account from India.
from blankly.
I was able to make it work by modifying "quote_account_value_in": "USDT" in utils.py.
default_backtest_settings = {
"price_data": {
"assets": []
},
"settings": {
"use_price": "close",
"smooth_prices": False,
"GUI_output": True,
"show_tickers_with_zero_delta": False,
"save_initial_account_value": True,
"show_progress_during_backtest": True,
"cache_location": "./price_caches",
"continuous_caching": True,
"resample_account_value_for_metrics": "1d",
"quote_account_value_in": "USDT",
"ignore_user_exceptions": False,
"risk_free_return_rate": 0.0,
"benchmark_symbol": None
}
}
from blankly.
Related Issues (20)
- Binance futures not working HOT 7
- IndexError: list index out of range HOT 1
- state.interface.history duplicating prices HOT 3
- Title:Trailing Stop with limit orders in Blankly Finance paper trading environment HOT 9
- Implementing Upbit Exchange HOT 1
- Cannot run blankly login HOT 6
- Alpaca not working with crypto HOT 1
- Integrate Blankly with a timeseries database HOT 1
- Accept in memory data for backtest
- strategy.backtest without `to` argument should infer `start_time` and `end_time`
- KeyError: 'bidMultiplierUp' HOT 3
- Alpaca Cryptocurrency error(maybe just an alpaca related data error) HOT 1
- Inconsistencies in asset visualisation HOT 1
- Ow
- Innaccurate Historical Data HOT 2
- bar_event squashes price_event price HOT 1
- `state.interface.history` not returning history with correct time intervals
- `ignore_user_exceptions=False` parameter in `strategy.backtest` doesn't work
- Error installing blankly. 'ti.pxd' not found HOT 1
- Can't place bracket orders (stop-loss and take-profit) one after the other HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blankly.