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"


09:59:34 Starting
10:00:30 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 datetime.datetime.now().strftime("%H:%M:%S"),"Completed"


10:00:31 Starting
10:00:45 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-5-15')
print datetime.datetime.now().strftime("%H:%M:%S"),"Completed Start Time was",stStart


10:00:45 Starting
Entire data start date: 2006-01-03
Entire data end date: 2017-02-17


Out-of-Sample Months: 9
Backtest Months: 124
Performance statistics All history Backtest Out of sample
annual_return 0.01 0.01 -0.05
cum_returns_final 0.06 0.10 -0.04
annual_volatility 0.03 0.03 0.02
sharpe_ratio 0.23 0.39 -1.93
calmar_ratio 0.09 0.19 -1.00
stability_of_timeseries 0.41 0.51 0.85
max_drawdown -0.06 -0.05 -0.05
omega_ratio 1.04 1.07 0.72
sortino_ratio 0.33 0.56 -2.33
skew -0.22 -0.18 -0.87
kurtosis 2.30 2.26 2.59
tail_ratio 1.03 1.04 0.79
common_sense_ratio 1.03 1.05 0.75
gross_leverage 1.04 1.04 1.08
information_ratio -0.03 -0.02 -0.15
alpha 0.01 0.01 -0.04
beta -0.01 -0.00 -0.05
Worst drawdown periods net drawdown in % peak date valley date recovery date duration
0 6.37 2014-07-28 2016-12-20 NaT NaN
1 5.02 2010-08-13 2014-01-10 2014-07-15 1023
2 2.69 2009-11-30 2010-05-17 2010-07-21 168
3 2.61 2008-07-03 2008-10-10 2009-05-06 220
4 1.43 2009-05-28 2009-07-01 2009-10-29 111

[-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
Lehmann -0.01% -0.57% 0.56%
US downgrade/European Debt Crisis 0.06% -0.33% 0.32%
Fukushima -0.04% -0.25% 0.21%
EZB IR Event -0.00% -0.17% 0.16%
Aug07 -0.01% -0.46% 0.33%
Mar08 0.01% -0.22% 0.31%
Sept08 0.00% -0.57% 0.56%
2009Q1 0.02% -0.33% 0.51%
2009Q2 0.01% -0.44% 0.45%
Flash Crash 0.02% -0.05% 0.14%
Apr14 0.09% -0.32% 0.58%
Oct14 -0.07% -0.47% 0.34%
Fall2015 0.01% -0.47% 0.38%
Low Volatility Bull Market 0.01% -0.25% 0.33%
GFC Crash 0.01% -1.12% 0.72%
Recovery 0.00% -0.81% 0.53%
New Normal -0.00% -0.77% 0.64%
Top 10 long positions of all time max
CTRX 0.70%
FHN 0.55%
CF 0.53%
NFLX 0.46%
ACAT 0.45%
CSOD 0.43%
CMCSK 0.37%
AAMC 0.37%
DAL 0.36%
EBIX 0.36%
Top 10 short positions of all time max
ICPT -1.80%
HOME -0.91%
AGIO -0.70%
ESPR -0.69%
MDVN -0.58%
ANAC -0.53%
ITMN -0.50%
CWEI -0.50%
GHM -0.50%
PPO -0.44%
Top 10 positions of all time max
ICPT 1.80%
HOME 0.91%
CTRX 0.70%
AGIO 0.70%
ESPR 0.69%
MDVN 0.58%
FHN 0.55%
ANAC 0.53%
CF 0.53%
ITMN 0.50%
All positions ever held max
ICPT 1.80%
HOME 0.91%
CTRX 0.70%
AGIO 0.70%
ESPR 0.69%
MDVN 0.58%
FHN 0.55%
ANAC 0.53%
CF 0.53%
ITMN 0.50%
CWEI 0.50%
GHM 0.50%
NFLX 0.46%
ACAT 0.45%
PPO 0.44%
AAMC 0.44%
CSOD 0.43%
AMWD 0.41%
NEU 0.40%
KRO 0.40%
CLW 0.39%
AVGO 0.38%
LFUS 0.38%
CMCSK 0.37%
DYAX 0.36%
DAL 0.36%
INCY 0.36%
FNSR 0.36%
EBIX 0.36%
PRGO 0.36%
... ...
SP 0.09%
USAK 0.09%
SFL 0.09%
JOE 0.09%
CYNI 0.09%
TTWO 0.09%
ERII 0.09%
KOS 0.09%
MRIN 0.09%
PCH 0.09%
EQU 0.09%
HL 0.09%
NEWP 0.09%
NM 0.09%
ARCB 0.09%
BDE 0.09%
NRCIA 0.09%
SENEA 0.09%
NYLD 0.09%
KIN 0.09%
SALM 0.09%
BXC 0.09%
WTM 0.09%
KEM 0.09%
CRCM 0.09%
ARNA 0.09%
PSEM 0.09%
PDLI 0.09%
NEWM 0.09%
RBCN 0.09%

2412 rows × 1 columns

/home/rproko01/pyfolio/local/lib/python2.7/site-packages/pyfolio/round_trips.py:211: UserWarning: Negative price detected, ignoring forround-trip.
  warnings.warn('Negative price detected, ignoring for'
Summary stats All trades Short trades Long trades
Total number of round_trips 20869.00 10687.00 10182.00
Percent profitable 0.51 0.44 0.59
Winning round_trips 10721.00 4735.00 5986.00
Losing round_trips 10119.00 5936.00 4183.00
Even round_trips 29.00 16.00 13.00
PnL stats All trades Short trades Long trades
Total profit $390956.10 $-4771964.65 $5162920.76
Gross profit $19985766.70 $8213694.38 $11772072.32
Gross loss $-19594810.60 $-12985659.03 $-6609151.56
Profit factor $1.02 $0.63 $1.78
Avg. trade net profit $18.73 $-446.52 $507.06
Avg. winning trade $1864.17 $1734.68 $1966.60
Avg. losing trade $-1936.44 $-2187.61 $-1580.00
Ratio Avg. Win:Avg. Loss $0.96 $0.79 $1.24
Largest winning trade $52772.42 $33800.13 $52772.42
Largest losing trade $-89655.00 $-89655.00 $-55935.39
Duration stats All trades Short trades Long trades
Avg duration 224 days 15:11:43.005318 220 days 22:52:59.986619 228 days 11:53:14.156452
Median duration 153 days 23:00:00 152 days 23:00:00 154 days 01: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.01%
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.49% 0.32% 0.49%
Largest losing trade -0.83% -0.83% -0.53%
Symbol stats AAPL ABBV ABC ABT ACE ACN AGN ADBE ADI ADM ... KRC ARCB GAIA STAR GOLD VOD REG ES JPM PGR
Avg returns all round_trips 0.01% 0.01% -0.01% -0.00% 0.00% 0.01% 0.02% 0.01% 0.00% 0.00% ... -0.01% 0.00% 0.01% 0.01% 0.04% -0.03% 0.02% 0.04% -0.00% -0.01%
Avg returns winning 0.03% 0.01% 0.01% 0.01% 0.01% 0.01% 0.04% 0.02% 0.02% 0.01% ... nan% 0.00% 0.01% 0.01% 0.04% nan% 0.02% 0.04% nan% nan%
Avg returns losing -0.02% -0.01% -0.01% -0.01% -0.01% -0.01% -0.02% -0.01% -0.01% -0.01% ... -0.01% nan% nan% nan% nan% -0.03% nan% nan% -0.00% -0.01%
Median returns all round_trips 0.00% 0.00% -0.01% -0.00% 0.00% 0.00% 0.00% 0.01% -0.00% 0.00% ... -0.01% 0.00% 0.01% 0.01% 0.04% -0.03% 0.02% 0.04% -0.00% -0.01%
Median returns winning 0.02% 0.01% 0.01% 0.00% 0.01% 0.01% 0.04% 0.02% 0.02% 0.01% ... nan% 0.00% 0.01% 0.01% 0.04% nan% 0.02% 0.04% nan% nan%
Median returns losing -0.01% -0.01% -0.01% -0.01% -0.01% -0.01% -0.02% -0.00% -0.01% -0.01% ... -0.01% nan% nan% nan% nan% -0.03% nan% nan% -0.00% -0.01%
Largest winning trade 0.13% 0.03% 0.01% 0.02% 0.02% 0.03% 0.09% 0.06% 0.03% 0.04% ... -0.01% 0.00% 0.01% 0.01% 0.04% -0.03% 0.02% 0.04% -0.00% -0.01%
Largest losing trade -0.07% -0.01% -0.04% -0.04% -0.01% -0.01% -0.02% -0.02% -0.03% -0.03% ... -0.01% 0.00% 0.01% 0.01% 0.04% -0.03% 0.02% 0.04% -0.00% -0.01%

8 rows × 2412 columns

Profitability (PnL / PnL total) per name pnl
CF 0.16%
NFLX 0.14%
ACAT 0.13%
CMG 0.10%
PCLN 0.10%
BYI 0.10%
BWLD 0.09%
WDC 0.09%
FHN 0.08%
GT 0.08%
CTRX 0.08%
NIHD 0.08%
ASPS 0.08%
AMZN 0.08%
TSO 0.08%
REGN 0.08%
ICE 0.08%
ALK 0.07%
PRGO 0.07%
TRAK 0.07%
FB 0.07%
TWC 0.07%
CROX 0.07%
ISRG 0.07%
AMBA 0.07%
VTR 0.07%
NVDA 0.06%
ABFS 0.06%
MOS 0.06%
AEIS 0.06%
... ...
MTD -0.07%
BJRI -0.07%
DLX -0.07%
COKE -0.07%
DXCM -0.07%
ALKS -0.07%
FFG -0.07%
ALCO -0.07%
HMSY -0.07%
CBT -0.07%
BMRN -0.07%
DRC -0.07%
DYAX -0.08%
AMWD -0.08%
KRO -0.08%
FICO -0.08%
IIVI -0.08%
GBX -0.08%
PPO -0.09%
CIR -0.09%
LFUS -0.09%
NEU -0.09%
OSK -0.11%
CLVS -0.11%
INCY -0.11%
MDVN -0.11%
AGIO -0.12%
ESPR -0.12%
ICPT -0.21%
CWEI -0.22%

2412 rows × 1 columns

<matplotlib.figure.Figure at 0x7f5efafc3890>
10:04:39 Completed Start Time was 09:59:34

In [ ]: