Instantly share code, notes, and snippets.

Embed
What would you like to do?
//#I @"D:\Projects\Bfexplorer\Development\Applications\BeloSoft.Bfexplorer.App\bin\Debug\"
#I @"C:\Program Files (x86)\BeloSoft\Bfexplorer\"
#r "DevExpress.Data.v15.1.dll"
#r "DevExpress.Office.v15.1.Core.dll"
#r "DevExpress.Spreadsheet.v15.1.Core.dll"
#r "BeloSoft.Data.dll"
#r "BeloSoft.Bfexplorer.Domain.dll"
#r "BeloSoft.Bfexplorer.Service.Core.dll"
open System.Threading
open DevExpress.Spreadsheet
open BeloSoft.Data
open BeloSoft.Bfexplorer.Domain
open BeloSoft.Bfexplorer.Service
//let bfexplorer = nil<IBfexplorerConsole>
let haveProfit (market : Market) =
(defaultNullableArg market.SettledProfit 0.0) > 0.0
let getBetsBookValue (market : Market) =
market.Bets
|> Seq.sumBy (fun bet -> toPriceProbability bet.Price)
let getNumberOfRunners (market : Market) =
market.Selections |> Seq.filter isNotRemovedSelection |> Seq.length
let getWinner (market : Market) =
market.Selections |> Seq.find isWinnerSelection
let getRaceDistanceAndType (raceDetails : string) =
let dataIndex = raceDetails.IndexOf(' ')
if dataIndex = -1
then
raceDetails, "Unknown"
else
raceDetails.Substring(0, dataIndex), raceDetails.Substring(dataIndex + 1)
(*
Analyze data
*)
let botName = "Horse Racing Dutching Strategy"
let settledMarkets = bfexplorer.GetMyStrategySettledMarkets(botName)
let profitMarkets, lossMarkets = settledMarkets |> List.partition haveProfit
let totalNumberOfMarkets = settledMarkets.Length
let profitNumberOfMarkets = profitMarkets.Length
printfn "Bet on %d markets, profit on %.2f%%" totalNumberOfMarkets ((float profitNumberOfMarkets / float totalNumberOfMarkets) * 100.0)
let bfexplorerUI = bfexplorer.BfexplorerUI
let bfexplorerSpreadsheet = bfexplorerUI.BfexplorerSpreadsheet
bfexplorerUI.ExecuteOnUiContext SynchronizationContext.Current <|
fun () ->
if isNotNullObj bfexplorerSpreadsheet
then
let workbook = bfexplorerSpreadsheet.Document
let worksheet =
if workbook.Worksheets.Contains(botName)
then
workbook.Worksheets.[botName]
else
workbook.Worksheets.Add(botName)
let mutable row = 0
let mutable totalProfit = 0.0
[ "Id"; "Racecorse"; "Race Distanace"; "Race Type"; "Number of Runners"; "Bets Book Value"; "Profit"; "Win"; "Total Profit"; "Winner"; "Maximal Price Traded" ]
|> List.iteri (fun column title -> worksheet.[row, column].SetValue(title))
settledMarkets
|> List.iter (fun market ->
let marketInfo = market.MarketInfo
let raceDistance, raceType = getRaceDistanceAndType marketInfo.MarketName
let profit = defaultNullableArg market.SettledProfit 0.0
let winner = getWinner market
totalProfit <- totalProfit + profit
row <- row + 1
worksheet.[row, 0].SetValue(row)
worksheet.[row, 1].SetValue(marketInfo.BetEvent.Details)
worksheet.[row, 2].SetValue(raceDistance)
worksheet.[row, 3].SetValue(raceType)
worksheet.[row, 4].SetValue(getNumberOfRunners market)
worksheet.[row, 5].SetValue(getBetsBookValue market)
worksheet.[row, 6].SetValue(profit)
worksheet.[row, 7].SetValue(profit > 0.0)
worksheet.[row, 8].SetValue(totalProfit)
worksheet.[row, 9].SetValue(winner.Name)
worksheet.[row, 10].SetValue(winner.PriceTradedHistory.MaximalPriceTraded)
)
else
printf "Open bfexplorer spreadsheet application!"
|> Async.RunSynchronously
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment