Posts

Showing posts from November, 2025
Image
   Modeling Buy-Sell Trades with SQL and EMAs: Lifecycle Segmentation and Strategy Comparison This post demonstrates how to transform a trading day ledger into segmented trades using SQL, and compares the performance of a buy-sell model against a buy-and-hold strategy—both across the full evaluation period and during a short-term market shock. It builds on concepts introduced in this prior post on preparing the trading day ledger, and is part of the broader Security Trading Analytics blog focused on lifecycle-aware strategy design and principled security selection. The raw close prices sourced from Tiingo start on 2022-01-03 and run through 2025-10-23.  The ledger contains a succession of trading row values that prescribe when to buy and sell tickers. This post demonstrates how to process the ledger from the prior post with a SQL model that indicates when to buy and sell tickers.  The current post examines how to assign trade_id values to each row in the ledger...