Skip to content

Commit

Permalink
Pricing multi from a selections file
Browse files Browse the repository at this point in the history
  • Loading branch information
ekoutanov committed Jan 2, 2024
1 parent 187dc12 commit 923aa1b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ Cargo.lock
/.idea
/coverage
lcov.info

selections.json
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ tracing-subscriber = "0.3.17"
bytes = "1.5.0"
linregress = "0.5.3"
ordinalizer = "0.1.0"
regex = "1.10.2"
strum = "0.25.0"
strum_macros = "0.25.3"
serde = { version = "1.0.189", features = ["derive"] }
Expand Down
1 change: 1 addition & 0 deletions brumby-soccer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ anyhow = { workspace = true }
clap = { workspace = true }
ordinalizer = { workspace = true }
racing_scraper = { workspace = true }
regex = { workspace = true }
rustc-hash = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
Expand Down
52 changes: 37 additions & 15 deletions brumby-soccer/src/bin/soc_prices.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use std::collections::HashMap;
use std::env;
use std::collections::HashMap;
use std::error::Error;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::PathBuf;

use anyhow::bail;
use anyhow::{bail, Context};
use clap::Parser;
use regex::Regex;
use rustc_hash::FxHashMap;
use stanza::renderer::console::Console;
use stanza::renderer::Renderer;
Expand All @@ -16,14 +19,14 @@ use brumby::hash_lookup::HashLookup;
use brumby::market::{Market, OverroundMethod, PriceBounds};
use brumby::tables;
use brumby::timed::Timed;
use brumby_soccer::data::{download_by_id, ContestSummary, SoccerFeedId};
use brumby_soccer::domain::{Offer, OfferType, Outcome, Over, Period, Player, Side};
use brumby_soccer::{fit, model, print};
use brumby_soccer::data::{ContestSummary, download_by_id, SoccerFeedId};
use brumby_soccer::domain::{Offer, OfferType, Outcome};
use brumby_soccer::fit::{ErrorType, FittingErrors};
use brumby_soccer::model::{Model, score_fitter, Stub};
use brumby_soccer::model::player_assist_fitter::PlayerAssistFitter;
use brumby_soccer::model::player_goal_fitter::PlayerGoalFitter;
use brumby_soccer::model::score_fitter::ScoreFitter;
use brumby_soccer::model::{score_fitter, Model, Stub};
use brumby_soccer::{fit, model, print};

const OVERROUND_METHOD: OverroundMethod = OverroundMethod::OddsRatio;
const SINGLE_PRICE_BOUNDS: PriceBounds = 1.01..=301.0;
Expand All @@ -48,6 +51,9 @@ struct Args {
/// print player assists markets
#[clap(long = "player-assists")]
player_assists: bool,

/// JSON file containing the selections to price
selections: Option<String>,
}
impl Args {
fn validate(&self) -> anyhow::Result<()> {
Expand All @@ -60,6 +66,21 @@ impl Args {
}
}

fn load_selections(filename: &str) -> anyhow::Result<Vec<(OfferType, Outcome)>> {
let file = File::open(filename).context(format!("opening file '{filename}'"))?;
let reader = BufReader::new(file);
let mut contents = String::new();
let comment = Regex::new(r"^.*#")?;
for line in reader.lines() {
let line = line?;
if !comment.is_match(&line) {
contents.push_str(&line);
}
}
let selections = serde_json::from_str(&contents)?;
Ok(selections)
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
if env::var("RUST_BACKTRACE").is_err() {
Expand Down Expand Up @@ -218,15 +239,16 @@ async fn main() -> Result<(), Box<dyn Error>> {
);
}

let selections = [
// (OfferType::TotalGoals(Period::FullTime, Over(2)), Outcome::Over(2)),
(OfferType::HeadToHead(Period::FullTime), Outcome::Win(Side::Home)),
(OfferType::FirstGoalscorer, Outcome::Player(Player::Named(Side::Away, String::from("João Pedro")))),
(OfferType::AnytimeGoalscorer, Outcome::Player(Player::Named(Side::Away, String::from("Welbeck")))),
// (OfferType::AnytimeGoalscorer, Outcome::Player(Player::Named(Side::Home, String::from("Bowen")))),
];
let encoded = serde_json::to_string(&selections)?;
info!("selections: {encoded}");
// let selections = [
// // (OfferType::TotalGoals(Period::FullTime, Over(2)), Outcome::Over(2)),
// (OfferType::HeadToHead(Period::FullTime), Outcome::Win(Side::Home)),
// (OfferType::FirstGoalscorer, Outcome::Player(Player::Named(Side::Away, String::from("João Pedro")))),
// (OfferType::AnytimeGoalscorer, Outcome::Player(Player::Named(Side::Away, String::from("Welbeck")))),
// // (OfferType::AnytimeGoalscorer, Outcome::Player(Player::Named(Side::Home, String::from("Bowen")))),
// ];
// let encoded = serde_json::to_string(&selections)?;
// info!("selections: {encoded}");
let selections = load_selections(args.selections.as_ref().unwrap())?;

let price = model.derive_multi(&selections)?;
let scaling_exponent = compute_scaling_exponent(price.relatedness);
Expand Down

0 comments on commit 923aa1b

Please sign in to comment.