Beispiel #1
0
def MarketMake(modeladmin,request,queryset):
	for p in queryset:
		market = Market(product = p, open_time = p.open_time, close_time = p.close_time,name = p.name, market_number = 1)
		market.save()
		pricehistory = PriceHistory(product = p, number = 1)
		pricehistory.save()
		securityprice = SecurityPrice(market = market)
		securityprice.save()
		for i in range(0,p.security_number):
			attributes = [""] * p.attribute_set.count()
			loop = True
			while loop:
				for att in p.attribute_set.all():
					rand = random.randint(0,(att.level_set.count()-1))
					level = att.level_set.get(number = rand)
					attributes[p.order[att.number]] = level.name
				try:
					test = Security.objects.get(market=market,attributes=attributes)
					attributes = [""] * p.attribute_set.count()
				except Security.DoesNotExist:
					name = ""
					for att_name in attributes:
						name = name + " " + att_name

					security = Security(market=market,number=i)
					security.attributes = attributes
					security.attribute_name = name
					security.save()
					loop = False
Beispiel #2
0
def MarketMake(modeladmin, request, queryset):
    for p in queryset:
        market = Market(product=p,
                        open_time=p.open_time,
                        close_time=p.close_time,
                        name=p.name,
                        market_number=1)
        market.save()
        pricehistory = PriceHistory(product=p, number=1)
        pricehistory.save()
        securityprice = SecurityPrice(market=market)
        securityprice.save()
        for i in range(0, p.security_number):
            attributes = [""] * p.attribute_set.count()
            loop = True
            while loop:
                for att in p.attribute_set.all():
                    rand = random.randint(0, (att.level_set.count() - 1))
                    level = att.level_set.get(number=rand)
                    attributes[p.order[att.number]] = level.name
                try:
                    test = Security.objects.get(market=market,
                                                attributes=attributes)
                    attributes = [""] * p.attribute_set.count()
                except Security.DoesNotExist:
                    name = ""
                    for att_name in attributes:
                        name = name + " " + att_name

                    security = Security(market=market, number=i)
                    security.attributes = attributes
                    security.attribute_name = name
                    security.save()
                    loop = False
Beispiel #3
0
def MaltipleMarketMake(modeladmin, request, queryset):
    for m in queryset:
        product = m.product
        MSP = SecurityPrice.objects.get(market=m)
        MPH = PriceHistory.objects.get(product=m.product, is_open=True)
        for i in range(2, (product.market_number + 1)):
            market = Market(product=product,
                            open_time=product.open_time,
                            close_time=product.close_time,
                            name=product.name,
                            market_number=i,
                            name_setting=True)
            market.save()
            securityprice = SecurityPrice(market=market,
                                          price=MSP.price,
                                          amount=MSP.amount)
            securityprice.save()
            pricehistory = PriceHistory(product=market.product,
                                        data=MPH.data,
                                        number=i)
            pricehistory.save()
            for security in m.security_set.all():
                new_security = Security(market=market,
                                        product_name=security.product_name,
                                        attributes=security.attributes,
                                        attribute_name=security.attribute_name,
                                        selling_price=security.selling_price,
                                        number=security.number)
                new_security.save()

        product.maltiple_market = True
        product.save()
        m.name_setting = True
        m.save()
Beispiel #4
0
def MaltipleMarketMake(modeladmin,request,queryset):
	for m in queryset:
		product = m.product
		MSP = SecurityPrice.objects.get(market = m)
		MPH = PriceHistory.objects.get(product = m.product, is_open = True)
		for i in range(2,(product.market_number+1)):
			market = Market(product = product, open_time = product.open_time, close_time = product.close_time,name = product.name, market_number = i,name_setting = True)
			market.save()
			securityprice = SecurityPrice(market = market,price = MSP.price, amount = MSP.amount)
			securityprice.save()
			pricehistory = PriceHistory(product = market.product,data = MPH.data, number = i)
			pricehistory.save()
			for security in m.security_set.all():
				new_security = Security(market=market,product_name=security.product_name,attributes = security.attributes,attribute_name = security.attribute_name,selling_price = security.selling_price,number=security.number)
				new_security.save()

		product.maltiple_market = True
		product.save()
		m.name_setting = True
		m.save()
