예제 #1
0
def basic(returns,
          benchmark=None,
          rf=0.,
          grayscale=False,
          figsize=(8, 5),
          display=True):

    if _utils._in_notebook():
        iDisplay(iHTML('<h4>Performance Metrics</h4>'))
        metrics(returns=returns,
                benchmark=benchmark,
                rf=rf,
                display=display,
                mode='basic')
        iDisplay(iHTML('<h4>Strategy Visualization</h4>'))
    else:
        print('[Performance Metrics]\n')
        metrics(returns=returns,
                benchmark=benchmark,
                rf=rf,
                display=display,
                mode='basic')

        print('\n\n')
        print('[Strategy Visualization]\nvia Matplotlib')

    plots(returns=returns,
          benchmark=benchmark,
          grayscale=grayscale,
          figsize=figsize,
          mode='basic')
예제 #2
0
def _open_html(html):
    jscode = _regex.sub(' +', ' ', """<script>
    var win=window.open();win.document.body.innerHTML='{{html}}';
    </script>""".replace('\n', ''))
    jscode = jscode.replace('{{html}}', _regex.sub(
        ' +', ' ', html.replace('\n', '')))
    if _utils._in_notebook():
        iDisplay(iHTML(jscode))
예제 #3
0
def _download_html(html, filename="quantstats-tearsheet.html"):
    jscode = _regex.sub(' +', ' ', """<script>
    var bl=new Blob(['{{html}}'],{type:"text/html"});
    var a=document.createElement("a");
    a.href=URL.createObjectURL(bl);
    a.download="{{filename}}";
    a.hidden=true;document.body.appendChild(a);
    a.innerHTML="download report";
    a.click();</script>""".replace('\n', ''))
    jscode = jscode.replace('{{html}}', _regex.sub(
        ' +', ' ', html.replace('\n', '')))
    if _utils._in_notebook():
        iDisplay(iHTML(jscode.replace('{{filename}}', filename)))
예제 #4
0
def full(returns,
         benchmark=None,
         rf=0.,
         grayscale=False,
         figsize=(8, 5),
         display=True,
         compounded=True):

    dd = _stats.to_drawdown_series(returns)
    dd_info = _stats.drawdown_details(dd).sort_values(by='max drawdown',
                                                      ascending=True)[:5]
    dd_info.index = range(1, 6)

    dd_info.columns = map(lambda x: str(x).title(), dd_info.columns)
    if _utils._in_notebook():
        iDisplay(iHTML('<h4>Performance Metrics</h4>'))
        iDisplay(
            metrics(returns=returns,
                    benchmark=benchmark,
                    rf=rf,
                    display=display,
                    mode='full',
                    compounded=compounded))
        iDisplay(iHTML('<h4>5 Worst Drawdowns</h4>'))
        iDisplay(dd_info)

        iDisplay(iHTML('<h4>Strategy Visualization</h4>'))
    else:
        print('[Performance Metrics]\n')
        metrics(returns=returns,
                benchmark=benchmark,
                rf=rf,
                display=display,
                mode='full',
                compounded=compounded)
        print('\n\n')
        print('[5 Worst Drawdowns]\n')
        print(
            _tabulate(dd_info,
                      headers="keys",
                      tablefmt='simple',
                      floatfmt=".2f"))
        print('\n\n')
        print('[Strategy Visualization]\nvia Matplotlib')

    plots(returns=returns,
          benchmark=benchmark,
          grayscale=grayscale,
          figsize=figsize,
          mode='full')
예제 #5
0
def basic(returns,
          benchmark=None,
          rf=0.,
          grayscale=False,
          figsize=(8, 5),
          display=True,
          compounded=True,
          periods_per_year=252,
          match_dates=False):

    # prepare timeseries
    returns = _utils._prepare_returns(returns)
    if benchmark is not None:
        benchmark = _utils._prepare_benchmark(benchmark, returns.index, rf)
        if match_dates is True:
            returns, benchmark = _match_dates(returns, benchmark)

    if _utils._in_notebook():
        iDisplay(iHTML('<h4>Performance Metrics</h4>'))
        metrics(returns=returns,
                benchmark=benchmark,
                rf=rf,
                display=display,
                mode='basic',
                compounded=compounded,
                periods_per_year=periods_per_year,
                prepare_returns=False)
        iDisplay(iHTML('<h4>Strategy Visualization</h4>'))
    else:
        print('[Performance Metrics]\n')
        metrics(returns=returns,
                benchmark=benchmark,
                rf=rf,
                display=display,
                mode='basic',
                compounded=compounded,
                periods_per_year=periods_per_year,
                prepare_returns=False)

        print('\n\n')
        print('[Strategy Visualization]\nvia Matplotlib')

    plots(returns=returns,
          benchmark=benchmark,
          grayscale=grayscale,
          figsize=figsize,
          mode='basic',
          periods_per_year=periods_per_year,
          prepare_returns=False)
예제 #6
0
def full(returns,
         benchmark=None,
         rf=0.,
         grayscale=False,
         figsize=(8, 5),
         display=True,
         compounded=True,
         periods_per_year=252,
         match_dates=False):

    # prepare timeseries
    returns = _utils._prepare_returns(returns)
    if benchmark is not None:
        benchmark = _utils._prepare_benchmark(benchmark, returns.index, rf)
        if match_dates is True:
            returns, benchmark = _match_dates(returns, benchmark)

    dd = _stats.to_drawdown_series(returns)
    dd_info = _stats.drawdown_details(dd).sort_values(by='max drawdown',
                                                      ascending=True)[:5]

    if not dd_info.empty:
        dd_info.index = range(1, min(6, len(dd_info) + 1))
        dd_info.columns = map(lambda x: str(x).title(), dd_info.columns)

    if _utils._in_notebook():
        iDisplay(iHTML('<h4>Performance Metrics</h4>'))
        iDisplay(
            metrics(returns=returns,
                    benchmark=benchmark,
                    rf=rf,
                    display=display,
                    mode='full',
                    compounded=compounded,
                    periods_per_year=periods_per_year,
                    prepare_returns=False))
        iDisplay(iHTML('<h4>5 Worst Drawdowns</h4>'))
        if dd_info.empty:
            iDisplay(iHTML("<p>(no drawdowns)</p>"))
        else:
            iDisplay(dd_info)

        iDisplay(iHTML('<h4>Strategy Visualization</h4>'))
    else:
        print('[Performance Metrics]\n')
        metrics(returns=returns,
                benchmark=benchmark,
                rf=rf,
                display=display,
                mode='full',
                compounded=compounded,
                periods_per_year=periods_per_year,
                prepare_returns=False)
        print('\n\n')
        print('[5 Worst Drawdowns]\n')
        if dd_info.empty:
            print("(no drawdowns)")
        else:
            print(
                _tabulate(dd_info,
                          headers="keys",
                          tablefmt='simple',
                          floatfmt=".2f"))
        print('\n\n')
        print('[Strategy Visualization]\nvia Matplotlib')

    plots(returns=returns,
          benchmark=benchmark,
          grayscale=grayscale,
          figsize=figsize,
          mode='full',
          periods_per_year=periods_per_year,
          prepare_returns=False)