mirror of
https://github.com/kernc/backtesting.py.git
synced 2024-01-28 15:29:30 +03:00
MNT: Adapt examples for updated jupytext behavior
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
# extension: .py
|
# extension: .py
|
||||||
# format_name: light
|
# format_name: light
|
||||||
# format_version: '1.3'
|
# format_version: '1.3'
|
||||||
# jupytext_version: 0.8.6
|
# jupytext_version: 1.0.2
|
||||||
# kernelspec:
|
# kernelspec:
|
||||||
# display_name: Python 3
|
# display_name: Python 3
|
||||||
# language: python
|
# language: python
|
||||||
@@ -51,6 +51,8 @@ def RSI(array, n):
|
|||||||
loss[loss > 0] = 0
|
loss[loss > 0] = 0
|
||||||
rs = gain.ewm(n).mean() / loss.abs().ewm(n).mean()
|
rs = gain.ewm(n).mean() / loss.abs().ewm(n).mean()
|
||||||
return 100 - 100 / (1 + rs)
|
return 100 - 100 / (1 + rs)
|
||||||
|
|
||||||
|
|
||||||
# -
|
# -
|
||||||
|
|
||||||
# The strategy roughly goes like this:
|
# The strategy roughly goes like this:
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
# extension: .py
|
# extension: .py
|
||||||
# format_name: light
|
# format_name: light
|
||||||
# format_version: '1.3'
|
# format_version: '1.3'
|
||||||
# jupytext_version: 0.8.6
|
# jupytext_version: 1.0.2
|
||||||
# kernelspec:
|
# kernelspec:
|
||||||
# display_name: Python 3
|
# display_name: Python 3
|
||||||
# language: python
|
# language: python
|
||||||
@@ -83,6 +83,8 @@ class Sma4Cross(Strategy):
|
|||||||
crossover(self.data.Close, self.sma_exit)):
|
crossover(self.data.Close, self.sma_exit)):
|
||||||
|
|
||||||
self.position.close()
|
self.position.close()
|
||||||
|
|
||||||
|
|
||||||
# -
|
# -
|
||||||
|
|
||||||
# It's not a robust strategy, but we can optimize it. Let's optimize our strategy on Google stock data.
|
# It's not a robust strategy, but we can optimize it. Let's optimize our strategy on Google stock data.
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
# extension: .py
|
# extension: .py
|
||||||
# format_name: light
|
# format_name: light
|
||||||
# format_version: '1.3'
|
# format_version: '1.3'
|
||||||
# jupytext_version: 0.8.6
|
# jupytext_version: 1.0.2
|
||||||
# kernelspec:
|
# kernelspec:
|
||||||
# display_name: Python 3
|
# display_name: Python 3
|
||||||
# language: python
|
# language: python
|
||||||
@@ -58,6 +58,8 @@ def SMA(values, n):
|
|||||||
each step taking into account `n` previous values.
|
each step taking into account `n` previous values.
|
||||||
"""
|
"""
|
||||||
return pd.Series(values).rolling(n).mean()
|
return pd.Series(values).rolling(n).mean()
|
||||||
|
|
||||||
|
|
||||||
# -
|
# -
|
||||||
|
|
||||||
# Note, this is the exact same helper function as the one used in the project unit tests, so we could just import that instead.
|
# Note, this is the exact same helper function as the one used in the project unit tests, so we could just import that instead.
|
||||||
@@ -99,6 +101,8 @@ class SmaCross(Strategy):
|
|||||||
# Else, if sma1 crosses below sma2, sell it
|
# Else, if sma1 crosses below sma2, sell it
|
||||||
elif crossover(self.sma2, self.sma1):
|
elif crossover(self.sma2, self.sma1):
|
||||||
self.sell()
|
self.sell()
|
||||||
|
|
||||||
|
|
||||||
# -
|
# -
|
||||||
|
|
||||||
# In `init()` as well as in `next()`, the data the strategy is simulated on is available as an instance variable
|
# In `init()` as well as in `next()`, the data the strategy is simulated on is available as an instance variable
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
# extension: .py
|
# extension: .py
|
||||||
# format_name: light
|
# format_name: light
|
||||||
# format_version: '1.3'
|
# format_version: '1.3'
|
||||||
# jupytext_version: 0.8.6
|
# jupytext_version: 1.0.2
|
||||||
# kernelspec:
|
# kernelspec:
|
||||||
# display_name: Python 3
|
# display_name: Python 3
|
||||||
# language: python
|
# language: python
|
||||||
@@ -79,6 +79,8 @@ class SmaCross(SignalStrategy,
|
|||||||
# Set trailing stop-loss to 4x ATR
|
# Set trailing stop-loss to 4x ATR
|
||||||
# using the method provided by TrailingStrategy
|
# using the method provided by TrailingStrategy
|
||||||
self.set_trailing_sl(4)
|
self.set_trailing_sl(4)
|
||||||
|
|
||||||
|
|
||||||
# -
|
# -
|
||||||
|
|
||||||
# Note, since the strategies in _lib_ may require their own intialization and next-tick logic, be sure to **always call `super().init()` and `super().next()` in your overridden methods**.
|
# Note, since the strategies in _lib_ may require their own intialization and next-tick logic, be sure to **always call `super().init()` and `super().next()` in your overridden methods**.
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -38,7 +38,7 @@ if __name__ == '__main__':
|
|||||||
extras_require={
|
extras_require={
|
||||||
'doc': [
|
'doc': [
|
||||||
'pdoc3',
|
'pdoc3',
|
||||||
'jupytext >= 0.7.0',
|
'jupytext >= 1.0.2',
|
||||||
'nbconvert',
|
'nbconvert',
|
||||||
'ipykernel', # for nbconvert
|
'ipykernel', # for nbconvert
|
||||||
'jupyter_client', # for nbconvert
|
'jupyter_client', # for nbconvert
|
||||||
|
|||||||
Reference in New Issue
Block a user