Ejemplo n.º 1
0
def DeterminLotNumber(modeladmin,request,queryset):
	for p in queryset:
		markets = Market.objects.filter(product = p)
		for m in markets:
			all_securities = Security.objects.filter(market__product = p)
			r = 1
			for s in all_securities:
				r = lcm(r,s.selling_price)

			try:
				lmsr = LMSR.objects.get(product = p)
			except LMSR.DoesNotExist:
				lmsr = LMSR(product = p)

			lmsr.P0 = r
			lmsr.save()
			start_price = [round(lmsr.P0/p.security_number,2)] * p.security_number
			amount = [0] * p.security_number
			securityprice = SecurityPrice.objects.get(market = m)
			securityprice.price = start_price
			securityprice.amount = amount
			securityprice.save()
			data = start_price
			data.insert(0,int(time.mktime(m.open_time.timetuple())) * 1000)
			pricehistory = PriceHistory.objects.get(product = p,is_open = True)
			pricehistory.data = [data]
			pricehistory.save()
			securities = Security.objects.filter(market = m)
			for s in securities:
				s.lot = r / s.selling_price
				s.save()

		p.lot_setting = True
		p.save()
Ejemplo n.º 2
0
def DeterminLotNumber(modeladmin, request, queryset):
    for p in queryset:
        markets = Market.objects.filter(product=p)
        for m in markets:
            all_securities = Security.objects.filter(market__product=p)
            r = 1
            for s in all_securities:
                r = lcm(r, s.selling_price)

            try:
                lmsr = LMSR.objects.get(product=p)
            except LMSR.DoesNotExist:
                lmsr = LMSR(product=p)

            lmsr.P0 = r
            lmsr.save()
            start_price = [round(lmsr.P0 / p.security_number, 2)
                           ] * p.security_number
            amount = [0] * p.security_number
            securityprice = SecurityPrice.objects.get(market=m)
            securityprice.price = start_price
            securityprice.amount = amount
            securityprice.save()
            data = start_price
            data.insert(0, int(time.mktime(m.open_time.timetuple())) * 1000)
            pricehistory = PriceHistory.objects.get(product=p, is_open=True)
            pricehistory.data = [data]
            pricehistory.save()
            securities = Security.objects.filter(market=m)
            for s in securities:
                s.lot = r / s.selling_price
                s.save()

        p.lot_setting = True
        p.save()
Ejemplo n.º 3
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()
Ejemplo n.º 4
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()