Rajandran R Creator of OpenAlgo Sketchmaker, RagZ. Building GenAI Applications. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Now the recent curiosity on building Trading AI Agents.

Leveraging Jupyter AI for Traders and Investors – Python Tutorial

2 min read

Jupyter AI for traders: talk to ChatGPT inside a Jupyter notebook

Jupyter AI is a tool for data scientists, data analysts, and traders/investors that improves Python programming productivity. It helps you write and run your Python code and strategies faster within a Jupyter notebook. With this tool, you now have the ability to interact through chat with leading Large Language Models (LLMs) such as AI21, Anthropic, Cohere, Hugging Face, OpenAI, and SageMaker, among others.

JupyterAI runs on most operating systems and integrates with various platforms like Google Colab and VSCode.

How to Use Jupyter AI for Traders and Investors

  1. Enhanced Analysis: Traders can use Jupyter AI to analyze complex financial data, generate predictive models, and even simulate market scenarios. The ability to quickly generate and test hypotheses can significantly improve decision-making.
  2. Automated Research: Investors can use Jupyter AI to automate parts of their research. By feeding prompts into the system, they can generate comprehensive market reports, summaries, and even predictive insights about market trends.
  3. Code Generation and Error Fixing: Jupyter AI’s ability to generate code snippets and fix errors is very useful. Traders can use this feature to develop custom algorithms, back-test trading strategies, or even automate parts of their trading systems.
  4. Interactive Learning: The platform can act as an educational tool, helping users understand complex financial concepts and algorithms through interactive examples and explanations.

Prerequisites

Jupyter AI is compatible with any system capable of running Python versions ranging from 3.8 to 3.11.

OpenAlgo: one API for 35+ Indian brokers

FREE AND OPEN SOURCE

OpenAlgo: one API for 35+ Indian brokers

Self-hosted algo trading platform. Send orders from Python, AmiBroker, TradingView, Excel or a no-code flow through one consistent API.

  • Unified REST and WebSocket API
  • Works with AmiBroker, TradingView, ChartInk and Excel
  • Sandbox mode to test before going live
Get OpenAlgo →by Marketcalls

Install VS Code with Python preferably less than 3.11 with Jupyter Extensions (remember at the time of writing the latest version is 3.12)

Installation

Install jupyterAI using the pip command

pip install jupyter_ai

Get the API Key from OpenAI

To integrate OpenAI with PandasAI, an API token is necessary. Follow the steps below to create your API_TOKEN with OpenAI.

  1. Go to https://platform.openai.com/apps and signup with your email address or connect your Google Account.
  2. Go to View API Keys on the left side of your Personal Account Settings
  3. Select Create New Secret key

The API access to openai is a paid service. You have to set up billing. Read the Pricing information before experimenting.

Load the JupyterAI extension

  1. Launch Visual Studio Code and Open a Jupyter Notebook
  2. Activate the Extension Using This Command in a Jupyter Cell:
%load_ext jupyter_ai

Set the Environmental Variable

import os
os.environ['OPENAI_API_KEY'] = 'sk-your-openai-api-key'

List of Supported AI LLM Models

The %%ai Magic Command

The %%ai cell magic allows the invocation of a chosen model with a prompt. This flexibility lets users tailor their experience, whether they require complex data analysis, natural language processing, or even image generation models.

%%ai chatgpt --format code
Write a Python Code to Fetch the data from yfinance and plot the line charts using plotly for the ticker HDFCBANK.NS

Get the Latex Math Formulas

%%ai chatgpt --format math
Write the Black Sholes Formula for Computing implied volatility

Create Automated Markdown with Brief Instructions

%%ai chatgpt --format markdown 
Explain Pandas Dataframe

List of Supported Format Types

Jupyter AI is programmed to anticipate markdown as the default output format from a model. Consequently, the results of an %%ai command are typically presented in markdown. However, this can be altered with the -f or --format option in your magic command, allowing for a variety of output formats. These formats include:

  • code: For output that is primarily code-centric.
  • image: This is exclusive to text-to-image models from Hugging Face Hub.
  • markdown: The default format, suitable for general text and formatting.
  • math: Ideal for mathematical expressions and equations.
  • html: Useful for outputs that should be in HTML format.
  • json: For outputs that are best represented in JSON format.
  • text: A simple, unformatted text output.

Pick the format that suits the output you need.

Jupyter AI for traders and investors is a practical way to bring AI models into their Python workflow. It is easy to set up, supports many models and output formats, and saves time when writing and testing analysis code.

Python Elite membership

MEMBERSHIP

Python Elite membership

15 Python, AI and algo trading programs in one plan, including QuantFlow and AI Bootcamp live mentorship.

  • Python from fundamentals to trading apps
  • Backtesting, broker APIs and OpenAlgo
  • Live QuantFlow and AI Bootcamp sessions
View Python Elite →by Marketcalls

Learn by watching: free videos every week

Market Profile, order flow, Python, AI and OpenAlgo tutorials on YouTube.

Rajandran R Creator of OpenAlgo Sketchmaker, RagZ. Building GenAI Applications. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Now the recent curiosity on building Trading AI Agents.

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More