
Sharpe Ratio in Python: Formula, Returns and Annualisation
Calculate the Sharpe ratio in Python with a worked example, matching cash returns and annualisation checks. Prepare daily market data with SiftingIO.
43 posts on Python from the SiftingIO market data blog, spanning real-time and historical coverage across stocks, forex, crypto, commodities, and on-chain venues.

Calculate the Sharpe ratio in Python with a worked example, matching cash returns and annualisation checks. Prepare daily market data with SiftingIO.

Calculate RSI in Python with Wilder's smoothing, check a worked example and update live candles without counting the same bar twice.

Compare VWAP and TWAP with worked examples and runnable Python code. Learn what OHLCV bars can estimate, how volume changes the result and why the window matters.

Calculate rolling historical volatility in Python from closing prices. Check log returns, missing data, price adjustments and 252 versus 365 annualization.

Calculate maximum drawdown in Python with pandas. Find peak, trough and recovery dates, handle unrecovered losses, and analyze historical market data.

Calculate Bollinger Bands in Python with pandas, verify the math, plot OHLCV closes and add live WebSocket prices without confusing ticks with candles.

Build a Python candlestick chart with Plotly and Bitcoin OHLCV data. Add volume, handle UTC timestamps, and save an interactive HTML chart with SiftingIO.

Calculate the gold-silver ratio with Python and commodity price data. Match timestamps, preserve missing bars and avoid misleading ratio candles.

Compare forex, gold, stocks and crypto on one chart. Rebase prices to 100 in Python with a shared baseline, tested pandas code and clear handling of gaps.

Detect same-candle stop-loss and take-profit ambiguity in Python, compare fill assumptions, and see when finer OHLCV data can resolve the sequence.

Monitor tick age, silent feeds and failed market-status polls with a small Python metrics adapter, Prometheus alerts and a credential-free demo.

Compare stock and crypto close-to-close returns on one session calendar. A tested pandas example handles DST, early closes and missing observations.

Diagnose SiftingIO API key errors with a 401/403 comparison table, curl checks and a Python test that keeps credentials out of logs.

Share one market data WebSocket across services: read max_conn and max_subs from the ack, republish ticks on Redis, snapshot for late joiners. Python code.

Build a clearer wallet balance screen with separate buckets for priced, dust, unpriced and unrecognised tokens, using a tested decimal-based classifier.

Preserve market data decimals from JSON to your database with tested Python, Go and JavaScript examples, plus a precision regression test.

Build a tested DEX pair TVL watcher with a fixed baseline, three-minute confirmation, timestamp checks and explicit handling of missing data.

Calculate forex ATR in Python from OHLCV bars. Test Wilder smoothing, convert ATR to pips and percentages, and avoid seed and unfinished-candle errors.

Record BTCUSD and ETHUSD reference-price updates to Parquet with Python. Includes a tested WebSocket recorder, session reports and clear data limitations.

Build a forex correlation matrix in Python with API data. Compare EURUSD, GBPUSD and USDJPY returns without hiding missing days or reversing quote direction.

Fix SiftingIO's 406 gzip_required error in curl, Python, Node and Go. Learn which clients decode automatically and when to handle gzip yourself.

How to use an economic calendar API to fetch scheduled US macro releases as JSON: UTC times, impact tiers, filtering by event, gating code and windowing a year of events.

Detect missing candles in OHLCV bar data with a UTC grid and a trading calendar, then backfill safely without forward-filling volume or range.

How cursor pagination works on a market data API, with request math, a Python loop, and a gap check for multi-year pulls of 1-minute OHLCV bars.

Pull US economic calendar events (CPI, NFP, FOMC) as JSON and join each release to the one-minute OHLCV bar that was open when it hit, using the real field names.

How to fetch the exact 1-minute OHLCV bar under each trade fill for stocks, forex, and crypto with one API, with verified page limits, intervals, and pagination.

Pull Form 4 insider transactions for US stocks from a REST API, decode transaction codes P, S, M, and F, and separate open-market buys from routine noise.

Pull profit margins, ROE, and debt to equity from SEC filings with one API call, and drop down to raw XBRL concepts when a precomputed ratio isn't enough.

How to pull daily and intraday OHLCV stock bars from a REST API: request format, response fields, intervals, cursor pagination, history depth, and pitfalls.

How Quantitative Trading at Brown uses intraday US equities OHLCV bars from the SiftingIO API for student research on returns, volatility, and trading volume.

The cross rate formula with worked math: derive EURGBP from EURUSD and GBPUSD, carry bid and ask through the triangulation, and compute it in Python.

TA-Lib won't install? Skip the C compile and numpy version matrix: pull RSI, MACD, and moving average readings from two REST endpoints with plain requests.

1-minute OHLCV bars are the base timeframe. The exact rules for resampling minute bars into 5m, 15m, and 1h bars, with the alignment and gap traps to avoid.
Build a stock portfolio tracker with a US stocks API: positions as data, daily-bar backfill, unrealized P&L from live quotes, and a WebSocket upgrade path.

Five ways historical price data silently corrupts a backtest: adjustment method, venue-dependent highs and lows, gap policy, session cuts, and restated bars.

Build a total-return series from as-traded prices, split factors, and cash dividends with reinvestment math, and see where the adjusted-close shortcut misleads a backtest.

Pull SEC Form 4 insider transactions for a stock watchlist with Python: decode transaction codes, paginate the API, and build a screening table with pandas.

How to pull scheduled US economic events from one endpoint and align them with OHLCV bars so a backtest knows when CPI, NFP, and FOMC actually hit.

yfinance rate limited or throwing Too Many Requests? A call-for-call map to move daily history, intraday bars, and latest-price pulls to a keyed API in Python.

How to read bid and ask from a quote snapshot, compute the bid ask spread in basis points, and flag wide or stale quotes in Python before users see them.
How to diff 13F-HR holdings between reporting cycles using SiftingIO, find new positions, exits, and meaningful size changes.

How to pull scheduled US economic events from one endpoint and align them with OHLCV bars so a backtest knows when CPI, NFP, and FOMC actually hit.

How to pull historical OHLCV bars and XBRL fundamentals for one stock ticker from SiftingIO, and avoid the split and fiscal-year pitfalls.