Explorar el Código

market_stats: ranking, gap

raylu hace 1 semana
padre
commit
6adcbdabe8
Se han modificado 1 ficheros con 14 adiciones y 10 borrados
  1. 14 10
      market_stats.py

+ 14 - 10
market_stats.py

@@ -38,18 +38,22 @@ def analyze_markets(prices: typing.Sequence[market.RawPrice]) -> None:
 			continue
 		markets[price['MaterialTicker']].append(price)
 
-	ic1_lowest = 0
-	for mat_prices in markets.values():
-		(ic1_price,) = (price for price in mat_prices if price['ExchangeCode'] == 'IC1')
-		lowest_traded = 1_000_000
-		for price in mat_prices:
+	markets_with_trades = ranking = ic1_lowest = gap = 0
+	for mat, mat_prices in markets.items():
+		mat_prices.sort(key=lambda p: (p['Traded7D'] or 0))
+		if mat_prices[0]['Traded7D'] == None:
+			continue
+		markets_with_trades += 1
+		for index, price in enumerate(mat_prices):
 			if price['ExchangeCode'] == 'IC1':
-				continue
-			if price['Traded7D'] is None or price['Traded7D'] < lowest_traded:
-				lowest_traded = price['Traded7D'] or 0
-		if (ic1_price['Traded7D'] or 0) < lowest_traded:
+				break
+		else:
+			raise AssertionError('IC1 not found for ' + mat)
+		ranking += index
+		if index == 0:
 			ic1_lowest += 1
-	print('IC1 lowest', ic1_lowest, 'of', len(markets))
+			gap += (mat_prices[1]['Traded7D'] - mat_prices[0]['Traded7D']) / mat_prices[1]['Traded7D'] # type: ignore
+	print(f'IC1 ranking {ranking}, lowest in {ic1_lowest} of {markets_with_trades} markets, gap {gap:.2f}')
 
 if __name__ == '__main__':
 	main()