TopicTrading Software
Backtesting, broker APIs and market-data tooling. Engineering only, never advice.
Short answer: To compute max drawdown in pandas, build an equity curve, take its running peak with cummax(), then compute equity / peak - 1 and call min(). Never apply cummax to raw returns, and include initial capital as the first peak.
Read the full answer
Short answer: To annualize Sharpe ratio, compute mean over standard deviation of per-period excess returns, then multiply by the square root of periods per year (252 daily, 365 crypto, 52 weekly, 12 monthly). A daily 0.06 becomes about 0.95.
Read the full answer
Short answer: CCXT fetch_ohlcv pagination means looping with since set to the last candle timestamp plus one timeframe and an explicit limit. Stop on an empty page or no progress, not on a short page. Dedupe, sort and save every page.
Read the full answer
Short answer: A pandas reindex duplicate labels error means the index repeats a timestamp, so pandas cannot map each label to one row position. Find the repeats with index.duplicated(keep=False), classify them, then dedupe with the right rule.
Read the full answer
Short answer: IBAPI error 354 'Requested market data is not subscribed' means no data will arrive for that request. Fix it by buying the real-time subscription, or call reqMarketDataType(3) before reqMktData to receive delayed ticks.
Read the full answer
Short answer: A Backtrader SMA crossover with no trades is usually warm-up: next() is not called until every indicator has a value, so SMA(50) skips 49 bars and CrossOver needs one more, giving a first signal at bar 51 at the earliest.
Read the full answer
Short answer: A backtest that gives different results each run depends on something that changes between runs: an unseeded RNG, hash-randomized ordering, parallel completion order, moving data, floating-point summation order, or the clock. Bisect the trade logs to find which.
Read the full answer
Short answer: Handling missing bars in OHLCV data for backtesting starts with building the expected timestamp index, diffing it against your data, and separating real closures from true gaps. Then you drop, flag, limit-fill or refetch each gap by its size.
Read the full answer
Short answer: In an adjusted vs unadjusted prices backtest, compute signals on a consistently adjusted series, then take fills, share counts and fees from raw prices as traded. Credit dividends as cash so P&L is total return.
Read the full answer
Short answer: A backtest limit order fill assumption that fills at the bar low is lookahead, because the low is only known after the bar closes. Decide on bar t, set the limit from known data, and fill on bar t+1 only if price trades through it, at min(open, limit).
Read the full answer
Short answer: Vectorbt vs backtrader different results almost always come from fill timing: vectorbt fills at the signal bar's close, Backtrader at the next open. Then check fees, sizing, share rounding, indicator seeding and data.
Read the full answer
Short answer: The ib_insync no current event loop error means the thread creating IB() has no asyncio loop, because get_event_loop() only auto-creates one in the main thread. Create a loop in that thread first, or move to ib_async.
Read the full answer