-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Multi-day backtesting now supported.
- Loading branch information
1 parent
17b36c5
commit 458f263
Showing
4 changed files
with
113 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
""" | ||
This is a small helper script written to help debug issues | ||
with performance calculation, that avoids having to re-run | ||
the full backtest. | ||
In this case it simply works off the "backtest.csv" file that | ||
is produced from a backtest.py run. | ||
""" | ||
|
||
|
||
import os | ||
|
||
import pandas as pd | ||
|
||
from qsforex.performance.performance import create_drawdowns | ||
from qsforex.settings import OUTPUT_RESULTS_DIR | ||
|
||
|
||
if __name__ == "__main__": | ||
in_filename = "backtest.csv" | ||
out_filename = "equity.csv" | ||
in_file = os.path.join(OUTPUT_RESULTS_DIR, in_filename) | ||
out_file = os.path.join(OUTPUT_RESULTS_DIR, out_filename) | ||
|
||
# Create equity curve dataframe | ||
df = pd.read_csv(in_file, index_col=0) | ||
df.dropna(inplace=True) | ||
df["Total"] = df.sum(axis=1) | ||
df["Returns"] = df["Total"].pct_change() | ||
df["Equity"] = (1.0+df["Returns"]).cumprod() | ||
|
||
# Create drawdown statistics | ||
drawdown, max_dd, dd_duration = create_drawdowns(df["Equity"]) | ||
df["Drawdown"] = drawdown | ||
df.to_csv(out_file, index=True) |
Just a tip:
glob
is a nice module https://docs.python.org/3/library/glob.html