- Solve real problems with our hands-on interface
- Progress from basic puts and calls to advanced strategies

Posted October 19, 2026 at 1:54 pm
The article “Analyzing Financial Trends: Kalman Filtering for Gold vs Bitcoin” was originally published on DataGeeek blog.

Source: Yahoo Finance
In their paper “A Synchronized Multi‑IMU Wearable System for Tracking of Joint‑Angles in Sports Motion Analysis” (arXiv:2607.26027v1), Samarasekera and colleagues set out to solve a very practical problem: how to reliably measure joint angles in dynamic sports movements using wearable IMUs. Their goal was to design a synchronized pipeline that could filter out noise, correct drift, and normalize ranges so that biomechanical signals could be trusted in real‑world conditions.
Academic paper at https://arxiv.org/html/2607.26027v1: “A Synchronized Multi-IMU Wearable System for Tracking of Joint-Angles in Sports Motion Analysis With Reference-Based Validation and Dynamic Task Characterization” – Thevindu Samarasekera, Praveen Rathnayaka, Sachintha Adhikari, Tharinda Navarathne, Mahela Pandukabhaya, Roshan Godaliyadda, Parakrama Ekanayake, Chanaka Senanayake, Vijitha Herath and Asela Ratnayake
Our goal is different but conceptually parallel: to apply the same pipeline logic to financial time‑series data. Instead of knee flexion angles, we analyze the comparative dynamics of Gold and Bitcoin. The challenge is similar — financial returns are noisy, prone to drift, and difficult to compare directly. By adapting their pipeline, we aim to extract latent trends, mitigate drift, normalize ranges, and highlight relative divergence between assets.
The pipeline consists of four sequential stages:
1. Indirect Kalman Filtering (IKF) – extracting latent trends from noisy log returns.
– State equation:

– Observation equation:

– IKF separates signal from noise, with and learned via maximum likelihood.
2. Drift Mitigation via High‑Pass Filtering – removing low‑frequency bias.
– High‑pass operator:

– This ensures long‑term drift does not dominate short‑term dynamics.
3. Range Normalization – mapping filtered values into a comparable scale.
– Normalization function:

– This allows Gold and Bitcoin to be compared on the same 0–100 scale.
4. Relative Notation (Directional Divergence) – highlighting when assets move in opposite directions.
– Divergence indicator:

