Skip to content

BeginnerUtilities & ToolsPython

Run this module

cd "Core Utilities"
python "datetime_utils.py"

View source on GitHub


Core Utilities

This folder contains core mathematical and date/time utilities that form the foundation for quantitative finance calculations.

Available Utilities

Date/Time (datetime_utils.py)

  • Timestamp generation and parsing
  • Trading day calculations
  • Market hours checking
  • Duration formatting

Mathematical (math_utils.py)

  • Percentage calculations
  • Compound interest and CAGR
  • Data normalization
  • Moving averages
  • Linear regression

Usage

# Date/time operations
from datetime_utils import get_trading_days, is_market_open, format_duration
from math_utils import calculate_cagr, moving_average, linear_regression

# Trading operations
trading_days = get_trading_days(start_date, end_date)
if is_market_open():
    print("Market is open!")

# Mathematical calculations
cagr = calculate_cagr(1000, 1500, 3)
ma = moving_average(prices, 20)
slope, intercept = linear_regression(x_data, y_data)

Installation

No additional dependencies required. Uses only Python standard library.

Testing

Run each utility directly to see demonstrations:

python datetime_utils.py
python math_utils.py

Common Use Cases

  • Time Analysis: Calculate trading days and market hours
  • Financial Calculations: Perform core mathematical operations
  • Data Analysis: Normalize and analyze time series data
  • Trend Analysis: Calculate moving averages and regressions
  • Investment Planning: Calculate compound growth and returns

Continue in Utilities & Tools

  • Currency Converter

    This utility does NOT use any external APIs. All exchange rates are entered manually for learning and experimentation.

  • Data Processing

    This folder contains utilities for data processing, validation, and manipulation in financial applications.

  • Economic Calendar

    This utility does NOT use any external APIs. All data is managed locally for learning and experimentation.

  • Historical Data

    A Node.js script that fetches historical bars (OHLCV data) for stocks or crypto from the Alpaca Market Data API. It prompts interactively for the symbol type, symbol, timeframe, and date range, then prints the results as JSON.

  • Logging

    A pair of minimal, dependency-light logging utilities implemented in both Python and JavaScript. Each supports adding, reading, editing, and deleting log entries through an interactive command-line menu. All entries are persisted to a plain-text log.txt file in the working directory.

  • Market Data

    This folder contains utilities for processing, analyzing, and fetching market data for financial applications.

Browse all modules Learning paths