Add usage example to strategies module documentation

This commit is contained in:
moshferatu 2025-01-07 12:08:00 -08:00
parent 4dd366ee16
commit d70a3ebbd6

View File

@ -4,6 +4,29 @@ This module provides implementations of various trading strategies.
The [Swing Trading Dashboard](https://moshferatu.dev/moshferatu/swing-trading-dashboard) depends on this module in order to provide an overview of recent trade signals.
## Example Usage
The following is an example of obtaining trade signals for the 2-Period RSI strategy:
```python
from datetime import datetime, timedelta
from ohlc import ohlc
from strategies import two_period_rsi
# Obtain the necessary OHLC data first.
today = datetime.today()
data = ohlc('SPY', start_date = today - timedelta(days = 365), end_date = today)
# Signals are returned as a pandas Series.
signals = two_period_rsi(data)
# Combining signals with date information from the OHLC data for demonstration purposes only.
result = data[['Date']].copy()
result['Signal'] = signals
print(result)
```
## Dependencies
The strategies module depends on the following Python packages: