public void MultipleAccount() { // setup defaults for 1st and 2nd accounts and positions string sym = "TST"; string a1 = "account1"; string a2 = "account2"; int s1 = 300; int s2 = 500; decimal p = 100m; // create position tracker PositionTracker pt = new PositionTracker(); // set initial position in 1st account pt.Adjust(new PositionImpl(sym, p, s1, 0, a1)); // set initial position in 2nd account pt.Adjust(new PositionImpl(sym, p, s2, 0, a2)); // verify I can query default account and it's correct Assert.AreEqual(s1, pt[sym].Size); // change default to 2nd account pt.DefaultAccount = a2; // verify I can query default and it's correct Assert.AreEqual(s2, pt[sym].Size); // verify I can query 1st account and correct Assert.AreEqual(s1, pt[sym, a1].Size); // verify I can query 2nd account and correct Assert.AreEqual(s2, pt[sym, a2].Size); // get fill in sym for 1st account TradeImpl f = new TradeImpl(sym, p, s1); f.Account = a1; pt.Adjust(f); // get fill in sym for 2nd account TradeImpl f2 = new TradeImpl(sym, p, s2); f2.Account = a2; pt.Adjust(f2); // verify that I can querry 1st account and correct Assert.AreEqual(s1 * 2, pt[sym, a1].Size); // verify I can query 2nd account and correct Assert.AreEqual(s2 * 2, pt[sym, a2].Size); // reset pt.Clear(); // ensure I can query first and second account and get flat symbols Assert.AreEqual(0, pt[sym].Size); Assert.AreEqual(0, pt[sym, a1].Size); Assert.AreEqual(0, pt[sym, a2].Size); Assert.IsTrue(pt[sym, a1].isFlat); Assert.IsTrue(pt[sym, a2].isFlat); Assert.IsTrue(pt[sym].isFlat); Assert.AreEqual(string.Empty, pt.DefaultAccount); }
public override void Reset() //对于新的一天来计算的时候要进行重置 { // enable prompting of system parameters to user, // so they do not have to recompile to change things ParamPrompt.Popup(this, true, _black); Int32 numOfInterval = 1; BarInterval[] intervaltypes = new BarInterval[numOfInterval]; Int32[] intervalValues = new Int32[numOfInterval]; for (Int32 i = 0; i < numOfInterval; i++) { intervaltypes[i] = BarType; intervalValues[i] = NumItemPerBar; } _blt = new BarListTracker(intervalValues, intervaltypes); _blt.GotNewBar += new SymBarIntervalDelegate(blt_GotNewBar); GenericParamUpdateHelper.updateParam(this, GenericParameter, false); Hashtable ShortSMAInputParamTmp = new Hashtable(); //对于SMA indicator进行更新,用今天重新计算的SMA,而不用昨天 Hashtable LongSMAInputParamTmp = new Hashtable(); ShortSMAInputParamTmp["lookbackperiod"] = _shortbarsback; LongSMAInputParamTmp["lookbackperiod"] = _shortbarsback + _incrementbarsback; ShortSMAInputParamTmp["minmumsignallength"] = _shortbarsback; LongSMAInputParamTmp["minmumsignallength"] = _shortbarsback + _incrementbarsback; _ShortSMAFromATSGlobalIndicator = new ATSGlobalIndicatorPersonal.SMA(); _LongSMAFromATSGlobalIndicator = new ATSGlobalIndicatorPersonal.SMA(); _ShortSMAFromATSGlobalIndicator.Param = ShortSMAInputParamTmp; _LongSMAFromATSGlobalIndicator.Param = LongSMAInputParamTmp; _ShortSMAFromATSGlobalIndicator.Initializatin(); _LongSMAFromATSGlobalIndicator.Initializatin(); // reset the parameters of ATR Hashtable ATRInputParamTmp = new Hashtable(); ATRInputParamTmp["lookbackperiod"] = _shortbarsback; ATRInputParamTmp["minmumsignallength"] = 14; _ATRFromATSGlobalIndicator = new ATSGlobalIndicatorPersonal.ATR(); _ATRFromATSGlobalIndicator.Param = ATRInputParamTmp; _ATRFromATSGlobalIndicator.Initializatin(); //--------------------------------------------------------- _isShutDown = false; TotalProfit = 0m; _pt.Clear(); if (_shortbarsback != 34 || _incrementbarsback != 84) { Console.WriteLine("yo hey"); } }
/// <summary> /// Reset the respose system /// </summary> public override void Reset() { // enable prompting of system parameters to user, // so they do not have to recompile to change things ParamPrompt.Popup(this, true, _black); // Initialize "_blt", the bar list tracker Initialize_blt(); // Update generic parameters GenericParamUpdateHelper.updateParam(this, GenericParameter, false); #if EXTERNAL_PARAM //传递优化参数或系统参数 GenericParamUpdateHelper.updateParam(this, GenericParameter, false); if (File.Exists(SMAExternalParam)) { DataTable paramTableInput = null; StreamReader sr = new StreamReader(SMAExternalParam, Encoding.GetEncoding("GB18030")); paramTableInput = CsvParser.Parse(sr, true); sr.Close(); foreach (DataRow dr in paramTableInput.Rows) { if (paramTableInput.Columns.Contains("key") && paramTableInput.Columns.Contains("value")) { string tmpKey = dr["key"].ToString(); string tmpValue = dr["value"].ToString(); if (tmpKey == "genericparam") { GenericParameter = tmpValue; } //传递外部参数 GenericParamUpdateHelper.updateParam(this, GenericParameter, false); } } } #endif //Initialize_Indicators(); // set to false to indicate the system is on _isShutDown = false; // clear total profit TotalProfit = 0m; // Clear all position _pt.Clear(); ResetIndicators(); LocalReset(); }
/// <summary> /// Reset the respose system /// </summary> public override void Reset() { // enable prompting of system parameters to user, // so they do not have to recompile to change things ParamPrompt.Popup(this, true, _black); // Initialize "_blt", the bar list tracker Initialize_blt(); // Update generic parameters GenericParamUpdateHelper.updateParam(this, GenericParameter, false); Initialize_Indicators(); // set to false to indicate the system is on _isShutDown = false; // clear total profit _totalprofit = 0m; // Clear all position _pt.Clear(); }
public void FillBidAskPartial() { PapertradeTracker ptt = new PapertradeTracker(); PositionTracker pt = new PositionTracker(); ptt.UseBidAskFills = true; ptt.GotFillEvent += new FillDelegate(pt.GotFill); foreach (bool side in new bool[] { true, false }) { pt.Clear(); Order o = new MarketOrder("IBM", side, 1000); int size = o.size; o.id = 1; ptt.sendorder(o); Tick k = TickImpl.NewQuote("IBM", 100, 101, 400, 400, "", ""); ptt.newTick(k); // partial fill ptt.newTick(k); // partial fill ptt.newTick(k); // partial fill, completed Expect(pt["IBM"].Size, Is.EqualTo(size)); } }
public void MultipleAccount() { // setup defaults for 1st and 2nd accounts and positions string s = "TST"; ForexSecurity sym = new ForexSecurity(s); IAccount a1 = new SimAccount("account1"); a1.Securities.AddSecurity(sym); IAccount a2 = new SimAccount("account2"); a1.Securities.AddSecurity(sym); int s1 = 300; int s2 = 500; decimal p = 100m; // create position tracker PositionTracker pt = new PositionTracker(a1); // set initial position in 1st account pt.Adjust(new PositionImpl(sym, p, s1, 0, a1)); // set initial position in 2nd account pt.Adjust(new PositionImpl(sym, p, s2, 0, a2)); // verify I can query default account and it's correct Assert.Equal(s1, pt[sym].Size); // change default to 2nd account pt.DefaultAccount = a2; // verify I can query default and it's correct Assert.Equal(s2, pt[sym].Size); // verify I can query 1st account and correct Assert.Equal(s1, pt[sym, a1].Size); // verify I can query 2nd account and correct Assert.Equal(s2, pt[sym, a2].Size); // get fill in sym for 1st account TradeImpl f = new TradeImpl(sym.Name, p, s1); f.Account = a1; f.Security = sym; pt.Adjust(f); // get fill in sym for 2nd account TradeImpl f2 = new TradeImpl(sym.Name, p, s2); f2.Account = a2; f2.Security = sym; pt.Adjust(f2); // verify that I can querry 1st account and correct Assert.Equal(s1 * 2, pt[sym, a1].Size); // verify I can query 2nd account and correct Assert.Equal(s2 * 2, pt[sym, a2].Size); // reset pt.Clear(); // ensure I can query first and second account and get flat symbols Assert.Equal(0, pt[sym].Size); Assert.Equal(0, pt[sym, a1].Size); Assert.Equal(0, pt[sym, a2].Size); Assert.True(pt[sym, a1].IsFlat); Assert.True(pt[sym, a2].IsFlat); Assert.True(pt[sym].IsFlat); Assert.Equal(null, pt.DefaultAccount); }