– If true, shaded regions show divergence; if false, alignment.
To make this pipeline reproducible and transparent, we rely on a set of R packages. Each package plays a specific role in the architecture:
mutate, rename, inner_join, drop_na.tq_get (download asset prices), tq_transmute (compute log returns).SSModel (define state‑space model), fitSSM (MLE parameter estimation), KFS (Kalman smoothing).rollmean.rescale.geom_braid.geom_line, labs, theme_classic.library(tidyverse)
library(tidyquant)
library(KFAS)
library(ggbraid)
# --- Step 1: Log returns ---
gold <- tq_get("GC=F", from = "2024-01-01") %>%
tq_transmute(select = close,
mutate_fun = periodReturn,
period = "daily",
type = "log")
btc <- tq_get("BTC-USD", from = "2024-01-01") %>%
tq_transmute(select = close,
mutate_fun = periodReturn,
period = "daily",
type = "log")
df <- gold %>%
rename(ret_gold = daily.returns) %>%
inner_join(btc %>% rename(ret_btc = daily.returns), by="date") %>%
drop_na()
# --- Step 2: IKF (Kalman filter) ---
model_gold <- SSModel(df$ret_gold ~ SSMtrend(1, Q = list(NA)), H = NA)
model_btc <- SSModel(df$ret_btc ~ SSMtrend(1, Q = list(NA)), H = NA)
fit_gold <- fitSSM(model_gold, inits = c(log(var(df$ret_gold)), log(var(df$ret_gold))))
fit_btc <- fitSSM(model_btc, inits = c(log(var(df$ret_btc)), log(var(df$ret_btc))))
kf_gold <- KFS(fit_gold$model, smoothing = c("state"))
kf_btc <- KFS(fit_btc$model, smoothing = c("state"))
trend_gold <- as.numeric(kf_gold$alphahat)
trend_btc <- as.numeric(kf_btc$alphahat)
# --- Step 3: High-pass filter (remove low-frequency drift) ---
hp_gold <- trend_gold - zoo::rollmean(trend_gold, k=30, fill=NA, align="right")
hp_btc <- trend_btc - zoo::rollmean(trend_btc, k=30, fill=NA, align="right")
# --- Step 4: Range normalization ---
gold_norm <- scales::rescale(hp_gold, to=c(0,100))
btc_norm <- scales::rescale(hp_btc, to=c(0,100))
# --- Step 5: Relative notation (directional divergence) ---
df_norm <- df %>%
mutate(
gold_norm = gold_norm,
btc_norm = btc_norm,
sign_gold = sign(ret_gold),
sign_btc = sign(ret_btc),
divergence = sign_gold != sign_btc
)
# --- Plot ---
ggplot(df_norm, aes(x=date)) +
geom_line(aes(y=gold_norm, color="Gold"), linewidth=1.2) +
geom_line(aes(y=btc_norm, color="Bitcoin"), linewidth=1.2) +
geom_braid(aes(ymin=gold_norm, ymax=btc_norm, fill=divergence), alpha=0.3) +
scale_color_manual(values=c("Gold"="#FFD700", "Bitcoin"="#1E3A8A"),
name = "") +
scale_fill_manual(values=c("TRUE"="#FF4C4C", "FALSE"="#87CEFA"),
name = "Divergence") +
scale_y_continuous(limits=c(0,100)) +
labs(title="Gold vs Bitcoin: Kalman-Filtered High-Pass Trends",
subtitle="Directional divergence highlighted with shaded regions",
x="", y="Normalized High-Pass Kalman Trend") +
theme_classic(base_family = "Roboto Slab") +
theme(
legend.position="bottom",
legend.title=element_text(size=12, face="bold"),
legend.text=element_text(size=10),
plot.title=element_text(size=16, face="bold"),
plot.subtitle=element_text(size=12),
axis.title=element_text(size=12, face="bold"),
axis.text=element_text(size=10),
panel.grid.minor=element_blank()
)
Source: Yahoo Finance
By adapting the IKF pipeline from the sports biomechanics paper, we demonstrate how state‑space filtering, drift mitigation, and normalization can reveal comparative dynamics among financial assets. This modular approach is reproducible and extensible to other domains where latent trends and divergence matter.
Information posted on IBKR Campus that is provided by third-parties does NOT constitute a recommendation that you should contract for the services of that third party. Third-party participants who contribute to IBKR Campus are independent of Interactive Brokers and Interactive Brokers does not make any representations or warranties concerning the services offered, their past or future performance, or the accuracy of the information provided by the third party. Past performance is no guarantee of future results.
This material is from DataGeeek and is being posted with its permission. The views expressed in this material are solely those of the author and/or DataGeeek and Interactive Brokers is not endorsing or recommending any investment or trading discussed in the material. This material is not and should not be construed as an offer to buy or sell any security. It should not be construed as research or investment advice or a recommendation to buy, sell or hold any security or commodity. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.
The third-party code discussed within this article is not investment or trading advice, and is for proof-of-concept, educational, and illustrative purposes only. IBKR makes no representations or warranty regarding its accuracy or completeness. Users are solely responsible for conducting their own independent testing and due diligence before applying any code or concepts in a live or production environment
U.S. Spot Gold trading through IB LLC accounts is only available to legal residents of the United States that do not reside in Arizona, Montana, New Hampshire, and Rhode Island.
Trading Bitcoin involves significant risk. Bitcoin prices can be highly volatile and may fluctuate rapidly, potentially resulting in substantial losses. Because Bitcoin operates on a decentralized blockchain, network congestion or technical issues may occasionally delay transaction settlement. Regulatory frameworks for digital assets are still evolving and could impact availability, liquidity, or pricing. When trading through Interactive Brokers, execution and custody are facilitated by regulated partners such as Paxos or Zero Hash; however, these arrangements do not eliminate the possibility of operational or counterparty risk.
Investments in certain commodities (precious metals) may be subject to significant price volatility and often involve risks related to market fluctuations, liquidity constraints, geopolitical events, and changes in global economic conditions that could adversely affect their value.
Trading in digital assets, including cryptocurrencies, is especially risky and is only for individuals with a high risk tolerance and the financial ability to sustain losses. Eligibility to trade in digital asset products may vary based on jurisdiction.
Join The Conversation
For specific platform feedback and suggestions, please submit it directly to our team using these instructions.
If you have an account-specific question or concern, please reach out to Client Services.
We encourage you to look through our FAQs before posting. Your question may already be covered!