preloader
post-thumb

Last Update: May 8, 2025


BYauthor-thumberic


Keywords

Building a RAG System with Onyx for Better Trading Strategies

In the fast-paced world of trading, information is power—but only if you can access and synthesize it effectively. Over the years, I’ve collected an extensive library of trading materials: research reports, technical guides, strategy notes, economic models, and annotated charts. The challenge has always been how to organize this knowledge and use it dynamically. Onyx, a LLM Chat UI that can be used for building Retrieval-Augmented Generation (RAG) systems.

In this article, I’ll walk through how I used Onyx to turn a trading knowledge base into a responsive AI assistant that not only helps traders but also supports them in crafting better strategies.

What Is Onyx?

Onyx is an open-source Chat UI tool designed for building LLM-based systems that can incorporate external knowledge via retrieval. It supports:

  • Multi-stage RAG pipelines
  • Flexible embedding support
  • Data loaders and chunking for various formats
  • Built-in support for vector databases like FAISS, Qdrant, and Weaviate

Unlike complex frameworks that require weeks of setup, Onyx is minimalist and modular. You can start small and scale later.

Why Use RAG for Trading?

RAG combines the reasoning ability of large language models (LLMs) with precise retrieval from curated knowledge sources. This hybrid setup is ideal for trading, where:

  • Context is critical – Historical events, policy shifts, and macro conditions must be considered.
  • Domain expertise matters – Pre-trained models lack specialized knowledge in niche trading strategies.
  • Speed is essential – A RAG system can instantly answer questions like “What’s the impact of rising bond yields on tech stocks?” using your own materials.

How to Use Onyx

Hardware Requirements

Here are the minimum hardware requirements for running Onyx:

  • 4vCPUs
  • 16GB RAM
  • 50GB SSD
  • GPU (optional, but recommended for faster inference)

Installation

Using Docker is the easiest way to get started. Here’s a quick command to set up Onyx:

Installation:

bash
git clone https://github.com/onyx-dot-app/onyx.git
cd onyx/deployment/docker_compose
cp env.prod.template .env
# You may need to change the AUTH_TYPE in .env file to basic or other authentication method you like 
# if you don't want to use Google OAuth2.0 which requires a client_id and client_secret
# AUTH_TYPE=disabled
cp env.nginx.template .env.nginx
ln -s docker-compose.prod.yml docker-compose.yml

Usage:

bash
cd onyx/deployment/docker_compose
docker compose up
## if you are plan to use Onyx constantly, you can run `docker compose up -d`, so the server will run in the background

To start the App: http://localhost

Step-by-Step: Creating the RAG with Onyx

1. Preparing the Knowledge Base

If you prefer you could separate your documents into following categories:

  • Macroeconomic theory
  • Technical analysis
  • Historical trades
  • Research papers
  • Earnings playbooks
  • Risk models

They can be in PDF, DOCX, or Markdown format. Onyx’s data loaders made it easy to convert and chunk these documents into retrievable vectors.

To me, for the sake of simplicity, I kept everything in a single folder called trading-materials.

2. Choosing an Embedding Model

The default embbedding model in Onyx is NomicAI’s nomic-embed-text-v1, which is fast and effective for most use cases. However, you can also use other cloud-based models from Cohere, OpenAI, Google, and Voyage.

Provider
Model
Description
Cohere
embed-english-v3.0
Good performance for English-language tasks
Cohere
embed-english-light-v3.0
Lightweight, faster and more efficient for simpler tasks
OpenAI
text-embedding-3-large
Large model with best performance
OpenAI
text-embedding-3-small
Efficient model with good performance and lower cost
Google
text-embedding-005
A cost-effective embedding model
Google
textembedding-gecko@003
Gecko model, powerful and efficient
Voyage
voyage-large-2-instruct
High-performance model with instruction fine-tuning
Voyage
voyage-light-2-instruct
Lightweight model with balanced performance and efficiency

From the account icon in the top right corner, you can go to the Admin Panel and from the panel on the left select Configuration > Search Settings to configure the Search Settings.

To change the model, just clicke on Upate Search Settings and select the model you want to use and follow the instruction.

