Ejemplo n.º 1
0
        /*****************************************************************************
        *  FUNCTION:       ManageDataConnections
        *  Description:
        *  Parameters:     None
        *****************************************************************************/
        private void ManageDataConnections()
        {
            String pUrl = TemplateRequestStr;

            MSHTML.HTMLDocument   htmlresponse = new MSHTML.HTMLDocument();
            MSHTML.IHTMLDocument2 webresponse  = (MSHTML.IHTMLDocument2)htmlresponse;

            if (LockedForUpdate == false)
            {
                LockedForUpdate = true;

                //Disable timer ticks
                LiveSessionTimer.Stop();
                SendMessage(this.ParentFormPtr, WM_UPDATING_DATA, IntPtr.Zero, IntPtr.Zero);

                /**** Download Data ****/
                pUrl += "?noconstruct=1" + "&smlID=" + ActiveMarket.smlId +
                        "&sid=" + ActiveMarket.sid + "&tabletype=price" + "&index_id=" + ActiveMarket.id;

                webresponse = Helpers.HTMLRequestResponse(pUrl);

                //Parse the downloaded HTML file
                if (HistoricalData == null)
                {
                    HistoricalData = new ExchangeMarket();
                }

                HistoricalData.parseHtmlLiveData(webresponse, pUrl, ActiveMarket.name);

                SendMessage(this.ParentFormPtr, WM_LIVEUPDATE, IntPtr.Zero, IntPtr.Zero);

                LockedForUpdate = false;
                LiveSessionTimer.Start();
            }
        }
Ejemplo n.º 2
0
 public void ReBindExchangeMarket(ExchangeMarket pMarket)
 {
     if (pMarket != null)
     {
         this.statsMarketData = pMarket;
     }
 }
Ejemplo n.º 3
0
 public void SetInputParams(ExchangeMarket pMktData, int pEqIn, String pBuyRule, String pSellRule, Double pPrincipal)
 {
     mktData        = pMktData;
     inEquity       = pMktData.Constituents[pEqIn];
     inBuyRule      = pBuyRule;
     inSellRule     = pSellRule;
     inPrincipalAmt = pPrincipal;
 }
Ejemplo n.º 4
0
 public VisualsTab(List <Equity> inputData, ExchangeMarket marketData = null)
 {
     InitializeComponent();
     InitializePrivateGlobals();
     //dataSet = inputData;
     dataSet = new List <Equity>(inputData);
     if (marketData != null)
     {
         statsMarketData = marketData;
     }
 }
Ejemplo n.º 5
0
        /*****************************************************************************
        *  FUNCTION:  BindCorrelationData
        *  Description:
        *  Parameters:
        *****************************************************************************/
        public void BindCorrelationData(ref ExchangeMarket mktData, int pIndex)
        {
            int i, j;
            Dictionary <int, Double> CoefficientList;

            DataRow row;

            if (TableType == StatTableType.INDIVIDUAL_PPC && (pIndex < mktData.Constituents.Count && pIndex > 0))
            {
                //CreateSingleCorrelationTable();
                CreateNewTable();

                // Create new columns
                AddColumnToSource(System.Type.GetType("System.String"), TableHeadings.Name, "Name", true, false);
                AddColumnToSource(System.Type.GetType("System.Double"), TableHeadings.PPC_Coeff, "Correlation", true, false);
                AddColumnToSource(System.Type.GetType("System.Double"), TableHeadings.PctChange[0], TableHeadings.PctChange[1], true, false);
                AddColumnToSource(System.Type.GetType("System.Double"), TableHeadings.Hist_Avg[0], TableHeadings.Hist_Avg[1], true, false);

                CoefficientList = mktData.GetPPCCoefficients(pIndex);

                for (i = 0; i < mktData.Constituents.Count; i++)
                {
                    if (i != pIndex)
                    {
                        row = tableSource.NewRow();
                        row[IndexColumnName]            = i + 1;
                        row[TableHeadings.Name]         = mktData.Constituents[i].Name;
                        row[TableHeadings.PctChange[0]] = mktData.Constituents[i].pctChange;
                        row[TableHeadings.Hist_Avg[0]]  = mktData.Constituents[i].avgPrice;

                        //Check for availability of PPC coefficients
                        if (i < CoefficientList.Count)
                        {
                            row[TableHeadings.PPC_Coeff] = CoefficientList[i];
                        }
                        else
                        {
                            row[TableHeadings.PPC_Coeff] = 0;
                        }

                        tableSource.Rows.Add(row);
                    }
                }

                //Bind Data
                BindTableSource(0.5);
            }

            NumberOfEntries = mktData.Constituents.Count();
        }
