mirror of
https://github.com/wassname/options_backtester.git
synced 2026-07-15 11:24:40 +08:00
988 KiB
988 KiB
In [1]:
import sys
sys.path.append('../..') # Add backtester base dir to $PYTHONPATHIn [2]:
%config InlineBackend.figure_format="retina"
%matplotlib inline
import pyfolio as pf
import pandas as pd
import os
import matplotlib.pyplot as plt
import altair as alt
plt.style.use("seaborn")
plt.rcParams["figure.figsize"] = (14, 8)/usr/local/anaconda3/lib/python3.7/site-packages/empyrical/utils.py:32: UserWarning: Unable to import pandas_datareader. Suppressing import error and continuing. All data reading functionality will raise errors; but has been deprecated and will be removed in a later version. warnings.warn(msg) /usr/local/anaconda3/lib/python3.7/site-packages/pyfolio/pos.py:27: UserWarning: Module "zipline.assets" not found; mutltipliers will not be applied to position notionals. 'Module "zipline.assets" not found; mutltipliers will not be applied' +
In [3]:
from backtester.datahandler import HistoricalOptionsData
from backtester.strategy import Strategy, StrategyLeg
from backtester.option import Type, Direction
from backtester import Backtest
from backtester.statistics import monthly_returns_heatmap, returns_histogram, returns_chartIn [4]:
# Cleaned up data
data = HistoricalOptionsData("options_data_clean_v2.h5", key="/SPX", where='quotedate >= "2006-12-06" & quotedate <= "2015-08-21"')
schema = data.schemaIn [5]:
# Iron Condor
iron_condor = Strategy(schema)
leg1 = StrategyLeg("leg_1", schema, option_type=Type.PUT, direction=Direction.BUY)
leg1.entry_filter = (schema.underlying == "SPX") & (schema.dte >= 40) & (schema.dte <= 50) & (schema.strike <= 0.85 * schema.underlying_last)
leg1.exit_filter = (schema.dte <= 2)
leg2 = StrategyLeg("leg_2", schema, option_type=Type.PUT, direction=Direction.SELL)
leg2.entry_filter = (schema.underlying == "SPX") & (schema.dte >= 40) & (schema.dte <= 50) & (schema.strike >= 0.90 * schema.underlying_last) & (schema.strike <= schema.underlying_last)
leg2.exit_filter = (schema.dte <= 2)
leg3 = StrategyLeg("leg_3", schema, option_type=Type.CALL, direction=Direction.SELL)
leg3.entry_filter = (schema.underlying == "SPX") & (schema.dte >= 40) & (schema.dte <= 50) & (schema.strike >= schema.underlying_last) & (schema.strike <= 1.10 * schema.underlying_last)
leg3.exit_filter = (schema.dte <= 2)
leg4 = StrategyLeg("leg_4", schema, option_type=Type.PUT, direction=Direction.BUY)
leg4.entry_filter = (schema.underlying == "SPX") & (schema.dte >= 40) & (schema.dte <= 50) & (schema.strike >= 1.15 * schema.underlying_last)
leg4.exit_filter = (schema.dte <= 2)
iron_condor.add_legs([leg1, leg2, leg3, leg4])
iron_condor.exit_thresholds = (0.25, 0.25)In [44]:
bt = Backtest()
bt.strategy = iron_condor
bt.data = data
bt.stop_if_broke = FalseIn [45]:
bt.run(monthly=False)Out [45]:
0% [██████████████████████████████] 100% | ETA: 00:00:00 Total time elapsed: 00:07:24
| leg_1 | leg_2 | ... | leg_4 | totals | |||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| contract | underlying | expiration | type | strike | cost | order | contract | underlying | expiration | ... | contract | underlying | expiration | type | strike | cost | order | cost | qty | date | |
| 0 | SPZ080419P00700000 | SPX | 2008-04-19 | put | 700.0 | 10.0 | Order.BTO | SPT080419P01170000 | SPX | 2008-04-19 | ... | SXM080419P01520000 | SPX | 2008-04-19 | put | 1520.0 | 22640.0 | Order.BTO | 17080.0 | 58.0 | 2008-03-07 |
| 1 | SPZ080419P00700000 | SPX | 2008-04-19 | put | 700.0 | -0.0 | Order.STC | SPT080419P01170000 | SPX | 2008-04-19 | ... | SXM080419P01520000 | SPX | 2008-04-19 | put | 1520.0 | -0.0 | Order.STC | 5400.0 | 58.0 | 2008-03-10 |
| 2 | SPV081220P00200000 | SPX | 2008-12-20 | put | 200.0 | 55.0 | Order.BTO | SPX081220P00815000 | SPX | 2008-12-20 | ... | SPQ081220P01045000 | SPX | 2008-12-20 | put | 1045.0 | 15440.0 | Order.BTO | 5505.0 | 181.0 | 2008-11-06 |
| 3 | SPV081220P00200000 | SPX | 2008-12-20 | put | 200.0 | -10.0 | Order.STC | SPX081220P00815000 | SPX | 2008-12-20 | ... | SPQ081220P01045000 | SPX | 2008-12-20 | put | 1045.0 | -12150.0 | Order.STC | -1070.0 | 181.0 | 2008-11-07 |
| 4 | SPV081220P00200000 | SPX | 2008-12-20 | put | 200.0 | 50.0 | Order.BTO | SPX081220P00830000 | SPX | 2008-12-20 | ... | SPQ081220P01060000 | SPX | 2008-12-20 | put | 1060.0 | 15100.0 | Order.BTO | 6240.0 | 160.0 | 2008-11-10 |
| 5 | SPV081220P00200000 | SPX | 2008-12-20 | put | 200.0 | -5.0 | Order.STC | SPX081220P00830000 | SPX | 2008-12-20 | ... | SPQ081220P01060000 | SPX | 2008-12-20 | put | 1060.0 | -20770.0 | Order.STC | -11775.0 | 160.0 | 2008-11-12 |
| 6 | SPV090117P00200000 | SPX | 2009-01-17 | put | 200.0 | 35.0 | Order.BTO | SPZ090117P00740000 | SPX | 2009-01-17 | ... | SXB090117P00940000 | SPX | 2009-01-17 | put | 940.0 | 14740.0 | Order.BTO | 4055.0 | 246.0 | 2008-12-01 |
| 7 | SPV090117P00200000 | SPX | 2009-01-17 | put | 200.0 | -0.0 | Order.STC | SPZ090117P00740000 | SPX | 2009-01-17 | ... | SXB090117P00940000 | SPX | 2009-01-17 | put | 940.0 | -11750.0 | Order.STC | -60.0 | 246.0 | 2008-12-02 |
| 8 | SPV090117P00300000 | SPX | 2009-01-17 | put | 300.0 | 40.0 | Order.BTO | SPZ090117P00765000 | SPX | 2009-01-17 | ... | SXB090117P00980000 | SPX | 2009-01-17 | put | 980.0 | 14870.0 | Order.BTO | 4830.0 | 207.0 | 2008-12-02 |
| 9 | SPV090117P00300000 | SPX | 2009-01-17 | put | 300.0 | -5.0 | Order.STC | SPZ090117P00765000 | SPX | 2009-01-17 | ... | SXB090117P00980000 | SPX | 2009-01-17 | put | 980.0 | -13250.0 | Order.STC | -2315.0 | 207.0 | 2008-12-03 |
| 10 | SPV090117P00200000 | SPX | 2009-01-17 | put | 200.0 | 40.0 | Order.BTO | SPZ090117P00765000 | SPX | 2009-01-17 | ... | SXB090117P00975000 | SPX | 2009-01-17 | put | 975.0 | 14870.0 | Order.BTO | 4880.0 | 204.0 | 2008-12-04 |
| 11 | SPV090117P00200000 | SPX | 2009-01-17 | put | 200.0 | -5.0 | Order.STC | SPZ090117P00765000 | SPX | 2009-01-17 | ... | SXB090117P00975000 | SPX | 2009-01-17 | put | 975.0 | -12140.0 | Order.STC | -1285.0 | 204.0 | 2008-12-05 |
| 12 | SPV090221P00200000 | SPX | 2009-02-21 | put | 200.0 | 15.0 | Order.BTO | SPX090221P00840000 | SPX | 2009-02-21 | ... | SPQ090221P01075000 | SPX | 2009-02-21 | put | 1075.0 | 15220.0 | Order.BTO | 9455.0 | 105.0 | 2009-01-02 |
| 13 | SPV090221P00325000 | SPX | 2009-02-21 | put | 325.0 | 45.0 | Order.BTO | SPX090221P00835000 | SPX | 2009-02-21 | ... | SPQ090221P01070000 | SPX | 2009-02-21 | put | 1070.0 | 14730.0 | Order.BTO | 8825.0 | 113.0 | 2009-01-05 |
| 14 | SPV090221P00350000 | SPX | 2009-02-21 | put | 350.0 | 30.0 | Order.BTO | SPX090221P00845000 | SPX | 2009-02-21 | ... | SPQ090221P01080000 | SPX | 2009-02-21 | put | 1080.0 | 15160.0 | Order.BTO | 9560.0 | 104.0 | 2009-01-06 |
| 15 | SPV090221P00375000 | SPX | 2009-02-21 | put | 375.0 | 70.0 | Order.BTO | SPX090221P00820000 | SPX | 2009-02-21 | ... | SPQ090221P01045000 | SPX | 2009-02-21 | put | 1045.0 | 14460.0 | Order.BTO | 8130.0 | 123.0 | 2009-01-07 |
| 16 | SYU090221P00425000 | SPX | 2009-02-21 | put | 425.0 | 80.0 | Order.BTO | SPX090221P00825000 | SPX | 2009-02-21 | ... | SPQ090221P01050000 | SPX | 2009-02-21 | put | 1050.0 | 14680.0 | Order.BTO | 8690.0 | 115.0 | 2009-01-08 |
| 17 | SPV090221P00200000 | SPX | 2009-02-21 | put | 200.0 | -0.0 | Order.STC | SPX090221P00840000 | SPX | 2009-02-21 | ... | SPQ090221P01075000 | SPX | 2009-02-21 | put | 1075.0 | -18720.0 | Order.STC | -13170.0 | 105.0 | 2009-01-09 |
| 18 | SPV090221P00325000 | SPX | 2009-02-21 | put | 325.0 | -0.0 | Order.STC | SPX090221P00835000 | SPX | 2009-02-21 | ... | SPQ090221P01070000 | SPX | 2009-02-21 | put | 1070.0 | -18230.0 | Order.STC | -12640.0 | 113.0 | 2009-01-09 |
| 19 | SPV090221P00350000 | SPX | 2009-02-21 | put | 350.0 | -0.0 | Order.STC | SPX090221P00845000 | SPX | 2009-02-21 | ... | SPQ090221P01080000 | SPX | 2009-02-21 | put | 1080.0 | -19220.0 | Order.STC | -13760.0 | 104.0 | 2009-01-09 |
| 20 | SYU090221P00450000 | SPX | 2009-02-21 | put | 450.0 | 100.0 | Order.BTO | SPX090221P00805000 | SPX | 2009-02-21 | ... | SPQ090221P01025000 | SPX | 2009-02-21 | put | 1025.0 | 14350.0 | Order.BTO | 8600.0 | 116.0 | 2009-01-09 |
| 21 | SPV090221P00375000 | SPX | 2009-02-21 | put | 375.0 | -0.0 | Order.STC | SPX090221P00820000 | SPX | 2009-02-21 | ... | SPQ090221P01045000 | SPX | 2009-02-21 | put | 1045.0 | -17640.0 | Order.STC | -11690.0 | 123.0 | 2009-01-12 |
| 22 | SYU090221P00425000 | SPX | 2009-02-21 | put | 425.0 | -10.0 | Order.STC | SPX090221P00825000 | SPX | 2009-02-21 | ... | SPQ090221P01050000 | SPX | 2009-02-21 | put | 1050.0 | -18110.0 | Order.STC | -12230.0 | 115.0 | 2009-01-12 |
| 23 | SPV090221P00200000 | SPX | 2009-02-21 | put | 200.0 | 10.0 | Order.BTO | SPZ090221P00785000 | SPX | 2009-02-21 | ... | SPQ090221P01005000 | SPX | 2009-02-21 | put | 1005.0 | 14220.0 | Order.BTO | 8100.0 | 123.0 | 2009-01-12 |
| 24 | SYU090221P00450000 | SPX | 2009-02-21 | put | 450.0 | -60.0 | Order.STC | SPX090221P00805000 | SPX | 2009-02-21 | ... | SPQ090221P01025000 | SPX | 2009-02-21 | put | 1025.0 | -18330.0 | Order.STC | -12600.0 | 116.0 | 2009-01-14 |
| 25 | SPV090221P00200000 | SPX | 2009-02-21 | put | 200.0 | -0.0 | Order.STC | SPZ090221P00785000 | SPX | 2009-02-21 | ... | SPQ090221P01005000 | SPX | 2009-02-21 | put | 1005.0 | -16410.0 | Order.STC | -10480.0 | 123.0 | 2009-01-14 |
| 26 | SPV090418P00200000 | SPX | 2009-04-18 | put | 200.0 | 10.0 | Order.BTO | SYG090418P00665000 | SPX | 2009-04-18 | ... | SPX090418P00850000 | SPX | 2009-04-18 | put | 850.0 | 12440.0 | Order.BTO | 6420.0 | 155.0 | 2009-02-27 |
| 27 | SPV090418P00200000 | SPX | 2009-04-18 | put | 200.0 | -0.0 | Order.STC | SYG090418P00665000 | SPX | 2009-04-18 | ... | SPX090418P00850000 | SPX | 2009-04-18 | put | 850.0 | -14990.0 | Order.STC | -8810.0 | 155.0 | 2009-03-02 |
| 28 | SPV090418P00300000 | SPX | 2009-04-18 | put | 300.0 | 40.0 | Order.BTO | SYG090418P00635000 | SPX | 2009-04-18 | ... | SPX090418P00810000 | SPX | 2009-04-18 | put | 810.0 | 11770.0 | Order.BTO | 5230.0 | 191.0 | 2009-03-02 |
| 29 | SPV090418P00200000 | SPX | 2009-04-18 | put | 200.0 | 10.0 | Order.BTO | SYG090418P00630000 | SPX | 2009-04-18 | ... | SPX090418P00805000 | SPX | 2009-04-18 | put | 805.0 | 12210.0 | Order.BTO | 6290.0 | 158.0 | 2009-03-03 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 807 | SPX141122P01100000 | SPX | 2014-11-22 | put | 1100.0 | -25.0 | Order.STC | SPX141122P01745000 | SPX | 2014-11-22 | ... | SPX141122P02250000 | SPX | 2014-11-22 | put | 2250.0 | -39320.0 | Order.STC | -36135.0 | 35.0 | 2014-10-15 |
| 808 | SPX141122P01150000 | SPX | 2014-11-22 | put | 1150.0 | -10.0 | Order.STC | SPX141122P01740000 | SPX | 2014-11-22 | ... | SPX141122P02225000 | SPX | 2014-11-22 | put | 2225.0 | -36820.0 | Order.STC | -33400.0 | 39.0 | 2014-10-15 |
| 809 | SPX141122P01075000 | SPX | 2014-11-22 | put | 1075.0 | -0.0 | Order.STC | SPX141122P01690000 | SPX | 2014-11-22 | ... | SPX141122P02160000 | SPX | 2014-11-22 | put | 2160.0 | -21900.0 | Order.STC | -15315.0 | 40.0 | 2014-10-21 |
| 810 | SPX141122P01050000 | SPX | 2014-11-22 | put | 1050.0 | -0.0 | Order.STC | SPX141122P01720000 | SPX | 2014-11-22 | ... | SPX141122P02200000 | SPX | 2014-11-22 | put | 2200.0 | -25000.0 | Order.STC | -18795.0 | 39.0 | 2014-10-23 |
| 811 | SPX141122P01000000 | SPX | 2014-11-22 | put | 1000.0 | -0.0 | Order.STC | SPX141122P01775000 | SPX | 2014-11-22 | ... | SPX141122P02500000 | SPX | 2014-11-22 | put | 2500.0 | -44670.0 | Order.STC | -36300.0 | 19.0 | 2014-11-18 |
| 812 | SPX150515P00500000 | SPX | 2015-05-15 | put | 500.0 | 5.0 | Order.BTO | SPX150515P01855000 | SPX | 2015-05-15 | ... | SPX150515P02375000 | SPX | 2015-05-15 | put | 2375.0 | 32600.0 | Order.BTO | 28235.0 | 35.0 | 2015-03-26 |
| 813 | SPX150515P00500000 | SPX | 2015-05-15 | put | 500.0 | -0.0 | Order.STC | SPX150515P01855000 | SPX | 2015-05-15 | ... | SPX150515P02375000 | SPX | 2015-05-15 | put | 2375.0 | -26970.0 | Order.STC | -20865.0 | 35.0 | 2015-04-15 |
| 814 | SPX150619P00100000 | SPX | 2015-06-19 | put | 100.0 | 5.0 | Order.BTO | SPX150619P01870000 | SPX | 2015-06-19 | ... | SPX150619P02390000 | SPX | 2015-06-19 | put | 2390.0 | 31720.0 | Order.BTO | 27445.0 | 36.0 | 2015-05-06 |
| 815 | SPX150619P00100000 | SPX | 2015-06-19 | put | 100.0 | -0.0 | Order.STC | SPX150619P01870000 | SPX | 2015-06-19 | ... | SPX150619P02390000 | SPX | 2015-06-19 | put | 2390.0 | -26200.0 | Order.STC | -19425.0 | 36.0 | 2015-05-18 |
| 816 | SPX150717P00500000 | SPX | 2015-07-17 | put | 500.0 | 15.0 | Order.BTO | SPX150717P01910000 | SPX | 2015-07-17 | ... | SPX150717P02500000 | SPX | 2015-07-17 | put | 2500.0 | 38320.0 | Order.BTO | 34705.0 | 28.0 | 2015-05-28 |
| 817 | SPX150821P00500000 | SPX | 2015-08-21 | put | 500.0 | 5.0 | Order.BTO | SPX150821P01870000 | SPX | 2015-08-21 | ... | SPX150821P02400000 | SPX | 2015-08-21 | put | 2400.0 | 33030.0 | Order.BTO | 28325.0 | 35.0 | 2015-07-02 |
| 818 | SPX150821P00600000 | SPX | 2015-08-21 | put | 600.0 | 5.0 | Order.BTO | SPX150821P01860000 | SPX | 2015-08-21 | ... | SPX150821P02450000 | SPX | 2015-08-21 | put | 2450.0 | 38530.0 | Order.BTO | 33705.0 | 29.0 | 2015-07-06 |
| 819 | SPX150821P00700000 | SPX | 2015-08-21 | put | 700.0 | 10.0 | Order.BTO | SPX150821P01875000 | SPX | 2015-08-21 | ... | SPX150821P02500000 | SPX | 2015-08-21 | put | 2500.0 | 42250.0 | Order.BTO | 38040.0 | 26.0 | 2015-07-07 |
| 820 | SPX150717P00500000 | SPX | 2015-07-17 | put | 500.0 | -0.0 | Order.STC | SPX150717P01910000 | SPX | 2015-07-17 | ... | SPX150717P02500000 | SPX | 2015-07-17 | put | 2500.0 | -45170.0 | Order.STC | -44870.0 | 28.0 | 2015-07-08 |
| 821 | SPX150821P00800000 | SPX | 2015-08-21 | put | 800.0 | 10.0 | Order.BTO | SPX150821P01845000 | SPX | 2015-08-21 | ... | SPX150821P02600000 | SPX | 2015-08-21 | put | 2600.0 | 55940.0 | Order.BTO | 50780.0 | 19.0 | 2015-07-08 |
| 822 | SPX150918P00500000 | SPX | 2015-09-18 | put | 500.0 | 35.0 | Order.BTO | SPX150918P01900000 | SPX | 2015-09-18 | ... | SPX150918P02450000 | SPX | 2015-09-18 | put | 2450.0 | 34940.0 | Order.BTO | 31575.0 | 31.0 | 2015-07-30 |
| 823 | SPX150918P00600000 | SPX | 2015-09-18 | put | 600.0 | 5.0 | Order.BTO | SPX150918P01895000 | SPX | 2015-09-18 | ... | SPX150918P02500000 | SPX | 2015-09-18 | put | 2500.0 | 40310.0 | Order.BTO | 36835.0 | 27.0 | 2015-07-31 |
| 824 | SPX150918P00700000 | SPX | 2015-09-18 | put | 700.0 | 5.0 | Order.BTO | SPX150918P01890000 | SPX | 2015-09-18 | ... | SPX150918P02550000 | SPX | 2015-09-18 | put | 2550.0 | 46130.0 | Order.BTO | 42715.0 | 23.0 | 2015-08-03 |
| 825 | SPX150918P00750000 | SPX | 2015-09-18 | put | 750.0 | 5.0 | Order.BTO | SPX150918P01885000 | SPX | 2015-09-18 | ... | SPX150918P02600000 | SPX | 2015-09-18 | put | 2600.0 | 51580.0 | Order.BTO | 48685.0 | 20.0 | 2015-08-04 |
| 826 | SPX150918P00800000 | SPX | 2015-09-18 | put | 800.0 | 10.0 | Order.BTO | SPX150918P01905000 | SPX | 2015-09-18 | ... | SPX150918P02650000 | SPX | 2015-09-18 | put | 2650.0 | 55850.0 | Order.BTO | 53450.0 | 18.0 | 2015-08-05 |
| 827 | SPX150918P00825000 | SPX | 2015-09-18 | put | 825.0 | 35.0 | Order.BTO | SPX150918P01880000 | SPX | 2015-09-18 | ... | SPX150918P02400000 | SPX | 2015-09-18 | put | 2400.0 | 32370.0 | Order.BTO | 28905.0 | 34.0 | 2015-08-06 |
| 828 | SPX150918P00850000 | SPX | 2015-09-18 | put | 850.0 | 35.0 | Order.BTO | SPX150918P01870000 | SPX | 2015-09-18 | ... | SPX150918P02700000 | SPX | 2015-09-18 | put | 2700.0 | 62870.0 | Order.BTO | 59525.0 | 16.0 | 2015-08-07 |
| 829 | SPX150821P00500000 | SPX | 2015-08-21 | put | 500.0 | -0.0 | Order.STC | SPX150821P01870000 | SPX | 2015-08-21 | ... | SPX150821P02400000 | SPX | 2015-08-21 | put | 2400.0 | -32120.0 | Order.STC | -31375.0 | 35.0 | 2015-08-19 |
| 830 | SPX150821P00600000 | SPX | 2015-08-21 | put | 600.0 | -0.0 | Order.STC | SPX150821P01860000 | SPX | 2015-08-21 | ... | SPX150821P02450000 | SPX | 2015-08-21 | put | 2450.0 | -37120.0 | Order.STC | -35755.0 | 29.0 | 2015-08-19 |
| 831 | SPX150821P00700000 | SPX | 2015-08-21 | put | 700.0 | -0.0 | Order.STC | SPX150821P01875000 | SPX | 2015-08-21 | ... | SPX150821P02500000 | SPX | 2015-08-21 | put | 2500.0 | -42120.0 | Order.STC | -41605.0 | 26.0 | 2015-08-19 |
| 832 | SPX150821P00800000 | SPX | 2015-08-21 | put | 800.0 | -0.0 | Order.STC | SPX150821P01845000 | SPX | 2015-08-21 | ... | SPX150821P02600000 | SPX | 2015-08-21 | put | 2600.0 | -52120.0 | Order.STC | -49045.0 | 19.0 | 2015-08-19 |
| 833 | SPX150918P00500000 | SPX | 2015-09-18 | put | 500.0 | -0.0 | Order.STC | SPX150918P01900000 | SPX | 2015-09-18 | ... | SPX150918P02450000 | SPX | 2015-09-18 | put | 2450.0 | -41660.0 | Order.STC | -39960.0 | 31.0 | 2015-08-20 |
| 834 | SPX150918P00600000 | SPX | 2015-09-18 | put | 600.0 | -0.0 | Order.STC | SPX150918P01895000 | SPX | 2015-09-18 | ... | SPX150918P02500000 | SPX | 2015-09-18 | put | 2500.0 | -52480.0 | Order.STC | -49100.0 | 27.0 | 2015-08-21 |
| 835 | SPX150918P00700000 | SPX | 2015-09-18 | put | 700.0 | -0.0 | Order.STC | SPX150918P01890000 | SPX | 2015-09-18 | ... | SPX150918P02550000 | SPX | 2015-09-18 | put | 2550.0 | -57480.0 | Order.STC | -54100.0 | 23.0 | 2015-08-21 |
| 836 | SPX150918P00825000 | SPX | 2015-09-18 | put | 825.0 | -0.0 | Order.STC | SPX150918P01880000 | SPX | 2015-09-18 | ... | SPX150918P02400000 | SPX | 2015-09-18 | put | 2400.0 | -42490.0 | Order.STC | -39160.0 | 34.0 | 2015-08-21 |
837 rows × 31 columns
In [46]:
bt.summary()Out [46]:
| Strategy | |
|---|---|
| Total trades | 417 |
| Number of wins | 141 |
| Number of losses | 276 |
| Win % | 33.81% |
| Largest loss | $1303840.00 |
| Profit factor | 0.51 |
| Average profit | $-126216.80 |
| Average P&L % | 0.44% |
| Total P&L % | -5657.95% |
In [47]:
pf.create_returns_tear_sheet(returns = bt.balance['% change'].dropna())/usr/local/anaconda3/lib/python3.7/site-packages/empyrical/stats.py:445: RuntimeWarning: invalid value encountered in double_scalars return ending_value ** (1 / num_years) - 1 /usr/local/anaconda3/lib/python3.7/site-packages/empyrical/stats.py:1492: RuntimeWarning: invalid value encountered in log1p cum_log_returns = np.log1p(returns).cumsum()
| Start date | 2006-12-06 | |
|---|---|---|
| End date | 2015-08-21 | |
| Total months | 104 | |
| Backtest | ||
| Annual return | nan% | |
| Cumulative returns | -5413.5% | |
| Annual volatility | 296.1% | |
| Sharpe ratio | 0.37 | |
| Calmar ratio | NaN | |
| Stability | NaN | |
| Max drawdown | -5009.7% | |
| Omega ratio | 1.64 | |
| Sortino ratio | 0.85 | |
| Skew | 24.28 | |
| Kurtosis | 981.85 | |
| Tail ratio | 1.59 | |
| Daily value at risk | -36.9% | |
/usr/local/anaconda3/lib/python3.7/site-packages/numpy/core/fromnumeric.py:61: FutureWarning: The current behaviour of 'Series.argmin' is deprecated, use 'idxmin' instead. The behavior of 'argmin' will be corrected to return the positional minimum in the future. For now, use 'series.values.argmin' or 'np.argmin(np.array(values))' to get the position of the minimum row. return bound(*args, **kwds)
| Worst drawdown periods | Net drawdown in % | Peak date | Valley date | Recovery date | Duration |
|---|---|---|---|---|---|
| 0 | 5009.68 | 2009-03-09 | 2015-07-20 | NaT | NaN |
| 1 | 386.80 | 2008-03-06 | 2009-01-06 | 2009-03-09 | 263 |
| 2 | 0.00 | 2006-12-06 | 2006-12-06 | 2006-12-06 | 1 |
| 3 | 0.00 | 2006-12-06 | 2006-12-06 | 2006-12-06 | 1 |
| 4 | 0.00 | 2006-12-06 | 2006-12-06 | 2006-12-06 | 1 |
In [ ]: