private void FillWatchArbitrage() { int currencyCount = m_a.Rows; int offset = 0; m_watchArbitrage.Clear(); for (int i = 0; i < currencyCount; i++) { for (int j = 0; j < currencyCount; j++) { int first = i; int second = j; if (first == second) continue; for (int k = 0; k < currencyCount; k++) { int third = k; if (third == first) continue; if (third == second) continue; ArbitrageCycle c = new ArbitrageCycle(DateTime.Now); c.Edges.Add(new DirectedEdge(first, second, offset++)); c.Edges.Add(new DirectedEdge(second, third, offset++)); c.Edges.Add(new DirectedEdge(third, first, offset++)); if (!m_watchArbitrage.Contains(c, ARBITRAGE_CYCLE_COMPARER)) { m_watchArbitrage.Add(c); } c = new ArbitrageCycle(DateTime.Now); c.Edges.Add(new DirectedEdge(first, third, offset++)); c.Edges.Add(new DirectedEdge(third, second, offset++)); c.Edges.Add(new DirectedEdge(second, first, offset++)); if (!m_watchArbitrage.Contains(c, ARBITRAGE_CYCLE_COMPARER)) { m_watchArbitrage.Add(c); } /* for (int l = 0; l < currencyCount; l++) { int forth = l; if (forth == first) continue; if (forth == second) continue; if (forth == third) continue; c = new ArbitrageCycle(DateTime.Now); c.Edges.Add(new DirectedEdge(first, second, offset++)); c.Edges.Add(new DirectedEdge(second, third, offset++)); c.Edges.Add(new DirectedEdge(third, forth, offset++)); c.Edges.Add(new DirectedEdge(forth, first, offset++)); if (!m_watchArbitrage.Contains(c, ARBITRAGE_CYCLE_COMPARER)) { m_watchArbitrage.Add(c); c = new ArbitrageCycle(DateTime.Now); c.Edges.Add(new DirectedEdge(first, second, offset++)); c.Edges.Add(new DirectedEdge(second, forth, offset++)); c.Edges.Add(new DirectedEdge(forth, third, offset++)); c.Edges.Add(new DirectedEdge(third, first, offset++)); if (!m_watchArbitrage.Contains(c, ARBITRAGE_CYCLE_COMPARER)) { m_watchArbitrage.Add(c); } c = new ArbitrageCycle(DateTime.Now); c.Edges.Add(new DirectedEdge(first, third, offset++)); c.Edges.Add(new DirectedEdge(third, forth, offset++)); c.Edges.Add(new DirectedEdge(forth, second, offset++)); c.Edges.Add(new DirectedEdge(second, first, offset++)); if (!m_watchArbitrage.Contains(c, ARBITRAGE_CYCLE_COMPARER)) { m_watchArbitrage.Add(c); } c = new ArbitrageCycle(DateTime.Now); c.Edges.Add(new DirectedEdge(first, third, offset++)); c.Edges.Add(new DirectedEdge(third, second, offset++)); c.Edges.Add(new DirectedEdge(second, forth, offset++)); c.Edges.Add(new DirectedEdge(forth, first, offset++)); if (!m_watchArbitrage.Contains(c, ARBITRAGE_CYCLE_COMPARER)) { m_watchArbitrage.Add(c); } c = new ArbitrageCycle(DateTime.Now); c.Edges.Add(new DirectedEdge(first, forth, offset++)); c.Edges.Add(new DirectedEdge(forth, third, offset++)); c.Edges.Add(new DirectedEdge(third, second, offset++)); c.Edges.Add(new DirectedEdge(second, first, offset++)); if (!m_watchArbitrage.Contains(c, ARBITRAGE_CYCLE_COMPARER)) { m_watchArbitrage.Add(c); } c = new ArbitrageCycle(DateTime.Now); c.Edges.Add(new DirectedEdge(first, forth, offset++)); c.Edges.Add(new DirectedEdge(forth, second, offset++)); c.Edges.Add(new DirectedEdge(second, third, offset++)); c.Edges.Add(new DirectedEdge(third, first, offset++)); if (!m_watchArbitrage.Contains(c, ARBITRAGE_CYCLE_COMPARER)) { m_watchArbitrage.Add(c); } } }*/ } } } }
private void CalculateShortestPath() { EdgeWeightedDigraph G = new EdgeWeightedDigraph(m_a.Rows); for (int v = 0; v < m_a.Rows; v++) { for (int w = 0; w < m_a.Cols; w++) { DirectedEdge e = new DirectedEdge(v, w, -Math.Log(m_a[v, w])); G.addEdge(e); } } BellmanFordSP spt = new BellmanFordSP(G, 0); if (spt.negativeCycleCount > 2) { double stake = 25000; double arbitrage = 1; ArbitrageCycle cycle = new ArbitrageCycle(m_currentTime); foreach (DirectedEdge e in spt.negativeCycle) { double weight = Math.Exp(-e.Weight); arbitrage *= weight; cycle.Edges.Add(new DirectedEdge(e.From, e.To, weight)); } if (!m_activeArbitrage.Contains(cycle, ARBITRAGE_CYCLE_COMPARER)) { m_activeArbitrage.Add(cycle); Status(cycle.Summary); Status("arbitrage(" + arbitrage + ") stake(" + stake + ") balance(" + (arbitrage * stake) + ") profit(" + Math.Round(((arbitrage * stake) / stake) - 1, 5) + "%)"); } } }