3. Creating a File Connector

In the Admin Panel, click on the Connectors > Add Connector, then choose File connector.

From there, you can drag and drop the trading-materials folder or whatever folder you want to use. This allows Onyx to automatically index new documents as they are added.

4. Setting Up Document Sets

In the Admin Panel > Document Management > Document Sets from the page click on New Document Set.

From there, you enter the name of the document set (Trading Materials) and the description (optional) and pick the trading materials file connector you just create.

5. Creating a Custom Assistants

In the Admin Panel > Custom Assistants > Assistants, from the page click on New Assistant.

From there, you enter the name of the assistant and the description, and turn on the Knowledge option pick the Trading Materials document set you just create.

For the Instrcutions, you might want to use something like:

markdown
You are an AI trading assistant designed to help users make informed trading decisions. Your primary tasks include analyzing market data, identifying trends, answering questions about financial instruments, providing risk assessments, and suggesting potential trading opportunities.

Always communicate clearly, concisely, and objectively. Avoid speculation and state when data is uncertain or incomplete. Use up-to-date financial reasoning, basic technical and fundamental analysis, and explain your suggestions in plain language.

When asked about specific assets, consider recent price movements, volume, relevant news, and broader market context. Tailor your answers to suit short-term traders or long-term investors based on user cues.

Do not provide financial advice. But also offer insights, highlight risks, and support decision-making by presenting pros and cons. Use markdown formatting for clarity, including bullet points, tables, and simple charts or examples when helpful.

6. Configuring Gen AI API

If you haven't done that already, you can go to the Admin Panel > Configuration > LLM and select the LLM Provider you want to use.

I configured Onyx to use GPT-4o as the reasoning engine.

If you haven't have an OpenAI account, you can sign up for one here. After signing up, you can create an API key by going to the API keys page.

Ask the Assistant

Once you have everything set up, you can start asking your assistant questions. If you haven't exited Admin Panel, click on th Exit Admin in the top left corner, then click on Assistants > Explore Assistants. You can find the assistant you just created and click on Start Chat to start asking questions.

Example Queries I Use

Once the system was live, I began using it for tasks like:

  • "How did I trade around rate hikes in 2018?"

    In 2018, trading strategies around rate hikes typically involved adjusting positions based on the anticipated impact of interest rate changes on various financial instruments. Traders often employed strategies such as:

    • Bull Put Spread: This strategy involves a long position in an out-of-the-money (OTM) put option and a short position in another OTM put option with a higher strike price. It is a net credit trade with a bullish outlook, profiting if the stock price rises

    *Bear Call Spread: This strategy consists of a long position in an OTM call option and a short position in another OTM call option with a lower strike price. It is a net credit trade with a bearish outlook, suitable for profiting from a decline in stock prices

    • Long Iron Condor: This is a combination of a bull put spread and a bear call spread, involving long and short positions in OTM put and call options. It is a net credit trade with a neutral outlook, aiming to profit from low volatility

    These strategies were used to manage risk and capitalize on expected market movements due to rate hikes. The choice of strategy depended on the trader's outlook on market direction and volatility.

  • "Help me develop a psar based strategy but it could also use other indicators for buy/ sell signals"

Developing a Trading Strategy Using the Parabolic SAR (PSAR)

To develop a trading strategy using the Parabolic SAR (PSAR) indicator, you can enhance it by incorporating additional indicators to generate more reliable buy and sell signals. Here's a structured approach:

Core Strategy: PSAR

PSAR Basics:
The Parabolic SAR is a trend-following indicator that provides potential reversal points. It is plotted as dots above or below the price chart.

  • When the dots are below the price, it indicates a bullish trend.
  • When they are above, it indicates a bearish trend.

Enhancing with Additional Indicators

Moving Averages
  • Simple Moving Average (SMA):
    Use a short-term SMA (e.g., 20-day) to confirm the trend direction.

    • A buy signal is stronger if the price is above the SMA.
    • A sell signal is stronger if the price is below the SMA.
  • Exponential Moving Average (EMA):
    Consider using a 50-day EMA for a smoother trend confirmation.

