protected override void CalcBar() { if (!__bStart) { double dOpen = Bars.Open[0]; int iBaseTarget = CalculateBaseTarget(dOpen); __cSCBars = GetBars("TXO0", 'C', iBaseTarget); __cBCBars = GetBars("TXO0", 'C', iBaseTarget + 100); __cSPBars = GetBars("TXO0", 'P', iBaseTarget); __cBPBars = GetBars("TXO0", 'P', iBaseTarget - 100); } if (__cSCBars != null && __cSPBars != null && __cBCBars != null && __cBPBars != null) { __bStart = true; DateTime cDate = Bars.Time[0].AddSeconds(900); __cSCBars.MoveBars(cDate); __cBCBars.MoveBars(cDate); __cSPBars.MoveBars(cDate); __cBPBars.MoveBars(cDate); System.Console.Write("回測時間... {0}", cDate.ToString("yyyy-MM-dd")); System.Console.CursorLeft = 0; DateTime cTWIDate = cDate.Date; if (cTWIDate == __cSCBars.Time[0].Date && cTWIDate == __cSPBars.Time[0].Date && cTWIDate == __cBCBars.Time[0].Date && cTWIDate == __cBPBars.Time[0].Date) { double dCDiff = __cSCBars.Open[0] - __cBCBars.Open[0]; double dPDiff = __cSPBars.Open[0] - __cBPBars.Open[0]; if (dCDiff < this.GapPoint && dPDiff < this.GapPoint) { __bStart = false; return; } bool bCALL = false;//dCDiff >= dPDiff; if (__cReport == null) { __cReport = new Report(); __cReport.TWIOpen = Bars.Open[0]; __cReport.TWIClose = Bars.Close[0]; __cReport.OPriceB = (bCALL) ? __cBCBars.Close[0] : __cBPBars.Close[0]; __cReport.OPriceS = (bCALL) ? __cSCBars.Close[0] : __cSPBars.Close[0]; __cReport.SymbolB = (bCALL) ? __cBCBars.Request.Symbol : __cBPBars.Request.Symbol; __cReport.SymbolS = (bCALL) ? __cSCBars.Request.Symbol : __cSPBars.Request.Symbol; __cReport.TWITime = Bars.Time[0]; } if (cDate > GetExpiration((bCALL) ? __cSCBars.Request.Symbol : __cSPBars.Request.Symbol, cDate)) { //周選擇權到期日 __cReport.CPriceB = (bCALL) ? __cBCBars.Close[0] : __cBPBars.Close[0]; __cReport.CPriceS = (bCALL) ? __cSCBars.Close[0] : __cSPBars.Close[0]; __cList.Add(__cReport); __cReport = null; __bStart = false; } } } }
private void CreateOrderService(Instrument buyBars, Instrument sellBars) { if(__cOrderService1 != null) { __cOrderService1.Dispose(); } #if __SIMULATE __cOrderService1 = OrderManager.Manager.CreateOrderService("Netwings.OrderService;Netwings.SimulateOrderService"); #else __cOrderService1 = OrderManager.Manager.CreateOrderService("Netwings.OrderService;Netwings.RealOrderService"); SetPipeNumber(InputAttribute.GetParameters(__cOrderService1), 1, 1); #endif __cOrderService1.onResponse += OrderService_onResponse; __cOrderService1.SetInstrument(buyBars); __cOrderService1.SetDefaultContracts(1); __cOrderService1.Initialize(); IOrderCreator cOrderCreator1 = __cOrderService1 as IOrderCreator; __cBOrderO = cOrderCreator1.MarketThisBar(new SOrderParameters(Contracts.UserSpecified, "CALL_BUY", EOrderAction.Buy, OrderExit.FromAll)); __cBOrderC = cOrderCreator1.MarketThisBar(new SOrderParameters(Contracts.Default, "CALL_CLOSE", EOrderAction.Sell, OrderExit.FromAll)); if (log.IsInfoEnabled) log.Info("[CreateOrderService] Set BUY \"Netwings.OrderService;Netwings.SimulateOrderService\" and create..."); if(__cOrderService2 != null) { __cOrderService2.Dispose(); } #if __SIMULATE __cOrderService2 = OrderManager.Manager.CreateOrderService("Netwings.OrderService;Netwings.SimulateOrderService"); #else __cOrderService2 = OrderManager.Manager.CreateOrderService("Netwings.OrderService;Netwings.RealOrderService"); SetPipeNumber(InputAttribute.GetParameters(__cOrderService2), 1, 2); #endif __cOrderService2.onResponse += OrderService_onResponse; __cOrderService2.SetInstrument(sellBars); __cOrderService2.SetDefaultContracts(1); __cOrderService2.Initialize(); IOrderCreator cOrderCreator2 = __cOrderService2 as IOrderCreator; __cSOrderO = cOrderCreator2.MarketThisBar(new SOrderParameters(Contracts.UserSpecified, "PUT_SELL", EOrderAction.SellShort, OrderExit.FromAll)); __cSOrderC = cOrderCreator2.MarketThisBar(new SOrderParameters(Contracts.Default, "PUT_CLOSE", EOrderAction.BuyToCover, OrderExit.FromAll)); if (log.IsInfoEnabled) log.Info("[CreateOrderService] Set SELL \"Netwings.OrderService;Netwings.SimulateOrderService\" and create..."); }
protected override void Create() { #if __BACKTEST __cCloses = new List<double[]>(1024); __cCloses.Add(new double[] {0, 0, 0, 0}); #endif __cTWIBars = BarsOfData(3) as Instrument; __cSymbolIds = new Dictionary<string, int>(32); //讀取未平倉量 __cOpenInterest = new OpenInterest(this, 2); __cOpenInterest.Initialize(); //讀取三大法人多空與未平倉量 __cForeignInvestment = new ForeignInvestment(this, 2); __cForeignInvestment.Initialize(); //建立歷史波動率指標 __cHistoryV = new HistoryVolatility(this, 2); //設定計時器(定期抓未平倉量) __cTimer = new Timer(1000); __cTimer.AutoReset = false; __cTimer.Elapsed += Timer_onElapsed; __cTimer.Start(); }
private void CreateInstrument(DataStream dataStream) { SeriesSymbolData cSeries = SeriesManager.Manager.GetSeries(dataStream.data); if (cSeries != null) { lock (__oLockBars) { int iIndex = dataStream.index; Instrument cInstrument = new Instrument(cSeries, (iIndex == 0) ? __iMaxBarsReference : 0); __cInstruments[iIndex] = cInstrument; ++__iMaxDataStream; } if (logger.IsInfoEnabled) logger.InfoFormat("[CStudyControl.CreateInstrument] {0}:{1}{2} Instrument create completed...", dataStream.data.Symbol, dataStream.data.Resolution.Size, dataStream.data.Resolution.Type); } }
private static DateTime GetExpiration(Instrument bars) { InstrumentSettings cSettings = bars.Info as InstrumentSettings; cSettings.SetExpirationFromTime(bars.BarUpdateTime); return cSettings.Expiration; }
/// <summary> /// 設定 Instrument 資訊 /// </summary> /// <param name="bars">Instrument 類別</param> public override void SetInstrument(Instrument bars) { base.SetInstrument(bars); __cCurrentPosition.SetBigPointValue(Bars.Info.BigPointValue); //設定每一大點的交易金額 }
/// <summary> /// 設定 Instrument 資訊 /// </summary> /// <param name="bars">Instrument 類別</param> public override void SetInstrument(Instrument bars) { base.SetInstrument(bars); __cProperty = (Bars.Info as InstrumentSettings).Property; //取得商品屬性 __cCurrentPosition.SetBigPointValue(__cProperty.BigPointValue); //設定每一大點的交易金額 }
/// <summary> /// 設定 Instrument 資訊 /// </summary> /// <param name="bars">Instrument 類別</param> public virtual void SetInstrument(Instrument bars) { this.Bars = bars; }