Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

Hey! This is my first time using Github so I might have chosed the wrong option to ask the question however:

I have built a code that calculate btc forecast and i really want to use backtesting.py to test its accuracy.
Im using Google Gemini to guide me since im new to coding and python in general.

Im reciving nice win rate on my code but im getting some wierd error message:
lib/python3.10/site-packages/backtesting/backtesting.py:954: UserWarning: time=3871: Broker canceled the relative-sized order due to insufficient margin.

I have tried to change cash up to 1.000.000 USD but that dosen't feel realtistic since btc has never been over 117k USD. According to Gemini this could be the problem:
Trade Size (Order Size)

Whole Bitcoin vs. Fractional Trading: As the previous warning indicated, the backtesting library does not support fractional trading by default. This means that if your strategy attempts to buy "1 Bitcoin" (i.e., a whole unit) when the price is $70,000, you need at least $70,000 in capital. If your strategy attempts to buy "2 Bitcoins" simultaneously, you would need $140,000.

Strategy Logic: The problem might lie in how your strategy (MyCandleStrategy) defines the size of its buy and sell orders. If your strategy attempts to buy a fixed quantity (e.g., always 1 BTC or 0.5 BTC) or a relative size based on a percentage of your available capital, problems can still arise:

If you have $200,000, but the strategy wants to buy 3 BTC when the price is $70,000/BTC (totaling $210,000), the order will be canceled.

If the strategy attempts to use a high percentage of your current equity (assets), and your equity has fallen due to losses, an order that was previously feasible might now exceed your available capital for a whole Bitcoin.

But what I dont understand is why am I getting this? Dosen't backtesting.py support BTC? Thanks and sorry again if i missplaced this question.

You must be logged in to vote

Replies: 1 comment

Comment options

See fractional trading, see also backtesting.lib.FractionalBacktest.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.