How to buy and sell "fractional shares" for Bitcoin backtest?
Hey everyone,
Intro: I'm trying to backtest a strategy using a minutely csv file of BTC data with the following fields: open, close, high, low, volume. Unfortunately, I'm having the following problem and don't see a way around it.
Background: Basically, I'm starting a backtest with $10,000. My strategy loses money for a little while, but then at some point it stops buying and selling completely because the price of BTC gets above however much total cash I have on hand so it can't buy at least one whole Bitcoin.
Question: Is there a good way to have Zipline buy and sell "fractional shares" so that this doesn't happen? I want it to buy as much bitcoin as I have cash on hand (maybe using a concept like $1 contracts?)
Convert the price feed so you are modelling in satoshi?
As @phatcher said, you can simulate your test on a smaller scale, e.g. on Satoshi level (1e8).
I can think of two methods:
- Increase your capital to the base of 1e8, and leave the input as is. This way you can analyse the result in Satoshi, but you need to correct for the final portfolio value and any other factors that are dependent on the capital base.
- Scale the input to Satoshi or any other level and change the
handle_datamethod to either order on Satoshi level or based on your portfolio percentage usingorder_target_percentmethod.
NOTE: Zipline rounds the inputs to 3 decimal points. So re-scaling to Satoshi turns prices that are lower than 5000 to NaN (not considering rounding errors for higher prices). My suggestion is to either use 1e5 for Bitcoin or log-scale.