Beispiel #5
0
def DeterminCostPrice(modeladmin,request,queryset):
	for p in queryset:
		stock = 100000.0 / (500 * (p.security_number + 1))
		first_market = Market.objects.filter(product = p).get(market_number = 1)	
		try:
			lmsr = LMSR.objects.get(product = p)
			player_number = Participation.objects.filter(market__product = p).count()
			if Market.objects.filter(product = p).count() == 1:
				if player_number >= 20:
					'''market make'''
					new_market = Market(product = p, open_time = p.open_time, close_time = p.close_time,name = p.name, market_number = 2,name_setting = True)
					new_market.save()
					new_securityprice = SecurityPrice(market = new_market,price = [], amount = [])
					new_securityprice.save()
					new_pricehistory = PriceHistory(product = p,data = [], number = 2)
					new_pricehistory.save()
					p.market_number = 2
					for security in first_market.security_set.all():
						new_security = Security(market=new_market,product_name=security.product_name,attributes = security.attributes,attribute_name = security.attribute_name,selling_price = security.selling_price,number=security.number,gross_margin = 500)
						new_security.save()

				elif player_number > 10:
					p.player_number = player_number
					lmsr.b = stock * p.player_number / math.log((1.0 - 1.0 / p.security_number)/(1.0 - 0.99))
					lmsr.save()
				else:
					pass

			elif Market.objects.filter(product = p).count() == 2:
			 	if player_number >= 40:
			 		'''market make'''
			 		new_market = Market(product = p, open_time = p.open_time, close_time = p.close_time,name = p.name, market_number = 3,name_setting = True)
					new_market.save()
					new_securityprice = SecurityPrice(market = new_market,price = [], amount = [])
					new_securityprice.save()
					new_pricehistory = PriceHistory(product = p,data = [], number = 3)
					new_pricehistory.save()
					p.market_number = 3
					for security in first_market.security_set.all():
						new_security = Security(market=new_market,product_name=security.product_name,attributes = security.attributes,attribute_name = security.attribute_name,selling_price = security.selling_price,number=security.number,gross_margin = 500)
						new_security.save()
			 	elif player_number > 21:
			 		p.player_number = player_number
					lmsr.b = stock * p.player_number / math.log((1.0 - 1.0 / p.security_number)/(1.0 - 0.99))
					lmsr.save()
				else:
					pass

			else:
				pass

		except LMSR.DoesNotExist:
			lmsr = LMSR(product = p)
			lmsr.P0 = 500
			lmsr.b = stock * p.player_number / math.log((1.0 - 1.0 / p.security_number)/(1.0 - 0.99))
			lmsr.save()
			securities = Security.objects.filter(market = first_market)
			for s in securities:
				s.gross_margin = 500
				s.save()

		markets = Market.objects.filter(product = p)
		markets.update(open_time = p.open_time)
		markets.update(close_time = p.close_time)
		start_price = [round(lmsr.P0/p.security_number,2)] * p.security_number
		amount = [0] * p.security_number
		start_rate = [round(1.0/p.security_number*0.5+0.5,2)] * p.security_number
		data = copy.copy(start_rate)
		data.insert(0,int(time.mktime(p.open_time.timetuple())) * 1000)
		ph = PriceHistory.objects.filter(product =p,is_open = True)
		ph.update(is_open = False)
		for m in markets:
			securityprice = SecurityPrice.objects.get(market = m)
			securityprice.price = start_price
			securityprice.amount = amount
			securityprice.sale_rate = start_rate
			securityprice.save()
			pricehistory = PriceHistory(product = p,data = [data], number = m.market_number,is_open = True)
			pricehistory.save()

		p.cost_setting = True
		p.save()