Ejemplo n.º 6
0
        private void InitializePrivateGlobals()
        {
            dataSet                         = null;
            statsMarketData                 = null;
            lastDisplayedCorrelation        = -1;
            lastSelectedTab                 = 0;
            CorrelationTableSortInstruction = new List <string>();
            AllTransformApplied             = false;
            DataIsValid                     = 0;

            for (int i = 0; i < TransformTList.Length; i++)
            {
                this.tsComboTransformation.Items.Add(StringEnum.GetStringValue(TransformTList[i]));
            }
        }
Ejemplo n.º 7
0
        /*****************************************************************************
        *  FUNCTION:       ReadHistoricalData
        *  Description:
        *  Parameters:     None
        *****************************************************************************/
        public Boolean ReadHistoricalData()
        {
            Boolean success = true;

            if (HistoricalDataSource == "")
            {
                success = false;
            }
            else
            {
                if (HistoricalData == null)
                {
                    HistoricalData = new ExchangeMarket(HistoricalDataSource);
                }
                success = HistoricalData.parseCsvHistoricalData();
            }

            return(success);
        }
Ejemplo n.º 8
0
        /*****************************************************************************
        *  FUNCTION:       SetHistoricalDataPath
        *  Description:
        *  Parameters:
        *          pPath -
        *****************************************************************************/
        public Boolean SetHistoricalDataPath(String pPath)
        {
            Boolean success = true;

            HistoricalDataSource = pPath;
            success = Helpers.ValidatePath(HistoricalDataSource);

            if (success)
            {
                if (HistoricalData == null)
                {
                    HistoricalData = new ExchangeMarket(HistoricalDataSource);
                }
                else
                {
                    HistoricalData.SetCurrentRepoPath(HistoricalDataSource);
                }
            }

            return(success);
        }
Ejemplo n.º 9
0
        public void BindMarketData(ExchangeMarket pData)
        {
            const int PCT_MAX_COLOR = 10;

            int    xfactor = 0, yfactor = 0;
            int    remainder = 0;
            double r, g, b;
            int    xcount = 0, ycount = 0;
            Color  eqColor = new Color();

            if (pData.Constituents != null)
            {
                if (this.Height < pData.Constituents.Count)
                {
                    this.Height = pData.Constituents.Count;
                }
                if (this.Width < pData.Constituents[0].HistoricalPctChange.Count)
                {
                    this.Width = pData.Constituents[0].HistoricalPctChange.Count;
                }

                if (this.Height > pData.Constituents.Count)
                {
                    yfactor      = (int)Math.Floor((double)this.Height / (double)pData.Constituents.Count);
                    remainder    = this.Height % pData.Constituents.Count;
                    this.Height -= remainder;
                }

                if (this.Width > pData.Constituents[0].HistoricalPctChange.Count)
                {
                    xfactor     = (int)Math.Floor((double)this.Width / (double)pData.Constituents[0].HistoricalPctChange.Count);
                    remainder   = this.Width % pData.Constituents[0].HistoricalPctChange.Count;
                    this.Width -= remainder;
                }

                foreach (Equity eq in pData.Constituents)
                {
                    ycount++;
                    xcount = 0;
                    foreach (double pct in eq.HistoricalPctChange)
                    {
                        xcount++;

                        b = 0;
                        if (eq.HistoricalPctChange[xcount - 1] <= 0)
                        {
                            r = 255;
                        }
                        else
                        {
                            r = (-255 * eq.HistoricalPctChange[xcount - 1] / PCT_MAX_COLOR) + 255;
                            r = (r < 0) ? 0 : r;
                        }

                        if (eq.HistoricalPctChange[xcount - 1] >= 0)
                        {
                            g = 255;
                        }
                        else
                        {
                            g = (255 * eq.HistoricalPctChange[xcount - 1] / PCT_MAX_COLOR) + 255;
                            g = (g < 0) ? 0 : g;
                            b = g;
                        }

                        eqColor = Color.FromArgb((int)r, (int)g, (int)b);

                        for (int x = 0; x < xfactor; x++)
                        {
                            for (int y = 0; y < yfactor; y++)
                            {
                                this.heatMapImage.SetPixel((xcount * xfactor) + x, (ycount * yfactor) + y, eqColor);
                            }
                        }
                    }
                }

                this.Invalidate();
            }
        }
