MCPcopy Create free account
hub / github.com/kernc/backtesting.py / init

Method init

backtesting/test/_test.py:132–151  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

130 def test_assertions(self):
131 class Assertive(Strategy):
132 def init(self):
133 self.sma = self.I(SMA, self.data.Close, 10)
134 self.remains_indicator = np.r_[2] * np.cumsum(self.sma * 5 + 1) * np.r_[2]
135
136 self.transpose_invalid = self.I(lambda: np.column_stack((self.data.Open,
137 self.data.Close)))
138
139 resampled = resample_apply('W', SMA, self.data.Close, 3)
140 resampled_ind = resample_apply('W', SMA, self.sma, 3)
141 assert np.unique(resampled[-5:]).size == 1
142 assert np.unique(resampled[-6:]).size == 2
143 assert resampled in self._indicators, "Strategy.I not called"
144 assert resampled_ind in self._indicators, "Strategy.I not called"
145
146 assert 1 == try_(lambda: self.data.X, 1, AttributeError)
147 assert 1 == try_(lambda: self.data['X'], 1, KeyError)
148
149 assert self.data.pip == .01
150
151 assert float(self.data.Close) == self.data.Close[-1]
152
153 def next(self, _FEW_DAYS=pd.Timedelta('3 days')): # noqa: N803
154 assert self.equity >= 0

Callers

nothing calls this directly

Calls 3

resample_applyFunction · 0.90
try_Function · 0.90
IMethod · 0.80

Tested by

no test coverage detected