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

Sign up
Appearance settings

Backtesting spread strategies #899

Unanswered
Tullix95 asked this question in Q&A
Discussion options

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).

image

When I try to run the backtest, I get an error for negative equity (even after setting initial cash in the range of billions).

image

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

You must be logged in to vote

Replies: 1 comment

Comment options

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()
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

AltStyle によって変換されたページ (->オリジナル) /