예제 #1
0
        public override MutualFundGroup GetMutualFunds(AFundCategory category)
        {
            try
            {
                //读取数据库
                this.LoadMutualFundInfo();

                //以Group输出
                MutualFundGroup mfg = new MutualFundGroup();

                foreach (DataRow oRow in _FundInfo.Tables[0].Rows)
                {
                    MutualFund f = new MutualFund(oRow[C_ColName_Code].ToString());
                    this.LoadMutualFundInfo(f);

                    if (category == null ||
                        (
                            (f.Category.AssetCategory == category.AssetCategory || category.AssetCategory == FundAssetCategory.Undefined) &&
                            (f.Category.InvestmentCategory == category.InvestmentCategory || category.InvestmentCategory == FundInvestmentCategory.Undefined) &&
                            (f.Category.OperationCategory == category.OperationCategory || category.OperationCategory == FundOperationCategory.Undefined) &&
                            (f.Category.StructureCategory == category.StructureCategory || category.StructureCategory == FundStructureCategory.Undefined)
                        )
                        )
                    {
                        mfg.Add(f);
                    }
                }

                return(mfg);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #2
0
        public override void LoadMutualFundInfo(MutualFund f)
        {
            try
            {
                //读取数据库
                this.LoadMutualFundInfo();

                //更新数据
                DataRow[] rows = _FundInfo.Tables[0].Select("SYMBOL='" + f.Code + "'");
                if (rows.Length >= 1)
                {
                    f.DataSource          = this.DataSource;
                    f.Category.DataSource = this.DataSource;

                    DataRow row = rows[0];
                    f.Name         = row[C_ColName_Name].ToString();
                    f.ListedDate   = DataManager.ConvertToDate(row[C_ColName_ListedDate]);
                    f.DelistedDate = DataManager.ConvertToDate(row[C_ColName_DelistedDate]);
                    f.Category.SetupCategory(row[C_ColName_GSFundType].ToString(), 3);

                    if (row[C_ColName_ParentCode] == DBNull.Value)
                    {
                        //非分级基金
                        f.IsStructured = false;
                        f.Category.StructureCategory = FundStructureCategory.Parent;
                    }
                    else
                    {
                        //分级基金
                        f.IsStructured   = true;
                        f.ParentFundCode = row[C_ColName_ParentCode].ToString();

                        if (row[C_ColName_ParentCode].ToString() == row[C_ColName_Code].ToString())
                        {
                            f.Category.StructureCategory = FundStructureCategory.Parent;

                            //查找子基金
                            string  sql = @"Select SYMBOL From CURFSCODE WHERE Symbol_Comp = '" + f.Code + "' AND Symbol <> Symbol_Comp";
                            DataSet ds  = base.DBInstance.ExecuteSQL(sql);

                            if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                            {
                                MessageManager.GetInstance().AddMessage(MessageType.Warning, Message.C_Msg_MF8, f.Code);
                            }
                            else
                            {
                                if (f.SubFundCodes == null)
                                {
                                    f.SubFundCodes = new List <string>();
                                }

                                foreach (DataRow rowsub in ds.Tables[0].Rows)
                                {
                                    string code = rowsub[C_ColName_Code].ToString();
                                    f.SubFundCodes.Add(code);
                                }
                            }
                        }
                        else
                        {
                            f.Category.StructureCategory = FundStructureCategory.Child;
                        }
                    }
                }
                else
                {
                    MessageManager.GetInstance().AddMessage(MessageType.Warning, Message.C_Msg_MF5, f.Code);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #3
0
        public MutualFund GetWholeFund()
        {
            if (base.SecurityHoldings == null || base.SecurityHoldings.Count == 0)
            {
                return(null);
            }

            WholeFund      = new MutualFund("");
            WholeFund.Name = "基金组中包含的所有基金组成的整体";
            WholeFund.SetDatePeriod(base.TimeSeriesStart, base.TimeSeriesEnd);

            #region 构造整体基金的累计净值序列
            //==========================
            //计算公式:
            //  NAVw = Sum(NAVi * SHAREi)/Sum(SHAREi)
            //==========================
            try
            {
                WholeFund.TradingNAV.TradingDates       = ((MutualFund)base.SecurityHoldings[0]).TradingNAV.TradingDates;
                WholeFund.TradingNAV.InsideSampleLength = ((MutualFund)base.SecurityHoldings[0]).TradingNAV.InsideSampleLength;
                WholeFund.TradingNAV.AdjustedTimeSeries = new List <ATimeItem>();
                WholeFund.FundReport.AdjustedTimeSeries = new List <ATimeItem>();

                //计算净值
                for (int i = 0; i < WholeFund.TradingNAV.TradingDates.Count; i++)
                {
                    NetAssetValue NAVw = new NetAssetValue();
                    NAVw.TradeDate = WholeFund.TradingNAV.TradingDates[i];
                    NAVw.IsTrading = true;

                    MutualFundReport RPTw = new MutualFundReport();
                    RPTw.TradeDate  = NAVw.TradeDate;
                    RPTw.ReportDate = new DateTime(1900, 1, 1);
                    RPTw.IsTrading  = true;

                    //SecurityHoldings[0]的时间序列可能不够长,不能在此处使用
                    //NAVw.IsOutsideSamplePeriod = ((MutualFund)base.SecurityHoldings[0]).TradingNAV.AdjustedTimeSeries[i].IsOutsideSamplePeriod;

                    foreach (MutualFund f in base.SecurityHoldings)
                    {
                        if (f.TradingNAV.AdjustedTimeSeries == null || f.FundReport.AdjustedTimeSeries == null ||
                            i >= f.TradingNAV.AdjustedTimeSeries.Count || i >= f.FundReport.AdjustedTimeSeries.Count)
                        {
                            continue;
                        }

                        NAVw.IsOutsideSamplePeriod = f.TradingNAV.AdjustedTimeSeries[i].IsOutsideSamplePeriod;
                        RPTw.IsOutsideSamplePeriod = NAVw.IsOutsideSamplePeriod;

                        //成立不足30天的去除
                        if (f.ListedDate.AddDays(30) > WholeFund.TradingNAV.TradingDates[i])
                        {
                            continue;
                        }

                        //计算净值 和 资产配置
                        NetAssetValue    NAVi = (NetAssetValue)f.TradingNAV.AdjustedTimeSeries[i];
                        MutualFundReport RPTi = (MutualFundReport)f.FundReport.AdjustedTimeSeries[i];
                        NAVw.UnitNAV    += NAVi.UnitNAV * RPTi.TotalShare;
                        RPTw.TotalShare += RPTi.TotalShare;

                        if (RPTw.ReportDate < RPTi.ReportDate)
                        {
                            RPTw.ReportDate = RPTi.ReportDate;
                        }

                        RPTw.TotalEquityAsset     += RPTi.TotalEquityAsset;
                        RPTw.TotalBondAsset       += RPTi.TotalBondAsset;
                        RPTw.TotalNetAsset        += RPTi.TotalNetAsset;
                        RPTw.PureBondAsset        += RPTi.PureBondAsset;
                        RPTw.ConvertableBondAsset += RPTi.ConvertableBondAsset;
                    }

                    NAVw.UnitNAV      = NAVw.UnitNAV / RPTw.TotalShare;
                    NAVw.AccumUnitNAV = NAVw.UnitNAV;
                    WholeFund.TradingNAV.AdjustedTimeSeries.Add(NAVw);
                    WholeFund.FundReport.AdjustedTimeSeries.Add(RPTw);
                }

                //计算净值收益率
                WholeFund.TradingNAV.Calculate();
                WholeFund.FundReport.Calculate();
            }
            catch (Exception ex)
            {
                throw new Exception(Message.C_Msg_MF11, ex);
            }
            #endregion

            return(WholeFund);
        }
예제 #4
0
 public abstract void LoadMutualFundInfo(MutualFund f);