Bläddra i källkod

New Wicket application

Axel Nordh 1 år sedan
förälder
incheckning
ee02bce3bf

+ 237 - 0
OddsJavaFx/src/controllers/strategytest/KellyFormulaStrategy.java

@@ -0,0 +1,237 @@
+package controllers.strategytest;
+
+import components.FloatStatRow;
+import components.IntTableStatRow;
+import components.NumberStatRow;
+import interfaces.strategytest.BettingStrategyInterface;
+import javafx.scene.layout.VBox;
+import objects.SoccerMatch;
+import objects.SoccerMatchAnalysis;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * The basic concept of betting according to the Fibonacci sequence is simple: bet on a tie.
+ If you lose, just bet on the next tie according to a certain key and start increasing your stake.
+
+ *
+ * It is important that the odds for the tie are above 2.62 (more precisely: 2.618);
+ * luckily for those who want to employ this strategy, there are many tie bets for this minimum odds.
+ The higher the rate, the better.
+
+ *
+ * Fibonacci Betting Strategy
+ * Betting after Fibonacci
+ * If you lose, you simply bet the next tie after a Fibonacci sequence.
+ It is a sequence of numbers in which the sum of two consecutive numbers results in the next number, making the Fibonacci sequence an infinite sequence of natural numbers.
+ You can find more information about the Fibonacci sequence on Wikipedia.
+
+ *
+ * Fibonacci numbers
+ * The Fibonacci sequence
+ * So if you start betting with 1 € on the first draw with odds> 2.
+62 and lose, then the next time you bet 1 € again, then 2 €, then 3 €, then 5 €, then 8 €, then 13 € and so on.
+
+ *
+ * It is mathematically understandable that every profit that you will achieve with this bet will offset the previous losses and you will even make a net profit.
+
+ *
+ * An example of the Fibonacci bet
+ *
+ * Let’s take the example of the situation where you lose ten times in a row and win your bet the eleventh time.
+ In this case, you have already gambled away 143 € and finally successfully placed the eleventh number in the Fibonacci sequence, 144, on a bet.
+ If we now assume that the successful bet had odds of @ 2.
+80, you win 403.
+20 €.
+ You have wagered a total of 287 €, making your net profit 116.
+20 €.
+
+ *
+ * The disadvantage of this strategy is also obvious.
+ Assuming you lose not ten bets in a row, but twenty, then you would have already lost 16,910 € in stakes.
+ This is a huge bankroll, which you should of course never risk for such a betting sequence.
+ You can find more about this in our explanations on bankroll management.
+
+ */
+public class FibonacciStrategy extends VBox implements BettingStrategyInterface {
+
+    public static final String NAME = "Fibonacci";
+    List<SoccerMatch> matches;
+    private FloatStatRow betAmount;
+    private FloatStatRow wonLossBankStatRow;
+    private NumberStatRow sequencesPlayedStatRow;
+    private IntTableStatRow resultStatRow;
+
+    private final int maxActiveFibonacciSequences = 4;
+    private final List<FibonacciSequence> fibonacciSequences = new ArrayList<>();
+    private NumberStatRow sequencesWonStatRow;
+
+    public FibonacciStrategy() {
+        super();
+        buildSettingsGuiPanel();
+        buildStatGuiPanel();
+        buildMatchSummaryPanel();
+    }
+
+    @Override
+    public void setMatches(List<SoccerMatch> matches) {
+        this.matches = matches;
+    }
+
+    @Override
+    public void buildSettingsGuiPanel() {
+        betAmount = new FloatStatRow("Bet Amount", 10f);
+        this.getChildren().add(betAmount);
+    }
+
+    @Override
+    public void buildStatGuiPanel() {
+        sequencesPlayedStatRow = new NumberStatRow("Number of sequences played", 0);
+        sequencesWonStatRow = new NumberStatRow("Number of sequences won", 0);
+        resultStatRow = new IntTableStatRow("Longest sequence without win");
+
+        wonLossBankStatRow = new FloatStatRow("Amount won or lost", 0f);
+
+        this.getChildren().add(sequencesPlayedStatRow);
+        this.getChildren().add(sequencesWonStatRow);
+        this.getChildren().add(resultStatRow);
+        this.getChildren().add(wonLossBankStatRow);
+    }
+
+    @Override
+    public void buildMatchSummaryPanel() {
+        // Empty for now
+    }
+
+    @Override
+    public void runTest() {
+
+        float lowestBankAmount = 0f;
+
+        for (int i = 0; i < matches.size(); i++) {
+            SoccerMatch m = matches.get(i);
+            List<SoccerMatch> soccerMatches = filterTodaysMatches(matches, m);
+
+            List<SoccerMatch> sortedMatchList = sortMatchesOnBetPotential(soccerMatches);
+
+            for (SoccerMatch match : sortedMatchList) {
+                boolean removeSequence = false;
+                String shouldBetOn = shouldBetOn(match);
+                FibonacciSequence activeSequence = null;
+                if (shouldBetOn.equals("X")) {
+                    Optional<FibonacciSequence> fibSeq = fibonacciSequences.stream().filter(fs -> !fs.containsMatchFromSameDate(match)).findFirst();
+                    if (fibSeq.isPresent()) {
+                        // Add to current sequence
+                        activeSequence = fibSeq.get();
+                        if (activeSequence.bets.size() + 1 > FibonacciSequence.fibonacciSequence.size()) {
+                            System.out.println("System FAILED " + match.getGameDate() + " lost " + activeSequence.totalBetValue + " current bank " + wonLossBankStatRow.getValue());
+                            System.out.println("Lowest bank amount " + lowestBankAmount);
+                            removeSequence = true;
+                        } else {
+                            activeSequence.addBet(match);
+                            wonLossBankStatRow.decreaseValue(activeSequence.currentBetValue);
+                            if (wonLossBankStatRow.getValue() < lowestBankAmount) {
+                                lowestBankAmount = wonLossBankStatRow.getValue();
+                            }
+                        }
+                    } else {
+                        // Start new if not at max active sequences
+                        if (fibonacciSequences.size() < maxActiveFibonacciSequences) {
+                            activeSequence = new FibonacciSequence(match);
+                            sequencesPlayedStatRow.increaseValue();
+                            wonLossBankStatRow.decreaseValue(activeSequence.currentBetValue);
+                            fibonacciSequences.add(activeSequence);
+                            if (wonLossBankStatRow.getValue() < lowestBankAmount) {
+                                lowestBankAmount = wonLossBankStatRow.getValue();
+                            }
+                        } else {
+                            // Should not add more sequences, break loop
+                            break;
+                        }
+                    }
+                }
+
+                if (activeSequence != null) {
+                    if (removeSequence) {
+                        // Sequence reached max size
+                        fibonacciSequences.remove(activeSequence);
+                    } else if (match.getMatchResult().equals("X")) {
+                        // WON
+                        resultStatRow.increaseValue(activeSequence.bets.size());
+                        sequencesWonStatRow.increaseValue();
+
+                        final float wonAmount = activeSequence.currentBetValue * match.getOddsX();
+                        wonLossBankStatRow.increaseValue(wonAmount);
+                        // Sequence won, remove sequence
+                        fibonacciSequences.remove(activeSequence);
+                    }
+                }
+            }
+            i += sortedMatchList.size();
+        }
+        System.out.println("FibonacciStrategy.runTest() lest unresolved sequences: ");
+        fibonacciSequences.forEach(fs -> System.out.println("Sequence: " + fs.bets.size() + " outstanding bets value: " + fs.totalBetValue));
+    }
+
+    /**
+     * Matchen måste ha ett odds på X på minst 2.618
+     */
+    @Override
+    public String shouldBetOn(SoccerMatch match) {
+        return match.getOddsX() >= 2.618 ? "X" : "";
+    }
+
+    @Override
+    public List<SoccerMatch> sortMatchesOnBetPotential(List<SoccerMatch> matches) {
+        //matches.sort((m1, m2) -> Float.compare(m1.getOddsX(), m2.getOddsX()));
+
+        matches.sort((m2, m1) -> Float.compare(new SoccerMatchAnalysis(m1).calculateWinPercentages().getDrawPercentage(),
+                new SoccerMatchAnalysis(m2).calculateWinPercentages().getDrawPercentage()));
+        return matches;
+    }
+
+    public void reset() {
+        fibonacciSequences.clear();
+        sequencesPlayedStatRow.getChildren().clear();
+        sequencesWonStatRow.getChildren().clear();
+        resultStatRow.getChildren().clear();
+        wonLossBankStatRow.getChildren().clear();
+
+        buildStatGuiPanel();
+        buildMatchSummaryPanel();
+    }
+
+
+    private class FibonacciSequence {
+
+        public static final List<Integer> fibonacciSequence = Arrays.asList(1, 1, 2, 3, 5, 8, 13, 21, 34, 55); //, 89, 144, 233, 377, 610);
+        List<SoccerMatch> bets = new ArrayList<>();
+        float totalBetValue = 0f;
+
+        float currentBetValue = 0f;
+
+        FibonacciSequence(SoccerMatch match) {
+            bets.add(match);
+            totalBetValue += betAmount.getValue();
+            currentBetValue = betAmount.getValue();
+        }
+
+        public void addBet(SoccerMatch match) {
+            totalBetValue += betAmount.getValue() * fibonacciSequence.get(bets.size());
+            currentBetValue = betAmount.getValue() * fibonacciSequence.get(bets.size());
+
+            bets.add(match);
+        }
+
+        public boolean containsBet(SoccerMatch match) {
+            return bets.contains(match);
+        }
+
+        public boolean containsMatchFromSameDate(SoccerMatch match) {
+            return bets.stream().anyMatch(b -> b.getGameDate().toLocalDate().isEqual(match.getGameDate().toLocalDate()));
+        }
+    }
+}

