Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AI4Finance Foundation FinGPT Pyfolio Tears

From Leeroopedia
Knowledge Sources
Domains Tear_Sheet_Generation, Portfolio_Analytics, Trading
Last Updated 2026-10-18 00:00 GMT

Overview

Concrete tool for generating complete pyfolio tear sheets (multi-section performance reports) for trading strategies provided by the vendored pyfolio package within the FinGPT Trading subproject.

Description

The tears module orchestrates all other pyfolio modules (plotting, timeseries, pos, txn, round_trips, perf_attrib, capacity) to produce a comprehensive tear sheet. `create_full_tear_sheet` is the top-level entry point, emitting returns analysis, position analysis, transaction analysis, round-trip analysis, and optional performance attribution. A `FACTOR_PARTITIONS` constant defines style vs. sector factor groupings.

Usage

Import `create_full_tear_sheet` when you need a one-call, comprehensive performance report for a trading strategy with returns, positions, and optional transactions.

Code Reference

Source Location

Signature

FACTOR_PARTITIONS = {
    'style': ['momentum', 'size', 'value', 'reversal_short_term', 'volatility'],
    'sector': ['basic_materials', 'consumer_cyclical', 'financial_services',
               'real_estate', 'consumer_defensive', 'health_care',
               'utilities', 'communication_services', 'energy', 'industrials',
               'technology']
}

def timer(msg_body, previous_time): ...

def create_full_tear_sheet(returns,
                           positions=None,
                           transactions=None,
                           market_data=None,
                           benchmark_rets=None,
                           slippage=None,
                           live_start_date=None,
                           sector_mappings=None,
                           round_trips=False,
                           estimate_intraday='infer',
                           hide_positions=False,
                           cone_std=(1.0, 1.5, 2.0),
                           bootstrap=False,
                           unadjusted_returns=None,
                           turnover_denom='AGB',
                           set_context=True,
                           factor_returns=None,
                           factor_loadings=None,
                           pos_in_dollars=True,
                           header_rows=None,
                           factor_partitions=FACTOR_PARTITIONS): ...

def create_returns_tear_sheet(returns, live_start_date=None, cone_std=(1.0, 1.5, 2.0),
                               benchmark_rets=None, bootstrap=False, ...): ...
def create_position_tear_sheet(positions, ...): ...
def create_txn_tear_sheet(transactions, positions, ...): ...
def create_round_trip_tear_sheet(round_trips, ...): ...
def create_perf_attrib_tear_sheet(...): ...
def create_interesting_times_tear_sheet(...): ...

Import

from pyfolio.tears import create_full_tear_sheet

I/O Contract

Inputs

Name Type Required Description
returns pd.Series Yes Daily noncumulative strategy returns
positions pd.DataFrame No Daily net position values
transactions pd.DataFrame No Executed trades
benchmark_rets pd.Series No Benchmark returns for comparison
live_start_date str/datetime No Marks in-sample vs out-of-sample
factor_returns pd.DataFrame No Factor returns for attribution
factor_loadings pd.DataFrame No Factor loadings for attribution

Outputs

Name Type Description
(displayed output) IPython.display Rendered tables and matplotlib figures

Usage Examples

Generate a Full Tear Sheet

import pandas as pd
from pyfolio.tears import create_full_tear_sheet

# 1. Load strategy data
returns = pd.read_csv("returns.csv", index_col=0, parse_dates=True)["returns"]
positions = pd.read_csv("positions.csv", index_col=0, parse_dates=True)
transactions = pd.read_csv("txn.csv", parse_dates=["dt"])

# 2. Generate the full tear sheet
create_full_tear_sheet(
    returns=returns,
    positions=positions,
    transactions=transactions,
    live_start_date="2024-01-01",
    round_trips=True,
)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment