コード例 #1
0
def test_evaluate_profitable():
    market = Market("test", 0, "", "SingleMarket")
    c1 = Contract("test", "test1", "")
    c2 = Contract("test", "test2", "")
    c3 = Contract("test", "test3", "")

    c1.long_offers = [Offer(c1, "YES", 0.1, 10)]
    c2.long_offers = [Offer(c2, "YES", 0.2, 10)]
    c3.long_offers = [Offer(c3, "YES", 0.3, 10)]

    market.contracts = [c1, c2, c3]

    r = buy_yes.evaluate(market)

    assert r is not None

    ret = r[0]
    gain = r[1]
    cost = r[2]
    shares = r[3]

    assert cost == 6
    assert shares == 10
    assert round(ret, 2) == 0.6
    assert round(gain, 2) == 4
コード例 #2
0
def test_evaluate_notprofitable():
    market = Market("test", 0, "", "SingleMarket")
    c1 = Contract("test", "test1", "")
    c2 = Contract("test", "test2", "")
    c3 = Contract("test", "test3", "")

    c1.long_offers = [Offer(c1, "YES", 0.4, 10)]
    c2.long_offers = [Offer(c2, "YES", 0.5, 10)]
    c3.long_offers = [Offer(c3, "YES", 0.6, 10)]

    market.contracts = [c1, c2, c3]

    r = buy_yes.evaluate(market)

    assert r is None
コード例 #3
0
def test_contract_costs():
	c = Contract('ticker', 'test', '')
	c.long_offers = [
		Offer(c, 'Yes', .1, 5),
		Offer(c, 'Yes', .16, 10),
		Offer(c, 'Yes', .2, 100),
	]

	c.short_offers = [
		Offer(c, 'Yes', .4, 6),
		Offer(c, 'Yes', .5, 4),
		Offer(c, 'Yes', .6, 10),
	]

	assert c.cost_to_buy_n_long(1000) is None
	assert c.cost_to_buy_n_short(1000) is None

	assert c.cost_to_buy_n_long(5) == .5
	assert c.cost_to_buy_n_long(10) == 1.3
	assert c.cost_to_buy_n_long(20) == 3.1

	assert c.cost_to_buy_n_short(6) == 2.4
	assert c.cost_to_buy_n_short(10) == 4.4
	assert c.cost_to_buy_n_short(12) == 5.6
	assert c.cost_to_buy_n_short(20) == 10.4
コード例 #4
0
def test_evaluate_notprofitable():
    market = Market('test', 0, '', 'SingleMarket')
    c1 = Contract('test', 'test1', '')

    c1.long_offers = [ Offer(c1, 'YES', .52, 10) ]
    c1.short_offers = [ Offer(c1, 'NO', .54, 5)]


    market.contracts = [ c1 ]

    r = buy_yes_no.evaluate(market)
    
    assert r is None
コード例 #5
0
def test_evaluate_profitable():
    market = Market('test', 0, '', 'SingleMarket')
    c1 = Contract('test', 'test1', '')

    c1.long_offers = [ Offer(c1, 'YES', .4, 10) ]
    c1.short_offers = [ Offer(c1, 'NO', .4, 5)]

    market.contracts = [ c1 ]

    r = buy_yes_no.evaluate(market)
    
    assert r is not None

    ret = r[0]
    gain = r[1]
    cost = r[2]
    shares = r[3]

    assert shares == 5
    assert cost == 4
    assert round(ret, 2) == .23
    assert round(gain, 2) == 1
コード例 #6
0
def load(path):
    raw = json.loads(open(path).read())
    markets = []
    for r in raw:
        m = Market(r['name'], r['id'], r['url'], r['type'])
        if('contracts' in r):
            for x in r['contracts'].keys():
                rc = r['contracts'][x]

                c = Contract(x, rc['name'], rc['url'])

                for z in rc['buy_yes_offers']:
                    o = Offer(c, 'buy_yes', z['price'], z['shares'])
                    c.long_offers.append(o)
                for z in rc['buy_no_offers']:
                    o = Offer(c, 'buy_no', z['price'], z['shares'])
                    c.short_offers.append(o)

                c.long_offers=sorted(c.long_offers, key=lambda x: x.price)
                c.short_offers=sorted(c.short_offers, key=lambda x: x.price)
                m.contracts.append(c)
            markets.append(m)
    return markets