Skip to content

Commit

Permalink
trades are being recommended by chatgpt
Browse files Browse the repository at this point in the history
  • Loading branch information
alexnicita committed Aug 2, 2024
1 parent 3619e64 commit 84050dd
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 38 deletions.
27 changes: 25 additions & 2 deletions application/executor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import json
import pdb
import ast

from dotenv import load_dotenv
from langchain_core.messages import HumanMessage, SystemMessage
Expand Down Expand Up @@ -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
Expand Down
107 changes: 73 additions & 34 deletions application/prompts.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from typing import List


class Prompter:

def generate_simple_ai_trader(market_description: str, relevant_info: str) -> str:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.
"""
)
6 changes: 4 additions & 2 deletions application/trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from connectors.polymarket import Polymarket

import pdb
import json


class Trader:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 84050dd

Please sign in to comment.