private void btnSynthTest_Click(object sender, EventArgs e) { var dlg = new SynthCurxForm(tbFolder.Text, int.Parse(tbInterval.Text), int.Parse(tbDataCount.Text), dpStartDate.Value); dlg.ShowDialog(); return; /*var index = "cad0.38769 eur0.33699# jpy0.1322 gbp0.0838# chf0.0302 aud0.0248# nzd0.0042#"; * var ci = new CurrencyIndexInfo(index); * * var startDate = new DateTime(2010, 1, 5); * var endDate = new DateTime(2010, 10, 14); * var priceZeroAsk = new decimal[ci.pairs.Length]; * var priceZeroBid = new decimal[ci.pairs.Length]; * * var currencyStream = new Dictionary<string, CurrencyStream>(); * // открыть потоки чтения * foreach (var curName in ci.pairs) * { * currencyStream.Add(curName, new CurrencyStream(curName, * tbFolder.Text)); * } * var streamOut = new StreamWriter("d:\\portfolio.quote"); * * try * { * for (var time = startDate; time <= endDate; time = time.AddMinutes(1)) * { * var sumAsk = 0M; * var sumBid = 0M; * for (var i = 0; i < ci.pairs.Length; i++) * { * var curName = ci.pairs[i]; * var quote = currencyStream[curName].GetQuote(time); * if (!quote.HasValue) continue; * if (priceZeroAsk[i] == 0) priceZeroAsk[i] = quote.Value.ask; * if (priceZeroBid[i] == 0) priceZeroBid[i] = quote.Value.bid; * * decimal deltaAsk; * if (ci.weights[i] < 0) * deltaAsk = (-ci.weights[i] / priceZeroAsk[i]) * (priceZeroAsk[i] - quote.Value.ask); * else * deltaAsk = ci.weights[i] * (quote.Value.ask - priceZeroAsk[i]); * sumAsk += deltaAsk; * * decimal deltaBid; * if (ci.weights[i] < 0) * deltaBid = (-ci.weights[i] / priceZeroBid[i]) * (priceZeroBid[i] - quote.Value.bid); * else * deltaBid = ci.weights[i] * (quote.Value.bid - priceZeroBid[i]); * sumBid += deltaBid; * } * var line = string.Format("{0};{1};{2}", * sumBid, sumAsk, * time.ToString("dd.MM.yyyy HH:mm:ss")); * streamOut.WriteLine(line); * } * } * finally * { * streamOut.Close(); * // закрыть потоки * foreach (var curName in ci.pairs) * { * currencyStream[curName].CloseStream(); * } * }*/ }
private void btnSynthTest_Click(object sender, EventArgs e) { var dlg = new SynthCurxForm(tbFolder.Text, int.Parse(tbInterval.Text), int.Parse(tbDataCount.Text), dpStartDate.Value); dlg.ShowDialog(); return; /*var index = "cad0.38769 eur0.33699# jpy0.1322 gbp0.0838# chf0.0302 aud0.0248# nzd0.0042#"; var ci = new CurrencyIndexInfo(index); var startDate = new DateTime(2010, 1, 5); var endDate = new DateTime(2010, 10, 14); var priceZeroAsk = new decimal[ci.pairs.Length]; var priceZeroBid = new decimal[ci.pairs.Length]; var currencyStream = new Dictionary<string, CurrencyStream>(); // открыть потоки чтения foreach (var curName in ci.pairs) { currencyStream.Add(curName, new CurrencyStream(curName, tbFolder.Text)); } var streamOut = new StreamWriter("d:\\portfolio.quote"); try { for (var time = startDate; time <= endDate; time = time.AddMinutes(1)) { var sumAsk = 0M; var sumBid = 0M; for (var i = 0; i < ci.pairs.Length; i++) { var curName = ci.pairs[i]; var quote = currencyStream[curName].GetQuote(time); if (!quote.HasValue) continue; if (priceZeroAsk[i] == 0) priceZeroAsk[i] = quote.Value.ask; if (priceZeroBid[i] == 0) priceZeroBid[i] = quote.Value.bid; decimal deltaAsk; if (ci.weights[i] < 0) deltaAsk = (-ci.weights[i] / priceZeroAsk[i]) * (priceZeroAsk[i] - quote.Value.ask); else deltaAsk = ci.weights[i] * (quote.Value.ask - priceZeroAsk[i]); sumAsk += deltaAsk; decimal deltaBid; if (ci.weights[i] < 0) deltaBid = (-ci.weights[i] / priceZeroBid[i]) * (priceZeroBid[i] - quote.Value.bid); else deltaBid = ci.weights[i] * (quote.Value.bid - priceZeroBid[i]); sumBid += deltaBid; } var line = string.Format("{0};{1};{2}", sumBid, sumAsk, time.ToString("dd.MM.yyyy HH:mm:ss")); streamOut.WriteLine(line); } } finally { streamOut.Close(); // закрыть потоки foreach (var curName in ci.pairs) { currencyStream[curName].CloseStream(); } }*/ }