Пример #1
0
        }//addNewConstraint

        private void addNewConstToTable(cConstraint cConst, String txtDisplay)
        { // Adds the specific constraint to the table displayed in control
            DataRow drNew = m_dtMainConsts.NewRow();

            if ((cConst.Minimum != double.MinValue) && (cConst.Maximum != double.MaxValue))
            {
                if ((cConst.Maximum - cConst.Minimum) < 0.01D)
                {
                    drNew["Vals"] = cGeneralFunctions.getFormatPercentFromDbl(cConst.Minimum, 2) + " - " + cGeneralFunctions.getFormatPercentFromDbl(cConst.Maximum, 4);
                }
                else
                {
                    drNew["Vals"] = cGeneralFunctions.getFormatPercentFromDbl(cConst.Minimum, 2) + " - " + cGeneralFunctions.getFormatPercentFromDbl(cConst.Maximum, 2);
                }
            }
            if (cConst.Equality != double.MaxValue)
            {
                drNew["Vals"] = cGeneralFunctions.getFormatPercentFromDbl(cConst.Equality, 2);
            }

            drNew["Dist"]  = (cConst.isOneSec) ? "Single" : "Totals";
            drNew["Items"] = txtDisplay;

            m_dtMainConsts.Rows.Add(drNew);
        }//addNewConstToTable
Пример #2
0
        }                                              //setSingleSecConst

        #endregion Initialization

        #region General methods

        public Boolean isEqual(cConstraint cConst)
        { // Checks if current constraint equals the constraint in the parameter
            if (this.m_dEqual != cConst.Equality)
            {
                return(false);
            }
            if ((this.m_dMin != cConst.Minimum) || (this.m_dMax != cConst.Maximum))
            {
                return(false);
            }
            return(isConstItemsMatch(cConst));
        }//isEqual
Пример #3
0
        }     //Double_addRangeConstsFromCollection

        private void addDefaultRange100OrLess()
        { // Adds the default constraint of all securities sum to 100% or less
            List <String> lstAllSecs = new List <String>();

            for (int iSecs = 0; iSecs < m_objColHandler.ActiveSecs.Count; iSecs++)
            {
                lstAllSecs.Add(m_objColHandler.ActiveSecs[iSecs].Properties.PortSecurityId);
            }
            cConstraint cNewConst = new cConstraint(lstAllSecs, "", enumConstraintType.Security, 0D, 1D);

            m_colDefaultRange.Add(cNewConst);
        }//addDefaultRange100OrLess
Пример #4
0
        }//Double_addEqualityConstsFromCollection

        private void addDefaultEqualitySumTo100(ISecurities cSecsCol)
        { // Adds the equality constraint of all weights summing up to 100%
            List <String> lstAllSecs = new List <String>();

            for (int iSecs = 0; iSecs < cSecsCol.Count; iSecs++)
            {
                lstAllSecs.Add(cSecsCol[iSecs].Properties.PortSecurityId);
            }
            cConstraint cNewConst = new cConstraint(lstAllSecs, "", enumConstraintType.Security, 1D);

            m_colDefaultEquality.Add(cNewConst);
        }//addDefaultEqualitySumTo100
Пример #5
0
        }//getDoubleOfConstraintSecs

        private int[] getArrOfConstraintSecs(cConstraint cConst, ISecurities cSecsCol)
        { // Returns array of participating securities in given constraint
            int[] iFinalArr = new int[cSecsCol.Count];
            for (int iItems = 0; iItems < cConst.ItemIds.Count; iItems++)
            { // Goes through constraint items
                iFinalArr = updtArrOfIndexes(iFinalArr, enumConstraintType.Security, cConst.ItemIds[iItems], iItems, cSecsCol);
                if (iFinalArr == null)
                {
                    return(iFinalArr);
                }
            }

            return(iFinalArr);
        }//getArrOfConstraintSecs
Пример #6
0
        }//isEqual

        private Boolean isConstItemsMatch(cConstraint cConst)
        { // Compares two constraints and checks whether their inner items match
            if (m_lstConstraintItems.Count != cConst.ItemIds.Count)
            {
                return(false);
            }
            for (int iItems = 0; iItems < m_lstConstraintItems.Count; iItems++)
            {
                if (m_lstConstraintItems[iItems] != cConst.ItemIds[iItems])
                {
                    return(false);
                }
            }
            return(true);
        }//isConstItemsMatch