Ejemplo n.º 10
0
        /*****************************************************************************
        *  FUNCTION:  BindMarketData
        *  Description:
        *  Parameters:
        *****************************************************************************/
        public void BindMarketData(ExchangeMarket mktData, bool updateExisting = false)
        {
            int    i, j;
            Double NameColWidth = 0.25;
            Dictionary <int, Double> CoefficientList;
            List <int> remSelectedRows = new List <int>(this.SelectedEntries);
            List <Tuple <int, int> > remSelectedCells = new List <Tuple <int, int> >(this.SelectedCells);
            String existingSort = this.GetDataViewSortInstruction();

            ScrollIndex = this.dataGridView1.FirstDisplayedScrollingRowIndex;

            DataRow row;

            if (TableType == StatTableType.HIST_STATS)
            {
                CreateNewTable();

                // Create new columns
                AddColumnToSource(System.Type.GetType("System.String"), TableHeadings.Name, "Name", true, false);
                AddColumnToSource(System.Type.GetType("System.Double"), TableHeadings.PctChange[0], TableHeadings.PctChange[1], true, false, false, ColumnStyle.PLUS_MINUS);
                AddColumnToSource(System.Type.GetType("System.Double"), TableHeadings.Hist_Avg[0], TableHeadings.Hist_Avg[1], true, false);
                AddColumnToSource(System.Type.GetType("System.Double"), TableHeadings.Hist_Vlty, "Volatility", true, false);
                AddColumnToSource(System.Type.GetType("System.DateTime"), TableHeadings.Hist_DtStart[0], TableHeadings.Hist_DtStart[1], true, false);
                AddColumnToSource(System.Type.GetType("System.DateTime"), TableHeadings.Hist_DtEnd[0], TableHeadings.Hist_DtEnd[1], true, false);

                NameColWidth = 0.25;
                for (i = 0; i < mktData.Constituents.Count(); i++)
                {
                    row = tableSource.NewRow();
                    row[IndexColumnName]               = i + 1;
                    row[TableHeadings.Name]            = mktData.Constituents[i].Name;
                    row[TableHeadings.PctChange[0]]    = mktData.Constituents[i].pctChange;
                    row[TableHeadings.Hist_Avg[0]]     = mktData.Constituents[i].avgPrice;
                    row[TableHeadings.Hist_Vlty]       = mktData.Constituents[i].Volatility;
                    row[TableHeadings.Hist_DtStart[0]] = mktData.Constituents[i].HistoricalPriceDate[0];
                    row[TableHeadings.Hist_DtEnd[0]]   = mktData.Constituents[i].HistoricalPriceDate[mktData.Constituents[i].HistoricalPriceDate.Count() - 1];
                    tableSource.Rows.Add(row);
                }
            }
            else if (TableType == StatTableType.ANALYSIS_PPC)
            {
                CreateNewTable();

                // Create new columns
                AddColumnToSource(System.Type.GetType("System.String"), TableHeadings.Name, "Name", true, false);
                AddColumnToSource(System.Type.GetType("System.Double"), TableHeadings.PPC_Max[0], TableHeadings.PPC_Max[1], true, false);
                AddColumnToSource(System.Type.GetType("System.Double"), TableHeadings.PPC_Min[0], TableHeadings.PPC_Min[1], true, false);

                NameColWidth = 0.5;
                for (i = 0; i < mktData.Constituents.Count(); i++)
                {
                    row = tableSource.NewRow();
                    row[IndexColumnName]    = i + 1;
                    row[TableHeadings.Name] = mktData.Constituents[i].Name;
                    CoefficientList         = mktData.GetPPCCoefficients(i);

                    row[TableHeadings.PPC_Max[0]] = CoefficientList.Values.Max();
                    row[TableHeadings.PPC_Min[0]] = CoefficientList.Values.Min();

                    tableSource.Rows.Add(row);
                }
            }
            else if (TableType == StatTableType.LIVE_STATS)
            {
                CreateNewTable();

                // Create new columns
                AddColumnToSource(System.Type.GetType("System.String"), TableHeadings.Name, "Name", true, false);
                AddColumnToSource(System.Type.GetType("System.Double"), TableHeadings.Live_Last, "Last", true, false);
                AddColumnToSource(System.Type.GetType("System.Double"), TableHeadings.Live_High, "High", true, false);
                AddColumnToSource(System.Type.GetType("System.Double"), TableHeadings.Live_Low, "Low", true, false);
                AddColumnToSource(System.Type.GetType("System.Double"), TableHeadings.Live_Chg, "Change", true, false, false, ColumnStyle.PLUS_MINUS);
                AddColumnToSource(System.Type.GetType("System.Double"), TableHeadings.PctChange[0], TableHeadings.PctChange[1], true, false, false, ColumnStyle.PLUS_MINUS);
                AddColumnToSource(System.Type.GetType("System.Double"), TableHeadings.Live_Vol, "Volume", true, false);
                AddColumnToSource(System.Type.GetType("System.DateTime"), TableHeadings.Live_Time, "Time", true, false);

                NameColWidth = 0.25;
                for (i = 0; i < mktData.Constituents.Count(); i++)
                {
                    row = tableSource.NewRow();
                    row[IndexColumnName]            = i + 1;
                    row[TableHeadings.Name]         = mktData.Constituents[i].Name;
                    row[TableHeadings.Live_Last]    = mktData.Constituents[i].DailyLast[mktData.Constituents[i].DailyLast.Count - 1];
                    row[TableHeadings.Live_High]    = mktData.Constituents[i].DailyHigh;
                    row[TableHeadings.Live_Low]     = mktData.Constituents[i].DailyLow;
                    row[TableHeadings.Live_Chg]     = mktData.Constituents[i].DailyChg;
                    row[TableHeadings.PctChange[0]] = mktData.Constituents[i].DailyChgPct;
                    row[TableHeadings.Live_Vol]     = mktData.Constituents[i].DailyVolume;
                    row[TableHeadings.Live_Time]    = mktData.Constituents[i].DailyTime[mktData.Constituents[i].DailyTime.Count - 1];
                    tableSource.Rows.Add(row);
                }
            }
            else
            {
                //Invalid table-type. Do nothing.
            }

            NumberOfEntries = mktData.Constituents.Count();

            //Get the column indices of columns where the set style is PLUS_MINUS
            PlusMinusColumns = ColumnStyles.Select((cs, ci) => cs == ColumnStyle.PLUS_MINUS ? ci : -1).Where(ci2 => ci2 >= 0).ToList();

            //Bind Data
            BindTableSource(NameColWidth);

            //Apply existing filter
            ApplyFilter();

            if (updateExisting)
            {
                this.SelectedEntries = new List <int>(remSelectedRows);
                //this.SelectedCells = new List<Tuple<int, int>>(remSelectedCells);
                this.SetDataViewSortInstruction(existingSort);
                this.UpdateSelection(remSelectedCells);
            }
        }