Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass fees to Kelly #507

Merged
merged 8 commits into from
Oct 17, 2024
Merged

Pass fees to Kelly #507

merged 8 commits into from
Oct 17, 2024

Conversation

kongzii
Copy link
Contributor

@kongzii kongzii commented Oct 17, 2024

I executed the betting strategy benchmark with no fees vs. with fees, comparison is here: https://www.diffchecker.com/bOvQec3S/

TLDR: With fees included in Kelly, profits are lower (which they also are in the reality), but the best strategies remain the same.

@kongzii kongzii marked this pull request as ready for review October 17, 2024 08:28
answer.p_yes,
answer.confidence,
)
kelly_bet = get_kelly_bet_full(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open to opinions here 😄

A few lines above, outcome_token_pool = check_not_none(market.outcome_token_pool) is used, which means that get_kelly_bet_simplified was never going to be used.

Also get_kelly_bet_simplified doesn't accept fees which goes against this PR, but then if someones is going to create markets with huge fees, this other PR should solve that #488

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, no objections your honour!

Copy link
Contributor

@evangriffiths evangriffiths left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Base automatically changed from peter/rethink-fees to main October 17, 2024 11:24
Copy link

coderabbitai bot commented Oct 17, 2024

Walkthrough

The changes in this pull request focus on modifying the KellyBettingStrategy and MaxAccuracyWithKellyScaledBetsStrategy classes within the betting_strategy.py file to consistently use the get_kelly_bet_full function, which now requires a fees parameter. This adjustment streamlines the calculation of bet amounts and enhances fee handling across methods. Additionally, the get_kelly_bet_full function in kelly_criterion.py has been updated to remove the default value for the fees parameter. Corresponding updates have been made to the tests in test_kelly.py to ensure that actual market fees are utilized in assertions.

Changes

File Change Summary
prediction_market_agent_tooling/deploy/betting_strategy.py Updated calculate_trades methods in KellyBettingStrategy and MaxAccuracyWithKellyScaledBetsStrategy classes to consistently use get_kelly_bet_full with a new fees parameter. Modified calculate_price_impact_for_bet_amount and calculate_bet_amount_for_price_impact methods to utilize market.fees.
prediction_market_agent_tooling/tools/betting_strategies/kelly_criterion.py Modified get_kelly_bet_full to remove default value for fees, making it a required parameter.
tests_integration/markets/omen/test_kelly.py Updated assert_price_impact_converges to handle fees parameter correctly in test assertions for get_kelly_bet_full and calculate_price_impact_for_bet_amount.

Possibly related issues

Possibly related PRs

Suggested reviewers

  • evangriffiths

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@kongzii kongzii merged commit cc21ebf into main Oct 17, 2024
13 of 14 checks passed
@kongzii kongzii deleted the peter/kelly-fees branch October 17, 2024 12:50
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
tests_integration/markets/omen/test_kelly.py (1)

109-109: Great addition of fees to the price impact calculation!

This change is consistent with the previous one and ensures that fees are considered in price impact calculations. Using omen_agent_market.fees maintains consistency and provides realistic fee handling, contributing to more accurate price impact assessments in the tests.

For improved code consistency, consider extracting omen_agent_market.fees to a local variable at the beginning of the function. This would make the code more readable and easier to maintain if you need to use the fees in more places within the function.

Here's a suggested improvement:

def assert_price_impact_converges(
    omen_agent_market: OmenAgentMarket,
    max_bet_amount: float,
    p_yes: float,
    confidence: float,
    max_price_impact: float,
) -> None:
    market_fees = omen_agent_market.fees
    # ... rest of the function ...
    
    kelly_bet = get_kelly_bet_full(
        # ... other parameters ...
        fees=market_fees,
    )
    
    # ... rest of the function ...
    
    price_impact = kelly.calculate_price_impact_for_bet_amount(
        # ... other parameters ...
        fees=market_fees,
    )
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 5ed2712 and e20bed2.

📒 Files selected for processing (3)
  • prediction_market_agent_tooling/deploy/betting_strategy.py (3 hunks)
  • prediction_market_agent_tooling/tools/betting_strategies/kelly_criterion.py (1 hunks)
  • tests_integration/markets/omen/test_kelly.py (2 hunks)
🧰 Additional context used
🔇 Additional comments (6)
prediction_market_agent_tooling/tools/betting_strategies/kelly_criterion.py (1)

65-65: Approve the removal of the default value for the fees parameter.

This change improves the accuracy of the Kelly Criterion calculation by ensuring that fees are always explicitly provided. It aligns well with the PR objective of incorporating fees into the betting strategy benchmark.

To ensure this change is consistently applied, please run the following script to check for any remaining calls to get_kelly_bet_full that might need updating:

✅ Verification successful

Error in the previous verification script: rg does not recognize the file type python.

Please run the following corrected script to ensure all calls to get_kelly_bet_full include the fees argument:


All calls to get_kelly_bet_full include the required fees argument.

The verification confirms that every invocation of get_kelly_bet_full in the codebase now properly includes the fees parameter, ensuring consistency and correctness in the implementation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all calls to get_kelly_bet_full and verify they include a fees argument

# Search for function calls to get_kelly_bet_full
rg --type python -g '!*test*' 'get_kelly_bet_full\s*\(' -A 10

# Note: Manually review the output to ensure all calls include a fees argument

Length of output: 94


Script:

#!/bin/bash
# Description: Find all calls to get_kelly_bet_full and verify they include a fees argument

# Search for function calls to get_kelly_bet_full in Python files, excluding test files
rg --type py -g '!*test*' 'get_kelly_bet_full\s*\(' -A 10

# Note: Manually review the output to ensure all calls include a fees argument

Length of output: 3382

tests_integration/markets/omen/test_kelly.py (2)

94-94: Excellent addition of fees to the Kelly bet calculation!

This change aligns perfectly with the PR objective of incorporating fees into the Kelly criterion calculations. By using omen_agent_market.fees, you ensure that the test uses actual market fees, which will provide more realistic and accurate test results. This is a crucial improvement that will help validate the behavior of the betting strategy under real-world conditions.


Line range hint 1-150: Overall, excellent improvements to the Kelly criterion tests!

The changes in this file consistently incorporate fees into both the Kelly criterion calculations and price impact assessments. These modifications align perfectly with the PR objectives and significantly enhance the accuracy and realism of the tests.

Key improvements:

  1. Fees are now considered in get_kelly_bet_full calculations.
  2. Price impact calculations also account for market fees.

These changes will provide more reliable test results that better reflect real-world scenarios, which is crucial for validating the betting strategy's behavior under actual market conditions.

The only suggestion for improvement is a minor code consistency enhancement, which has been detailed in a previous comment.

Great work on improving the test suite!

prediction_market_agent_tooling/deploy/betting_strategy.py (3)

155-165: Consistent use of get_kelly_bet_full with fees parameter.

Great job updating the KellyBettingStrategy to consistently use get_kelly_bet_full with the fees parameter. This ensures that fees are accurately accounted for in the Kelly bet calculation, aligning the strategy with real-world scenarios where fees impact profitability.


224-224: Including market.fees in price impact calculation enhances accuracy.

By passing market.fees to calculate_price_impact_for_bet_amount, the price impact calculations now properly consider fees, improving the precision of the betting strategy and ensuring more realistic trade evaluations.


283-293: Updated MaxAccuracyWithKellyScaledBetsStrategy to account for fees in Kelly bet calculation.

Updating the calculate_trades method to use get_kelly_bet_full with fees=market.fees ensures that fees are considered in the bet sizing for this strategy as well. This change enhances the strategy's accuracy by reflecting the true cost of trades in markets with fees.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants