Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def winst(koers, acties):
- if not isinstance(acties, str) or len(koers) != len(acties):
- raise AssertionError("ongeldige acties")
- geld = 0
- verkoop = False
- for i, action in enumerate(acties):
- if action == 'K' and not verkoop:
- geld -= koers[i]
- verkoop = True
- elif action == 'V' and verkoop:
- geld += koers[i]
- verkoop = False
- elif action != '-':
- raise AssertionError("ongeldige acties")
- if verkoop:
- raise AssertionError("ongeldige acties")
- return geld
- def maximale_winst(koers):
- geld = 0
- vorig = koers[0]
- bitcoin = False
- for prijs in koers:
- if not bitcoin and prijs > vorig:
- geld -= vorig
- bitcoin = True
- elif bitcoin and prijs < vorig:
- geld += vorig
- bitcoin = False
- vorig = prijs
- if bitcoin:
- geld += vorig
- return geld
- def optimale_acties(koers):
- acties = ''
- vorig = koers[0]
- bitcoin = False
- for prijs in koers:
- if not bitcoin and prijs > vorig:
- acties += 'K'
- bitcoin = True
- elif bitcoin and prijs < vorig:
- acties += 'V'
- bitcoin = False
- else:
- acties += '-'
- vorig = prijs
- if bitcoin:
- acties += 'V'
- else:
- acties += '-'
- return acties[1:]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement