forked from laholmes/node-python-roulette
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 051c4f7
Showing
1,580 changed files
with
134,577 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import sys | ||
import random | ||
|
||
# startingFunds = float(sys.argv[1]) | ||
# wagerSize = float(sys.argv[2]) | ||
# wagerCount = float(sys.argv[3]) | ||
# daSampSize = float(sys.argv[4]) | ||
|
||
counter = 1 | ||
ret = 0.0 | ||
da_busts = 0.0 | ||
da_profits = 0.0 | ||
|
||
def rollDice(): | ||
roll = random.randint(1,100) | ||
|
||
if roll <= 50: | ||
return False | ||
elif roll >= 51: | ||
return True | ||
|
||
def dAlembert(funds,initial_wager,wager_count): | ||
global ret | ||
global da_busts | ||
global da_profits | ||
|
||
value = funds | ||
wager = initial_wager | ||
currentWager = 1 | ||
previousWager = 1 | ||
previousWagerAmount = initial_wager | ||
|
||
while currentWager <= wager_count: | ||
if previousWager == 1: | ||
if wager == initial_wager: | ||
pass | ||
else: | ||
wager -= initial_wager | ||
|
||
if rollDice(): | ||
value += wager | ||
previousWagerAmount = wager | ||
else: | ||
value -= wager | ||
previousWager = 0 | ||
previousWagerAmount = wager | ||
|
||
if value <= 0: | ||
da_busts += 1 | ||
break | ||
|
||
elif previousWager == 0: | ||
wager = previousWagerAmount + initial_wager | ||
if(value - wager) <= 0: | ||
wager = value | ||
|
||
if rollDice(): | ||
value += wager | ||
previousWager = 1 | ||
previousWagerAmount = wager | ||
else: | ||
value -= wager | ||
previousWagerAmount = wager | ||
|
||
if value <= 0: | ||
da_busts += 1 | ||
break | ||
|
||
currentWager += 1 | ||
|
||
ret += value | ||
|
||
if value > funds: | ||
da_profits += 1 | ||
|
||
# while counter <= daSampSize: | ||
# dAlembert(startingFunds, wagerSize, wagerCount) | ||
# counter += 1 | ||
|
||
# results = { | ||
# 'totalInvested': daSampSize*startingFunds, | ||
# 'totalReturn': ret, | ||
# 'roi': ret - (daSampSize*startingFunds), | ||
# 'bustRate': (da_busts/daSampSize) * 100.00, | ||
# 'profitRate': (da_profits/daSampSize) * 100.00 | ||
# } | ||
|
||
# sys.stdout.write(str(results)) | ||
# print(str(results)) | ||
# sys.stdout.flush() | ||
# sys.exit(0) | ||
|
||
def simulate(startingFunds, wagerSize, wagerCount, daSampSize): | ||
counter = 1 | ||
|
||
while counter <= daSampSize: | ||
dAlembert(startingFunds, wagerSize, wagerCount) | ||
counter += 1 | ||
|
||
results = { | ||
'totalInvested': daSampSize*startingFunds, | ||
'totalReturn': ret, | ||
'roi': ret - (daSampSize*startingFunds), | ||
'bustRate': (da_busts/daSampSize) * 100.00, | ||
'profitRate': (da_profits/daSampSize) * 100.00 | ||
} | ||
return results | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env python | ||
import pika | ||
import d_alembert | ||
import json | ||
|
||
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost')) | ||
channel = connection.channel() | ||
|
||
channel.queue_declare(queue='simulations') | ||
channel.queue_declare(queue='results') | ||
|
||
def callback(ch, method, properties, body): | ||
requestParams = json.loads(body.decode('utf-8')) | ||
funds = int(requestParams[0]) | ||
size = int(requestParams[1]) | ||
count = int(requestParams[2]) | ||
sims = int(requestParams[3]) | ||
|
||
results = d_alembert.simulate(funds, size, count, sims) | ||
print(results) | ||
|
||
# send a message back | ||
channel.basic_publish(exchange='', | ||
routing_key='results', | ||
body=json.dumps(results, ensure_ascii=False)) | ||
|
||
# connection.close() | ||
|
||
# receive message and complete simulation | ||
channel.basic_consume(callback, | ||
queue='simulations', | ||
no_ack=True) | ||
|
||
channel.start_consuming() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.