33< head >
44< meta charset ="utf-8 ">
55< meta name ="viewport " content ="width=device-width, initial-scale=1, minimum-scale=1 " />
6- < meta name ="generator " content ="pdoc 0.9.2 " />
6+ < meta name ="generator " content ="pdoc 0.10.0 " />
77< title > backtesting.lib API documentation</ title >
88< meta name ="description " content ="Collection of common building blocks, helper auxiliary functions and
99composable strategy classes for reuse β¦ " />
@@ -49,7 +49,7 @@ <h2 class="section-title" id="header-variables">Global variables</h2>
4949< dd >
5050< div class ="desc "> < p > Dictionary of rules for aggregating resampled OHLCV data frames,
5151e.g.</ p >
52- < pre > < code > df.resample('4H', label='right').agg(OHLCV_AGG)
52+ < pre > < code > df.resample('4H', label='right').agg(OHLCV_AGG).dropna()
5353</ code > </ pre > </ div >
5454</ dd >
5555< dt id ="backtesting.lib.TRADES_AGG "> < code class ="name "> var < span class ="ident "> TRADES_AGG</ span > </ code > </ dt >
@@ -75,6 +75,22 @@ <h2 class="section-title" id="header-functions">Functions</h2>
75753
7676</ code > </ pre > </ div >
7777</ dd >
78+ < dt id ="backtesting.lib.compute_stats "> < code class ="name flex ">
79+ < span > def < span class ="ident "> compute_stats</ span > </ span > (< span > *, stats, data, trades=None, risk_free_rate=0.0)</ span >
80+ </ code > </ dt >
81+ < dd >
82+ < div class ="desc "> < p > (Re-)compute strategy performance metrics.</ p >
83+ < p > < code > stats</ code > is the statistics series as returned by < code > < a title ="backtesting.backtesting.Backtest.run " href ="backtesting.html#backtesting.backtesting.Backtest.run "> Backtest.run()</ a > </ code > .
84+ < code > data</ code > is OHLC data as passed to the < code > < a title ="backtesting.backtesting.Backtest " href ="backtesting.html#backtesting.backtesting.Backtest "> Backtest</ a > </ code >
85+ the < code > stats</ code > were obtained in.
86+ < code > trades</ code > can be a dataframe subset of < code > stats._trades</ code > (e.g. only long trades).
87+ You can also tune < code > risk_free_rate</ code > , used in calculation of Sharpe and Sortino ratios.</ p >
88+ < pre > < code > >>> stats = Backtest(GOOG, MyStrategy).run()
89+ >>> only_long_trades = stats._trades[stats._trades.Size > 0]
90+ >>> long_stats = compute_stats(stats=stats, trades=only_long_trades,
91+ ... data=GOOG, risk_free_rate=.02)
92+ </ code > </ pre > </ div >
93+ </ dd >
7894< dt id ="backtesting.lib.cross "> < code class ="name flex ">
7995< span > def < span class ="ident "> cross</ span > </ span > (< span > series1, series2)</ span >
8096</ code > </ dt >
@@ -355,6 +371,7 @@ <h1>Index</h1>
355371< li > < h3 > < a href ="#header-functions "> Functions</ a > </ h3 >
356372< ul class ="two-column ">
357373< li > < code > < a title ="backtesting.lib.barssince " href ="#backtesting.lib.barssince "> barssince</ a > </ code > </ li >
374+ < li > < code > < a title ="backtesting.lib.compute_stats " href ="#backtesting.lib.compute_stats "> compute_stats</ a > </ code > </ li >
358375< li > < code > < a title ="backtesting.lib.cross " href ="#backtesting.lib.cross "> cross</ a > </ code > </ li >
359376< li > < code > < a title ="backtesting.lib.crossover " href ="#backtesting.lib.crossover "> crossover</ a > </ code > </ li >
360377< li > < code > < a title ="backtesting.lib.plot_heatmaps " href ="#backtesting.lib.plot_heatmaps "> plot_heatmaps</ a > </ code > </ li >
@@ -385,12 +402,12 @@ <h4><code><a title="backtesting.lib.TrailingStrategy" href="#backtesting.lib.Tra
385402</ main >
386403< footer id ="footer ">
387404< p >
388- < a href ="https://kernc.github.io/backtesting.py/ "> < cite > backtesting</ cite > 0.3.1 </ a >
405+ < a href ="https://kernc.github.io/backtesting.py/ "> < cite > backtesting</ cite > 0.3.2 </ a >
389406< span style ="color:#ddd "> 卐</ span >
390407</ p >
391408< script src ="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js "> </ script >
392409< script > hljs . configure ( { languages : [ 'python' ] } ) ; hljs . initHighlightingOnLoad ( ) </ script >
393- < p > Generated by < a href ="https://pdoc3.github.io/pdoc "> < cite > pdoc</ cite > 0.9.2 </ a > .</ p >
410+ < p > Generated by < a href ="https://pdoc3.github.io/pdoc " title =" pdoc: Python API documentation generator " > < cite > pdoc</ cite > 0.10.0 </ a > .</ p >
394411</ footer >
395412< script > window . ga = window . ga || function ( ) { ( ga . q = ga . q || [ ] ) . push ( arguments ) } ; ga . l = + new Date ; ga ( 'create' , 'UA-43663477-4' , 'auto' ) ; ga ( 'require' , 'cleanUrlTracker' , { indexFilename :'index.html' , trailingSlash :'add' } ) ; ga ( 'require' , 'outboundLinkTracker' , { events :[ 'click' , 'auxclick' , 'contextmenu' ] } ) ; ga ( 'require' , 'maxScrollTracker' ) ; ga ( 'require' , 'pageVisibilityTracker' ) ; ga ( 'send' , 'pageview' ) ; setTimeout ( function ( ) { ga ( 'send' , 'event' , 'pageview' , 'view' ) } , 15000 ) ; </ script > < script async src ='https://www.google-analytics.com/analytics.js '> </ script > < script async src ='https://cdnjs.cloudflare.com/ajax/libs/autotrack/2.4.1/autotrack.js '> </ script > </ body >
396413</ html >
0 commit comments