Пример #7
0
        }//addDefaultRange100OrLess

        private void Double_addSingleInequalityConstraint(cConstraint cConst, Boolean isInverse, Boolean isMax, ISecurities cSecsCol)
        { // Inserts a single inequality constraint to string
            double        dVal = (isMax) ? cConst.Maximum : -cConst.Minimum;
            List <double> row  = getDoubleOfConstraintSecs(cConst, isInverse, cSecsCol);

            if (row != null)
            {
                m_doubleRangeSecs.Add(row);
            }

            m_doubleRangeVals.Add(dVal);
            //     --b2--
            if (!isMax && (dVal > 0))
            {
                updtIndividualSecsValRange(-1D); // Only negative minimum value
            }
        }//Double_addSingleInequalityConstraint
Пример #8
0
        }//getStringOfConstraintSecs

        private List <double> getDoubleOfConstraintSecs(cConstraint cConst, Boolean isInverse, ISecurities cSecsCol)
        { // Returns a List representing the securities active in current constraint (from all secs)
            m_arrConstItemsState = getArrOfConstraintSecs(cConst, cSecsCol);
            List <double> doubleFinal = new List <double>();

            if ((m_arrConstItemsState == null) || (m_arrConstItemsState.Length == 0))
            {
                return(null);
            }
            for (int iSecs = 0; iSecs < m_arrConstItemsState.Length; iSecs++)
            {
                if (isInverse)
                {
                    doubleFinal.Add(m_arrConstItemsState[iSecs] * -1);
                }
                else
                {
                    doubleFinal.Add(m_arrConstItemsState[iSecs]);
                }
            }

            return(doubleFinal);
        }//getDoubleOfConstraintSecs
