Skip to content
Permalink
Browse files

DOC: Fixed documentation

Some minor documentation fixes.
  • Loading branch information...
nemi83 authored and kernc committed Jan 15, 2019
1 parent 046fb0e commit 74ff445b44a7a539858dc42eacc8fd93a71d9869
@@ -13,9 +13,9 @@
"It is assumed you're already familiar with\n",
"[basic _backtesting.py_ usage](https://kernc.github.io/backtesting.py/doc/examples/Quick Start User Guide.html).\n",
"\n",
"We will test this supposed long-only\n",
"We will put to the test this long-only, supposed\n",
"[400%-a-year trading strategy](http://jbmarwood.com/stock-trading-strategy-300/),\n",
"which daily and weekly\n",
"which uses daily and weekly\n",
"[relative strength index](https://en.wikipedia.org/wiki/Relative_strength_index)\n",
"(RSI) values and moving averages (MA).\n",
"\n",
@@ -64,10 +64,10 @@
"* Close $>$ MA(10) $>$ MA(20) $>$ MA(50) $>$ MA(100)\n",
"\n",
"Close the position when:\n",
"* Close more than 2% _below_ MA(10)\n",
"* Daily close is more than 2% _below_ MA(10)\n",
"* 8% fixed stop loss is hit\n",
"\n",
"We need to provide bars data in the _lowest time frame_ (i.e. daily) and resample it to any higher time frames (i.e. weekly) that our strategy requires."
"We need to provide bars data in the _lowest time frame_ (i.e. daily) and resample it to any higher time frame (i.e. weekly) that our strategy requires."
]
},
{
@@ -481,7 +481,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Meager four trades in a span of nine years with effectively zero return? How about if we optimize the parameters a bit?"
"Meager four trades in the span of nine years and with zero return? How about if we optimize the parameters a bit?"
]
},
{
@@ -21,9 +21,9 @@
# It is assumed you're already familiar with
# [basic _backtesting.py_ usage](https://kernc.github.io/backtesting.py/doc/examples/Quick Start User Guide.html).
#
# We will test this supposed long-only
# We will put to the test this long-only, supposed
# [400%-a-year trading strategy](http://jbmarwood.com/stock-trading-strategy-300/),
# which daily and weekly
# which uses daily and weekly
# [relative strength index](https://en.wikipedia.org/wiki/Relative_strength_index)
# (RSI) values and moving averages (MA).
#
@@ -60,10 +60,10 @@ def RSI(array, n):
# * Close $>$ MA(10) $>$ MA(20) $>$ MA(50) $>$ MA(100)
#
# Close the position when:
# * Close more than 2% _below_ MA(10)
# * Daily close is more than 2% _below_ MA(10)
# * 8% fixed stop loss is hit
#
# We need to provide bars data in the _lowest time frame_ (i.e. daily) and resample it to any higher time frames (i.e. weekly) that our strategy requires.
# We need to provide bars data in the _lowest time frame_ (i.e. daily) and resample it to any higher time frame (i.e. weekly) that our strategy requires.

# +
from backtesting import Strategy, Backtest
@@ -122,7 +122,7 @@ def next(self):
backtest.run()
# -

# Meager four trades in a span of nine years with effectively zero return? How about if we optimize the parameters a bit?
# Meager four trades in the span of nine years and with zero return? How about if we optimize the parameters a bit?

# +
# %%time
@@ -11,7 +11,7 @@
"It is assumed you're already familiar with\n",
"[basic _backtesting.py_ usage](https://kernc.github.io/backtesting.py/doc/examples/Quick Start User Guide.html).\n",
"\n",
"First, let's again import a helper moving average function.\n",
"First, let's again import our helper moving average function.\n",
"In practice, one can use functions from any indicator library, such as\n",
"[TA-Lib](https://github.com/mrjbq7/ta-lib),\n",
"[Tulipy](https://tulipindicators.org),\n",
@@ -324,7 +324,7 @@
"source": [
"Our strategy will be a similar moving average cross-over strategy to the one in\n",
"[Quick Start User Guide](https://kernc.github.io/backtesting.py/doc/examples/Quick Start User Guide.html),\n",
"but there will be four moving averages in total:\n",
"but we will use four moving averages in total:\n",
"two moving averages whose relationship determines a general trend\n",
"(we only trade long when the shorter MA is above the longer one, and vice versa),\n",
"and two moving averages whose cross-over with Close prices determine the signal to enter or exit the position."
@@ -435,7 +435,7 @@
"[`Backtest.optimize()`](https://kernc.github.io/backtesting.py/doc/backtesting/backtesting.html#backtesting.backtesting.Backtest.optimize).\n",
"It makes the function return a heatmap series along with the usual stats of the best run.\n",
"`heatmap` is a pandas Series indexed with a MultiIndex, a cartesian product of all permissible parameter values.\n",
"The series vales are from the `maximize=` field we provided."
"The series values are from the `maximize=` argument we provided."
]
},
{
@@ -495,7 +495,7 @@
"metadata": {},
"source": [
"This heatmap contains the results of all the runs,\n",
"and it's very easy to obtain parameter combinations for e.g. three best runs:"
"making it very easy to obtain parameter combinations for e.g. three best runs:"
]
},
{
@@ -526,9 +526,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"But people have this enormous faculty of vision we use to make judgements on much larger data sets much faster.\n",
"But people have this enormous faculty of vision, used to make judgements on much larger data sets much faster.\n",
"Let's plot the whole heatmap by projecting it on two chosen dimensions.\n",
"Say we're mostly interested how parameters `n1` and `n2`, on average, affect the outcome."
"Say we're mostly interested in how parameters `n1` and `n2`, on average, affect the outcome."
]
},
{
@@ -733,7 +733,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's plot that using the excellent [_Seaborn_](https://seaborn.pydata.org) package:"
"Let's plot this table using the excellent [_Seaborn_](https://seaborn.pydata.org) package:"
]
},
{
@@ -20,7 +20,7 @@
# It is assumed you're already familiar with
# [basic _backtesting.py_ usage](https://kernc.github.io/backtesting.py/doc/examples/Quick Start User Guide.html).
#
# First, let's again import a helper moving average function.
# First, let's again import our helper moving average function.
# In practice, one can use functions from any indicator library, such as
# [TA-Lib](https://github.com/mrjbq7/ta-lib),
# [Tulipy](https://tulipindicators.org),
@@ -30,7 +30,7 @@

# Our strategy will be a similar moving average cross-over strategy to the one in
# [Quick Start User Guide](https://kernc.github.io/backtesting.py/doc/examples/Quick Start User Guide.html),
# but there will be four moving averages in total:
# but we will use four moving averages in total:
# two moving averages whose relationship determines a general trend
# (we only trade long when the shorter MA is above the longer one, and vice versa),
# and two moving averages whose cross-over with Close prices determine the signal to enter or exit the position.
@@ -110,23 +110,23 @@ def next(self):
# [`Backtest.optimize()`](https://kernc.github.io/backtesting.py/doc/backtesting/backtesting.html#backtesting.backtesting.Backtest.optimize).
# It makes the function return a heatmap series along with the usual stats of the best run.
# `heatmap` is a pandas Series indexed with a MultiIndex, a cartesian product of all permissible parameter values.
# The series vales are from the `maximize=` field we provided.
# The series values are from the `maximize=` argument we provided.

heatmap

# This heatmap contains the results of all the runs,
# and it's very easy to obtain parameter combinations for e.g. three best runs:
# making it very easy to obtain parameter combinations for e.g. three best runs:

heatmap.sort_values().iloc[-3:]

# But people have this enormous faculty of vision we use to make judgements on much larger data sets much faster.
# But people have this enormous faculty of vision, used to make judgements on much larger data sets much faster.
# Let's plot the whole heatmap by projecting it on two chosen dimensions.
# Say we're mostly interested how parameters `n1` and `n2`, on average, affect the outcome.
# Say we're mostly interested in how parameters `n1` and `n2`, on average, affect the outcome.

hm = heatmap.groupby(['n1', 'n2']).mean().unstack()
hm

# Let's plot that using the excellent [_Seaborn_](https://seaborn.pydata.org) package:
# Let's plot this table using the excellent [_Seaborn_](https://seaborn.pydata.org) package:

# +
# %matplotlib inline
@@ -15,7 +15,7 @@
"[Quick Start User Guide](https://kernc.github.io/backtesting.py/doc/examples/Quick Start User Guide.html),\n",
"but we'll rewrite it as a vectorized signal strategy and add trailing stop-loss.\n",
"\n",
"We'll again use a helper moving average function.\n",
"Again, we use our helper moving average function.\n",
"In practice, one can use functions from any indicator library, such as\n",
"[TA-Lib](https://github.com/mrjbq7/ta-lib),\n",
"[Tulipy](https://tulipindicators.org),\n",
@@ -23,7 +23,7 @@
# [Quick Start User Guide](https://kernc.github.io/backtesting.py/doc/examples/Quick Start User Guide.html),
# but we'll rewrite it as a vectorized signal strategy and add trailing stop-loss.
#
# We'll again use a helper moving average function.
# Again, we use our helper moving average function.
# In practice, one can use functions from any indicator library, such as
# [TA-Lib](https://github.com/mrjbq7/ta-lib),
# [Tulipy](https://tulipindicators.org),

0 comments on commit 74ff445

Please sign in to comment.
You can’t perform that action at this time.