Skip to content

Commit 37c13e4

Browse files
committed
Agent improvements
1 parent 3dd40d2 commit 37c13e4

6 files changed

Lines changed: 25 additions & 9 deletions

File tree

brain/agent.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ def prompt(
3636
4. Propose the alpha and run the alpha simulation.
3737
3838
- Try applying different functions and changing parameter values.
39+
- For d parameter use one of the following values: 2, 5, 10, 20, 30, 50, 100, 120, 250
3940
- Do NOT nest functions unless necessary, create simple alphas that are easy to understand
4041
and explain using basic operations like +, -, *, /.
41-
- Use only one operator in the alpha expression.
4242
- Try combining multiple data fields to create a new alpha.
4343
- Apply vec_avg(x) or vec_sum(x) if data field is a type VECTOR.
44-
- You can apply - to the alpha expression to negate fitness.
4544
- Change alpha completely if you think it is not good enough.
45+
- Self-correlation must be less than 0.5
4646
4747
Working with equity in universe: {conf['universe']}, region: {conf['region']}
4848
and delay {conf['delay']}.
@@ -59,7 +59,7 @@ class CustomState(AgentState):
5959
tools=[
6060
submit_alpha,
6161
describe_operators,
62-
search_datafields,
62+
# search_datafields,
6363
get_random_datafields,
6464
get_random_idea,
6565
],

brain/alpha_class.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,4 @@ def from_stats(cls, stats: dict) -> "Alpha":
110110
@classmethod
111111
def from_row(cls, row: sqlite3.Row) -> "Alpha":
112112
"""Build an Alpha from a sqlite3.Row."""
113-
return cls(**{k: row[k] for k in cls.__dataclass_fields__.keys() if k in row.keys()})
113+
return cls(**{k: row[k] for k in cls.__dataclass_fields__ if k in row.keys()})

brain/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ def _request(self, method: str, endpoint: str, max_retries: int = 200, **kwargs)
591591
continue
592592

593593
if float(response.headers.get("Retry-After", 0)) != 0:
594-
time.sleep(float(response.headers["Retry-After"]))
594+
time.sleep(float(response.headers["Retry-After"]) * 2)
595595
max_retries -= 1
596596
else:
597597
return response

brain/search_algorithm.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ def update_alphas_dict(alphas_dict, alphas_categories, stats, temp_id):
114114
else:
115115
alphas_categories["failing"].append(alpha_id)
116116

117+
return alphas_dict[alpha_id]
118+
117119

118120
def main():
119121
"""Main function to run the agent."""
@@ -140,13 +142,17 @@ def main():
140142
while live_jobs:
141143
for job in as_completed(live_jobs):
142144
# Update alphas_dict with the results
143-
temp_id, _ = live_jobs.pop(job) # remove from “running” set
145+
temp_id, alpha_config = live_jobs.pop(job) # remove from “running” set
144146
stats = job.result()
145147
print(f"Stats: {stats}")
146-
update_alphas_dict(alphas_dict, alphas_categories, stats, temp_id)
148+
alpha = update_alphas_dict(alphas_dict, alphas_categories, stats, temp_id)
147149

148150
# Start a new alpha simulation
149-
response, alpha_config = create_alpha_simulation(alphas_dict, alphas_categories)
151+
if alpha is not None and alpha.alpha_id is not None and alpha.fitness < -0.5:
152+
alpha_config = {**alpha_config, "regular": f"-{alpha.regular}"}
153+
response = BrainAPI.start_simulation(alpha_config)
154+
else:
155+
response, alpha_config = create_alpha_simulation(alphas_dict, alphas_categories)
150156
# Generate a unique ID for the alpha
151157
temp_id = str(uuid.uuid4())
152158
alphas_categories["pending"].append(temp_id)

brain/tools/datafields.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
DELAY_0 = pd.read_csv(data_folder / "delay_0.csv", index_col=0)
1818
DELAY_1 = pd.read_csv(data_folder / "delay_1.csv", index_col=0)
1919

20+
INDEX = len(DELAY_0) + len(DELAY_1)
21+
2022

2123
def format_datafields(data: pd.DataFrame) -> str:
2224
"""Format the datafields DataFrame into a string."""
@@ -35,12 +37,19 @@ def search_datafields(datafield: str, config: RunnableConfig) -> str:
3537

3638
def get_random_datafields(config: RunnableConfig) -> str:
3739
"""Get a random datafields."""
40+
global INDEX, DELAY_0, DELAY_1
3841
conf = get_universe_config(config)
3942

43+
if INDEX + 20 > len(DELAY_0 if conf["delay"] == 0 else DELAY_1):
44+
DELAY_0 = DELAY_0.sample(frac=1).reset_index(drop=True)
45+
DELAY_1 = DELAY_1.sample(frac=1).reset_index(drop=True)
46+
INDEX = 0
47+
4048
if conf["delay"] == 0:
4149
data = DELAY_0
4250
else:
4351
data = DELAY_1
4452

45-
data = data.sample(20)
53+
data = data.iloc[INDEX : INDEX + 20]
54+
INDEX += 20
4655
return format_datafields(data)

brain/tools/ideas.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ def get_random_idea():
1515
```
1616
1717
Think of the key features of this alpha and how you can use them to create a new alpha.
18+
Create a new alpha using the same features but with different data fields.
1819
"""

0 commit comments

Comments
 (0)