Пример #9
0
        }//initSecBounds

        #endregion Data initialization

        #region Save / Load

        //public void saveConstraints(int idPort, cDbOleConnection oleDBConn)
        //{ // save the cunstraints to the DB
        //    deleteCurConstFromDB(idPort, oleDBConn);
        //    int idInsertConst;
        //    for (int i = 0; i < m_colConstraints.Count; i++)
        //    { // Browses constraints
        //        idInsertConst = (int)cDbOleConnection.executeSqlScalar(cSqlStatements.insertNewConstraint(m_colConstraints[i], idPort), oleDBConn.dbConnection);

        //        for (int j = 0; j < m_colConstraints[i].ItemIds.Count; j++)
        //            cDbOleConnection.executeSqlSatatement(cSqlStatements.insertNewConstraintItem(idInsertConst, m_colConstraints[i].ItemIds[j]), oleDBConn.dbConnection);
        //    }
        //}//saveConstraints

        //private void deleteCurConstFromDB(int portId, cDbOleConnection oleDBConn)
        //{//delete all constraint in current portfolio that we can save them and wont be duplication
        //    DataTable dtConsts = cDbOleConnection.FillDataTable(cSqlStatements.getTblValsByIntConditionSQL(cDbOleConnection.TblConstraints, "idPortFolio", portId), oleDBConn.dbConnection);

        //    for (int iRows = 0; iRows < dtConsts.Rows.Count; iRows++)
        //        cDbOleConnection.executeSqlSatatement("DELETE FROM tbl_ConstraintItems WHERE idConstraint = " + dtConsts.Rows[iRows]["idConstraint"].ToString() + ";", oleDBConn.dbConnection);

        //    cDbOleConnection.executeSqlSatatement(cSqlStatements.removeDataFromTblByIdIntSQL("tbl_Constraints", "idPortFolio", portId), oleDBConn.dbConnection);
        //}//deleteCurConstFromDB

        //public void updateConstraints(int portId, cDbOleConnection oleDBConn, cSecurities cSecsCol)
        //{//update the Constraints collection
        //    try
        //    {
        //        DataTable dtConsts = cDbOleConnection.FillDataTable(cSqlStatements.getTblValsByIntConditionSQL(cDbOleConnection.TblConstraints, "idPortFolio", portId), oleDBConn.dbConnection);

        //        m_colConstraints.Clear();
        //        for (int iRows = 0; iRows < dtConsts.Rows.Count; iRows++)
        //            m_colConstraints.Add(getNewConstraintFromDB(dtConsts.Rows[iRows], oleDBConn));   //add the new cConstraint to th collection

        //        setDataTableStruct();
        //        showExistConstraint();
        //        refreshConstList();
        //        setConstraintValues(cSecsCol); // Sets empty collections
        //    } catch (Exception ex) {
        //        m_objErrorHandler.LogInfo(ex);
        //    }
        //}//updateConstraints

        //public cConstraint getNewConstraintFromDB(DataRow drNew, cDbOleConnection oleDBConn)
        //{ // Reads constraint from DB
        //    List<String> itemList = getListOfItems(Convert.ToInt32(drNew["idConstraint"]), oleDBConn); // Fills constraint items (secs)
        //    string sTxtDisplaye = Convert.ToString(drNew["txtDisplay"]);
        //    int iConstType = Convert.ToInt32(drNew["iConstraintType"]);
        //    double dEqual = getConstValue(drNew["dEquality"]);

        //    //saves all relevant details in temp variables
        //    if (dEqual != double.MaxValue)
        //        return new cConstraint(itemList, sTxtDisplaye, getTypeOfConst(iConstType), dEqual);  //create new cConstraint with m_dEqual value
        //    else return new cConstraint(itemList, sTxtDisplaye, getTypeOfConst(iConstType), Convert.ToDouble(drNew["dMin"]), Convert.ToDouble(drNew["dMax"])); //create new cConstraint with min / max values
        //}//getNewConstraintFromDB

        //private double getConstValue(object objVal)
        //{ // Returns double value (if exists), returns maximal double value otherwise
        //    try { return Convert.ToDouble(objVal); }
        //    catch (Exception ex) { }
        //    return double.MaxValue;
        //}//getConstValue

        #endregion Save / Load

        #region Security Index retrieval

        private String getStringOfConstraintSecs(cConstraint cConst, Boolean isInverse, cSecurities cSecsCol)
        { // Returns a String representing the securities active in current constraint (from all secs)
            m_arrConstItemsState = getArrOfConstraintSecs(cConst, cSecsCol);
            String strFinal = "";

            if (m_arrConstItemsState.Length == 0)
            {
                return("");
            }
            for (int iSecs = 0; iSecs < m_arrConstItemsState.Length; iSecs++)
            {
                if (isInverse)
                {
                    strFinal += (m_arrConstItemsState[iSecs] * -1).ToString() + ",";
                }
                else
                {
                    strFinal += m_arrConstItemsState[iSecs].ToString() + ",";
                }
            }
            strFinal = cGeneralFunctions.cropStrEnding(strFinal, 1);
            return(strFinal);
        }//getStringOfConstraintSecs
Пример #10
0
 public virtual void Add(cConstraint NewConstraint)
 { // Adds a constraint to collection
     this.List.Add(NewConstraint);
 }//Add
Пример #11
0
        }                                                                                                 //addNewConstraint

        public void addNewConstraint(cConstraint cConst, String txtDisplay)
        {                                 // Converts item to constraint + add to grid and collections
            m_colConstraints.Add(cConst); // Add to collection
            addNewConstToTable(cConst, txtDisplay);
        }//addNewConstraint
Пример #12
0
        }//getStringOfIndSecs

        //private List<String> getListOfItems(int idCons, cDbOleConnection oleDBConn)
        //{//return list of security that participant in current constraint
        //    List<String> colConstItems = new List<String>();
        //    try
        //    {
        //        DataTable dtConstItems = cDbOleConnection.FillDataTable(cSqlStatements.getTblValsByIntConditionSQL(cDbOleConnection.TblConstraintItems, "idConstraint", idCons), oleDBConn.dbConnection);
        //        for (int iRows = 0; iRows < dtConstItems.Rows.Count; iRows++)
        //            colConstItems.Add(dtConstItems.Rows[iRows]["idItem"].ToString());

        //    } catch (Exception ex) {
        //        m_objErrorHandler.LogInfo(ex);
        //    }
        //    return colConstItems;
        //}//getListOfItems

        #endregion Security Index retrieval

        #region Add / Remove Methods

        public void addNewConstraint(cConstraint cConst)
        {
            addNewConstraint(cConst, cConst.DisplayText);
        }                                                                                                 //addNewConstraint