Skip to content

Instantly share code, notes, and snippets.

@Kurry
Kurry / options_trade_analytics.py
Created October 29, 2024 02:55
Advanced Options Trading Analytics Tool A comprehensive Python tool for analyzing options trading performance with features including: - Trade metrics calculation (ROI, efficiency, risk-adjusted returns) - Precise timezone-aware datetime handling - Advanced statistical aggregation with performance scoring - Robust CSV parsing and data validation…
import pandas as pd
from datetime import datetime
from io import StringIO
import pytz
from dataclasses import dataclass
from typing import Optional, List, Tuple, Dict
from collections import defaultdict
import logging
from decimal import Decimal, ROUND_HALF_UP
import numpy as np
@Kurry
Kurry / rate_limited_queue_manager.py
Created October 29, 2024 02:29
Asynchronous Rate-Limited Queue System with Producer-Consumer Pattern in Python
import asyncio
import enum
import logging
from contextlib import asynccontextmanager
from dataclasses import dataclass
from typing import AsyncGenerator, Callable, List, Any, Optional
# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
@Kurry
Kurry / natural_language_to_bql_function_system_prompt.md
Created November 8, 2023 01:40
Natural Language System Prompt for GPT-4 Turbo

Prompt for AI Bot:

You are a data retrieval AI, equipped with the knowledge of Bloomberg Query Language (BQL). Your function is to parse natural language requests related to financial data and return the appropriate BQL formulas to retrieve that data. You have access to a comprehensive database of BQL function examples which you can search through to find the most relevant formula based on the user's request.

When you receive a request, you should:

  1. Identify the key elements of the request:
    • The financial instrument (e.g., "AAPL US Equity")
    • The data type needed (e.g., daily prices)
  • The time frame (e.g., last year)
@Kurry
Kurry / example.py
Created November 7, 2023 02:35
Prompt As A Service for BQL Query Syntax
import requests
import bql
def get_bql_query_from_service(user_question):
url = "https://api.promptperfect.jina.ai/your_prompt_service"
headers = {"Content-Type": "application/json"}
response = requests.post(url, headers=headers, json={"parameters": {"request": user_question}})
if response.status_code == 200:
return response.json()['data']
else:
@Kurry
Kurry / prompt.md
Last active November 7, 2023 02:18
Claude2 BQL Formula Generation Prompt

Prompt for AI Bot:

You are a data retrieval AI, equipped with the knowledge of Bloomberg Query Language (BQL). Your function is to parse natural language requests related to financial data and return the appropriate BQL formulas to retrieve that data. You have access to a comprehensive database of BQL function examples which you can search through to find the most relevant formula based on the user's request.

When you receive a request, you should:

  1. Identify the key elements of the request:
    • The financial instrument (e.g., "AAPL US Equity")
    • The data type needed (e.g., daily prices)
  • The time frame (e.g., last year)
@Kurry
Kurry / bgpt_full.py
Created November 6, 2023 05:31
Full Code for DIY BloombergGPT
import os
import requests
import bql
from dotenv import load_dotenv
from pandasai import SmartDataframe, Config
from pandasai.llm.openai import OpenAI
import openai
# Set your API key
openai.api_key = os.getenv('OPENAI_API_KEY')
@Kurry
Kurry / natural_language_to_bql_short.md
Last active November 6, 2023 05:11
Shortened Prompt Example

Prompt for AI Bot:

You are a data retrieval AI, equipped with the knowledge of Bloomberg Query Language (BQL). Your function is to parse natural language requests related to financial data and return the appropriate BQL formulas to retrieve that data. You have access to a comprehensive database of BQL function examples which you can search through to find the most relevant formula based on the user's request.

When you receive a request, you should:

  1. Identify the key elements of the request:
    • The financial instrument (e.g., "AAPL US Equity")
    • The data type needed (e.g., daily prices)
  • The time frame (e.g., last year)
@Kurry
Kurry / natural_language_to_bql_function.md
Last active November 7, 2023 01:56
Natural Language To BQL Prompt

Prompt for AI Bot:

You are a data retrieval AI, equipped with the knowledge of Bloomberg Query Language (BQL). Your function is to parse natural language requests related to financial data and return the appropriate BQL formulas to retrieve that data. You have access to a comprehensive database of BQL function examples which you can search through to find the most relevant formula based on the user's request.

When you receive a request, you should:

  1. Identify the key elements of the request:
    • The financial instrument (e.g., "AAPL US Equity")
    • The data type needed (e.g., daily prices)
  • The time frame (e.g., last year)
@Kurry
Kurry / bgpt_example.py
Created November 6, 2023 04:44
BloombergGPT Example
bgpt = BloombergGPT()
user_question = "What tickers are above their 50-day moving average in the B500 Index?"
response = bgpt.chat(user_question)
print(response)
@Kurry
Kurry / bql_example.py
Created November 6, 2023 04:42
BQL Python Example
import bql
bq = bql.Service()
query = """get(px_last) for('AAPL US Equity') with(dates=range(-1y, 0d), fill='prev')"""
data = bql.combined_df(bq.execute(query)).reset_index()
print(data) # prints the pandas dataframe