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

Environment:AI4Finance Foundation FinGPT Pandas

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

Overview

Pandas data analysis library used across the FinGPT Trading subproject's vendored pyfolio package for portfolio performance metrics, tear sheet generation, and time-series risk calculations.

Description

This environment covers the `pandas` dependency used by the pyfolio package and other FinGPT implementations that process structured financial data. Pyfolio modules use `pd.Series` for returns, `pd.DataFrame` for positions and transactions, and `pd.MultiIndex` for factor loadings. The TruthfulQA utilities and market sentiment labeler also rely on pandas for CSV I/O and data manipulation.

Usage

Use this environment for any implementation that processes tabular financial data. Required by all pyfolio modules (perf_attrib, plotting, tears, timeseries, pos, txn, round_trips, capacity, utils), the TruthfulQA utilities, and the market sentiment labeler.

System Requirements

Category Requirement Notes
OS Any Cross-platform
Python >= 3.8 3.10+ recommended
Hardware CPU sufficient No GPU needed

Dependencies

Python Packages

Credentials

No credentials required.

Quick Install

pip install "pandas>=1.5.0"

Code Evidence

Returns series from `pyfolio/timeseries.py`:

import pandas as pd
import numpy as np

def sharpe_ratio(returns, risk_free=0, period='daily'):
    returns = pd.Series(returns)
    ...

Position data from `pyfolio/pos.py`:

positions = pd.DataFrame(positions, index=dates)

Common Errors

Error Message Cause Solution
`KeyError: 'returns'` Column name mismatch Check DataFrame column names
`dtype mismatch` Mixed types in column Use `pd.to_numeric()` with `errors='coerce'`
`NumPy 2.x incompatibility` numpy>=2 installed Pin `numpy<2`

Compatibility Notes

  • NumPy pin: Must use `numpy<2` for compatibility with pyfolio and PyTorch.
  • Date indexing: Pyfolio expects date-indexed Series/DataFrame for all metrics.

Related Pages

Page Connections

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