Ejemplo n.º 1
0
	def __init__(self, api, secret, saved=None, n=26):
		self.account = account(api, secret)
		self.balances = np.array([self.account.balances[c] if c in self.account.balances else 0.0 for c in [RISKLESS] + QUOTES + CURRENCIES])

		

		if saved is not None:
			try:
				with open(saved, 'rb') as file:
					loaded = pickle.load(file)
					self.manager = loaded.manager
					self.prices = loaded.prices
					self.returns = loaded.returns
					self.update_times = loaded.update_times
					self.portfolio = np.array(loaded.portfolio)
					return

			except FileNotFoundError:
				pass

		#get the portfolio...
		self.manager = MAMRPortfolioManager(len(CURRENCIES) + len(QUOTES) + 1, 4.105, 9.5, 1000, 0.0, n)
		

		from data.get_candles_spot import main as get_candles
		get_candles()

		

		price_changes = []
		times = []
		self.prices = []
		
		for candle in candleLoader(DATABASE):
			#consider markets trading against BTC, so we need to invert the USDT price
			self.prices.append(np.array([1] + [candle[currency + 'USDT_OPEN'] for currency in QUOTES + CURRENCIES]))
			if len(self.prices) == 1:
				continue
			else:
				price_changes.append(self.prices[-1] / self.prices[-2])
				times.append(candle['open_time'])

		for change, time in zip(price_changes[-n:], times[-n:]):
			self.manager.update(time, change)


		self.returns = price_changes
		self.update_times = times
		self.portfolio = self.account.get_portfolio_weighted(['USDT'] + QUOTES + CURRENCIES)
		
		self.manager.portfolio = np.array(self.portfolio)
		self.prices.append(np.array([1.05 ** (0.5 / 365)] + [np.mean(market.prices([a + 'USDT' for a in QUOTES + CURRENCIES])[b + 'USDT']) for b in QUOTES + CURRENCIES]))
Ejemplo n.º 2
0
def main():
	#get all the candles and calculate the price changes
	price_changes = []
	prices = []
	times = []

	for candle in candleLoader(DATABASE):
		#consider markets trading against BTC, so we need to invert the USDT price
		prices.append(np.array([1] + [candle[currency + 'USDT_OPEN'] for currency in CURRENCIES]))
		if len(prices) == 1:
			continue
		else:
			price_changes.append(prices[-1] / prices[-2])
			price_changes[-1][0] = 1.05 ** (0.5 / 365)
			times.append(candle['open_time'])

	#manager = MAMRPortfolioManager(len(CURRENCIES) + 1, 11.75, 371, 995, 0.001, 23)
	#manager = MAMRPortfolioManager(len(CURRENCIES) + 1, 4.105, 9.5, 1000, 0.00075, 26)
	manager = MAMRPortfolioManager(len(CURRENCIES) + 1, 4.105, 9.5, 1000, 0.000, 26)
	#manager = MAMRPortfolioManager(len(CURRENCIES) + 1, 50, 50, 60, 0.000, 26)

	for change, time in zip(price_changes, times):
		manager.update(time, change)


	print(manager.value)
	
	
	plt.figure(0)



	plt.plot([datetime.datetime.fromtimestamp(time / 1000) for time in times], np.array(manager.values[1:]), label='MAMR Portfolio Value')
	plt.plot([datetime.datetime.fromtimestamp(time / 1000) for time in times], [p[1]/prices[0][1] for p in prices[1:]], label='BTC Return')
	plt.yscale('log')
	plt.ylabel('Return')
	plt.title('MAMR 12 hour updates, 0.001 Transaction Fee')
	plt.legend()


	plt.figure(1)

	for i, currency in enumerate(['USDT'] + CURRENCIES):
		plt.plot([datetime.datetime.fromtimestamp(time / 1000) for time in times], [p[i] for p in manager.portfolios[1:]], label=currency)
	plt.legend()

	plt.show()
def main():
    #get all the candles and calculate the price changes
    price_changes = []
    prices = []
    times = []
    funding_rates = []

    for candle in candleLoader(DATABASE):
        funding_rates.append([
            candle[currency + 'USDT_funding_rate'] for currency in CURRENCIES
        ])
        prices.append(
            np.array(
                [candle[currency + 'USDT_open'] for currency in CURRENCIES]))
        if len(prices) == 1:
            continue
        else:
            price_changes.append(prices[-1] / prices[-2])
            times.append(candle['open_time'])

    manager = PAMRPortfolioManager(len(CURRENCIES), 0, 200, 0.0000, 1)
    for i, (change, time,
            funding_rate) in enumerate(zip(price_changes, times,
                                           funding_rates)):
        print((times[-1] - time) / (1000 * 60 * 30))

        if i % 16 == 0:
            manager.update(time, change, np.array(funding_rate))
            #manager.update(time, change, np.zeros(len(CURRENCIES)))

        else:
            manager.update(time, change, np.zeros(len(CURRENCIES)))
    plt.figure(0)

    plt.plot([datetime.datetime.fromtimestamp(time / 1000) for time in times],
             manager.values[1:])
    plt.plot([datetime.datetime.fromtimestamp(time / 1000) for time in times],
             [p[1] / prices[0][1] for p in prices[1:]])
    plt.yscale('log')
    plt.figure(1)

    for i, currency in enumerate(CURRENCIES):
        plt.plot([p[i] for p in manager.portfolios], label=currency)
    plt.legend()

    plt.show()
Ejemplo n.º 4
0
def main():
	#get all the candles and calculate the price changes
	price_changes = []
	prices = []
	times = []

	for candle in candleLoader(DATABASE):
		#consider markets trading against BTC, so we need to invert the USDT price
		prices.append(np.array([1 / candle['BTCUSDT_OPEN'], 1] + [candle[currency + 'BTC_OPEN'] for currency in CURRENCIES]))
		if len(prices) == 1:
			continue
		else:
			price_changes.append(prices[-1] / prices[-2])
			times.append(candle['open_time'])

	manager = PAMRPortfolioManager(len(CURRENCIES) + 2, 0.99, 4, 0.001)

	for i, (change, time) in enumerate(zip(price_changes, times)):
		print((times[-1] - time) / (1000 * 60 * 30))		
		manager.update(time, change)
	plt.figure(0)



	plt.plot([datetime.datetime.fromtimestamp(time / 1000) for time in times], np.array(manager.values[1:]) / np.array([p[0]/prices[0][0] for p in prices[1:]]), label='PAMR Portfolio Value')
	plt.plot([datetime.datetime.fromtimestamp(time / 1000) for time in times], [prices[0][0]/p[0] for p in prices[1:]], label='BTC Return')
	plt.yscale('log')
	plt.ylabel('Return')
	plt.title('PAMR Daily Updates, 0.001 Transaction Fee')
	plt.legend()


	plt.figure(1)

	for i, currency in enumerate(['USDT', 'BTC'] + CURRENCIES):
		print(currency)
		plt.plot([p[i] for p in manager.portfolios], label=currency)
	plt.legend()

	plt.show()