public void Stats() { double _perc_gain2 = 0; for (int i = 0; i < ops_tot; i++) { Position pos = posdb.ClosedPositions.ElementAt(i); int q = pos.Quantity; double open = pos.Title.Close[pos.TOpen]; double close = pos.Title.Close[pos.TClose]; double investment = q * open; double raw_gain = q * (close - open); double _commission = CalculateCommission(investment) + CalculateCommission(q * close); double _taxes = Tax(raw_gain); double gain = raw_gain - _commission - _taxes; double _perc_gain = gain / investment; total_investment += investment; total_gain += gain; taxes += _taxes; commission += _commission; delta_t += pos.Delta_t; perc_gain += _perc_gain; _perc_gain2 += Math.Pow(_perc_gain, 2); if (gain > 0) { ops_good++; ops_good_gain += gain; } else { ops_bad++; ops_bad_gain -= gain; } double threshold = TI.SimulationSigmaALL(pos.Delta_t); if (_perc_gain > threshold) { ops_very_good++; ops_very_good_gain += gain; } else if (_perc_gain < (-1 * threshold)) { ops_very_bad++; ops_very_bad_gain -= gain; } } if (ops_tot != 0) { delta_t /= ops_tot; perc_gain /= ops_tot; _perc_gain2 /= ops_tot; perc_gain_sigma = Math.Sqrt(_perc_gain2 - Math.Pow(perc_gain, 2)); } if (ops_bad != 0) { ops_bad_gain /= ops_bad; } if (ops_good != 0) { ops_good_gain /= ops_good; } if (ops_very_bad != 0) { ops_very_bad_gain /= ops_very_bad; } if (ops_very_good != 0) { ops_very_good_gain /= ops_very_good; } }