Momentum Indicators
  • MACD (Moving Average Convergence Divergence):
    Look for MACD line crossovers to confirm PSAR signals.

    • A bullish crossover (MACD line crossing above the signal line) can confirm a PSAR buy signal.
    • A bearish crossover can confirm a sell signal.
  • RSI (Relative Strength Index):
    Use RSI to identify overbought or oversold conditions.

    • An RSI below 30 can strengthen a PSAR buy signal.
    • An RSI above 70 can strengthen a sell signal.
Volume Indicators
  • On-Balance Volume (OBV):
    Use OBV to confirm the strength of a trend.
    • Rising OBV can support a PSAR buy signal.
    • Falling OBV can support a sell signal.

Strategy Implementation

Buy Signal
  • PSAR dots switch from above to below the price.
  • Price is above the 20-day SMA and 50-day EMA.
  • MACD line crosses above the signal line.
  • RSI is above 30, indicating the end of an oversold condition.
  • OBV is rising, indicating increasing buying pressure.
Sell Signal
  • PSAR dots switch from below to above the price.
  • Price is below the 20-day SMA and 50-day EMA.
  • MACD line crosses below the signal line.
  • RSI is below 70, indicating the end of an overbought condition.
  • OBV is falling, indicating increasing selling pressure.

Risk Management

  • Stop-Loss:
    Set a stop-loss slightly below the recent swing low for buy positions and above the recent swing high for sell positions.

  • Position Sizing:
    Use a fixed percentage of your capital for each trade to manage risk effectively.

Backtesting and Optimization

  • Backtest:
    Test the strategy on historical data to evaluate its performance. Adjust parameters like the period of moving averages and the sensitivity of the PSAR to optimize results.

  • Review and Adjust:
    Continuously review the strategy's performance and make necessary adjustments based on market conditions.

This strategy combines the trend-following nature of the PSAR with confirmation from moving averages, momentum, and volume indicators to enhance the reliability of trading signals.

What about the Cloud-based LLMs?

I also tried using OpenAI and Claude to answer the same question about develping the PSAR strategy. Here’s how they performed:

OpenAI

Claude

By comparing the responses, it's evident that both OpenAI and Claude provided solid, reasonable answers—likely due to being trained on similar materials. However, their responses tend to lack depth, concreteness, and specificity when faced with more detailed or domain-specific questions—something a custom knowledge base could address more effectively.

Final Thoughts

As shown above, even without a custom knowledge base, cloud-based LLM services like OpenAI and Claude can provide reasonable answers. However, the real strength of a Retrieval-Augmented Generation (RAG) system lies in its ability to incorporate your own knowledge and experience. By building a high-quality, domain-specific knowledge base—unique to you—you can dramatically enhance the usefulness and accuracy of your AI assistant.

Tools like Onyx, RagFlow, or LobeChat offer traders a powerful and flexible way to transform years of accumulated trading insights into an active, consultative resource. If you're a trader with a trove of notes, recordings, or charts, creating a RAG system could be one of the most impactful ways to integrate AI into your workflow.

Helping traders find edge is just one application that A RAG system could be used for. You could also use it to build a research assistant that could help you for study analysis, or even a engineering assistant that could help you write and debug code, generate documentation, or explore technical specifications across large sets of engineering data. Onyx is one of the many open source tools that could help you to build a RAG system that could be used for various applications. Here is an article discussing a list of these open source tools that you could use to build a RAG system.

If you'd like help setting up your own Onyx-based RAG system for trading or research, feel free to reach out.

Previous Article
post-thumb

May 08, 2025

Using AI as Your Personal, Cost-Free Mechanic

In this article, we explore how AI can help you diagnose car issues and save money on mechanic fees.

Next Article
post-thumb

May 07, 2025

Jumpstarting My Project UI with v0.dev: From CLI Tool to Web App

In this post, I share my experience using v0.dev to create a frontend for my CLI tool that calculates profit and loss for trading.

agico

We transform visions into reality. We specializes in crafting digital experiences that captivate, engage, and innovate. With a fusion of creativity and expertise, we bring your ideas to life, one pixel at a time. Let's build the future together.

Copyright ©  2025  TYO Lab