Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. def winst(koers, acties):
  2. if not isinstance(acties, str) or len(koers) != len(acties):
  3. raise AssertionError("ongeldige acties")
  4. geld = 0
  5. verkoop = False
  6. for i, action in enumerate(acties):
  7. if action == 'K' and not verkoop:
  8. geld -= koers[i]
  9. verkoop = True
  10. elif action == 'V' and verkoop:
  11. geld += koers[i]
  12. verkoop = False
  13. elif action != '-':
  14. raise AssertionError("ongeldige acties")
  15. if verkoop:
  16. raise AssertionError("ongeldige acties")
  17. return geld
  18.  
  19.  
  20. def maximale_winst(koers):
  21. geld = 0
  22. vorig = koers[0]
  23. bitcoin = False
  24. for prijs in koers:
  25. if not bitcoin and prijs > vorig:
  26. geld -= vorig
  27. bitcoin = True
  28. elif bitcoin and prijs < vorig:
  29. geld += vorig
  30. bitcoin = False
  31. vorig = prijs
  32. if bitcoin:
  33. geld += vorig
  34. return geld
  35.  
  36.  
  37. def optimale_acties(koers):
  38. acties = ''
  39. vorig = koers[0]
  40. bitcoin = False
  41. for prijs in koers:
  42. if not bitcoin and prijs > vorig:
  43. acties += 'K'
  44. bitcoin = True
  45. elif bitcoin and prijs < vorig:
  46. acties += 'V'
  47. bitcoin = False
  48. else:
  49. acties += '-'
  50. vorig = prijs
  51. if bitcoin:
  52. acties += 'V'
  53. else:
  54. acties += '-'
  55. return acties[1:]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement