Advertisement
KillianMills

2nd Year R Project

Nov 3rd, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 2.49 KB | None | 0 0
  1. #Question 1 -------------------------------------------------------------------------
  2.  
  3. attach(results)
  4. summary(X)
  5. summary(Fav.Odds)
  6.  
  7. #Mean of both
  8. #X: 4.257 Fav.Odds: 6.72
  9. For<- 6.72
  10. Against<- 4.257
  11. print(Against/Against)
  12. print(For/Against)
  13.  
  14. #4.257 / 4.257 = 1
  15. #6.72 / 4.257 = 1.578576462
  16. #1.578576462 : 1
  17. #2 : 1
  18. # odds rounded up are 2:1 when in reality they are more close to 3:1 as
  19. # we have 192 losses to 108 wins
  20.  
  21.  
  22.  
  23. #Question 2 -------------------------------------------------------------------------
  24.  
  25. Summary(results)
  26. Wins <- 108
  27. Losses <- 192
  28. TotalRaces <- 300
  29. ProbOfFav <- Wins/TotalRaces
  30. print(ProbOfFav)
  31.  
  32. #108/300 = 0.36
  33. #36% probability of the favourite winning
  34.  
  35.  
  36. #Question 3 -------------------------------------------------------------------------
  37.  
  38. #1- P(win / %Odds ) = answer for question 3, bookies gain
  39. #P(win) = win / total races = 108/300 = 0.36
  40. #%odds = ( for/ for + against ) = ( 1 / 2+ 1) = (1/3) = 0.33
  41.  
  42. probwin <- 0.36
  43. print(probwin)
  44. percentodds <- 0.33
  45. formula <- probwin / percentodds
  46. print(formula)
  47. #[1] 1.090909
  48.  
  49. answer<- 1 - formula
  50. print(answer)
  51.  
  52. #the bookies are making a 9% loss or a €0.09 loss on every €1 bet
  53.  
  54.  
  55.  
  56. # Question 4 -------------------------------------------------------------------------
  57.  
  58. bet<- 1
  59. loss<- 0
  60. wins<- 0
  61. return<- 0
  62.  
  63. # a for loop that runs through all 300 races and uses the double up betting strategy and records the end profit
  64.  
  65. for (i in 1:300) {
  66.   if (results$win[i]=="y"){
  67.     wins <- bet - loss
  68.     return <- return + wins
  69.     bet <- 1
  70.     wins <- 0
  71.     loss <- 0
  72.     TRUE
  73.   }
  74.   if (results$win[i]=="n"){
  75.     if (results$place[i]=="n"){
  76.     loss <- bet + loss
  77.     return
  78.     bet <- bet * 2
  79.     FALSE
  80.   }
  81.  
  82.   else{
  83.     TRUE
  84.   }
  85.  
  86.   if(i==300){
  87.     return<-return-loss
  88.     TRUE
  89.   }
  90.  
  91.   FALSE
  92.  
  93.   }
  94. }  
  95. print(return)
  96.  
  97.  
  98.  
  99. # Question 5 -------------------------------------------------------------------------
  100.  
  101. # this for loop determines the total amount of capital we need at the start to get the €1 return
  102.  
  103. bet<- 0.01
  104. loss<- 0
  105. wins<- 0
  106. return<- 0
  107. capital<-0
  108.  
  109. for (i in 1:300) {
  110.  
  111.   if (results$win[i]=="y"){
  112.     wins <- bet - loss
  113.     return <- return + wins
  114.     bet <- 0.01
  115.     wins <- 0
  116.     loss <- 0
  117.     TRUE
  118.   }
  119.  
  120.   if (results$win[i]=="n"){
  121.     if (results$place[i]=="n"){
  122.       loss <- bet + loss
  123.       bet <- bet * 2
  124.       FALSE
  125.     }
  126.  
  127.     if(i==300){
  128.       return<-return-loss
  129.       capital<-capital*2
  130.       TRUE
  131.     }
  132.  
  133.     FALSE
  134.   }
  135.  
  136. }
  137.  
  138. print(capital)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement