This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Create betfair data table. | |
CREATE TABLE [dbo].[betfair_data]( | |
[SPORTS_ID] [varchar](50) NOT NULL, | |
[EVENT_ID] [int] NOT NULL, | |
[SETTLED_DATE] [datetime] NULL, | |
[FULL_DESCRIPTION] [varchar](255) NOT NULL, | |
[SCHEDULED_OFF] [datetime] NOT NULL, | |
[EVENT] [varchar](50) NOT NULL, | |
[DT_ACTUAL_OFF] [datetime] NULL, | |
[SELECTION_ID] [int] NOT NULL, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--get markets for calculating probabilities | |
select event_id,full_description,scheduled_off, selection_id,selection from markets where sports_id=2 and event='Match Odds' and full_description like'%/Mens%' order by event_id | |
--insert market probabilities to mssql | |
BULK | |
INSERT market_prob | |
FROM 'C:\daniel\betfair_data\tennis_prob_data.csv' | |
WITH | |
( | |
FIELDTERMINATOR = ',', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select SUM(total) from bets | |
select sum(total) from (select *, row_number() over (partition by event_id,selection_id order by latest_taken desc) as row from bets) A where row=1 | |
-- P&L per weeek | |
select row_number() over (order by DATEPART(year,settled_date),DATEPART(wk,settled_date)),DATEPART(year,settled_date),DATEPART(wk,settled_date) as week | |
,SUM(total) as total from bets group by DATEPART(year,settled_date),DATEPART(wk,settled_date) | |
--P&L per probability range | |
select cast((1/odds)*100 as int) as price_implied_prob,sum(total) as profit,count(*) as num_of_markets, SUM(cast(win_flag as int)) as wins, | |
100*SUM(cast(win_flag as real)) / count(*) as true_prob, 100*avg(predicted_prob) as predicted_prob |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package dk.tennis.compare | |
import dk.atp.api.AtpWorldTourApi._ | |
import SurfaceEnum._ | |
import dk.tennisprob.TennisProbCalc.MatchTypeEnum._ | |
/** | |
* Calculates probability of winning a tennis match by player A against player B. For instance Roger Federer vs Novak Djokovic | |
* | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package dk.tennisprob | |
object TennisProbCalc { | |
object MatchTypeEnum extends Enumeration { | |
type MatchTypeEnum = Value | |
val THREE_SET_MATCH, FIVE_SET_MATCH = Value | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package dk.atp.api | |
import AtpWorldTourApi._ | |
/** | |
* API interface for atpworldtour.com tennis statistics. | |
* | |
*/ | |
object AtpWorldTourApi { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package dk.tennisprob | |
object TennisProbCalc { | |
object MatchTypeEnum extends Enumeration { | |
type MatchTypeEnum = Value | |
val THREE_SET_MATCH, FIVE_SET_MATCH = Value | |
} | |
} |