+ 2 - 0
OddsJavaFx/src/data/BetStrategyMysql/BetStrategyMysql.java

@@ -0,0 +1,2 @@
+package data.BetStrategyMysql;public class BetStrategyMysql {
+}

+ 2 - 0
OddsJavaFx/src/data/DTO/FibonacciDTO/FibonacciDTO.java

@@ -0,0 +1,2 @@
+package data.DTO.FibonacciDTO;public class FibonacciDTO {
+}

+ 2 - 0
OddsJavaFx/src/objects/visual/FibonacciBets.java

@@ -0,0 +1,2 @@
+package objects.visual;public class FibonacciBets {
+}

+ 35 - 0
OddsStrategyWeb/pom.xml

@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>Odds</groupId>
+        <artifactId>Odds</artifactId>
+        <version>0.0.1-SNAPSHOT</version>
+        <relativePath>../Odds/pom.xml</relativePath>
+    </parent>
+
+    <artifactId>OddsStrategyWeb</artifactId>
+
+    <properties>
+        <maven.compiler.source>21</maven.compiler.source>
+        <maven.compiler.target>21</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.wicket</groupId>
+            <artifactId>wicket-core</artifactId>
+            <version>10.0.0</version>
+        </dependency>
+    </dependencies>
+    <repositories>
+        <repository>
+            <id>nordhs-repo</id>
+            <name>Nords Repo</name>
+            <url>http://nordh.xyz:9099/repository/nordhs-repo/</url>
+        </repository>
+    </repositories>
+
+</project>

+ 5 - 0
OddsStrategyWeb/src/main/java/Main.html

@@ -0,0 +1,5 @@
+<html xmlns:wicket="http://www.w3.org/1999/xhtml">
+<body>
+<span wicket:id="message">Message is here</span>
+</body>
+</html>

+ 11 - 0
OddsStrategyWeb/src/main/java/Main.java

@@ -0,0 +1,11 @@
+package main.java;
+
+
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+
+public class Main extends WebPage {
+    public Main() {
+        add(new Label("message", "Hello World!"));
+    }
+}

+ 15 - 0
OddsStrategyWeb/src/main/java/MainApplication.java

@@ -0,0 +1,15 @@
+package main.java;
+
+import org.apache.wicket.Page;
+import org.apache.wicket.protocol.http.WebApplication;
+
+public class MainApplication extends WebApplication {
+
+    public MainApplication() {
+    }
+
+    @Override
+    public Class<? extends Page> getHomePage() {
+        return Main.class;
+    }
+}

+ 20 - 0
OddsStrategyWeb/src/main/java/web.xml

@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE web-app
+        PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+        "http://java.sun.com/dtd/web-app_2_3.dtd">
+
+<web-app>
+    <display-name>Wicket Examples</display-name>
+    <filter>
+        <filter-name>MainApplication</filter-name>
+        <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
+        <init-param>
+            <param-name>applicationClassName</param-name>
+            <param-value>main.java.MainApplication</param-value>
+        </init-param>
+    </filter>
+    <filter-mapping>
+        <filter-name>MainApplication</filter-name>
+        <url-pattern>/*</url-pattern>
+    </filter-mapping>
+</web-app>