🚀
Finter
PlaygroundData Catalogue
Quick Start
Quick Start
  • Getting Started with Finter: A Quick Guide
  • Explore Finter
    • Finter Labs (Recommended)
    • Other Ways
      • Google Colab
      • Conda, venv, or Docker
      • Setting Up a .env File (Optional)
  • Framework
    • CM (Content Model)
    • AM (Alpha Model)
    • PM (Portfolio Model)
    • Simulatior
      • Target Volume Limit
    • Finter Cli Submission
      • Validation
      • GitHub Sync
      • [Legacy] JupyterLab Submission
      • [Legacy] Submission
  • MODELING
    • MetaPortfolio
      • Equal weight meta portfolio
      • Fixed weight meta portfolio
      • Risk parity meta portfolio
    • StrategicAssetAllocation
    • DateConverter
    • BuyHoldConverter
  • Supporting Tools
    • FileManager
    • Finter AI (alpha ver.)
    • Data
      • FinHelper
        • filter_unchanged
        • unify_idx
        • shift_fundamental
        • rolling
        • expand_to_gvkeyiid
      • ModelData
      • ID Table
      • ID Converter
      • Quanda Data
    • Evaluator
      • top_n_assets
      • bottom_n_assets
      • compare_with_bm
    • PortfolioAnalyzer
    • Email
Powered by GitBook
On this page
  • Method Signature
  • Return Value
  • Examples

Was this helpful?

Edit on GitHub
  1. MODELING

DateConverter

The `DateConverter` class provides utility methods for date manipulation, including calculating pre-start dates based on given start dates and lookback periods.

To avoid errors in date calculations, always use specialized tools like Python's datetime or a custom DateConverter. These handle all the tricky parts of dates, like leap years or month lengths, making your calculations accurate and straightforward.

Method Signature

from finter.modeling import DateConverter

DateConverter.get_pre_start(start, lookback_days, trading_day=False)
  • start (int, str, datetime): The start date. Can be an integer in YYYYMMDD format, a string with 'YYYYMMDD' format, or a datetime object.

  • lookback_days (int): The number of days to look back from the start date.

  • trading_day (bool, optional): If True, only considers trading days. Defaults to False.

Return Value

  • Returns an integer in YYYYMMDD format if the input is an integer or string.

  • Returns a datetime object if the input is a datetime object.

Examples

from datetime import datetime
from finter.modeling import DateConverter

# Example 1: Input as integer
print(DateConverter.get_pre_start(20220101, 5))

# Example 2: Input as string
print(DateConverter.get_pre_start('20220101', 5))

# Example 3: Input as datetime object
print(DateConverter.get_pre_start(datetime(2022, 1, 1), 5))

Last updated 1 year ago

Was this helpful?