Ejemplo n.º 1
0
        /// <summary>
        /// Primary constructor
        /// </summary>
        public BreakoutTrader(string u, string p)
        {
            m_username = u;
            m_password = p;

            todayDate    = DateTime.Now.Date;
            OutputFolder = TA.DirectoryNames.GetDirectoryName("overnightCandlestick") + TA.DirectoryNames.GetDirectoryExtension(todayDate);

            LogFile        = new StreamWriter(OutputFolder + "/Log" + DateTime.Now.ToString("HHmmss") + ".txt", true);
            BreakoutLogger = new Logger(LogFile);

            instrumentList = ContractUtilities.ContractMetaInfo.cmeFuturesTickerheadList.Union(ContractUtilities.ContractMetaInfo.iceFuturesTickerheadList).ToArray();

            liquidContractList     = new ContractUtilities.ContractList(instrumentList);
            ttapiTickerList        = liquidContractList.ttapiTickerList;
            dbTickerList           = liquidContractList.dbTickerList;
            DateTimePastPnlDisplay = DateTime.MinValue;


            BreakoutPosition = new Portfolio.Position(fullTickerList: dbTickerList);

            CovMatrix = Risk.PorfolioRisk.LoadCovMatrix();

            candleStickData = new DataTable();

            rangeMinList  = new List <double>();
            rangeMaxList  = new List <double>();
            ilsUpdateList = new List <EventHandler <InstrumentLookupSubscriptionEventArgs> >();
            candleStickData.ReadXml(OutputFolder + "/" + TA.FileNames.candlestick_signal_file);

            StdDict = new Dictionary <string, double>();
            QtyDict = new Dictionary <string, int>();


            startTime          = new DateTime(todayDate.Year, todayDate.Month, todayDate.Day, 8, 30, 0);
            endTime            = new DateTime(todayDate.Year, todayDate.Month, todayDate.Day, 9, 0, 0);  //900
            LastTradeEntryTime = new DateTime(todayDate.Year, todayDate.Month, todayDate.Day, 9, 20, 0); //920

            selectedCandleStickData = candleStickData.Select("start>= #" + startTime.ToString() + "# AND end<= #" + endTime.ToString() + " # ");

            for (int i = 0; i < dbTickerList.Count; i++)
            {
                double rangeMin = double.MaxValue;
                double rangeMax = double.MinValue;


                for (int j = 0; j < selectedCandleStickData.Length; j++)
                {
                    rangeMax = Math.Max(selectedCandleStickData[j].Field <Double>(dbTickerList[i] + "_high"), rangeMax);
                    rangeMin = Math.Min(selectedCandleStickData[j].Field <Double>(dbTickerList[i] + "_low"), rangeMin);
                }
                rangeMinList.Add(rangeMin);
                rangeMaxList.Add(rangeMax);

                StdDict.Add(dbTickerList[i], Risk.PorfolioRisk.GetStd4Ticker(dbTickerList[i], CovMatrix));
                QtyDict.Add(dbTickerList[i], (int)Math.Min(MaxQty4Ticker, Math.Floor(StdPerBet / StdDict[dbTickerList[i]])));
            }

            //

            ttapiSubs = new ttapiUtils.Subscription(m_username, m_password);
            ttapiSubs.dbTickerList = dbTickerList;

            ilsUpdateList.Add(ttapiSubs.startPriceSubscriptions);
            ilsUpdateList.Add(ttapiSubs.startTradeSubscriptions);

            ttapiSubs.ilsUpdateList            = ilsUpdateList;
            ttapiSubs.asu_update               = ttapiSubs.startInstrumentLookupSubscriptions;
            ttapiSubs.priceUpdatedEventHandler = BreakoutAlgo;
            ttapiSubs.orderFilledEventHandler  = BreakoutStopLogic;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Primary constructor
        /// </summary>
        public BreakoutTrader(string u, string p)
        {
            m_username = u;
            m_password = p;

            todayDate = DateTime.Now.Date;
            OutputFolder = TA.DirectoryNames.GetDirectoryName("overnightCandlestick") + TA.DirectoryNames.GetDirectoryExtension(todayDate);

            LogFile = new StreamWriter(OutputFolder + "/Log" + DateTime.Now.ToString("HHmmss") + ".txt", true);
            BreakoutLogger = new Logger(LogFile);

            instrumentList = ContractUtilities.ContractMetaInfo.cmeFuturesTickerheadList.Union(ContractUtilities.ContractMetaInfo.iceFuturesTickerheadList).ToArray();

            liquidContractList = new ContractUtilities.ContractList(instrumentList);
            ttapiTickerList = liquidContractList.ttapiTickerList;
            dbTickerList = liquidContractList.dbTickerList;
            DateTimePastPnlDisplay = DateTime.MinValue;


            BreakoutPosition = new Portfolio.Position(fullTickerList: dbTickerList);

            CovMatrix = Risk.PorfolioRisk.LoadCovMatrix();

            candleStickData = new DataTable();

            rangeMinList = new List<double>();
            rangeMaxList = new List<double>();
            ilsUpdateList = new List<EventHandler<InstrumentLookupSubscriptionEventArgs>>();
            candleStickData.ReadXml(OutputFolder + "/" + TA.FileNames.candlestick_signal_file);

            StdDict = new Dictionary<string, double>();
            QtyDict = new Dictionary<string, int>();


            startTime = new DateTime(todayDate.Year, todayDate.Month, todayDate.Day, 8, 30, 0);
            endTime = new DateTime(todayDate.Year, todayDate.Month, todayDate.Day, 9, 0, 0);    //900
            LastTradeEntryTime = new DateTime(todayDate.Year, todayDate.Month, todayDate.Day, 9, 20, 0);    //920

            selectedCandleStickData = candleStickData.Select("start>= #" + startTime.ToString() + "# AND end<= #" + endTime.ToString() + " # ");

            for (int i = 0; i < dbTickerList.Count; i++)
            {
                double rangeMin = double.MaxValue;
                double rangeMax = double.MinValue;


                for (int j = 0; j < selectedCandleStickData.Length; j++)
                {
                    rangeMax = Math.Max(selectedCandleStickData[j].Field<Double>(dbTickerList[i] + "_high"), rangeMax);
                    rangeMin = Math.Min(selectedCandleStickData[j].Field<Double>(dbTickerList[i] + "_low"), rangeMin);
                }
                rangeMinList.Add(rangeMin);
                rangeMaxList.Add(rangeMax);
                
                StdDict.Add(dbTickerList[i], Risk.PorfolioRisk.GetStd4Ticker(dbTickerList[i], CovMatrix));
                QtyDict.Add(dbTickerList[i], (int)Math.Min(MaxQty4Ticker, Math.Floor(StdPerBet / StdDict[dbTickerList[i]])));
                
            }

            //

            ttapiSubs = new ttapiUtils.Subscription(m_username, m_password);
            ttapiSubs.dbTickerList = dbTickerList;

            ilsUpdateList.Add(ttapiSubs.startPriceSubscriptions);
            ilsUpdateList.Add(ttapiSubs.startTradeSubscriptions);

            ttapiSubs.ilsUpdateList = ilsUpdateList;
            ttapiSubs.asu_update = ttapiSubs.startInstrumentLookupSubscriptions;
            ttapiSubs.priceUpdatedEventHandler = BreakoutAlgo;
            ttapiSubs.orderFilledEventHandler = BreakoutStopLogic;

        }