From 84050dd5e626a3f45438280f9aa46aecaf20257e Mon Sep 17 00:00:00 2001 From: alexnicita Date: Fri, 2 Aug 2024 18:31:16 -0400 Subject: [PATCH] trades are being recommended by chatgpt --- application/executor.py | 27 +++++++++- application/prompts.py | 107 +++++++++++++++++++++++++++------------- application/trade.py | 6 ++- 3 files changed, 102 insertions(+), 38 deletions(-) diff --git a/application/executor.py b/application/executor.py index 1ad4e54..3fcb702 100644 --- a/application/executor.py +++ b/application/executor.py @@ -1,6 +1,7 @@ import os import json import pdb +import ast from dotenv import load_dotenv from langchain_core.messages import HumanMessage, SystemMessage @@ -86,8 +87,30 @@ def filter_markets(self, markets): def filter_orderbooks(self): pass - def source_best_trade(self, market): - pass + def source_best_trade(self, market_object): + market_document = market_object[0].dict() + market = market_document["metadata"] + outcome_prices = ast.literal_eval(market["outcome_prices"]) + outcomes = ast.literal_eval(market["outcomes"]) + question = market["question"] + description = market_document["page_content"] + + prompt = self.prompter.superforecaster(question, description, outcomes) + print() + print("... prompting ... ", prompt) + print() + result = self.llm.invoke(prompt) + content = result.content + print("result: ", content) + print() + prompt = self.prompter.one_best_trade(content, outcomes, outcome_prices) + print("... prompting ... ", prompt) + print() + result = self.llm.invoke(prompt) + content = result.content + print("result: ", content) + print() + return content def format_trade_prompt_for_execution(self): pass diff --git a/application/prompts.py b/application/prompts.py index d3da47b..b174125 100644 --- a/application/prompts.py +++ b/application/prompts.py @@ -1,3 +1,6 @@ +from typing import List + + class Prompter: def generate_simple_ai_trader(market_description: str, relevant_info: str) -> str: @@ -29,40 +32,6 @@ def sentiment_analyzer(question: str, outcome: str) -> float: """ - def superforecaster(event_title: str, market_question: str, outcome: str) -> str: - return f""" - You are a Superforecaster tasked with correctly predicting the likelihood of events. - Use the following systematic process to develop an accurate prediction for the following - {event_title} and {market_question} combination. - - Here are the key steps to use in your analysis: - - 1. Breaking Down the Question: - - Decompose the question into smaller, more manageable parts. - - Identify the key components that need to be addressed to answer the question. - 2. Gathering Information: - - Seek out diverse sources of information. - - Look for both quantitative data and qualitative insights. - - Stay updated on relevant news and expert analyses. - 3. Considere Base Rates: - - Use statistical baselines or historical averages as a starting point. - - Compare the current situation to similar past events to establish a benchmark probability. - 4. Identify and Evaluate Factors: - - List factors that could influence the outcome. - - Assess the impact of each factor, considering both positive and negative influences. - - Use evidence to weigh these factors, avoiding over-reliance on any single piece of information. - 5. Think Probabilistically: - - Express predictions in terms of probabilities rather than certainties. - - Assign likelihoods to different outcomes and avoid binary thinking. - - Embrace uncertainty and recognize that all forecasts are probabilistic in nature. - - Given these steps produce a statement on the probability of {outcome} occuring. - - Give your response in the following format: - - I believe {market_question} has a likelihood {float} for outcome of {outcome}. - """ - def prompts_polymarket( data1: str, data2: str, market_question: str, outcome: str ) -> str: @@ -139,3 +108,73 @@ def filter_markets(self) -> str: """ ) + + def superforecaster(self, question: str, description: str, outcome: str) -> str: + return f""" + You are a Superforecaster tasked with correctly predicting the likelihood of events. + Use the following systematic process to develop an accurate prediction for the following + question=`{question}` and description=`{description}` combination. + + Here are the key steps to use in your analysis: + + 1. Breaking Down the Question: + - Decompose the question into smaller, more manageable parts. + - Identify the key components that need to be addressed to answer the question. + 2. Gathering Information: + - Seek out diverse sources of information. + - Look for both quantitative data and qualitative insights. + - Stay updated on relevant news and expert analyses. + 3. Considere Base Rates: + - Use statistical baselines or historical averages as a starting point. + - Compare the current situation to similar past events to establish a benchmark probability. + 4. Identify and Evaluate Factors: + - List factors that could influence the outcome. + - Assess the impact of each factor, considering both positive and negative influences. + - Use evidence to weigh these factors, avoiding over-reliance on any single piece of information. + 5. Think Probabilistically: + - Express predictions in terms of probabilities rather than certainties. + - Assign likelihoods to different outcomes and avoid binary thinking. + - Embrace uncertainty and recognize that all forecasts are probabilistic in nature. + + Given these steps produce a statement on the probability of outcome=`{outcome}` occuring. + + Give your response in the following format: + + I believe {question} has a likelihood `{float}` for outcome of `{str}`. + """ + + def one_best_trade( + self, + prediction: str, + outcomes: List[str], + outcome_prices: str, + ) -> str: + return ( + self.polymarket_analyst_api() + + f""" + + Imagine yourself as the top trader on Polymarket, dominating the world of information markets with your keen insights and strategic acumen. You have an extraordinary ability to analyze and interpret data from diverse sources, turning complex information into profitable trading opportunities. + You excel in predicting the outcomes of global events, from political elections to economic developments, using a combination of data analysis and intuition. Your deep understanding of probability and statistics allows you to assess market sentiment and make informed decisions quickly. + Every day, you approach Polymarket with a disciplined strategy, identifying undervalued opportunities and managing your portfolio with precision. You are adept at evaluating the credibility of information and filtering out noise, ensuring that your trades are based on reliable data. + Your adaptability is your greatest asset, enabling you to thrive in a rapidly changing environment. You leverage cutting-edge technology and tools to gain an edge over other traders, constantly seeking innovative ways to enhance your strategies. + In your journey on Polymarket, you are committed to continuous learning, staying informed about the latest trends and developments in various sectors. Your emotional intelligence empowers you to remain composed under pressure, making rational decisions even when the stakes are high. + Visualize yourself consistently achieving outstanding returns, earning recognition as the top trader on Polymarket. You inspire others with your success, setting new standards of excellence in the world of information markets. + + """ + + f""" + + You made the following prediction for a market: {prediction} + + The current outcomes ${outcomes} prices are: ${outcome_prices} + + Given your prediction, respond with a genius trade in the format: + ` + price: price on the orderbook + size: percentage of total funds + side: BUY or SELL + ` + + Your trade should approximate price using the likelihood in your prediction. + + """ + ) diff --git a/application/trade.py b/application/trade.py index 959ea17..c528d0c 100644 --- a/application/trade.py +++ b/application/trade.py @@ -3,7 +3,6 @@ from connectors.polymarket import Polymarket import pdb -import json class Trader: @@ -35,10 +34,13 @@ def one_best_trade(self): filtered_markets = self.agent.filter_markets(markets) print(f"4. FILTERED {len(filtered_markets)} MARKETS") + # TODO: use even more data to build even better models! + # orderbooks = [self.polymarket.get_orderbooks(m) for m in markets] # orderbooks = self.agent.filter_orderbooks() - # best_trade = self.agent.source_best_trade(filtered_markets[0]) + best_trade = self.agent.source_best_trade(filtered_markets[0]) + print(f"5. CALCULATED TRADE {best_trade}") # formatted_best_trade = self.agent.format_trade_prompt_for_execution(best_trade) # return self.polymarket.execute_order(**formatted_best_trade)