MCPcopy Index your code
hub / github.com/kernc/backtesting.py / crossover

Function crossover

backtesting/lib.py:96–115  ·  view source on GitHub ↗

Return `True` if `series1` just crossed over (above) `series2`. >>> crossover(self.data.Close, self.sma) True

(series1: Sequence, series2: Sequence)

Source from the content-addressed store, hash-verified

94
95
96def crossover(series1: Sequence, series2: Sequence) -> bool:
97 """
98 Return `True` if `series1` just crossed over (above)
99 `series2`.
100
101 >>> crossover(self.data.Close, self.sma)
102 True
103 """
104 series1 = (
105 series1.values if isinstance(series1, pd.Series) else
106 (series1, series1) if isinstance(series1, Number) else
107 series1)
108 series2 = (
109 series2.values if isinstance(series2, pd.Series) else
110 (series2, series2) if isinstance(series2, Number) else
111 series2)
112 try:
113 return series1[-2] < series2[-2] and series1[-1] > series2[-1] # type: ignore
114 except IndexError:
115 return False
116
117
118def plot_heatmaps(heatmap: pd.Series,

Callers 7

nextMethod · 0.90
nextMethod · 0.90
nextMethod · 0.90
nextMethod · 0.90
nextMethod · 0.90
test_crossoverMethod · 0.90
crossFunction · 0.85

Calls

no outgoing calls

Tested by 4

nextMethod · 0.72
nextMethod · 0.72
nextMethod · 0.72
test_crossoverMethod · 0.72