-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
-
Hello everyone,
I'm looking to build a strategy to trade spreads (FX, futures, ...), by first calculating the spread (for each security, open minus open, high minus high, etc. ). This may result in negative values (see screenshot below).
When I try to run the backtest, I get an error for negative equity (even after setting initial cash in the range of billions).
Is there a way to work this issue around using Backtesting.py? Or is there any alternative that allows for that?
Please let me know,
Thank you
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
Have you tried computing the spread by subtracting bids from asks (df_ask - df_bid
)? You shouldn't have been left with negative prices in that case.
Alternatively, you can try:
ohlc_cols = ['Open', 'High', 'Low', 'Close'] df_spread[ohlc_cols] += df_spread[ohlc_cols].min() + eps assert (df_spread[ohlc_cols] > 0).all().all()
Beta Was this translation helpful? Give feedback.