public void TestTradeCollectionWeightedMean() { TradeCollection trades = new TradeCollection(); TimeSpan span1 = new TimeSpan(0, 5, 0); // 5 minutes TimeSpan span2 = new TimeSpan(0, 10, 0); // 10 minutes TimeSpan span3 = new TimeSpan(0, 20, 0); // 20 minutes float vwp; // no trades => no result vwp = trades.GetVolumeWeightedPrice(new TimeSpan(0, 15, 0)); Assert.AreEqual(float.NaN, vwp); int qty1 = 10; float price1 = 100; int qty2 = 5; float price2 = 50; // Mean based on these trades.Add(new Trade(DateTime.Now.Subtract(span1), qty1, TRADE_SIGN.Sell, price1)); trades.Add(new Trade(DateTime.Now.Subtract(span2), qty2, TRADE_SIGN.Buy, price2)); trades.Add(new Trade(DateTime.Now.Subtract(span2), qty2, TRADE_SIGN.Sell, price2)); // This must be excluded trades.Add(new Trade(DateTime.Now.Subtract(span3), 100, TRADE_SIGN.Sell, 1000)); vwp = trades.GetVolumeWeightedPrice(new TimeSpan(0, 15, 0)); Assert.AreEqual((qty1 * price1 + qty2 * price2 * 2) / (qty1 + qty2 * 2), vwp); }
public void TestTradeCollectionWeightedMean() { TradeCollection trades = new TradeCollection(); TimeSpan span1 = new TimeSpan(0, 5, 0); // 5 minutes TimeSpan span2 = new TimeSpan(0, 10, 0); // 10 minutes TimeSpan span3 = new TimeSpan(0, 20, 0); // 20 minutes float vwp; // no trades => no result vwp = trades.GetVolumeWeightedPrice(new TimeSpan(0, 15, 0)); Assert.AreEqual(float.NaN, vwp); int qty1 = 10; float price1 = 100; int qty2 = 5; float price2 = 50; // Mean based on these trades.Add(new Trade(DateTime.Now.Subtract(span1), qty1, TRADE_SIGN.Sell, price1)); trades.Add(new Trade(DateTime.Now.Subtract(span2), qty2, TRADE_SIGN.Buy, price2)); trades.Add(new Trade(DateTime.Now.Subtract(span2), qty2, TRADE_SIGN.Sell, price2)); // This must be excluded trades.Add(new Trade(DateTime.Now.Subtract(span3), 100, TRADE_SIGN.Sell, 1000)); vwp = trades.GetVolumeWeightedPrice(new TimeSpan(0, 15, 0)); Assert.AreEqual((qty1 * price1 + qty2 * price2 * 2) / (qty1 + qty2 * 2), vwp); }
public void TestTradeCollectionAddTrades() { // Collection Order Test TradeCollection trades = new TradeCollection(); Trade trade1 = new Trade(new DateTime(2015, 10, 2), 1, TRADE_SIGN.Buy, 100); Trade trade2 = new Trade(new DateTime(2015, 10, 3), 1, TRADE_SIGN.Buy, 100); Trade trade3 = new Trade(new DateTime(2015, 10, 1), 1, TRADE_SIGN.Buy, 100); Trade trade4 = new Trade(new DateTime(2015, 10, 4), 1, TRADE_SIGN.Buy, 100); Trade trade5 = new Trade(new DateTime(2015, 09, 1), 1, TRADE_SIGN.Buy, 100); trades.Add(trade1); trades.Add(trade2); trades.Add(trade3); trades.Add(trade4); trades.Add(trade5); Assert.AreEqual(5, trades.Count); Assert.AreSame(trades.ElementAt(0), trade4); Assert.AreSame(trades.ElementAt(1), trade2); Assert.AreSame(trades.ElementAt(2), trade1); Assert.AreSame(trades.ElementAt(3), trade3); Assert.AreSame(trades.ElementAt(4), trade5); }
public void TestTradeCollectionAddTrades() { // Collection Order Test TradeCollection trades = new TradeCollection(); Trade trade1 = new Trade(new DateTime(2015, 10, 2), 1, TRADE_SIGN.Buy, 100); Trade trade2 = new Trade(new DateTime(2015, 10, 3), 1, TRADE_SIGN.Buy, 100); Trade trade3 = new Trade(new DateTime(2015, 10, 1), 1, TRADE_SIGN.Buy, 100); Trade trade4 = new Trade(new DateTime(2015, 10, 4), 1, TRADE_SIGN.Buy, 100); Trade trade5 = new Trade(new DateTime(2015, 09, 1), 1, TRADE_SIGN.Buy, 100); trades.Add(trade1); trades.Add(trade2); trades.Add(trade3); trades.Add(trade4); trades.Add(trade5); Assert.AreEqual(5, trades.Count); Assert.AreSame(trades.ElementAt(0), trade4); Assert.AreSame(trades.ElementAt(1), trade2); Assert.AreSame(trades.ElementAt(2), trade1); Assert.AreSame(trades.ElementAt(3), trade3); Assert.AreSame(trades.ElementAt(4), trade5); }
// Standard constructor protected GenericStock(string Symbol, float LastDividend, float ParValue) { m_Trades = new TradeCollection(); m_LastPrice = float.NaN; m_Symbol = Symbol; m_LastDividend = LastDividend; m_ParValue = ParValue; }
public MainViewModel() { OpenFileCommand = new OpenFileCommand(this); FilterBestTradesCommand = new FilterBestTradesCommand(this); FilterWorstTradesCommand = new FilterWorstTradesCommand(this); FilterClearCommand = new FilterClearCommand(this); Trades = new TradeCollection(); Filters = new ObservableCollection <FilterViewModel>(); Title = "Testing Results Analyzer"; InitFilters(); FilterMax = "10"; }
public void CalculateSummary(TradeCollection trades) { _trades = trades; var includedTrades = trades.Where(x => Filter.IsIncluded(x)); var excludedTrades = trades.Where(x => !Filter.IsIncluded(x)); CalculateSummary(includedTrades, PerformanceData); CalculateSummary(excludedTrades, ExcludedPerformanceData); var basicStrategyPerformance = new PerformanceData(); CalculateSummary(trades, basicStrategyPerformance); CalculateComparisonSummary(basicStrategyPerformance, PerformanceData); }
public virtual TradeCollection GetTradesToday(PerformanceUnit unit) { TradeCollection tdtoday = null; Dictionary <object, TradeCollection> dt; DateTime now = Time[0].Date; if (IsLiveTrading()) { // foreach(Trade td in SystemPerformance.RealTimeTrades) { // capTotal = capTotal + td.Entry.Price * td.Entry.Quantity; // } dt = SystemPerformance.RealTimeTrades.ByDay; // foreach(var item in dt){ // Print(string.Format("ByDayRT: k={0}, v={1}", item.Key, item.Value)); // } } else { // foreach(Trade td in SystemPerformance.AllTrades) { // capTotal = capTotal + td.Entry.Price * td.Entry.Quantity; // } dt = SystemPerformance.AllTrades.ByDay; // foreach(var item in dt){ // Print(string.Format("ByDay: k={0}, ktype={1}, v={2}, tdtoday={3}", // item.Key, item.Key.GetType(), item.Value, tdtoday)); // } } if (dt != null) { dt.TryGetValue(now, out tdtoday); } if (tdtoday != null) { Print(string.Format("ByDay tdtoday: now={0}, tdtoday={1}, count={2}, TradesCount={3}", now, tdtoday, tdtoday.Count, tdtoday.TradesCount)); } return(tdtoday); }
void OnEntryPositions(IndicatorEventArgs e) { TradeCollection tc = GetTradesToday(PerformanceUnit.Currency); if (tc != null && tc.TradesCount > 0) { // Print(string.Format("{0}:TotalQuantity={1}, NetProfit={2}", Time[0].Date, tc.TradesPerformance.TotalQuantity, tc.TradesPerformance.NetProfit)); return; } LongBip = giSQRSpd.LongBip; ShortBip = giSQRSpd.ShortBip; MidLongBip = giSQRSpd.MidLongBip; MidShortBip = giSQRSpd.MidShortBip; int q_Ln = GetTradeQuantity(LongBip, -1); int q_St = GetTradeQuantity(ShortBip, -1); int q_midLn = GetTradeQuantity(MidLongBip, -1); int q_midSt = GetTradeQuantity(MidShortBip, -1); // Print(String.Format("{0}:OnTradeBySQRSpd Entry Bip={1}: q_Ln={2}, q_St={3}, q_midLn={4}, q_midSt={5}", // CurrentBars[BarsInProgress], BarsInProgress, // q_Ln, q_St, q_midLn, q_midSt)); if (LongBip >= 0 && LongBip <= 8 && ShortBip >= 0 && ShortBip <= 8 && MidLongBip >= 0 && MidLongBip <= 8 && MidShortBip >= 0 && MidShortBip <= 8 && q_Ln > 0 && q_St > 0 && q_midLn > 0 && q_midSt > 0) { EnSQRSpdMA = giSQRSpd.MiddleBB[0]; EnterLong(ShortBip, q_St, SigName_EnSt); EnterLong(LongBip, q_Ln, SigName_EnLn); //EnterLong(MidLongBip, q_midLn, SigName_EnMidLn); //EnterLong(MidShortBip, q_midSt, SigName_EnMidSt); } //EnterLong(BipIWMSt, q_iwmSt, "GIEnIWMSt"); }
// Standard constructor protected GenericStock(string Symbol, float LastDividend, float ParValue) { m_Trades = new TradeCollection(); m_LastPrice = float.NaN; m_Symbol = Symbol; m_LastDividend = LastDividend; m_ParValue = ParValue; }