Skip to content

GenjiYin/alphalens_modify

Repository files navigation

AlphaLens Modify

🇨🇳 中文 | 🇺🇸 English

Author: XiaoYinXu

AlphaLens Modify is a modified version of the original AlphaLens library with updated dependencies and compatibility fixes for modern Python environments.

📊 Analysis Results Showcase

This project includes comprehensive factor analysis capabilities. Here are some example results:

本项目包含全面的因子分析功能。以下是一些示例结果:

🔍 Information Coefficient (IC) Analysis

IC Value Distribution

The Information Coefficient measures the predictive power of alpha factors, showing the correlation between factor values and future returns.

📈 Cumulative Return Analysis

Cumulative Returns

Cumulative returns demonstrate the long-term performance of factor-based investment strategies over time.

📊 Group Mean Return Analysis

Group Mean Returns

Group analysis shows how different factor quantiles perform, helping identify the most effective investment segments.

🔄 Factor Turnover Analysis

Turnover Analysis

Turnover analysis evaluates the stability and trading frequency of factor-based strategies.

🚀 Quick Start

import alphalens_modify as al
import pandas as pd

# Load your factor data and pricing data
factor_data = pd.read_csv('factor_data.csv')
price_data = pd.read_csv('price_data.csv')
factor_data['date'] = pd.to_datetime(factor_data['date'])
price_data['date'] = pd.to_datetime(price_data['date'])
factor_data = factor_data.set_index(['date', 'instrument'])
price_data = price_data.pivot(values='close', index='date', columns='instrument')

# Get clean factor and forward returns
factor_returns = al.utils.get_clean_factor_and_forward_returns(
    factor_data, 
    price_data, 
    periods=[1, 5, 10]
)

# Create comprehensive analysis
al.tears.create_summary_tear_sheet(factor_returns)
al.tears.create_returns_tear_sheet(factor_returns)
al.tears.create_information_tear_sheet(factor_returns)

📦 Installation

From PyPI

pip install alphalens-modify

From Source

git clone https://github.com/GenjiYin/alphalens-modify.git
cd alphalens-modify
pip install -e .

📋 Requirements

  • Python >= 3.12
  • pandas >= 2.2.3
  • numpy >= 1.26.4
  • scipy >= 1.14.1
  • statsmodels >= 0.14.5
  • matplotlib >= 3.9.2
  • seaborn >= 0.13.2
  • IPython

🎯 Key Features

  • Factor Performance Analysis: Analyze the predictive power of alpha factors
  • Information Coefficient: Calculate and visualize IC metrics
  • Quantile Analysis: Performance analysis by factor quantiles
  • Group Analysis: Sector-based and custom group analysis
  • Turnover Analysis: Evaluate factor stability and trading frequency
  • Event Studies: Analyze factor performance around specific events

📊 Complete Analysis Pipeline

The library provides a complete factor analysis workflow:

  1. Data Preparation: Clean and prepare factor and price data
  2. Performance Metrics: Calculate IC, returns, turnover metrics
  3. Visualization: Generate comprehensive charts and plots
  4. Reporting: Create detailed tear sheets for analysis

🔧 Example Usage

See the included Jupyter notebook market_cap_factor_analys.ipynb for a complete example using market capitalization factor analysis.

Note: To run the market_cap_factor_analys.ipynb notebook, you need to download the test_data folder from the GitHub repository:

  1. Go to the GitHub repository
  2. Navigate to the test_data folder
  3. Download all the files in the test_data folder
  4. Place them in a test_data directory in your local project root

The notebook requires these data files to demonstrate the factor analysis functionality.

🤝 Support

If you encounter any issues or have questions, please open an issue on GitHub.

📄 License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

👤 Author

XiaoYinXu - 965418170@qq.com

🙏 Acknowledgments

This project is based on the original AlphaLens library by Quantopian. Thanks to the original contributors for their work on the factor analysis framework.

About

A modified version of alphalens with updated dependencies and fixes

Resources

License

Stars

Watchers

Forks

Packages

No packages published