> ## Documentation Index
> Fetch the complete documentation index at: https://fruitstand.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Build a Stock Dashboard With Streamlit in Snowflake

> Build a stock price dashboard with Streamlit in Snowflake: full tested app code, deployment SQL, the runtime that bills least, and a query gotcha to avoid.

*By [Fruit Stand Team](https://fruitstand.dev/about.md) · November 20, 2026 · Guides*

To build a stock price dashboard in Streamlit in Snowflake, write one
`streamlit_app.py` that queries daily adjusted prices with
`st.connection("snowflake")`, upload it to a stage, and run `CREATE
STREAMLIT`. The app below is under 100 lines, needs no extra packages, and
charts growth of \$10,000, prices and drawdowns for any US stock or ETF.

Below are the full code, the SQL to deploy it, how to share it, and what it
costs to keep running, which depends on a runtime setting most tutorials
skip.

> [!NOTE]
>
> The app reads `security_vw` and `security_price_history_vw` from Fruit
> Stand's [Historical Stock Prices
> listing](https://app.snowflake.com/marketplace/listing/GZTYZTG3LNFA), which
> we publish. We deployed it on the container runtime on November 20, 2026,
> with prices through November 19. It works with any
> table of tickers, dates and adjusted closes.

## What the dashboard does

![The stock price dashboard showing growth of \$10,000 in SPY, QQQ and KO over five years, with a table of returns, volatility and maximum drawdown](https://mintcdn.com/fruit-stand/gbsJJzawTsD4yEzm/images/blog/streamlit-stock-price-dashboard.jpg?fit=max\&auto=format\&n=gbsJJzawTsD4yEzm\&q=85\&s=513b9586cf48f47d5fbcbe2cd39820ac)

* **Pick up to 10 tickers** from every active US stock and ETF in the
  listing, 23,332 of them, searchable by ticker or name.
* **Choose a date range**, five years by default.
* **Switch the chart** between growth of \$10,000, adjusted close and
  drawdown from the running peak.
* **Read a summary table** with the last close, total and annualized
  return, annualized volatility and maximum drawdown for each ticker.

Every number uses `adjusted_close`, so returns include dividends and splits
don't show up as crashes. For the five years to November 19, 2026, Coca-Cola
(KO) returned 100.5% with dividends, more than SPY's 63.7%, with a maximum
drawdown of 17.3% against SPY's 24.5%.

## The app code

Save this as `streamlit_app.py`. Change `SOURCE` to the database name you
chose when you got the listing:

```python theme={null}
from datetime import date, timedelta

import pandas as pd
import streamlit as st

# The database name you chose when you got the listing, plus its EXT schema.
SOURCE = "STOCK_PRICES.EXT"

st.set_page_config(page_title="Stock price dashboard", layout="wide")
conn = st.connection("snowflake")


@st.cache_data(ttl="12h")
def load_tickers():
    df = conn.query(f"""
        select code, name
        from {SOURCE}.security_vw
        where exchange_code = 'US'
          and not is_inactive
          and type in ('Common Stock', 'ETF')
        order by code
    """, ttl="12h")
    return dict(zip(df["CODE"], df["NAME"]))


def load_prices(tickers, start, end):
    return conn.query(f"""
        select code, date, close, adjusted_close,
               10000 * adjusted_close
                   / first_value(adjusted_close) over (partition by code order by date) as value_of_10k,
               adjusted_close
                   / max(adjusted_close) over (partition by code order by date) - 1 as drawdown
        from {SOURCE}.security_price_history_vw
        where exchange_code = 'US'
          and array_contains(code::variant, split(?, ','))
          and date between ? and ?
        order by code, date
    """, params=[",".join(tickers), start, end], ttl="1h")


names = load_tickers()

st.sidebar.header("Settings")
tickers = st.sidebar.multiselect(
    "Tickers", options=list(names), default=["SPY", "QQQ", "KO"],
    format_func=lambda c: f"{c} · {names[c]}", max_selections=10,
)
dates = st.sidebar.date_input(
    "Date range", value=(date.today() - timedelta(days=5 * 365), date.today()),
    min_value=date(1990, 1, 1), max_value=date.today(),
)
view = st.sidebar.radio("Chart", ["Growth of $10,000", "Adjusted close", "Drawdown"])

st.title("Stock price dashboard")
if not tickers or len(dates) != 2:
    st.info("Pick at least one ticker and a start and end date in the sidebar.")
    st.stop()

df = load_prices(tickers, *dates)
if df.empty:
    st.warning("No prices for those tickers in that date range.")
    st.stop()

df["DATE"] = pd.to_datetime(df["DATE"])
column = {"Growth of $10,000": "VALUE_OF_10K",
          "Adjusted close": "ADJUSTED_CLOSE",
          "Drawdown": "DRAWDOWN"}[view]
chart = df.pivot(index="DATE", columns="CODE", values=column)
st.line_chart(chart, y_label=view)

daily = df.pivot(index="DATE", columns="CODE", values="ADJUSTED_CLOSE").pct_change()
summary = df.groupby("CODE").agg(
    first_date=("DATE", "min"), last_date=("DATE", "max"),
    last_close=("CLOSE", "last"), first_adj=("ADJUSTED_CLOSE", "first"),
    last_adj=("ADJUSTED_CLOSE", "last"), max_drawdown=("DRAWDOWN", "min"),
)
years = (summary["last_date"] - summary["first_date"]).dt.days / 365.25
summary["total_return"] = summary["last_adj"] / summary["first_adj"] - 1
summary["annualized_return"] = (1 + summary["total_return"]) ** (1 / years) - 1
summary["annualized_volatility"] = daily.std() * 252 ** 0.5

st.dataframe(
    summary[["last_date", "last_close", "total_return", "annualized_return",
             "annualized_volatility", "max_drawdown"]],
    column_config={
        "last_date": st.column_config.DateColumn("Last date"),
        "last_close": st.column_config.NumberColumn("Last close", format="$%.2f"),
        "total_return": st.column_config.NumberColumn("Total return", format="percent"),
        "annualized_return": st.column_config.NumberColumn("Annualized", format="percent"),
        "annualized_volatility": st.column_config.NumberColumn("Volatility", format="percent"),
        "max_drawdown": st.column_config.NumberColumn("Max drawdown", format="percent"),
    },
)
st.caption("Returns use adjusted close, so they include dividends. "
           "Data: Fruit Stand Historical Stock Prices on the Snowflake Marketplace.")
```

## How the code works

* **Snowflake does the filtering.** The price query asks for only the
  selected tickers and dates, and computes growth of \$10,000 and drawdown
  with window functions. Snowflake's own [stock dashboard
  quickstart](https://www.snowflake.com/en/developers/guides/getting-started-with-snowpark-for-python-streamlit/)
  instead loads seven tickers' whole history into pandas and filters there,
  which doesn't scale to thousands of tickers.
* **Parameters use `?` and a list.** `conn.query` binds parameters
  server-side, so named placeholders like `%(start)s` with a dictionary
  fail with "Binding parameters must be a list". An `in` list doesn't bind
  either; joining the tickers into one string and using `split()` with
  `array_contains` does, and keeps the query safe from injection.
* **Results are cached.** `ttl="1h"` on the price query and `"12h"` on the
  ticker list mean a repeat selection doesn't hit the warehouse. On our
  X-Small warehouse, a three-ticker, five-year query took 3 to 4 seconds
  uncached.
* **Prices are adjusted.** Chart a raw close and every stock split looks
  like a crash. `adjusted_close` fixes that and adds back dividends; see
  [Adjusted Close vs. Close](https://fruitstand.dev/blog/adjusted-close-vs-close.md).
* **No extra packages.** The app uses only Streamlit's built-in charts and
  pandas, which ship with the runtime, so there's no `requirements.txt` and
  no external access integration to set up.

## Deploy it with SQL

You can paste the code into a new app in Snowsight (**Projects »
Streamlit » + Streamlit App**), or deploy it with SQL. Upload the file with
`PUT` from a client such as the Snowflake CLI or SnowSQL, using your own
file path:

```sql theme={null}
create database if not exists dashboards;
create schema if not exists dashboards.apps;
create stage if not exists dashboards.apps.app_stage;

put file:///path/to/streamlit_app.py @dashboards.apps.app_stage/stock_dashboard
    overwrite = true auto_compress = false;

create or replace streamlit dashboards.apps.stock_dashboard
  from '@dashboards.apps.app_stage/stock_dashboard'
  main_file = 'streamlit_app.py'
  runtime_name = 'SYSTEM$ST_CONTAINER_RUNTIME_PY3_11'
  compute_pool = system_compute_pool_cpu
  query_warehouse = compute_wh
  title = 'Stock price dashboard';

alter streamlit dashboards.apps.stock_dashboard add live version from last;
```

The last line matters: an app isn't live after `CREATE STREAMLIT` until
you add a live version or its owner opens it in Snowsight. `CREATE
STREAMLIT` copies the files once, so after you change the code, `PUT` it
again and re-run the last two statements.

To let colleagues open it, grant a role usage on the app (the role also
needs usage on the `dashboards` database and `apps` schema):

```sql theme={null}
grant usage on streamlit dashboards.apps.stock_dashboard to role analyst;
```

## Container or warehouse runtime: what it costs

Streamlit in Snowflake has two runtimes, and they bill in different ways.
In accounts with Snowflake's 2026\_06 behavior change bundle enabled,
which includes ours, a new app uses the container runtime unless you name
another, so it's worth knowing what that means.

| | Container runtime | Warehouse runtime |
| - | - | - |
| Runs on | A node of a Snowpark Container Services compute pool | A virtual warehouse, the "code warehouse" |
| Instances | One server shared by every viewer | A new server for each viewer |
| Stays running | Until 3 days after the last viewer leaves | About 15 minutes after the last activity in the app |
| Caching | Shared across viewers | Per viewer session |
| Packages | PyPI, with an external access integration | Snowflake's Anaconda channel |
| Streamlit version | 1.50 or later | 1.22 or later, from a limited list |

On the default `SYSTEM_COMPUTE_POOL_CPU`, a node is a `CPU_X64_S`, which
billed about 0.12 credits an hour in our account, and up to three apps
share one. An app opened once and then left keeps its node running for
three days: about 8.6 credits, shared with any other apps on the node.
Its queries run separately on the query warehouse.

On the warehouse runtime, an X-Small warehouse costs 1 credit an hour
while anyone has the app open, plus about 15 minutes after. A 10-minute
visit costs about 0.4 credits.

So for a dashboard one person opens a few times a week, the warehouse
runtime is cheaper. For one a team opens every day, the container runtime
is cheaper and faster, because every viewer shares one running server and
its cache. To use the warehouse runtime, leave out `runtime_name` and
`compute_pool` in an account without the bundle, or set `runtime_name =
'SYSTEM$WAREHOUSE_RUNTIME'`. We tested the app on the container runtime;
on the warehouse runtime, pin a recent Streamlit in an `environment.yml`
(1.52.2 was the newest in Snowflake's channel in November 2026), because
`format="percent"` and `y_label` need a newer version than the oldest it
offers. Snowflake's [cost
documentation](https://docs.snowflake.com/en/developer-guide/streamlit/object-management/billing)
has the details.

## Things to know

* **The listing's database name is yours.** Snowflake asks for a database
  name when you get a listing; `SOURCE` must match it. The views are in its
  `EXT` schema.
* **The app runs with its owner's rights.** Viewers see what the owner's
  role can query, so they don't need their own access to the listing.
* **Annualized return over a short range is misleading.** The table
  annualizes whatever range you pick; for under a year, read the total
  return instead.
* **Prices are end of day.** The listing updates once a day, so the
  dashboard isn't a live ticker. The last date is in the table.
* **Only active tickers are listed.** The ticker picker filters out
  inactive symbols; remove `and not is_inactive` to include them.

For the SQL behind the return and drawdown figures, see [How to Calculate
Stock Returns From Daily Prices in SQL](https://fruitstand.dev/blog/calculate-stock-returns-sql.md)
and [How to Calculate Rolling Returns and Max Drawdown in
SQL](https://fruitstand.dev/blog/rolling-returns-max-drawdown-sql.md).

## F.A.Q.

> [accordion] Do I need to install any packages?
>
> No. Streamlit, pandas and the Snowflake connector come with both runtimes, and the app uses Streamlit's built-in `st.line_chart`. You need a `requirements.txt` (container) or `environment.yml` (warehouse) only for extra libraries such as Plotly.

> [accordion] Why does my query fail with 'Binding parameters must be a list'?
>
> `st.connection("snowflake").query` binds with `?` placeholders and a list of values. Replace `%(name)s` placeholders with `?` and pass `params=[...]` in the same order.

> [accordion] How do I update the app after changing the code?
>
> Upload the file again with `PUT`, then run `CREATE OR REPLACE STREAMLIT` and `ALTER STREAMLIT ... ADD LIVE VERSION FROM LAST`. In Snowsight, edit the code in the app's editor and click Run.

> [accordion] Which runtime is cheaper?
>
> For occasional use, the warehouse runtime, which stops about 15 minutes after the last activity. For daily use by several people, the container runtime, which keeps one shared server running for up to 3 days after the last viewer.

> [accordion] Can I show intraday or real-time prices?
>
> Not from this listing, which has daily open, high, low, close, adjusted close and volume. Real-time quotes need an external feed and an external access integration.

To build this dashboard on every US stock and ETF, start a free 30-day
trial of the [Historical Stock Prices listing on the Snowflake
Marketplace](https://app.snowflake.com/marketplace/listing/GZTYZTG3LNFA).
The schema is in the [dataset docs](https://fruitstand.dev/datasets/historical-stock-prices.md).
Questions? Reach out at [contact@fruitstand.dev](mailto:contact@fruitstand.dev).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.