Skip to content

Commit

Permalink
Test case for PercentageTrailingStrategy kernc#223
Browse files Browse the repository at this point in the history
  • Loading branch information
zlpatel authored Jun 13, 2021
1 parent 8eab87c commit d6fa851
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions backtesting/test/_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
quantile,
SignalStrategy,
TrailingStrategy,
PercentageTrailingStrategy,
resample_apply,
plot_heatmaps,
random_ohlc_data,
Expand Down Expand Up @@ -862,6 +863,20 @@ def next(self):
stats = Backtest(GOOG, S).run()
self.assertEqual(stats['# Trades'], 57)

def test_PercentageTrailingStrategy(self):
class S(PercentageTrailingStrategy):
def init(self):
super().init()
self.set_trailing_sl(5)
self.sma = self.I(lambda: self.data.Close.s.rolling(10).mean())

def next(self):
super().next()
if not self.position and self.data.Close > self.sma:
self.buy()

stats = Backtest(GOOG, S).run()
self.assertEqual(stats['# Trades'], 91)

class TestUtil(TestCase):
def test_as_str(self):
Expand Down

0 comments on commit d6fa851

Please sign in to comment.