<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: SIGNUM HQ</title>
    <description>The latest articles on DEV Community by SIGNUM HQ (@signumhq).</description>
    <link>https://dev.to/signumhq</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4191805%2Ff0c815a0-0283-4003-84cc-a623fab8588b.png</url>
      <title>DEV Community: SIGNUM HQ</title>
      <link>https://dev.to/signumhq</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/signumhq"/>
    <language>en</language>
    <item>
      <title>How we compute session VWAP from 1-minute bars when the data feed does not give you one</title>
      <dc:creator>SIGNUM HQ</dc:creator>
      <pubDate>Sun, 18 Oct 2026 09:27:48 +0000</pubDate>
      <link>https://dev.to/signumhq/how-we-compute-session-vwap-from-1-minute-bars-when-the-data-feed-does-not-give-you-one-bc</link>
      <guid>https://dev.to/signumhq/how-we-compute-session-vwap-from-1-minute-bars-when-the-data-feed-does-not-give-you-one-bc</guid>
      <description>&lt;p&gt;Our stock app showed a "VWAP" number for every ticker. For a while that number was a lie. This is a short write-up of how we found out, and how we now compute session VWAP from 1-minute bars when the data feed does not give you one.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F64gjt91fspirtvkci98x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F64gjt91fspirtvkci98x.png" alt="SIGNUM HQ command screen showing the NVDA session VWAP row (Korean UI)" width="800" height="1731"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The VWAP row on the stock command screen, now computed from 1-minute bars.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What was wrong
&lt;/h2&gt;

&lt;p&gt;The market-data snapshot we use has a &lt;code&gt;vwap&lt;/code&gt; field on the daily aggregate, but it is empty for a lot of tickers, during the session and on weekends. At some point someone (me) filled the gap with the usual shortcut from a daily bar:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vwap ≈ (high + low + close) / 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is the &lt;em&gt;typical price&lt;/em&gt; of one bar. It is not a volume-weighted average of anything. It happens to land near the real VWAP on quiet days, which is why nobody noticed. On a day with a big gap and a late-session fade it can be off by a lot, and it was labelled "VWAP" in the UI.&lt;/p&gt;

&lt;p&gt;We removed the fake value. The field then became &lt;code&gt;null&lt;/code&gt; everywhere and the screen showed an em dash. Honest, but useless. So the real fix was to compute it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The computation
&lt;/h2&gt;

&lt;p&gt;VWAP for a session is the sum of price times volume divided by the sum of volume, over the regular session only. We already cache the 1-minute chart bars per ticker for the chart screen, so we reuse them and make zero extra calls to the data vendor.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// bars: 1-minute bars, each tagged with its ET date and session (PRE | REG | POST)&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;sessionVwap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bars&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;reg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;bars&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;session&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;REG&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;volume&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nf"&gt;valid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;reg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;day&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;latest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;reg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;etDate&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;          &lt;span class="c1"&gt;// newest trading day only&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;pv&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;vol&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;reg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;etDate&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;day&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;pv&lt;/span&gt;  &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;high&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;low&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;close&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;volume&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// typical price x volume&lt;/span&gt;
    &lt;span class="nx"&gt;vol&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;volume&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;vol&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;pv&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;vol&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pre-market and after-hours bars are excluded on purpose. They are thin, they print at odd prices, and most people mean "regular session" when they say VWAP.&lt;/p&gt;

&lt;h2&gt;
  
  
  The guards that took longer than the formula
&lt;/h2&gt;

&lt;p&gt;The formula is five lines. These were the parts that actually broke:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. During the session, show only today's value.&lt;/strong&gt; An early version merged the previous trading day's value when today's bars were not there yet (right after the open, or when the cache was stale). A VWAP that silently mixes two days is worse than a dash. During market hours we now accept only bars with today's ET date, and otherwise return null.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Treating &lt;code&gt;null&lt;/code&gt; from the source as authoritative wiped good data.&lt;/strong&gt; On weekends the vendor returns &lt;code&gt;vwap = null&lt;/code&gt; for every ticker. A change that said "if the source says null, show null" erased Friday's perfectly valid session VWAP. We reverted it. The rule is now: decide by the &lt;em&gt;session date&lt;/em&gt;, not by whether a field is null.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Holidays are not weekends.&lt;/strong&gt; On a weekday market holiday there are no new bars, but the "latest trading day" logic must still point at the previous session. We wired the exit check to a US market holiday calendar so a Monday holiday keeps showing Friday's VWAP.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Stale cache refresh without a stampede.&lt;/strong&gt; If the minute-bar cache is old, we refresh it in the background rather than making the user wait. The first version used "read lock, then set lock", which has a race: two requests could both refresh. It is now a single atomic &lt;code&gt;SET key NX EX 60&lt;/code&gt; per ticker, and if the lock is not acquired we simply do not call the vendor.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tests that mattered
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Empty bars (volume 0, null prices) are skipped, not treated as zero.&lt;/li&gt;
&lt;li&gt;A PRE-only or zero-volume series returns null, not 0.&lt;/li&gt;
&lt;li&gt;Two bars with known prices and volumes give an exactly checkable VWAP.&lt;/li&gt;
&lt;li&gt;A "closed" lookup time and a "last trade" time are separate inputs. One of our tests failed because it used the 20:30 ET query time as the trade time. The test was wrong, the product code was fine.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A cheap approximation with the real name on it is a bug, even if it looks right most days.&lt;/li&gt;
&lt;li&gt;When a field is missing, decide what "missing" means (before open, holiday, vendor gap) before you decide what to display.&lt;/li&gt;
&lt;li&gt;Reusing data you already cache is the cheapest way to avoid new vendor calls and new rate limits.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is from the data layer of &lt;a href="https://www.signumhq.com/app?from=devto_post1" rel="noopener noreferrer"&gt;SIGNUM HQ&lt;/a&gt;, a US-stock app I build solo (options flow, dark pool prints, earnings calendar).&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Disclosure: I used an AI assistant to help draft and edit this post. The incident, the code and the conclusions are from my own project.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>fintech</category>
      <category>typescript</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
