In [1]:
%matplotlib inline
import pyfolio as pf
In [2]:
import datetime
import pickle
import pandas as pd
print "pandas version is",pd.__version__
pandas version is 0.19.2
In [3]:
stStart =datetime.datetime.now().strftime("%H:%M:%S")
print stStart,"Starting"
# dfPerf=pickle.load(open("perf2.pickle",'r'))
# dfPerf=pickle.load(open("perf.pickle",'r'))
# dfPerf=pickle.load(open("test_STK.pickle",'r'))
dfPerf=pickle.load(open("/home/rproko01/py/large_u_test.pickle",'r'))
print datetime.datetime.now().strftime("%H:%M:%S"),"Completed"
07:58:13 Starting
07:58:39 Completed
In [4]:
# print dfPerf.columns
In [5]:
print datetime.datetime.now().strftime("%H:%M:%S"),"Starting"
# returns, positions, transactions, gross_lev = pf.utils.extract_rets_pos_txn_from_zipline(dfPerf)
returns, positions, transactions = pf.utils.extract_rets_pos_txn_from_zipline(dfPerf)
# Get back some memory
del dfPerf
print "returns",len(returns),"positions",len(positions),"transactions",len(transactions)
print datetime.datetime.now().strftime("%H:%M:%S"),"Completed"
07:58:39 Starting
returns 4236 positions 4233 transactions 145190
07:58:50 Completed
In [6]:
if False:
print transactions.columns
print returns
print transactions[['price','amount']]
print positions
In [7]:
print datetime.datetime.now().strftime("%H:%M:%S"),"Starting"
pf.create_full_tear_sheet(returns, positions=positions, transactions=transactions,round_trips=True,
live_start_date='2016-2-9')
print datetime.datetime.now().strftime("%H:%M:%S"),"Completed Start Time was",stStart
07:58:51 Starting
Entire data start date: 2000-01-03
Entire data end date: 2016-11-01
Out-of-Sample Months: 8
Backtest Months: 192
Performance statistics
All history
Backtest
Out of sample
annual_return
-0.00
-0.01
0.02
cum_returns_final
-0.07
-0.09
0.02
annual_volatility
0.03
0.03
0.03
sharpe_ratio
-0.15
-0.20
0.76
calmar_ratio
-0.03
-0.03
1.27
stability_of_timeseries
0.71
0.67
0.77
max_drawdown
-0.18
-0.17
-0.02
omega_ratio
0.98
0.97
1.13
sortino_ratio
-0.22
-0.27
1.14
skew
0.01
0.00
0.12
kurtosis
0.10
0.11
-0.19
tail_ratio
1.01
1.01
0.98
common_sense_ratio
1.00
1.00
1.00
gross_leverage
2.00
2.00
2.00
information_ratio
-0.02
-0.02
-0.10
alpha
-0.00
-0.01
0.02
beta
-0.00
-0.00
0.01
Worst drawdown periods
net drawdown in %
peak date
valley date
recovery date
duration
0
17.83
2003-09-09
2016-03-28
NaT
NaN
1
4.10
2001-04-11
2001-12-18
2002-10-30
406
2
1.50
2002-10-31
2002-11-22
2002-12-19
36
3
1.37
2000-08-24
2000-11-02
2000-11-17
62
4
1.33
2003-06-04
2003-07-28
2003-08-15
53
[-0.003 -0.007]
/home/rproko01/pyfolio/local/lib/python2.7/site-packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family [u'sans-serif'] not found. Falling back to DejaVu Sans
(prop.get_family(), self.defaultFamily[fontext]))
Stress Events
mean
min
max
Dotcom
0.02%
-0.38%
0.38%
Lehmann
0.01%
-0.37%
0.44%
9/11
-0.02%
-0.30%
0.11%
US downgrade/European Debt Crisis
0.04%
-0.20%
0.38%
Fukushima
0.03%
-0.25%
0.42%
US Housing
0.03%
-0.29%
0.31%
EZB IR Event
-0.03%
-0.45%
0.23%
Aug07
-0.01%
-0.31%
0.23%
Mar08
0.01%
-0.41%
0.34%
Sept08
0.04%
-0.35%
0.34%
2009Q1
-0.01%
-0.28%
0.47%
2009Q2
-0.02%
-0.41%
0.34%
Flash Crash
0.01%
-0.08%
0.18%
Apr14
0.04%
-0.24%
0.55%
Oct14
-0.02%
-0.41%
0.45%
Fall2015
-0.01%
-0.28%
0.26%
Low Volatility Bull Market
-0.01%
-0.52%
0.51%
GFC Crash
0.00%
-0.63%
0.67%
Recovery
-0.01%
-0.57%
0.63%
New Normal
-0.00%
-0.51%
0.55%
Top 10 long positions of all time
max
A1699
2.43%
A4778
2.42%
A3002
2.41%
A5493
2.41%
A1026
2.40%
A1309
2.40%
A1866
2.39%
A3111
2.39%
A5406
2.39%
A3365
2.39%
Top 10 short positions of all time
max
A5243
-2.49%
A2496
-2.46%
A1247
-2.45%
A4945
-2.45%
A2577
-2.44%
A1851
-2.44%
A3973
-2.43%
A2066
-2.41%
A2368
-2.40%
A4246
-2.40%
Top 10 positions of all time
max
A5243
2.49%
A2496
2.46%
A1247
2.45%
A4945
2.45%
A2577
2.44%
A1851
2.44%
A3973
2.43%
A1699
2.43%
A4778
2.42%
A3002
2.41%
All positions ever held
max
A5243
2.49%
A2496
2.46%
A1247
2.45%
A4945
2.45%
A2577
2.44%
A1851
2.44%
A3973
2.43%
A1699
2.43%
A4778
2.42%
A3002
2.41%
A5493
2.41%
A2066
2.41%
A1026
2.40%
A2368
2.40%
A1309
2.40%
A4246
2.40%
A1813
2.39%
A1866
2.39%
A3111
2.39%
A2114
2.39%
A5406
2.39%
A3365
2.39%
A1898
2.39%
A3516
2.39%
A2397
2.38%
A4166
2.38%
A3044
2.38%
A1007
2.38%
A2395
2.38%
A4196
2.38%
...
...
A2292
0.98%
A2067
0.98%
A4884
0.98%
A2157
0.97%
A4409
0.97%
A3185
0.97%
A4794
0.96%
A4882
0.95%
A1987
0.92%
A2052
0.92%
A2890
0.91%
A3263
0.89%
A3623
0.56%
A4292
0.55%
A2413
0.55%
A1768
0.54%
A4812
0.53%
A1982
0.53%
A2075
0.53%
A3304
0.53%
A1104
0.52%
A4007
0.51%
A2913
0.51%
A4300
0.51%
A1477
0.50%
A3934
0.50%
A3665
0.50%
A3168
0.49%
A5048
0.48%
A1047
0.47%
3185 rows × 1 columns
Summary stats
All trades
Short trades
Long trades
Total number of round_trips
72506.00
36255.00
36251.00
Percent profitable
0.50
0.49
0.51
Winning round_trips
36344.00
17849.00
18495.00
Losing round_trips
36127.00
18390.00
17737.00
Even round_trips
35.00
16.00
19.00
PnL stats
All trades
Short trades
Long trades
Total profit
$-728956.28
$-897709.00
$168752.72
Gross profit
$74145007.21
$36758515.43
$37386491.77
Gross loss
$-74873963.49
$-37656224.44
$-37217739.05
Profit factor
$0.99
$0.98
$1.00
Avg. trade net profit
$-10.05
$-24.76
$4.66
Avg. winning trade
$2040.09
$2059.42
$2021.44
Avg. losing trade
$-2072.52
$-2047.65
$-2098.31
Ratio Avg. Win:Avg. Loss
$0.98
$1.01
$0.96
Largest winning trade
$38554.19
$23151.26
$38554.19
Largest losing trade
$-20057.74
$-20057.74
$-20050.90
Duration stats
All trades
Short trades
Long trades
Avg duration
33 days 09:58:10.918820
33 days 10:12:31.578540
33 days 09:43:50.164133
Median duration
34 days 23:00:00
34 days 23:00:00
34 days 21:00:00
Return stats
All trades
Short trades
Long trades
Avg returns all round_trips
-0.00%
-0.00%
0.00%
Avg returns winning
0.02%
0.02%
0.02%
Avg returns losing
-0.02%
-0.02%
-0.02%
Median returns all round_trips
0.00%
-0.00%
0.00%
Median returns winning
0.01%
0.01%
0.01%
Median returns losing
-0.01%
-0.01%
-0.01%
Largest winning trade
0.36%
0.24%
0.36%
Largest losing trade
-0.20%
-0.20%
-0.20%
Symbol stats
A1778
A1673
A1477
A1771
A1770
A1773
A1772
A1775
A1774
A1777
...
A2974
A2972
A2973
A4709
A1395
A1499
A1392
A1628
A1390
A1398
Avg returns all round_trips
-0.00%
0.05%
-0.00%
0.02%
-0.01%
-0.00%
-0.00%
-0.01%
-0.01%
-0.01%
...
0.00%
0.00%
0.01%
0.02%
0.00%
0.01%
0.01%
-0.01%
-0.02%
0.01%
Avg returns winning
0.02%
0.05%
nan%
0.02%
0.01%
0.02%
0.02%
0.01%
0.02%
0.03%
...
0.03%
0.02%
0.03%
0.02%
0.06%
0.02%
0.01%
0.03%
nan%
0.01%
Avg returns losing
-0.02%
nan%
-0.00%
nan%
-0.01%
-0.02%
-0.02%
-0.02%
-0.04%
-0.03%
...
-0.02%
-0.01%
-0.02%
-0.02%
-0.03%
-0.01%
-0.02%
-0.03%
-0.02%
-0.01%
Median returns all round_trips
-0.00%
0.05%
-0.00%
0.02%
-0.00%
-0.00%
-0.00%
-0.01%
0.00%
-0.01%
...
-0.00%
-0.00%
0.00%
0.01%
-0.01%
0.00%
0.00%
-0.01%
-0.02%
0.00%
Median returns winning
0.02%
0.05%
nan%
0.02%
0.01%
0.01%
0.01%
0.01%
0.00%
0.01%
...
0.01%
0.01%
0.01%
0.02%
0.06%
0.01%
0.00%
0.01%
nan%
0.01%
Median returns losing
-0.02%
nan%
-0.00%
nan%
-0.01%
-0.01%
-0.01%
-0.02%
-0.03%
-0.02%
...
-0.01%
-0.00%
-0.02%
-0.01%
-0.03%
-0.01%
-0.02%
-0.02%
-0.02%
-0.01%
Largest winning trade
0.09%
0.05%
-0.00%
0.07%
0.01%
0.06%
0.13%
0.04%
0.10%
0.08%
...
0.12%
0.07%
0.11%
0.10%
0.06%
0.06%
0.04%
0.09%
-0.02%
0.04%
Largest losing trade
-0.09%
0.05%
-0.00%
0.00%
-0.06%
-0.08%
-0.06%
-0.05%
-0.10%
-0.07%
...
-0.08%
-0.08%
-0.03%
-0.04%
-0.05%
-0.03%
-0.02%
-0.11%
-0.02%
-0.01%
8 rows × 3185 columns
Profitability (PnL / PnL total) per name
pnl
A3475
0.13%
A2798
0.12%
A4018
0.12%
A5169
0.11%
A4985
0.11%
A2503
0.11%
A2667
0.11%
A1542
0.10%
A2188
0.10%
A4149
0.10%
A1038
0.10%
A4166
0.09%
A4540
0.09%
A1027
0.09%
A5134
0.09%
A1746
0.09%
A1628
0.09%
A1464
0.09%
A2268
0.09%
A3336
0.09%
A4212
0.09%
A4530
0.09%
A2668
0.08%
A4623
0.08%
A4353
0.08%
A3222
0.08%
A1145
0.08%
A1179
0.08%
A1445
0.08%
A3400
0.08%
...
...
A4197
-0.08%
A3973
-0.08%
A3576
-0.08%
A1729
-0.08%
A2077
-0.08%
A5268
-0.08%
A4051
-0.09%
A5329
-0.09%
A3557
-0.09%
A1842
-0.09%
A3186
-0.09%
A2806
-0.09%
A3193
-0.09%
A5288
-0.10%
A4725
-0.10%
A1680
-0.10%
A5213
-0.10%
A1960
-0.10%
A3631
-0.11%
A3349
-0.11%
A1023
-0.11%
A2148
-0.12%
A3667
-0.12%
A3422
-0.12%
A2839
-0.12%
A1105
-0.13%
A3708
-0.13%
A1961
-0.14%
A4584
-0.15%
A2397
-0.15%
3185 rows × 1 columns
<matplotlib.figure.Figure at 0x7fb1db33bbd0>
08:04:43 Completed Start Time was 07:58:13
In [ ]:
Content source: rproko01/FunPythonStuff
Similar notebooks: