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

How to access equity history during backtest #1001

Unanswered
eervin123 asked this question in Q&A
Discussion options

I'm looking to calculate the max drawdown point and measure my current distance from that point since I started opening trades. Something like the following:

# Deleverage if we are over a certain percent invested and the market is recovering from the low point
elif highly_leveraged and bounce_from_low_pct > 2*atr_threshold_pct: 
 if self.position.pl_pct > decayed_take_profit:
 self.position.close(size = 0.2)

the bounce_from_low_pct is

low_point_in_trade = self.equity[-bars_since_trade_open:].min() # The lowest value our account hit since the first trade was entered if we are in a trade
bounce_from_low_pct = (self.equity[-1] - low_point_in_trade)/low_point_in_trade

but obviously this doesn't work because self.equity is simply the current equity. I can't access the history.

Should I keep a list that I append the new equity every run of the next() method?

Is there a way to access the _equity[-bars_since_trade_open:] ?

You must be logged in to vote

Replies: 3 comments

Comment options

this is what i came up with but I'm sure I'm not doing this the best way.

if self.position.size > 0:
 self.equity_during_trade.append(self.equity)
else:
 self.equity_during_trade = []
You must be logged in to vote
0 replies
Comment options

The above works btw, I just wasn't sure if there was a more proper way.

You must be logged in to vote
0 replies
Comment options

Here's an alternative:

if buy_condition:
 order = self.buy(...)
if order not in self.orders: # trade was executed
 self.low_point_in_trade = self.equity
self.low_point_in_trade = min(self.equity, self.low_point_in_trade)

I think I like yours better.

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 によって変換されたページ (->オリジナル) /