<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Shreya Nair on Medium]]></title>
        <description><![CDATA[Stories by Shreya Nair on Medium]]></description>
        <link>https://medium.com/@shreyanair.1697?source=rss-bcd6de3f0dd3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*t3hTYu_r6yCjXzK8nCv0lQ.jpeg</url>
            <title>Stories by Shreya Nair on Medium</title>
            <link>https://medium.com/@shreyanair.1697?source=rss-bcd6de3f0dd3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 19:25:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shreyanair.1697/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building Meridian in Public: Week 0–1 — The Bones and the First Real Data]]></title>
            <link>https://medium.com/@shreyanair.1697/building-meridian-in-public-week-0-1-the-bones-and-the-first-real-data-9226a26e7fb7?source=rss-bcd6de3f0dd3------2</link>
            <guid isPermaLink="false">https://medium.com/p/9226a26e7fb7</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[quantdevelopment]]></category>
            <category><![CDATA[build-in-public]]></category>
            <category><![CDATA[portfolio-management]]></category>
            <category><![CDATA[quantitative-finance]]></category>
            <dc:creator><![CDATA[Shreya Nair]]></dc:creator>
            <pubDate>Mon, 21 Sep 2026 01:51:59 GMT</pubDate>
            <atom:updated>2026-09-21T01:51:59.198Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*InIdGgQav3l1jBFY" /><figcaption>Photo by <a href="https://unsplash.com/@jakubzerdzicki?utm_source=medium&amp;utm_medium=referral">Jakub Żerdzicki</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I am in the process of creating my capstone project ‘Meridian’ publicly. It is not just about completing a few tutorial modules; it&#39;s about building and implementing a real system with several components, including a data pipeline, financial math, options and fixed income pricing, signal detection, portfolio optimisation, risk evaluation, and an executed dashboard, to name a few.</p><p>This first post, however, introduces ideas I encountered while developing the first system components, such as the framework, schema, and the initial data present in the database.</p><h4>Why one project instead of a stack of exercises?</h4><p>Initially, I planned to implement a series of smaller modules: one for returns and volatility, another for constructing an investment portfolio, another for backtesting, and so on. After discovering that true quant infrastructure doesn’t work the way I initially thought, I dismissed this plan. The backtester requires an effective data pipeline; the risk engine relies on a factor model, and so on.</p><p>If I had built everything in isolated modules, I would have learned syntax without understanding how the components fit together, which is what actually matters.</p><p>Now the plan is different: it will involve a single platform with ten phases built in a logical order. Phase 0 focuses on developing an environment and repository. Phase 1, which I am currently working on, involves designing the data pipeline on which everything else in this project will be built.</p><h4>Phase 0: the boring part that has to be right</h4><p>Phase 0 was a complete Python project structure that includes uv for managing dependencies, ruff for checking code quality, pytest for testing, and a set of continuous integration steps that run tests on every code push to the repository.</p><p>It might seem trivial, but the difference between “a directory of scripts” and “a project” is defined by including CI as early as Phase 0, rather than adding it at Phase 6 when its usefulness would have declined significantly.</p><p><em>CI is green. Phase 0 is done.</em></p><h4>Phase 1, Piece 1: the schema comes before the code</h4><p>Before touching yfinance or any live data source, I designed the database schema. Four tables so far, and each one forced a real decision:</p><ol><li>Equity bars — Daily OHLC data, volume, and adjusted close are recorded as a single row for each symbol per trading day. The natural key here is (symbol, date), while the real question is whether to create an adjusted close column or derive it during later calculations. All return calculations depend on adjusted close, so we acquire this value to avoid recalculating it at every stage.</li><li>Corporate actions — Splits and dividends are not the kind of data occurring on a daily basis, they happen regularly in the course of time. For example, there might be split events several years without any corporate actions. Therefore, it is necessary to have three columns in the natural key instead of two: (symbol, date, action_type).</li><li>Macro series — Treasury yields and related FRED data went in as long, tidy rows keyed on (series_id, date) rather than a wide table with one column per series. That was the least obvious call at first; wide felt more “normal,” but tidy means adding VIX or credit spreads later is a data load, not a schema migration.</li><li>Fama-French factors — This one went wide instead of tidy: Market, SMB, HML, RF as actual columns, because the factor set is small, fixed, and academically defined, not something I’ll be extending later. The catch was that French’s data comes in daily, monthly, and annual files, and a naive (date) key would collide as soon as I loaded more than one frequency. It’s (date, frequency) instead.</li></ol><p><em>Once it&#39;s decided, none of this is complicated. Getting to the decision was the real work.</em></p><h4>Phase 1, Piece 2: config and a database connection.</h4><p>With the schema written, next was the boring-but-load-bearing plumbing: a config.py that resolves the .env file by path rather than assuming a working directory, and a db.py with a lazily-initialised, cached engine singleton so the app doesn&#39;t open a new database connection every time something imports the module.</p><p>One real bug worth mentioning: my Docker Compose credentials, and my .env&#39;s DATABASE_URL didn&#39;t match. The container spun up fine, Postgres was healthy, and the connection still failed, because I was authenticating with one set of credentials against a database that had been initialised with another. Small thing, but the kind of small thing that eats an evening, and exactly the kind of thing no tutorial mentions because tutorials don&#39;t hit real state.</p><p>I verified the connection worked against both a running container and a freshly stopped-and-restarted one, since “works once” and “works reliably” are different bars.</p><h4>Phase 1, Piece 3: equities ingestion, and the first real data</h4><p>This piece pulls daily OHLCV bars from yfinance and writes them into equity_bars. The straightforward part was the pull. The hard part was getting the adjustment-factor math right for splits and dividends, which is the whole reason adj_close exists as its own column instead of being derived somewhere downstream.</p><p>A stock split changes the share price without changing anything about the company. A dividend does the opposite: it pays cash out of the company, which should show up as a real drop in raw price on the ex-dividend date. Adjusted close exists to make historical prices comparable across both of these events, and getting that adjustment factor wrong quietly corrupts every return calculation built on top of it later. Working through that math by hand, rather than trusting a library to do it invisibly, was the point of this piece.</p><p>Two smaller decisions came out of writing this code that are worth recording, because they’re the kind of thing no tutorial mentions and every real pipeline runs into.</p><p><strong>Volume needed to distinguish “missing” from “zero.”</strong> A day with no trading volume and a day where the data source simply failed to report volume are not the same thing, but a naive fillna(0) approach treats them identically. equity_bars.volume is stored as pandas nullable Int64 type instead, so a genuinely missing volume day stays visibly missing all the way through to the quality checks that come later in this phase, instead of silently becoming a zero that looks like real data.</p><p><strong>Broad exception handlers turned out to be the wrong instinct.</strong> The obvious defensive move when calling an external API is to wrap the call in a broad except Exception and move on. Testing that against yfinance directly showed it was actively the wrong call here: yfinance already swallows real network and API failures internally, so a broad handler on top of it didn&#39;t catch real failures; it caught bugs, like passing the wrong input type, and hid them. Ticker and input validation now happens explicitly at each function&#39;s boundary instead, which means a bug fails loudly where it happened instead of disappearing into a silent except block three layers away.</p><p><em>Piece 3 is committed and done: equities ingestion with dividend-adjustment math, tested against real tickers, not synthetic ones.</em></p><h3>Phase 1, Piece 4: rates and macro data, underway</h3><p>Piece 4 is the FRED ingestion piece: Treasury yields, VIX, and credit spreads, going into the macro_series table designed back in Piece 1 specifically so this piece wouldn&#39;t require a schema change. Right now this is at the research stage, working through the fredapi interface and confirming the correct series IDs before writing the ingestion function itself.</p><h3>Where this leaves things</h3><ul><li>Phase 0: done, CI green</li><li>Phase 1, Piece 1 (schema + Docker Compose): done</li><li>Phase 1, Piece 2 (config + DB engine): done</li><li>Phase 1, Piece 3 (equities ingestion, split/dividend adjustment math): done</li><li>Phase 1, Piece 4 (FRED macro/rates ingestion): in progress</li></ul><p>There’s a real database now, with a real schema, real prices flowing into it, and correct split and dividend adjustments. The rates data is next.</p><p><em>Building Meridian in public. Follow along for the next update.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9226a26e7fb7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding the Three Pointer Technique in Data Structures]]></title>
            <link>https://medium.com/@shreyanair.1697/understanding-the-three-pointer-technique-in-data-structures-0bd6b2c76a72?source=rss-bcd6de3f0dd3------2</link>
            <guid isPermaLink="false">https://medium.com/p/0bd6b2c76a72</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[dsa-problem]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[data-structure-algorithm]]></category>
            <category><![CDATA[3-pointer]]></category>
            <dc:creator><![CDATA[Shreya Nair]]></dc:creator>
            <pubDate>Wed, 07 Jan 2026 00:00:12 GMT</pubDate>
            <atom:updated>2026-01-07T00:00:12.216Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*XSfqpezxSVq8d62s5LmLnw.webp" /><figcaption>Image from dev.to</figcaption></figure><p>When people struggle with array problems, it is rarely because the problem is hard. It is usually because the movement of pointers feels chaotic. The three-pointer technique is a perfect example. At first glance, it doesn&#39;t look very clear. Once understood, it becomes one of the cleanest and most powerful patterns in DSA.</p><p>This article explains three pointers from first principles, without jumping straight into code. The goal is to help you build intuition that transfers across problems.</p><h3>What a Pointer Really Is</h3><p>A pointer is not just an index variable like i or j.<br>A pointer represents a role.</p><p>Each pointer answers a specific question about the array:</p><ul><li>Where does the left sorted region end?</li><li>Which element am I currently inspecting?</li><li>Where does the right sorted region begin?</li></ul><p>If you keep thinking of pointers as roles instead of numbers, the confusion drops immediately.</p><h3>Why Three Pointers Are Needed</h3><p>Two pointers work well when:</p><ul><li>You are comparing two ends</li><li>You are shrinking a range from both sides</li></ul><p>Three pointers are required when:</p><ul><li>One part of the array is already correct</li><li>Another part is also already correct</li><li>The middle part is unknown and still needs processing</li></ul><p>In other words, three pointers appear when you must protect two completed regions while scanning an unsorted region.</p><h3>The Classic Example</h3><p>Consider an array containing only three values:</p><pre>0, 1, 2</pre><p>The task is to sort the array in place so that:</p><ul><li>All 0s are on the left</li><li>All 1s are in the middle</li><li>All 2s are on the right</li></ul><p>Example input:</p><pre>[2, 0, 2, 1, 1, 0]</pre><h3>Defining the Roles</h3><p>We define three pointers with clear responsibilities:</p><ul><li><strong>low</strong><br>Everything before this index is already correct and contains only 0s.</li><li><strong>mid</strong><br>This pointer inspects the current element.</li><li><strong>high</strong><br>Everything after this index is already correct and contains only 2s.</li></ul><p>At any moment, the array looks like this:</p><pre>[ 0s | unknown | 2s ]<br>       ^<br>      mid</pre><p>The unknown region is the only part we actively process.</p><h3>The Key Rule</h3><p>Only one pointer makes decisions.</p><p>That pointer is <strong>mid</strong>.</p><p>The low and high pointers exist only to protect boundaries.<br>Every decision is based on the value at nums[mid].</p><h3>The Three Possible Cases</h3><h4>Case 1: nums[mid] == 0</h4><p>Zero belongs on the left.</p><p>Action:</p><ul><li>Swap nums[mid] with nums[low]</li><li>Move low forward</li><li>Move mid forward</li></ul><p>Why this works:<br>The element swapped from the left side has already been processed, so it is safe to move on.</p><h4>Case 2: nums[mid] == 1</h4><p>One belongs in the middle.</p><p>Action:</p><ul><li>Do nothing</li><li>Move mid forward</li></ul><p>Why this works:<br>The element is already in the correct region.</p><h4>Case 3: nums[mid] == 2</h4><p>Two belongs on the right.</p><p>Action:</p><ul><li>Swap nums[mid] with nums[high]</li><li>Move high backward</li><li>Do not move mid</li></ul><p>This is the most important rule.</p><h3>Why Mid Does Not Move After Swapping With High</h3><p>When swapping with high, the element that comes into mid is unknown.<br>It could be 0, 1, or 2.</p><p>If mid were moved forward, that new element would never be checked.<br>This would leave the array partially unsorted.</p><p>In contrast, when swapping with low, the element coming into mid is already verified, which is why mid can safely move forward in that case.</p><p>This distinction is the heart of the three-pointer technique.</p><h3>Walking Through One Example</h3><p>Starting state:</p><pre>[2, 0, 2, 1, 1, 0]<br>low = 0, mid = 0, high = 5</pre><ol><li>nums[mid] is 2<br>Swap with high<br>high moves left, mid stays</li><li>nums[mid] is now 0<br>Swap with low<br>low and mid move right</li><li>nums[mid] is 0 again<br>Swap with low<br>low and mid move right</li><li>nums[mid] is 2<br>Swap with high<br>high moves left, mid stays</li><li>nums[mid] is 1<br>Move mid</li><li>nums[mid] is 1<br>Move mid<br>mid crosses high, algorithm stops</li></ol><p>The array is sorted in one pass with constant space.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2h6GHVHH3-8YPCix-HcXMw.png" /></figure><h3>This would help you when coding</h3><p>Say this while solving problems:</p><p>Low and high protect finished zones.<br>Mid cleans the unknown zone.</p><p>If you can say this confidently, you can implement the solution.</p><h3>Tips and Tricks for Interviews</h3><ul><li>Do not start coding immediately. First, describe the zones.</li><li>Clearly state the invariant. What parts of the array are always correct?</li><li>Explain why mid does not move in one case.</li><li>If confused, redraw the array with labelled zones instead of values.</li></ul><h3>Where This Pattern Appears Again</h3><p>Once you understand this technique, you will start seeing it everywhere:</p><ul><li>Partitioning problems</li><li>In place sorting variants</li><li>Problems involving categorisation into fixed groups</li></ul><p>The surface problem may change, but the roles stay the same.</p><h3>Final Thought</h3><p>The three-pointer technique is not about memorising conditions.<br>It is about controlling chaos while preserving order.</p><p>Once that clicks, many array problems stop being intimidating and start feeling mechanical.</p><p>Try for yourself — <a href="https://leetcode.com/problems/merge-sorted-array">https://leetcode.com/problems/merge-sorted-array</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0bd6b2c76a72" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Loop Invariants: The Invisible Superpower Behind Clean Algorithms]]></title>
            <link>https://medium.com/@shreyanair.1697/loop-invariants-the-invisible-superpower-behind-clean-algorithms-0ed6edc8152b?source=rss-bcd6de3f0dd3------2</link>
            <guid isPermaLink="false">https://medium.com/p/0ed6edc8152b</guid>
            <category><![CDATA[problem-solving]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Shreya Nair]]></dc:creator>
            <pubDate>Sat, 03 Jan 2026 01:23:20 GMT</pubDate>
            <atom:updated>2026-01-03T01:23:20.007Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bcX-EBgLnvYdODueRkcWUA.png" /></figure><p>When people start learning Data Structures and Algorithms, most of the effort goes into <strong>syntax</strong> and <strong>patterns</strong>: two pointers, sliding windows, hash maps, and binary search. But there is a deeper concept that quietly separates <em>people who write working code</em> from <em>people who understand why their code works</em>.</p><p>That concept is the <strong>loop invariant</strong>.</p><p>I didn’t truly understand invariants when I first encountered them. They sounded academic, abstract, almost philosophical. But once they clicked, something fundamental changed: debugging became easier, algorithms became calmer, and interview explanations became sharper.</p><p>This article explains loop invariants from first principles, using a real LeetCode problem as a concrete anchor.</p><h3>What Is a Loop Invariant?</h3><p>A <strong>loop invariant</strong> is a condition that is <strong>always true at a specific point during every iteration of a loop</strong>.</p><p>Not just at the end.<br> Not just at the beginning.<br> But <em>throughout</em> the execution of the loop.</p><p>Think of it as a <strong>promise</strong> your algorithm makes and never breaks.</p><blockquote><em>A loop invariant is a truth you protect while the algorithm runs.</em></blockquote><h3>A Real-Life Analogy</h3><p>Imagine cleaning a long table from left to right</p><ul><li>The left side of the table is already cleaned.</li><li>The right side is still messy.</li><li>Your hand marks the boundary.</li></ul><p>Your invariant is simple:</p><blockquote><em>“Everything to the left of my hand is clean.”</em></blockquote><p>Even though the table isn’t fully clean yet, that statement is <em>always true</em>.<br> You never need to recheck the left side — you trust the invariant. Algorithms work the same way.</p><h3>The Problem: Remove Duplicates from a Sorted Array</h3><p>Consider this classic problem:</p><blockquote><em>Given a sorted array of integers, remove duplicates </em><strong><em>in-place</em></strong><em> such that each unique element appears only once. Return the number of unique elements </em><em>k. The first </em><em>k elements of the array must contain the unique values in sorted order.</em></blockquote><p>Example:</p><pre>Input:  [1, 1, 2]<br>Output: k = 2, nums = [1, 2, _]</pre><p>The key constraint is <strong>in-place modification</strong>, which means we overwrite values instead of creating new arrays.</p><h3>The Code (Optimised Solution)</h3><pre>def removeDuplicates(nums):<br>    if not nums:<br>        return 0<br>    k = 1<br>        for i in range(1, len(nums)):<br>            if nums[k - 1] != nums[i]:<br>                nums[k] = nums[i]<br>                k += 1<br>        return k</pre><p>This solution runs in <strong>O(n)</strong> time and <strong>O(1)</strong> extra space — optimal.</p><p>But the real value lies in understanding <em>why</em> it works.</p><h3>The Loop Invariant in This Algorithm</h3><p>Here is the invariant that makes everything click:</p><blockquote><strong><em>At any point during the loop, the first </em></strong><strong><em>k elements of the array contain all unique elements seen so far, in sorted order.</em></strong></blockquote><p>That’s it. That’s the backbone of the algorithm.</p><p>Let’s see how this invariant is maintained.</p><h3>Step-by-Step With an Example</h3><p>Input:</p><pre>nums = [1, 1, 2]</pre><h3>Initialization</h3><ul><li>k = 1</li><li>The first element is always unique by definition.</li></ul><p>Invariant holds:</p><pre>nums[0:k] = [1]  → unique and sorted</pre><h4>First Iteration (i = 1)</h4><ul><li>Compare nums[i] = 1 with the last unique element nums[k - 1] = 1</li><li>They are equal → duplicate</li><li>Do nothing</li></ul><p>Invariant still holds:</p><pre>nums[0:k] = [1]</pre><h4>Second Iteration (i = 2)</h4><ul><li>Compare nums[i] = 2 with nums[k - 1] = 1</li><li>They are different → new unique value</li><li>Write it to nums[k]</li><li>Increment k</li></ul><p>Array becomes:</p><pre>[1, 2, 2]</pre><p>Invariant holds again:</p><pre>nums[0:k] = [1, 2]</pre><h3>Loop Ends</h3><p>The invariant guarantees correctness when the loop finishes.<br> We return k = 2.</p><p>The judge only checks the first k elements — everything else is irrelevant.</p><h3>Why Invariants Matter More Than You Think</h3><p>Without invariants:</p><ul><li>Code feels fragile</li><li>Debugging is guesswork</li><li>Edge cases feel mysterious</li><li>Interview explanations sound shallow</li></ul><p>With invariants:</p><ul><li>You know exactly what part of the data is “done”</li><li>You know what is safe to overwrite</li><li>You can explain correctness, not just behaviour</li><li>Bugs are found by asking: <em>“When did my invariant break?”</em></li></ul><p>This is how experienced engineers reason.</p><h3>A Second, Simpler Example</h3><p>Consider summing an array:</p><pre>total = 0<br>for x in nums:<br>    total += x</pre><p>The invariant is:</p><blockquote><em>“</em><em>total equals the sum of all elements processed so far.”</em></blockquote><p>That invariant is what makes the algorithm obviously correct.</p><h3>Why This Concept Is Interview Gold</h3><p>In strong interviews, especially at top companies, candidates are often asked:</p><ul><li>“Why does this algorithm work?”</li><li>“How do you know this is correct?”</li><li>“What does this variable represent?”</li></ul><p>Stating an invariant out loud instantly elevates your answer:</p><blockquote><em>“At every iteration, the first </em><em>k elements are guaranteed to be unique.”</em></blockquote><p>That’s not just coding. That’s reasoning.</p><h3>How to Practice Using Invariants</h3><p>For every loop-based algorithm, ask yourself:</p><ul><li>What part of the data is already finalised?</li><li>What part is still being processed?</li><li>What must always be true about the finalised part?</li></ul><p>Write that sentence first.<br> Then write the code.</p><p>Over time, you’ll notice that many problems: two pointers, sliding windows, and array compression are just different invariants wearing different clothes.</p><h3>Final Thought</h3><p>Loop invariants aren’t an academic trick.<br> They are the mental scaffolding that holds good algorithms together.</p><p>Once you start seeing them, you’ll realise that great code doesn’t come from clever hacks, it comes from <strong>protecting simple truths, one iteration at a time</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0ed6edc8152b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>