Beispiel #6
0
def DeterminCostPrice(modeladmin, request, queryset):
    for p in queryset:
        stock = 100000.0 / (500 * (p.security_number + 1))
        first_market = Market.objects.filter(product=p).get(market_number=1)
        try:
            lmsr = LMSR.objects.get(product=p)
            player_number = Participation.objects.filter(
                market__product=p).count()
            if Market.objects.filter(product=p).count() == 1:
                if player_number >= 20:
                    '''market make'''
                    new_market = Market(product=p,
                                        open_time=p.open_time,
                                        close_time=p.close_time,
                                        name=p.name,
                                        market_number=2,
                                        name_setting=True)
                    new_market.save()
                    new_securityprice = SecurityPrice(market=new_market,
                                                      price=[],
                                                      amount=[])
                    new_securityprice.save()
                    new_pricehistory = PriceHistory(product=p,
                                                    data=[],
                                                    number=2)
                    new_pricehistory.save()
                    p.market_number = 2
                    for security in first_market.security_set.all():
                        new_security = Security(
                            market=new_market,
                            product_name=security.product_name,
                            attributes=security.attributes,
                            attribute_name=security.attribute_name,
                            selling_price=security.selling_price,
                            number=security.number,
                            gross_margin=500)
                        new_security.save()

                elif player_number > 10:
                    p.player_number = player_number
                    lmsr.b = stock * p.player_number / math.log(
                        (1.0 - 1.0 / p.security_number) / (1.0 - 0.99))
                    lmsr.save()
                else:
                    pass

            elif Market.objects.filter(product=p).count() == 2:
                if player_number >= 40:
                    '''market make'''
                    new_market = Market(product=p,
                                        open_time=p.open_time,
                                        close_time=p.close_time,
                                        name=p.name,
                                        market_number=3,
                                        name_setting=True)
                    new_market.save()
                    new_securityprice = SecurityPrice(market=new_market,
                                                      price=[],
                                                      amount=[])
                    new_securityprice.save()
                    new_pricehistory = PriceHistory(product=p,
                                                    data=[],
                                                    number=3)
                    new_pricehistory.save()
                    p.market_number = 3
                    for security in first_market.security_set.all():
                        new_security = Security(
                            market=new_market,
                            product_name=security.product_name,
                            attributes=security.attributes,
                            attribute_name=security.attribute_name,
                            selling_price=security.selling_price,
                            number=security.number,
                            gross_margin=500)
                        new_security.save()
                elif player_number > 21:
                    p.player_number = player_number
                    lmsr.b = stock * p.player_number / math.log(
                        (1.0 - 1.0 / p.security_number) / (1.0 - 0.99))
                    lmsr.save()
                else:
                    pass

            else:
                pass

        except LMSR.DoesNotExist:
            lmsr = LMSR(product=p)
            lmsr.P0 = 500
            lmsr.b = stock * p.player_number / math.log(
                (1.0 - 1.0 / p.security_number) / (1.0 - 0.99))
            lmsr.save()
            securities = Security.objects.filter(market=first_market)
            for s in securities:
                s.gross_margin = 500
                s.save()

        markets = Market.objects.filter(product=p)
        markets.update(open_time=p.open_time)
        markets.update(close_time=p.close_time)
        start_price = [round(lmsr.P0 / p.security_number, 2)
                       ] * p.security_number
        amount = [0] * p.security_number
        start_rate = [round(1.0 / p.security_number * 0.5 + 0.5, 2)
                      ] * p.security_number
        data = copy.copy(start_rate)
        data.insert(0, int(time.mktime(p.open_time.timetuple())) * 1000)
        ph = PriceHistory.objects.filter(product=p, is_open=True)
        ph.update(is_open=False)
        for m in markets:
            securityprice = SecurityPrice.objects.get(market=m)
            securityprice.price = start_price
            securityprice.amount = amount
            securityprice.sale_rate = start_rate
            securityprice.save()
            pricehistory = PriceHistory(product=p,
                                        data=[data],
                                        number=m.market_number,
                                        is_open=True)
            pricehistory.save()

        p.cost_setting = True
        p.save()