-
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.
Added the ability for the backtester to use unrealised PnL from the P…
…osition objects to calculate a tick-by-tick equity curve. Added a performance directory that calculates drawdown statistics. Modified the output.py script to use Seaborn and output the equity curve, returns and drawdown curve.
- Loading branch information
1 parent
a03bc7a
commit 4380200
Showing
8 changed files
with
137 additions
and
28 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
Empty file.
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,32 @@ | ||
import numpy as np | ||
import pandas as pd | ||
|
||
|
||
def create_drawdowns(pnl): | ||
""" | ||
Calculate the largest peak-to-trough drawdown of the PnL curve | ||
as well as the duration of the drawdown. Requires that the | ||
pnl_returns is a pandas Series. | ||
Parameters: | ||
pnl - A pandas Series representing period percentage returns. | ||
Returns: | ||
drawdown, duration - Highest peak-to-trough drawdown and duration. | ||
""" | ||
|
||
# Calculate the cumulative returns curve | ||
# and set up the High Water Mark | ||
hwm = [0] | ||
|
||
# Create the drawdown and duration series | ||
idx = pnl.index | ||
drawdown = pd.Series(index = idx) | ||
duration = pd.Series(index = idx) | ||
|
||
# Loop over the index range | ||
for t in range(1, len(idx)): | ||
hwm.append(max(hwm[t-1], pnl[t])) | ||
drawdown[t]= (hwm[t]-pnl[t]) | ||
duration[t]= (0 if drawdown[t] == 0 else duration[t-1]+1) | ||
return drawdown, drawdown.max(), duration.max() |
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 |
---|---|---|
@@ -1,15 +1,15 @@ | ||
argparse==1.2.1 | ||
ipython==2.3.1 | ||
ipython==3.1.0 | ||
matplotlib==1.4.3 | ||
mock==1.0.1 | ||
nose==1.3.6 | ||
numpy==1.9.1 | ||
pandas==0.15.2 | ||
numpy==1.9.2 | ||
pandas==0.16.1 | ||
pyparsing==2.0.3 | ||
python-dateutil==2.4.0 | ||
python-dateutil==2.4.2 | ||
pytz==2014.10 | ||
requests==2.5.1 | ||
scikit-learn==0.15.2 | ||
requests==2.7.0 | ||
scikit-learn==0.16.1 | ||
scipy==0.15.1 | ||
seaborn==0.5.1 | ||
six==1.9.0 | ||
wsgiref==0.1.2 | ||
urllib3==1.10.4 |
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