Example #1
0
        public static void TestMultiSymbolGraph(this AbstractMultiSymbolIndicator ind, string[] filename, int length)
        {
            

            List<Quantum> lq = new List<Quantum>();

            foreach (string s in filename)
            {
                lq.Add(Quantum.ExcelToQuantum(s, s, 0));
            }
            MultiQuantum multiQuantum = MultiQuantum.OrganizeMultiQuantum(lq);


            var dz = new DenseMatrix(4 + 1 + ind.SubIndicatorSize, multiQuantum.Length);
            List<string> names = new List<string>();
            names.Add("symbol");
            names.Add(ind.ToString());
            foreach (var indicator in ind.SubIndicators) names.Add(indicator.Key);

            //chartoptions
            ChartOption[] chartOptions = new ChartOption[names.Count];
            chartOptions[0] = new ChartOption() { Height = 400, YPosition = 0 };
            chartOptions[1] = new ChartOption() { Height = 200, YPosition = 1 };
            for (int i = 2; i < chartOptions.Length; i++)
                chartOptions[i] = new ChartOption() { Height = 0, YPosition = 1, Layover = true };

            int counter = 0;
            foreach (List<Tick> t in multiQuantum)
            {
                dz[0, counter] = t[0].BidOpen;
                dz[1, counter] = t[0].BidHigh;
                dz[2, counter] = t[0].BidLow;
                dz[3, counter] = t[0].BidClose;

                dz[4, counter] = ind.HandleNextTicks(t.ToArray());

                int icounter = 5;
                foreach (var subind in ind.SubIndicators.Values)
                {
                    dz[icounter, counter] = subind[0];
                    icounter++;
                }

                counter++;
            }


            Visualize.GenerateMultiPaneGraph(names.ToArray(), multiQuantum.Keys.ToArray(), dz, QSConstants.DEFAULT_DATA_FILEPATH + @"results.html",
                chartOptions);

            Console.WriteLine("Done Generating Graph for " + ind.ToString());
        }
Example #2
0
        public static void TestGraph(this AbstractIndicator ind, string filename, int length)
        {
            Quantum q = Quantum.ExcelToQuantum(filename, "symbol", 0);

            var dz = new DenseMatrix(4+1+ind.SubIndicatorSize, q.Data.Count);
            List<string> names = new List<string>();
            names.Add("symbol");
            names.Add(ind.ToString());
            foreach(var indicator in ind.SubIndicators) names.Add(indicator.Key);

            //chartoptions
            ChartOption[] chartOptions = new ChartOption[names.Count];
            chartOptions[0] = new ChartOption() {Height = 400, YPosition = 0};
            chartOptions[1] = new ChartOption() { Height = 200, YPosition = 1};
            for(int i = 2; i < chartOptions.Length; i++)
                chartOptions[i] = new ChartOption(){Height = 0, YPosition = 1, Layover = true};

            int counter = 0;
            foreach (Tick tick in q)
            {
                dz[0, counter] = tick.BidOpen;
                dz[1, counter] = tick.BidHigh;
                dz[2, counter] = tick.BidLow;
                dz[3, counter] = tick.BidClose;

                dz[4, counter] = ind.HandleNextTick(tick);

                int icounter = 5;
                foreach (var subind in ind.SubIndicators.Values)
                {
                    dz[icounter, counter] = subind[0];
                    icounter++;
                }

                counter++;
            }


            Visualize.GenerateMultiPaneGraph(names.ToArray(), q.Data.Keys.ToArray(), dz, QSConstants.DEFAULT_DATA_FILEPATH + @"results.html",
                chartOptions);

            Console.WriteLine("Done Generating Graph for " + ind.ToString());
        }
Example #3
0
        public static void GenerateMultiPaneGraph(string[] symbols, DateTime[] dateTimes, DenseMatrix data, string filename, ChartOption[] options = null, HighstockFlag[] flags = null, string JSONFILENAME = "temp.json")
        {
            //Set default options
            if (ReferenceEquals(null,options) || options.Length != symbols.Length)
            {
                options = new ChartOption[symbols.Length];
                for (int i = 0; i < symbols.Length; i++)
                {
                    options[i] = new ChartOption() {ChartType = "spline", Height = 200, YPosition = i};
                }
            }

            WriteDataToJson(symbols, dateTimes, data, JSONFILENAME);

            StringBuilder GraphJSBuilder = new StringBuilder();
            GraphJSBuilder.Append(@"<script type='text/javascript'>                             " + "\n");
            GraphJSBuilder.Append(@"$(function() {                                              " + "\n");
            GraphJSBuilder.Append(@"	$.getJSON('" + JSONFILENAME + "', function(data) {                 " + "\n");

            //add ohlc data (first 4 values)
            GraphJSBuilder.Append("var ohlc =[];" + "\n");

            for (int i = 1; i < symbols.Length; i++)
            {
                GraphJSBuilder.Append("var " + "symbol" + i + "=[];" + "\n");
            }

            GraphJSBuilder.Append(@"dataLength = data.length;"           + "\n");
            GraphJSBuilder.Append(@"for (i = 0; i < dataLength; i++) { " + "\n");
            for (int i = 1; i < symbols.Length; i++)
            {
                
                GraphJSBuilder.Append(@"ohlc.push([ data[i][0], data[i][1], data[i][2], data[i][3], data[i][4] ]);" + "\n"); //ohlc
                GraphJSBuilder.Append(@"symbol" + i + ".push([ data[i][0],data[i][" + (i + 4) + "]]);" + "\n"); //push indicator data
            }
            GraphJSBuilder.Append(@"}" + "\n");
            GraphJSBuilder.Append(@"      var groupingUnits = [                           " + "\n");
            GraphJSBuilder.Append(@"            ['hour', [1,2,3] ],                       " + "\n");
            GraphJSBuilder.Append(@"            ['day',  [1,2,3] ],                       " + "\n");
            GraphJSBuilder.Append(@"            ['week', [1,2]   ],                       " + "\n");
            GraphJSBuilder.Append(@"            ['month',[1]     ]];                      " + "\n");
            GraphJSBuilder.Append(@"		$('#container').highcharts('StockChart', {    " + "\n");
            GraphJSBuilder.Append(@"		    rangeSelector: {selected: 1  },           " + "\n");
            GraphJSBuilder.Append(@"		    title: {  text: '" + symbols[0] + "'},    " + "\n");
            GraphJSBuilder.Append(@"            legend: { enabled: true },                " + "\n");
            GraphJSBuilder.Append(@"            chart:{zoomType: 'x'},                    " + "\n");
            GraphJSBuilder.Append(@"            scrollbar: { enabled:false},              " + "\n");

            GraphJSBuilder.Append(" yAxis: [" + "\n");
            for (int i = 0; i < symbols.Length; i++)
            {
                double top = 70;
                //get height of element
                for (int j = 0; j < i; j++)
                {
                    top += options[j].Height + 10;
                }
                
                GraphJSBuilder.Append(
                    "{" +
                        (!options[i].Layover?"title: {text: '" + symbols[i] + "'}, ":"") +
                        "height:" + options[i].Height + ", " +
                        ((i == 0) ? "" : "top:" + top + ",") + 
                        "lineWidth:2, " +
                        "offset:0" +
                    "}" +
                    ((i == symbols.Length - 1) ? "" : ",") +  "\n");
            }
            GraphJSBuilder.Append(@"]," + "\n");

            //Add Series Data----------------------
            GraphJSBuilder.Append(@"series: [" + "\n");

            //ohlc
            GraphJSBuilder.Append(
                "{" +
                    "type: 'candlestick'," +
                    "name: '" + symbols[0] + "', " +
                    "id: '" + symbols[0] + "', " +
                    "data: ohlc," +
                    "dataGroup:{units:groupingUnits}" +
                "}," + "\n");

            //indicator
            for (int i = 1; i < symbols.Length; i++)
            {
                GraphJSBuilder.Append(
                    "{" +
                        "type: '"+ options[i].ChartType +"'," + 
                        "name: '" + symbols[i] + "', " +
                        "id: '" + symbols[i] + "', " +
                        "data:symbol" + i +"," +
                        "yAxis:" + options[i].YPosition + "," +
                        "dataGroup:{units:groupingUnits}" +
                    "}" +  ((i == symbols.Length - 1) ? "" : ",") +  "\n");
            }

            if (flags != null)
            {
                //add flags------------
                GraphJSBuilder.Append(
                    ",{" +
                    "type : 'flags'," +
                    "data : [");

                if (!ReferenceEquals(null, flags))
                {
                    for (int i = 0; i < flags.Length; i++)
                    {
                        GraphJSBuilder.Append(
                            "{" +
                            "x : Date.UTC(" + flags[i].Date.Year + "," + (flags[i].Date.Month - 1) + "," +
                            flags[i].Date.Day + "," +
                            flags[i].Date.Hour + "," + flags[i].Date.Minute + ")," +
                            "title : '" + flags[i].Title + "'," +
                            "text : '" + flags[i].Text + "'" +
                            "}" + ((i == flags.Length - 1) ? "" : ",") + "\n"
                            );
                    }
                }

                GraphJSBuilder.Append(
                    "]," +
                    "onSeries : '" + symbols[0] + "'," +
                    "shape : 'squarepin'," +
                    "width : 9," +
                    "height: 10," +
                    "stickyTracking: false," +
                    "style: {fontSize:'9px',fontWeight: 'normal'}" +
                    "}"
                    );

                //endflags---------------------
            }

            GraphJSBuilder.Append(@"]" + "\n");
            //endseries-------------------------------------


            //calculate height
            double height = 170;
            for (int i = 0; i < options.Length; i++)
            {
                height += options[i].Height + ((options[i].Height > 0)? 20:0);
            }
            
            GraphJSBuilder.Append(@"});});});   " + "\n");
            GraphJSBuilder.Append(@"</script>     " + "\n");
            GraphJSBuilder.Append(@"<div id='container' style='height:"+height+"; width:90%; margin: 0 auto'></div>" );
            


            using (var file = new StreamWriter(@filename))
            {
                file.WriteLine("<html><head>");
                foreach(string s in HighStocksIncludes)
                    file.WriteLine(s);
                file.WriteLine("</head><body>");
                file.WriteLine(GraphJSBuilder.ToString());
                file.WriteLine("<script src=\"style.js\"></script>");
                file.WriteLine("</body></html>");
            }

        }
Example #4
0
        public static void TestChannel(this AbstractChannel ind, string filename, int length)
        {

            Quantum q = Quantum.ExcelToQuantum(filename, "symbol", 0);

            var dz = new DenseMatrix(4 + 3, q.Data.Count);
            
            List<string> names = new List<string>();
            names.Add("symbol");
            names.Add("HIGH");
            names.Add(ind.ToString());
            names.Add("LOW");

            //chartoptions
            ChartOption[] chartOptions = new ChartOption[names.Count];
            chartOptions[0] = new ChartOption() { Height = 500, YPosition = 0 };
            chartOptions[1] = new ChartOption() { Height = 0, YPosition = 0 , Layover = true};
            chartOptions[2] = new ChartOption() { Height = 0, YPosition = 0 , Layover = true};
            chartOptions[3] = new ChartOption() { Height = 0, YPosition = 0 , Layover = true};

            int counter = 0;
            foreach (Tick tick in q)
            {
                ind.HandleNextTick(tick);
                dz[0, counter] = tick.BidOpen;
                dz[1, counter] = tick.BidHigh;
                dz[2, counter] = tick.BidLow;
                dz[3, counter] = tick.BidClose;
                dz[4, counter] = ind.HI(0);
                dz[5, counter] = ind.MID(0);
                dz[6, counter] = ind.LOW(0);

                counter++;
            }

            Visualize.GenerateMultiPaneGraph(new[] { "data", "high", ind.ToString(), "low" }, q.Data.Keys.ToArray(), dz, QSConstants.DEFAULT_DATA_FILEPATH + @"results.html"
                , new ChartOption[]
                {
                    new ChartOption(){Height = 500}, 
                    new ChartOption(){Height = 0, Layover = true, YPosition = 0},
                    new ChartOption(){Height = 0, Layover = true, YPosition = 0},
                    new ChartOption(){Height = 0, Layover = true, YPosition = 0}
                });

            Console.WriteLine("Done Generating Graph for " + ind.ToString());
        }
Example #5
0
        public static void TestGraphLive(this AbstractIndicator ind, string timeframe, string symbol, int length)
        {
            //------------grab data
            FXSession session = new FXSession();
            session.InitializeSession();

            HistoricPriceEngine h = new HistoricPriceEngine(session);
            h.GetLongHistoricPrices(symbol, timeframe, length);

            while (!h.Complete)
            {
                Thread.Sleep(100);
            }
            //-----------------------

            Quantum q = h.Data;
            var dz = new DenseMatrix(4 + 1 + ind.SubIndicatorSize, q.Data.Count);
            List<string> names = new List<string>();
            names.Add("symbol");
            names.Add(ind.ToString());
            foreach (var indicator in ind.SubIndicators) names.Add(indicator.Key);

            //chartoptions
            ChartOption[] chartOptions = new ChartOption[names.Count];
            chartOptions[0] = new ChartOption() { Height = 400, YPosition = 0 };
            chartOptions[1] = new ChartOption() { Height = 200, YPosition = 1 };
            for (int i = 2; i < chartOptions.Length; i++)
                chartOptions[i] = new ChartOption() { Height = 0, YPosition = 1, Layover = true };

            int counter = 0;
            foreach (Tick tick in q)
            {
                dz[0, counter] = tick.BidOpen;
                dz[1, counter] = tick.BidHigh;
                dz[2, counter] = tick.BidLow;
                dz[3, counter] = tick.BidClose;

                dz[4, counter] = ind.HandleNextTick(tick);

                int icounter = 5;
                foreach (var subind in ind.SubIndicators.Values)
                {
                    dz[icounter, counter] = subind[0];
                    icounter++;
                }

                counter++;
            }


            Visualize.GenerateMultiPaneGraph(names.ToArray(), q.Data.Keys.ToArray(), dz, QSConstants.DEFAULT_DATA_FILEPATH + @"results.html",
                chartOptions);

            Console.WriteLine("Done Generating Graph for " + ind.ToString());
        }