Skip to content

Trading Strategy API Reference

financelib.trading.strategy.CompositeStrategy(strategies: List[tuple])

Bases: BaseStrategy

Combine multiple strategies with weighted voting.

Parameters:

Name Type Description Default
strategies List[tuple]

List of (strategy, weight) tuples.

required
Example

composite = CompositeStrategy([ ... (MomentumStrategy(), 0.5), ... (MeanReversionStrategy(), 0.3), ... (BreakoutStrategy(), 0.2), ... ]) signal = composite.generate_signal(df)

Source code in financelib/trading/strategy.py
def __init__(self, strategies: List[tuple]) -> None:
    self.strategies = strategies
    total_weight = sum(w for _, w in strategies)
    if abs(total_weight - 1.0) > 0.01:
        logger.warning(f"Strategy weights sum to {total_weight}, normalizing to 1.0")
        self.strategies = [(s, w / total_weight) for s, w in strategies]

financelib.trading.strategy.MomentumStrategy(short_period: int = 10, long_period: int = 50, rsi_period: int = 14)

Bases: BaseStrategy

Momentum-based trading strategy using SMA crossover and RSI.

Buys when short SMA crosses above long SMA and RSI is not overbought. Sells on the reverse crossover or RSI overbought.

Source code in financelib/trading/strategy.py
def __init__(self, short_period: int = 10, long_period: int = 50, rsi_period: int = 14) -> None:
    self.short_period = short_period
    self.long_period = long_period
    self.rsi_period = rsi_period

financelib.trading.strategy.MeanReversionStrategy(bb_period: int = 20, bb_std: int = 2, rsi_period: int = 14)

Bases: BaseStrategy

Mean reversion strategy using Bollinger Bands and RSI.

Buys when price drops below lower Bollinger Band with RSI oversold. Sells when price rises above upper Bollinger Band with RSI overbought.

Source code in financelib/trading/strategy.py
def __init__(self, bb_period: int = 20, bb_std: int = 2, rsi_period: int = 14) -> None:
    self.bb_period = bb_period
    self.bb_std = bb_std
    self.rsi_period = rsi_period

financelib.trading.strategy.BreakoutStrategy(lookback: int = 20)

Bases: BaseStrategy

Breakout strategy based on N-period high/low channels.

Buys when price breaks above N-period high. Sells when price breaks below N-period low.

Source code in financelib/trading/strategy.py
def __init__(self, lookback: int = 20) -> None:
    self.lookback = lookback