Exemple #1
0
class TestAccountant(unittest.TestCase):
    def test initial balance(self):
        acc = Accountant()
        self.assertEqual(acc.balance, 0)
    
        acc = Accountant(100)
        self.assertEqual(acc.balance, 100)
Exemple #2
0
    def test_initial_balance(self):
        # Default balance should be 0
        acc = Accountant()
        self.assertEqual(acc.balance, 0)

        # Test non-default balance.
        acc = Accountant(100)
        self.assertEqual(acc.balance, 100)
Exemple #3
0
class TestAccountant(unittest.TestCase):

    # a == b or a !=b
    # assertEqual(a, b) or assertNotEqual(a, b)
    # x is True or x is False
    # assertTrue(x) or assertFalse(x)
    # veryfity an item is in list or not in list
    #assertIn(item, list) or assertNotIn(item, list)

    def setUp(self):
        self.acc = Accountant()

    #default balance shood be 0
    def test_initial_balance(self):
        self.assertEqual(self.acc.balance, 0)
        #non-default balance
        acc = Accountant(100)
        self.assertEqual(acc.balance, 100)

    #test depsit
    def test_deposit(self):
        self.acc.deposit(100)
        self.assertEqual(self.acc.balance, 100)
        #test multiple deposit
        self.acc.deposit(100)
        self.acc.deposit(100)
        self.assertEqual(self.acc.balance, 300)

    def test_withdrawal(self):
        self.acc.deposit(1000)
        self.acc.withdraw(100)
        self.assertEqual(
            self.acc.balance,
            900)  #if you change 900 to 800 -> AssertionError: 900 != 800
Exemple #4
0
class TestAccount(unittest.TestCase):
    """Test for the class Accountant."""
    def setUp(self):
        self.acc = Accountant()

    def test_initial_balance(self):
        # Default balance should be 0.
        self.assertEqual(self.acc.balance, 0)

        # Test non-default balance.
        acc = Accountant(100)
        self.assertEqual(acc.balance, 100)

    def test_deposit(self):
        # Test single deposit.
        self.acc.deposit(100)
        self.assertEqual(self.acc.balance, 100)

        # Test multiple deposits.
        self.acc.deposit(100)
        self.acc.deposit(100)
        self.assertEqual(self.acc.balance, 300)

    def test_withdrawal(self):
        # Test single withdrawal.
        self.acc.deposit(1000)
        self.acc.withdraw(100)
        self.assertEqual(self.acc.balance, 900)
Exemple #5
0
class MarketPlace:
    def __init__(self, robots: ['Robot'], ticker: str):
        self.data_provider = DataProvider()
        self.robots = robots
        self.accountant = Accountant(robots)
        self.order_book = OrderBook(ticker)

    def training(self, data: 'pd.DataFrame'):
        for robot in self.robots:
            robot.train(data)

    def trading(self):
        orders = []
        data_from_order_book = self.order_book.get_data()
        robots_orders = self.order_book.get_robots_orders()
        for robot in self.robots:
            data_from_accountant = self.accountant.get_data(robot.username)
            robot.update(data_from_order_book, robots_orders[robot.username],
                         data_from_accountant)
            robot.on_tick()
            orders += robot.gather_new_orders()
        self.order_book.register_orders(orders)
        trades = self.order_book.get_last_trades()
        self.accountant.register_trades(trades)

    def start(self, path: str):
        #training_data = self.data_provider.get_training_data()
        #self.training(training_data)
        self.data_provider.prepare_for_trading(path)
        i = 0
        total_orders = 0
        for orders in self.data_provider:
            i += 1
            total_orders += len(orders)
            #try:
            self.order_book.register_orders(orders)
            print(i)
        print(self.order_book.total_deals)
        print(total_orders)
class App(object):
    def __init__(self):
        self._accountant = Accountant()

    def execute(self, change_contract):
        staff = self._create_staff_fixtures()

        if change_contract:
            self._change_contract_for_hourly_to_fixed(staff)

        print(self._accountant.calculate_staff_salary(staff))

    def _create_staff_fixtures(self):
        return Staff([
            self._new_employee(150, 'hourly', [5, 5]),
            self._new_employee(200, 'hourly', [10, 5, 5]),
            self._new_employee(3000, 'fixed', [40, 40, 40, 38]),
            self._new_employee(5000, 'fixed', [40, 40, 40, 43]),
            self._new_employee(0, 'voluntary', [50, 50, 60, 50]),
        ])

    def _new_employee(self, salary, contract, tracked_hours):
        if contract == 'hourly':
            cards = self._from_hours_to_cards(tracked_hours)
            return Employee(Hourly(salary), HourlyCalculator(), cards)

        if contract == 'voluntary':
            cards = self._from_hours_to_cards(tracked_hours)
            return Employee(Voluntary(), VoluntaryCalculator(), cards)

        if contract == 'fixed':
            cards = self._from_hours_to_cards(tracked_hours)
            return Employee(Fixed(salary), FixedCalculator(), cards)

        pass

    def _from_hours_to_cards(self, tracked_hours):
        cards = []
        for hours in tracked_hours:
            cards.append(Card(hours))
        return cards

    def _change_contract_for_hourly_to_fixed(self, staff):
        employee = staff.employees()[1]  # Getting an hourly
        employee.change_contract(Fixed(2500), FixedCalculator())
        employee.add_card(Card(10))
Exemple #7
0
class TestAccountant(unittest.TestCase):

    def setUp(self):
        self.acc = Accountant()
    def test_initial_balance(self):
        self.assertEqual(self.acc.balance, 0)

        acc = Accountant(100)
        self.assertEqual(acc.balance, 100)

    def test_deposit(self):
        self.acc.deposit(100)
        self.assertEqual(self.acc.balance, 100)

        self.acc.deposit(100)
        self.acc.deposit(100)
        self.assertEqual(self.acc.balance, 300)

    def test_withdrawal(self):
        self.acc.deposit(1000)
        self.acc.withdraw(100)
        self.assertEqual(self.acc.balance, 900)
Exemple #8
0
def main():
    # parse arguments
    parser = argparse.ArgumentParser()
    parser.add_argument('--agent', type=str, default='GAMBLER', help='Which agent to use')
    parser.add_argument('--learning_rate', type=float, default=0.1, help='How quickly the algorithm tries to learn')
    parser.add_argument('--discount', type=float, default=0.95, help='Discount for estimated future action')
    parser.add_argument('--iterations', type=int, default=2000, help='Iteration count')
    FLAGS, unparsed = parser.parse_known_args()

    # select agent
    if FLAGS.agent == 'GAMBLER':
        agent = Gambler(learning_rate=FLAGS.learning_rate, discount=FLAGS.discount, iterations=FLAGS.iterations)
    elif FLAGS.agent == 'ACCOUNTANT':
        agent = Accountant()
    elif FLAGS.agent == 'DEEPGAMBLER':
        agent = DeepGambler(learning_rate=FLAGS.learning_rate, discount=FLAGS.discount, iterations=FLAGS.iterations)
    else:
        agent = Drunkard()

    # setup simulation
    dungeon = DungeonSimulator()
    dungeon.reset()
    total_reward = 0 # Score keeping
    last_total = 0

    # main loop
    for step in range(FLAGS.iterations):
        old_state = dungeon.state # Store current state
        action = agent.get_next_action(old_state) # Query agent for the next action
        new_state, reward = dungeon.take_action(action) # Take action, get new state and reward
        agent.update(old_state, new_state, action, reward) # Let the agent update internals

        total_reward += reward # Keep score
        if step % 250 == 0: # Print out metadata every 250th iteration
            performance = (total_reward - last_total) / 250.0
            print(json.dumps({'step': step, 'performance': performance, 'total_reward': total_reward}))
            last_total = total_reward

        time.sleep(0.0001) # Avoid spamming stdout too fast!
def main():
    print("xxx")
    parser=argparse.ArgumentParser()
    parser.add_argument("--agent", type=str, default = 'DEEPGAMBLER',help="Which agent to use")
    parser.add_argument("--learning_agent", type=float, default = 0.1,help="Choose Learning Rate ")
    parser.add_argument("--discount", type=float, default = 0.95, help="choose discount")
    parser.add_argument("--iterations", type=int, default = 1000,help="No of iterations")

    FLAGS,unparsed = parser.parse_known_args()
    print("xxx")
    if FLAGS.agent == "DRUNKARD":
        agent= Drunkard()
    elif FLAGS.agent=="ACCOUNTANT":
        agent=Accountant()
    elif FLAGS.agent == "GAMBLER":
        agent=Gambler(FLAGS.learning_agent,FLAGS.discount,1.0,FLAGS.iterations)
    else:
        agent=DeepGambler(FLAGS.learning_agent,FLAGS.discount,1.0,FLAGS.iterations)
    dungeon= DungeonSimulator()

    dungeon.reset()
    total_reward = 0
    print("agent created")
    for step in range(FLAGS.iterations):
        old_state = dungeon.state
        action = agent.get_next_action(old_state)
        new_state , reward = dungeon.take_action(action)

        agent.update(old_state, new_state, action, reward)
        
        total_reward += reward

        if step %250 ==0: 
            print(json.dumps({'step': step,'total-reward':total_reward, }))

        time.sleep(0.0001)

    print("FINAL Q TABLE", agent.q_table)
Exemple #10
0
 def test_initial_balance(self):
     self.assertEqual(self.acc.balance, 0)
     #non-default balance
     acc = Accountant(100)
     self.assertEqual(acc.balance, 100)
Exemple #11
0
 def setUp(self):
     self.acc = Accountant()
 def test_calculates_staff_total_salary(self):
     accountant = Accountant()
     staff = Mock()
     staff.obtain_salary = Mock(return_value=6000)
     result = accountant.calculate_staff_salary(staff)
     expected = 6000
Exemple #13
0
 def __init__(self, robots: ['Robot'], ticker: str):
     self.data_provider = DataProvider()
     self.robots = robots
     self.accountant = Accountant(robots)
     self.order_book = OrderBook(ticker)
 def __init__(self):
     self._accountant = Accountant()
Exemple #15
0
            accountant.alpaca_key,
            "https://paper-api.alpaca.markets",
            api_version="v2",
        )

    def get_polygon_financial_statement(self, symbol, limit):
        params = {}
        params["limit"] = limit
        financial_statement = self.api.polygon.get(
            path="/reference/financials/" + symbol,
            params=params,
            version="v2")
        return financial_statement["results"]


polygon = PolygonInterface(Accountant())

result = polygon.get_polygon_financial_statement("TSLA", 0)
print(result)
# def get_polygon_ticker_symbols(self, pages, perpage=50):
#     params = {
#         "market": "STOCKS",
#         "page": pages,
#         # 'perpage': perpage,
#         "active": "true",
#     }
#     data = self.api.polygon.get(
#         path="/reference/tickers", params=params, version="v2"
#     )
#     tickers = data["tickers"]
#     return tickers
 def __init__(self):
     self.accountant = Accountant()
     self.polygon = PolygonGateway(self.accountant)
     self.investor = Investor()