Skip to content

High-performance C++ library for retrieving financial data from Yahoo Finance, as a native C++ alternative to Python yfinance

License

Notifications You must be signed in to change notification settings

Mi-ds/yfinance_cpp

Repository files navigation

yfinance_cpp - Yahoo Finance Data Library in C++

A high-performance C++ library for retrieving financial data from Yahoo Finance, designed as a native C++ alternative to the Python yfinance library.

Features

  • Fast, native C++ implementation (significantly faster than Python)
  • Low memory footprint
  • Comprehensive financial data access (prices, fundamentals, earnings, etc.)
  • Thread-safe design
  • Robust error handling and retry logic
  • Full session management with proper cookie/crumb handling
  • Both static (.a) and shared (.so) library formats

Dependencies

This library requires the following external dependencies:

  • nlohmann/json - JSON parsing
  • libcurl - HTTP client functionality
  • CMake - Build system (minimum version 3.15)
  • A C++17 compatible compiler

Installing Dependencies (Ubuntu/Debian):

sudo apt-get update
sudo apt-get install cmake libcurl4-openssl-dev nlohmann-json3-dev build-essential

Installing Dependencies (macOS):

brew install cmake nlohmann-json curl

Building

mkdir build
cd build
cmake ..
make -j$(nproc)

This will create both:

  • Static library: libyfinance_cpp.a
  • Shared library: libyfinance_cpp.so

Usage

#include "yfconvert.h"
#include "ticker.h"

int main() {
    try {
        yfconvert::initialize();
        
        // Create a ticker object
        yfconvert::Ticker apple("AAPL");
        
        // Get company info
        auto info = apple.get_info();
        std::cout << "Company: " << info["longName"] << std::endl;
        
        // Get historical data
        auto history = apple.history(30, "1d");  // Last 30 days, daily
        
        // Process data...
        
        yfconvert::cleanup();
    } catch (const std::exception& e) {
        std::cerr << "Error: " << e.what() << std::endl;
        return 1;
    }
    
    return 0;
}

To compile your program with the library:

g++ -std=c++17 your_program.cpp -lyfinance_cpp -lcurl -o your_program -L/path/to/lib

API Coverage

This library aims to provide equivalent functionality to the original yfinance Python library:

  • Basic ticker data (price, volume, etc.)
  • Historical price data
  • Company information
  • Financial statements
  • Earnings data
  • Dividends and splits
  • Institutional holders
  • Options chains
  • Screener functionality (planned)

Performance Comparison

The C++ implementation provides significant performance improvements over the Python version:

  • Up to 5-10x faster execution for data retrieval
  • Lower memory usage
  • No Python interpreter overhead
  • Direct system calls without GIL limitations

Error Handling

The library implements comprehensive error handling:

  • Network timeouts and retries
  • HTTP error status codes
  • JSON parsing errors
  • Invalid ticker symbols
  • Rate limiting detection

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

To contribute:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

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

Authors

  • Original Python yfinance library: ranaroussi
  • C++ Conversion: Created by yfinance_cpp team

Disclaimer

This is an unofficial library for educational and research purposes. It is not affiliated with Yahoo Finance or Yahoo Inc. Please review Yahoo's terms of service before using this library in production. The authors are not responsible for any misuse of this library or violations of Yahoo's terms of service.

Yahoo, Y!Finance, and Yahoo! Finance are registered trademarks of Yahoo, Inc.

About

High-performance C++ library for retrieving financial data from Yahoo Finance, as a native C++ alternative to Python yfinance

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors