Skip to content

Commit

Permalink
Get final ev tallies
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelnindodev committed Oct 21, 2023
1 parent ed537e0 commit 2f86d8b
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 6 deletions.
17 changes: 17 additions & 0 deletions src/core/analysis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@ import { getAnalyzableThreeWayGames, getMatchingThreeWayGameEventsTrigram } from
const {logger} = getConfig();

export class BaseAnalyser {

private getWinnings(stake: number, oddsForEvent: number): number {
const totalWithdrawableOnWin = stake * oddsForEvent;
return totalWithdrawableOnWin - stake;
}

/**
* Gets the expected value of staking on an event.
* Positive and higher results are better;
* @param probabilityOfEvent "True" Probability between 0 and 1.
* @param oddsForEvent Odds by the bet provider for the event.
*/
protected getEventEvPercent(probabilityOfEvent: number, oddsForEvent: number): number {
const theoreticalStake = 10;
const evAsNumber = (this.getWinnings(theoreticalStake, oddsForEvent) * probabilityOfEvent) - (theoreticalStake * (1-probabilityOfEvent));
return evAsNumber; // TODO: Return as a percentage
}
/**
* Get two way game events that can be analyzed.
* Analyzable data is the data where the start event is greater than the current time.
Expand Down
32 changes: 29 additions & 3 deletions src/core/analysis/three_way/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,47 @@
import { BaseAnalyser } from "..";
import { getConfig } from "../../..";
import { ThreeWayGameEventEntity } from "../../../datastores/postgres/entities";

const {logger} = getConfig();

export class ThreeWayAnalyzer extends BaseAnalyser {
public async getData() {
const gameEventsWithEv: {clubAWinEv: number, clubBWinEv: number, drawEv: number, event: ThreeWayGameEventEntity}[] = [];

const getEventDataResult = await this.getThreeWayGameEventData();

if (getEventDataResult.result === "error") {
logger.error("Error while fetching event data: ", getEventDataResult.value.message);
return;
}

getEventDataResult.value.map(async event => {
const matchingEvents = await this.getMatchingThreeWayGameEvents(event);
const results = await getEventDataResult.value.map(async event => {
const getMatchingEventsResult = await this.getMatchingThreeWayGameEvents(event);
logger.info("Event: ", event);
logger.info("Matching events: ", matchingEvents);
logger.info("Matching events: ", getMatchingEventsResult);

if (getMatchingEventsResult.result === "success" && getMatchingEventsResult.value !== null) {
getMatchingEventsResult.value.forEach(gameEvent => {
const clubAWinTrueProbability = (1 / event.odds_a_win);
const clubBWinTrueProbability = (1 / event.odds_b_win);
const drawTrueProbability = (1 / event.odds_draw);

const clubAWinEv = this.getEventEvPercent(clubAWinTrueProbability, gameEvent.odds_a_win);
const clubBWinEv = this.getEventEvPercent(clubBWinTrueProbability, gameEvent.odds_b_win);
const drawEv = this.getEventEvPercent(drawTrueProbability, gameEvent.odds_draw);

gameEventsWithEv.push({
clubAWinEv,
clubBWinEv,
drawEv,
event: gameEvent
});
});
}
});

await Promise.all(results);
logger.info("Game events with EV: ", gameEventsWithEv);
}

}
28 changes: 25 additions & 3 deletions src/core/analysis/two_way/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@
import { BaseAnalyser } from "..";
import { getConfig } from "../../..";
import { TwoWayGameEventEntity } from "../../../datastores/postgres/entities";

const {logger} = getConfig();

export class TwoWayAnalyser extends BaseAnalyser {
public async getData(): Promise<void> {
const gameEventsWithEv: {clubAWinEv: Number, clubBWinEv: number, event: TwoWayGameEventEntity}[] = [];

const getEventDataResult = await this.getTwoWayGameEventData();

if (getEventDataResult.result === "error") {
logger.error("Error while fetching event data: ", getEventDataResult.value.message);
return;
}

getEventDataResult.value.map(async event => {
const matchingEvents = await this.getMatchingTwoWayGameEvents(event);
const results = await getEventDataResult.value.map(async event => {
const getMatchingEventsResult = await this.getMatchingTwoWayGameEvents(event);
logger.info("Event: ", event);
logger.info("Matching events: ", matchingEvents);
logger.info("Matching events: ", getMatchingEventsResult);

if (getMatchingEventsResult.result === "success" && getMatchingEventsResult.value !== null) {
getMatchingEventsResult.value.forEach(gameEvent => {
const clubAWinTrueProbability = (1 / event.odds_a_win);
const clubBWinTrueProbability = (1 / event.odds_b_win);

const clubAWinEv = this.getEventEvPercent(clubAWinTrueProbability, gameEvent.odds_a_win);
const clubBWinEv = this.getEventEvPercent(clubBWinTrueProbability, gameEvent.odds_b_win);

gameEventsWithEv.push({
clubAWinEv,
clubBWinEv,
event: gameEvent
});
});
}
});

await Promise.all(results);
logger.info("Game events with EV: ", gameEventsWithEv);
}
}

0 comments on commit 2f86d8b

Please sign in to comment.