Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions docs/strategies/obv_breakout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

# OBV Breakout

This is a trading strategy called "OBV Breakout Strategy" implemented in Python using the PyAlgoTrading library. The strategy relies on On-Balance Volume (OBV) crossovers with its smoothed average to signal potential trades in equities.

!!! Links
- **[Strategy Code (.py)](https://github.com/algobulls/pyalgostrategypool/blob/master/pyalgostrategypool/obv_breakout/_strategy.py){target=_blank}**
- **[Strategy Structure (common methods used in a regular and options strategy)](strategy_guides/common_strategy_guide.md){target=_blank}**

!!! Tips "Jupyter Notebooks for US Exchange (NASDAQ)"
- **[Click here to view a working notebook for NASDAQ exchange in cloud. No installation required. ](https://nbviewer.org/github/algobulls/pyalgotrading/blob/master/jupyter/nasdaq_equity/obv_breakout_us.ipynb){target=_blank}**
- **[Click here to execute a working notebook for NASDAQ exchange in cloud. No installation required. ](https://mybinder.org/v2/gh/algobulls/pyalgotrading/master?urlpath=lab%2Ftree%2Fjupyter%2Fnasdaq_equity%2Fobv_breakout_us.ipynb){target=_blank}**

## What is OBV
On-Balance Volume (OBV) is a volume-based technical indicator that accumulates or depletes volume depending on whether prices close higher or lower. It can move ahead of price, offering early signals of momentum shifts. A rising OBV usually indicates increased buying pressure, while a falling OBV often signals selling pressure.

## Strategy Overview
This strategy checks for breakouts in the OBV relative to its smoothed average. A bullish breakout occurs when the raw OBV crosses above its smoothed OBV (SMA) over the last `TIME_PERIOD` bars, indicating a potential increase in buying pressure. A bearish breakout occurs when the raw OBV crosses below its smoothed OBV, signaling a potential increase in selling pressure. These breakouts help confirm momentum and signal potential entry for trades.

## Strategy Parameters
The following parameters can be configured for the strategy:

| Name | Default Value | Expected Value | Description |
|:------------------------|:------------:|:---------------:|:-------------------------------------------------------------------------------------------|
| **TIME_PERIOD** | 10 | > 0 | Period used to smooth the raw OBV (e.g., 10 bars). |

## Breakout Calculation
The code computes raw OBV and a smoothed OBV (using `talib.SMA`). A bullish breakout occurs when the raw OBV crosses above its smoothed OBV (SMA), and a bearish breakout occurs when the raw OBV crosses below its smoothed OBV (SMA).
43 changes: 43 additions & 0 deletions docs/strategies/options_box_spread.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

## Options Box Spread

This is a template for implementing the Options Box Spread strategy in Python.

!!! Links
- **[Strategy Code (.py)](https://github.com/your-username/pyalgostrategypool/blob/master/pyalgostrategypool/options_box_spread/_strategy.py){target=_blank}**
- **[Strategy Structure (common methods used in a regular and options strategy)](strategy_guides/common_strategy_guide.md){target=_blank}**

[//]: # (Optional placeholder for any Jupyter notebook references)

### Introduction

The Box Spread strategy is a market-neutral arbitrage approach combining a bull call spread and a bear put spread on the same underlying asset, with matching expiration dates but differing strike prices. The strategy locks in a fixed payoff, \( B - A \), by selecting a lower strike (A) and a higher strike (B), ensuring a consistent return regardless of the underlying asset's price movement.

To construct a box spread:
1. **Bull Call Spread**
- Buy a call option at strike A (lower strike).
- Sell a call option at strike B (higher strike).
2. **Bear Put Spread**
- Buy a put option at strike B (higher strike).
- Sell a put option at strike A (lower strike).

### Strategy Parameters

| Name | Default Value | Expected Value | Description |
|:------------------------------------|:------------:|:--------------:|:------------------------------------------------------------------------------------------------------------------|
| **LEG_ONE_TRANSACTION_TYPE** | 1 | 1 or 2 | Transaction type for leg one (call buy or sell). [**BUY**: 1, **SELL**: 2] |
| **LEG_ONE_TRADING_SYMBOL_SUFFIX** | 1 | 1 or 2 | Trading symbol suffix ([CE: 1, PE: 2]) for leg one. |
| **LEG_ONE_STRIKE_DIRECTION** | 0 | 0, 1, or 2 | Strike direction ([ITM: 0, ATM: 1, OTM: 2]) for leg one. |
| **LEG_ONE_NUMBER_OF_STRIKES** | 0 | >= 0 | Number of strikes offset for leg one. |
| **LEG_TWO_TRANSACTION_TYPE** | 2 | 1 or 2 | Transaction type for leg two (call buy or sell). [**BUY**: 1, **SELL**: 2] |
| **LEG_TWO_TRADING_SYMBOL_SUFFIX** | 1 | 1 or 2 | Trading symbol suffix ([CE: 1, PE: 2]) for leg two. |
| **LEG_TWO_STRIKE_DIRECTION** | 2 | 0, 1, or 2 | Strike direction ([ITM: 0, ATM: 1, OTM: 2]) for leg two. |
| **LEG_TWO_NUMBER_OF_STRIKES** | 2 | >= 0 | Number of strikes offset for leg two. |
| **LEG_THREE_TRANSACTION_TYPE** | 1 | 1 or 2 | Transaction type for leg three (put buy or sell). [**BUY**: 1, **SELL**: 2] |
| **LEG_THREE_TRADING_SYMBOL_SUFFIX** | 2 | 1 or 2 | Trading symbol suffix ([CE: 1, PE: 2]) for leg three. |
| **LEG_THREE_STRIKE_DIRECTION** | 0 | 0, 1, or 2 | Strike direction ([ITM: 0, ATM: 1, OTM: 2]) for leg three. |
| **LEG_THREE_NUMBER_OF_STRIKES** | 2 | >= 0 | Number of strikes offset for leg three. |
| **LEG_FOUR_TRANSACTION_TYPE** | 2 | 1 or 2 | Transaction type for leg four (put buy or sell). [**BUY**: 1, **SELL**: 2] |
| **LEG_FOUR_TRADING_SYMBOL_SUFFIX** | 2 | 1 or 2 | Trading symbol suffix ([CE: 1, PE: 2]) for leg four. |
| **LEG_FOUR_STRIKE_DIRECTION** | 2 | 0, 1, or 2 | Strike direction ([ITM: 0, ATM: 1, OTM: 2]) for leg four. |
| **LEG_FOUR_NUMBER_OF_STRIKES** | 0 | >= 0 | Number of strikes offset for leg four. |
32 changes: 32 additions & 0 deletions docs/strategies/strategy_guides/obv_breakout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

# OBV Breakout

This is a trading strategy called "OBV Breakout Strategy" implemented in Python using the PyAlgoTrading library. The strategy relies on On-Balance Volume (OBV) breakouts coinciding with price breakouts to signal potential trades in equities.

!!! Links
- **[Strategy Code (.py)](https://github.com/algobulls/pyalgostrategypool/blob/master/pyalgostrategypool/obv_breakout/_strategy.py){target=_blank}**
- **[Strategy Structure (common methods used in a regular and options strategy)](strategy_guides/common_strategy_guide.md){target=_blank}**

!!! Tips "Jupyter Notebooks for US Exchange (NASDAQ)"
- **[Click here to view a working notebook for NASDAQ exchange in cloud. No installation required. ](https://nbviewer.org/github/algobulls/pyalgotrading/blob/master/jupyter/nasdaq_equity/obv_breakout_us.ipynb){target=_blank}**
- **[Click here to execute a working notebook for NASDAQ exchange in cloud. No installation required. ](https://mybinder.org/v2/gh/algobulls/pyalgotrading/master?urlpath=lab%2Ftree%2Fjupyter%2Fnasdaq_equity%2Fobv_breakout_us.ipynb){target=_blank}**

## What is OBV
On-Balance Volume (OBV) is a volume-based technical indicator that accumulates or depletes volume depending on whether prices close higher or lower. It can move ahead of price, offering early signals of momentum shifts. A rising OBV usually indicates increased buying pressure, while a falling OBV often signals selling pressure.

## Strategy Overview
This strategy checks whether the smoothed OBV (e.g., 10-period moving average) and price both exceed or drop below their respective lookback highs or lows. A bullish setup occurs when OBV moves above its highest level of the last N bars and the closing price simultaneously breaks above its own recent high. A bearish setup occurs when both OBV and price break below their respective lows. These combined breakouts aim to confirm momentum before entering a trade.

## Strategy Parameters
The following parameters can be configured for the strategy:

| Name | Default Value | Expected Value | Description |
|:------------------------|:------------:|:---------------:|:-------------------------------------------------------------------------------------------|
| **OBV_MA_PERIOD** | 10 | > 0 | Period used to smooth the raw OBV (e.g., 10 bars). |
| **LOOKBACK_PERIOD** | 10 | > 0 | Number of past bars for OBV and price breakout checks. |
| **TRAILING_STOP_PERIOD**| 10 | > 0 | Lookback window for trailing stops (lowest low for longs, highest high for shorts). |
| **ATR_PERIOD** | 14 | > 0 | Period for Average True Range (ATR) calculation used in volatility-based trailing stops. |
| **ATR_MULTIPLIER** | 1.5 | > 0 | Multiplier for ATR-based stop, e.g., entry ± (m × ATR). |

## Breakout Calculation
The code computes raw OBV and a smoothed OBV (using `talib.SMA`). A bullish breakout requires `OBV_SMA` to exceed its lookback maximum and the closing price to exceed its own N-bar high; a bearish breakout requires both OBV and price to break below their recent lows. The exit logic considers OBV dips/rises relative to its SMA or trailing stops using both lookback lows/highs and ATR-based thresholds.
Loading