示例#1
0
文件: DcfVM.cs 项目: AFFA/Project
        public DcfVM(DataGrid dataGrid, DcfDataDao dcfDataDao, DcfInput dcfInput, FinDataDao finDataDao, FinDataAdapter finDataAdapter)
        {
            _dataGrid = dataGrid;
            _rowMapping = Rowmapping.DcfRows();
            _showForecastTable = new ObservableCollection<ForecastData>();
            _columnHeader = new List<string>();
            _dcfDataDao = dcfDataDao;
            _dcfInput = dcfInput;
            _finDataDao = finDataDao;
            _finDataAdapter = finDataAdapter;

            _finDataAdapter.DcfOutput.PropertyChanged += OutputChangedEventHandler;
        }
示例#2
0
 public void AddDcfInput(DcfInput di)
 {
     _dcfInput = di;
 }
示例#3
0
        /// <summary>
        /// Beta arvutus
        /// </summary>
        /// <param name="finDataAdapter">Adapter kõigi finantsandmete kättesaamise jaoks</param>
        /// <param name="dcfInput">DCF arvutuste eelduste hoidja</param>
        public static void CalculateBeta(FinDataAdapter finDataAdapter, DcfInput dcfInput)
        {
            BivariateSample bivariate = new BivariateSample();
            MultivariateSample mv = new MultivariateSample(2);
            decimal prevPrice = 0;
            double? prevIndex = null;
            decimal curPrice = 0;
            double? curIndex = null;
            int k = 0;
            for (int i = 0; i < finDataAdapter.PriceDataDao.PriceDatas.Count; i = i + 22)
            {
                if (k < 36)
                {
                    PriceData pd = finDataAdapter.PriceDataDao.PriceDatas[i];
                    curPrice = pd.AdjClose;
                    curIndex = finDataAdapter.PriceDataDao.GetClosePrice(pd.PriceDate, finDataAdapter.PriceDataDao.IndexDatas)[0];
                    if (curPrice != 0 && curIndex != null && prevPrice != 0 && prevIndex != null)
                    {
                        //MessageBox.Show("s:" + ((double)(prevPrice / curPrice) - 1));
                        //MessageBox.Show("i:" + ((double)(prevIndex / curIndex) - 1));
                        ////bivariate.Add((double) (prevPrice/curPrice)-1,(double) (prevIndex/curIndex)-1);
                        double[] db = new double[2];
                        db[0] = ((double)(prevPrice / curPrice) - 1);
                        db[1] = ((double)(prevIndex / curIndex) - 1);
                        mv.Add(db);
                    }
                    prevPrice = curPrice;
                    prevIndex = curIndex;

                    //DateTime dt = finDataAdapter.PriceDataDao.PriceDatas[i].PriceDate;

                    //MessageBox.Show(finDataAdapter.PriceDataDao.PriceDatas[i].AdjClose + " " +
                    //                dt.ToShortDateString());
                    //MessageBox.Show(finDataAdapter.PriceDataDao.GetClosePrice(dt, finDataAdapter.PriceDataDao.IndexDatas)[0].ToString());
                }
                k++;
            }

            if (mv.Count > 10)
            {
                //FitResult fitResult = bivariate.LinearRegression();
                FitResult fitResult = mv.LinearRegression(0);
                dcfInput.Beta = fitResult.Parameter(1).Value;
                List<FinData> finDatas = finDataAdapter.FinDataDao.FinDatas;

                dcfInput.CostOfEquity = dcfInput.RiskFreeRate + dcfInput.Beta * dcfInput.MarketRiskPremium;
                double debt = 0;
                if (finDatas[finDatas.Count - 1].BsCurrentPortionOfLongTermDebt != null)
                {
                    debt += (double)finDatas[finDatas.Count - 1].BsCurrentPortionOfLongTermDebt;
                }
                if (finDatas[finDatas.Count - 1].BsTotalLongTermDebt != null)
                {
                    debt += (double)finDatas[finDatas.Count - 1].BsTotalLongTermDebt;
                }
                double total = 0.0;
                if (finDatas[finDatas.Count - 1].BsShareholdersEquity1 != null)
                {
                    total += (double)(finDatas[finDatas.Count - 1].BsShareholdersEquity1);
                }
                total += debt;

                try
                {
                    dcfInput.Wacc = dcfInput.CostOfEquity *
                                    (double)(finDatas[finDatas.Count - 1].BsShareholdersEquity1 / total) +
                                    dcfInput.CostOfDebt * (double)(debt / total) * (1 - dcfInput.TaxRate);
                }
                catch (InvalidOperationException) { }
                //MessageBox.Show("beta: "+fitResult.Parameter(1).Value.ToString());
                //double[] pars = fitResult.Parameters();
                //foreach (var par in pars)
                //{
                //    MessageBox.Show(par.ToString());

                //}

                //MessageBox.Show(fitResult.CorrelationCoefficient(0,1).ToString());
                //double[] gfit = fitResult.
                //MessageBox.Show(fitResult.);

                //MessageBox.Show(fitResult.Parameter(2).ToString());
            }
        }
示例#4
0
        /// <summary>
        /// Meetod kõigi sisendite (ehk eelduste) välja arvutamiseks
        /// </summary>
        /// <param name="finDataAdapter">Adapter kõigi finantsandmete kättesaamise jaoks</param>
        /// <param name="dcfInput">DCF arvutuste eelduste hoidja</param>
        public static void CalculateInput(FinDataAdapter finDataAdapter, DcfInput dcfInput)
        {
            CalculateCorrelation(finDataAdapter, dcfInput);
            int requiredPeriodsForMean = 1;
            List<FinData> finDatas = finDataAdapter.FinDataDao.FinDatas;
            int k = 0;
            Sample sampleRevenue = new Sample();
            Sample sampleTax = new Sample();
            Sample sampleInterest = new Sample();

            Sample sampleTotalAssets = new Sample();
            Sample sampleTotalLiabilities = new Sample();
            Sample sampleTotalCurrentAssets = new Sample();
            Sample sampleTotalCurrentLiabilities = new Sample();
            Sample sampleAllCosts = new Sample();
            Sample sampleEbitda = new Sample();
            Sample sampleDepreciation = new Sample();
            Sample sampleEbit = new Sample();

            for (int i = finDatas.Count - 1; i >= 4; i--)
            {
                if (k < 12)
                {
                    if (k == 0)
                    {
                        try
                        {
                            dcfInput.SharesOutstanding = (double)finDatas[i].BsCommonSharesOutstanding;
                        }
                        catch (InvalidOperationException) { }
                    }
                    try
                    {
                        double RevenueGrowth = (double)(finDatas[i].IsRevenue / finDatas[i - 4].IsRevenue) - 1;
                        sampleRevenue.Add(RevenueGrowth);
                    }
                    catch (InvalidOperationException) { }

                    try
                    {
                        double taxRate = (double)((finDatas[i].IsPretaxIncome - finDatas[i].IsIncomeAfterTax) / finDatas[i].IsPretaxIncome);
                        sampleTax.Add(taxRate);
                    }
                    catch (InvalidOperationException) { }

                    double debt = 0;
                    if (finDatas[i].BsCurrentPortionOfLongTermDebt != null)
                    {
                        debt += (double)finDatas[i].BsCurrentPortionOfLongTermDebt;
                    }
                    if (finDatas[i].BsTotalLongTermDebt != null)
                    {
                        debt += (double)finDatas[i].BsTotalLongTermDebt;
                    }
                    if (finDatas[i].FrInterestExpense != null && debt != 0.0)
                    {
                        double interest = (double)(finDatas[i].FrInterestExpense) / debt;
                        if (interest < 0.2)
                        {
                            sampleInterest.Add(interest);
                        }
                    }

                    if (finDatas[i].IsRevenue != null && finDatas[i].IsRevenue != 0.0 && finDatas[i].BsTotalAssets != null)
                    {
                        double temp = (double)(finDatas[i].BsTotalAssets / finDatas[i].IsRevenue);
                        if (temp > 0.5 && temp < 50)
                        {
                            sampleTotalAssets.Add(temp);
                        }
                    }
                    if (finDatas[i].IsRevenue != null && finDatas[i].IsRevenue != 0.0 && finDatas[i].BsTotalLiabilities != null)
                    {
                        double temp = (double)(finDatas[i].BsTotalLiabilities / finDatas[i].IsRevenue);
                        if (temp > 0.5 && temp < 50)
                        {
                            sampleTotalLiabilities.Add(temp);
                        }
                    }

                    if (finDatas[i].IsRevenue != null && finDatas[i].IsRevenue != 0.0 && finDatas[i].BsTotalCurrentAssets != null)
                    {
                        double temp = (double)(finDatas[i].BsTotalCurrentAssets / finDatas[i].IsRevenue);
                        if (temp > 0.5 && temp < 50)
                        {
                            sampleTotalCurrentAssets.Add(temp);
                        }
                    }
                    if (finDatas[i].IsRevenue != null && finDatas[i].IsRevenue != 0.0 && finDatas[i].BsTotalCurrentLiabilities != null)
                    {
                        double temp = (double)(finDatas[i].BsTotalCurrentLiabilities / finDatas[i].IsRevenue);
                        if (temp > 0.5 && temp < 50)
                        {
                            sampleTotalCurrentLiabilities.Add(temp);
                        }
                    }

                    double allCosts = 0.0;
                    if (finDatas[i].IsTotalOperatingExpenses != null)
                    {
                        allCosts += (double)finDatas[i].IsTotalOperatingExpenses;
                    }
                    if (finDatas[i].IsDepreciationAmortization != null)
                    {
                        allCosts -= (double)finDatas[i].IsDepreciationAmortization;
                    }
                    if (finDatas[i].IsRevenue != null && finDatas[i].IsRevenue != 0.0 && allCosts != 0.0)
                    {
                        double temp = (double)(allCosts / finDatas[i].IsRevenue);
                        if (temp > 0.1 && temp < 1)
                        {
                            sampleAllCosts.Add(temp);
                        }
                    }

                    if (finDatas[i].IsRevenue != null && finDatas[i].IsRevenue != 0.0 && finDatas[i].FrEbitda != null)
                    {
                        double temp = (double)(finDatas[i].FrEbitda / finDatas[i].IsRevenue);
                        if (temp > -1.0 && temp < 1.0)
                        {
                            sampleEbitda.Add(temp);
                        }
                    }

                    if (finDatas[i].IsRevenue != null && finDatas[i].IsRevenue != 0.0 && finDatas[i].IsDepreciationAmortization != null)
                    {
                        double temp = (double)(finDatas[i].IsDepreciationAmortization / finDatas[i].IsRevenue);
                        if (temp > -1.0 && temp < 1.0)
                        {
                            sampleDepreciation.Add(temp);
                        }
                    }
                    if (finDatas[i].IsRevenue != null && finDatas[i].IsRevenue != 0.0 && finDatas[i].FrEbit != null)
                    {
                        double temp = (double)(finDatas[i].FrEbit / finDatas[i].IsRevenue);
                        if (temp > -1.0 && temp < 1.0)
                        {
                            sampleEbit.Add(temp);
                        }
                    }

                }

                k++;
            }

            if (sampleRevenue.Count >= requiredPeriodsForMean)
            {
                dcfInput.GrowthRatePrognosis = sampleRevenue.Mean;
            }
            if (sampleTax.Count >= requiredPeriodsForMean)
            {
                dcfInput.TaxRate = sampleTax.Mean;
            }
            if (sampleInterest.Count >= requiredPeriodsForMean)
            {
                dcfInput.CostOfDebt = sampleInterest.Mean;
            }

            if (sampleTotalAssets.Count >= requiredPeriodsForMean)
            {
                dcfInput.TotalAssetsPrcRevenue = sampleTotalAssets.Mean;
            }
            if (sampleTotalLiabilities.Count >= requiredPeriodsForMean)
            {
                dcfInput.TotalLiabilitiesPrcRevenue = sampleTotalLiabilities.Mean;
            }
            if (sampleTotalCurrentAssets.Count >= requiredPeriodsForMean)
            {
                dcfInput.TotalCurrentAssetsPrcRevenue = sampleTotalCurrentAssets.Mean;
            }
            if (sampleTotalCurrentLiabilities.Count >= requiredPeriodsForMean)
            {
                dcfInput.TotalCurrentLiabilitiesPrcRevenue = sampleTotalCurrentLiabilities.Mean;
            }
            if (sampleAllCosts.Count >= requiredPeriodsForMean)
            {
                dcfInput.AllCostsPrcRevenue = sampleAllCosts.Mean;
            }
            if (sampleEbitda.Count >= requiredPeriodsForMean)
            {
                dcfInput.EbitdaPrcRevenue = sampleEbitda.Mean;
            }
            if (sampleDepreciation.Count >= requiredPeriodsForMean)
            {
                dcfInput.DepreciationPrcRevenue = sampleDepreciation.Mean;
            }
            if (sampleEbit.Count >= requiredPeriodsForMean)
            {
                dcfInput.EbitPrcRevenue = sampleEbit.Mean;
            }
        }
示例#5
0
        /// <summary>
        /// Korrelatsiooni arvutus valitud näitajate jaoks (Total Assets, Total Liabilities, Total Current Assets, Total Current Liabilities: vs Reveneue)
        /// </summary>
        /// <param name="finDataAdapter">Adapter kõigi finantsandmete kättesaamise jaoks</param>
        /// <param name="dcfInput">DCF arvutuste eelduste hoidja</param>
        public static void CalculateCorrelation(FinDataAdapter finDataAdapter, DcfInput dcfInput)
        {
            MultivariateSample mvTA = new MultivariateSample(2);
            MultivariateSample mvTL = new MultivariateSample(2);
            MultivariateSample mvCA = new MultivariateSample(2);
            MultivariateSample mvCL = new MultivariateSample(2);
            int k = 0;
            List<FinData> finDatas = finDataAdapter.FinDataDao.FinDatas;
            for (int i = finDataAdapter.FinDataDao.FinDatas.Count - 1; i >= 0; i--)
            {
                if (k < 20)
                {
                    double revChange = 0;
                    try
                    {
                        //revChange = (double) (finDatas[i].IsRevenue/finDatas[i - 5].IsRevenue);
                        revChange = (double)finDatas[i].IsRevenue;
                    }
                    catch (InvalidOperationException) { }
                    double caChange = 0;
                    try
                    {
                        //secChange = (double)(finDatas[i].BsTotalCurrentAssets / finDatas[i - 5].BsTotalCurrentAssets);
                        caChange = (double)finDatas[i].BsTotalCurrentAssets;
                    }
                    catch (InvalidOperationException) { }

                    double clChange = 0;
                    try
                    {
                        //secChange = (double)(finDatas[i].BsTotalCurrentAssets / finDatas[i - 5].BsTotalCurrentAssets);
                        clChange = (double)finDatas[i].BsTotalCurrentLiabilities;
                    }
                    catch (InvalidOperationException) { }
                    double taChange = 0;
                    try
                    {
                        //secChange = (double)(finDatas[i].BsTotalCurrentAssets / finDatas[i - 5].BsTotalCurrentAssets);
                        taChange = (double)finDatas[i].BsTotalAssets;
                    }
                    catch (InvalidOperationException) { }
                    double tlChange = 0;
                    try
                    {
                        //secChange = (double)(finDatas[i].BsTotalCurrentAssets / finDatas[i - 5].BsTotalCurrentAssets);
                        tlChange = (double)finDatas[i].BsTotalLiabilities;
                    }
                    catch (InvalidOperationException) { }

                    //MessageBox.Show("s:" + ((double)(prevPrice / curPrice) - 1));
                    //MessageBox.Show("i:" + ((double)(prevIndex / curIndex) - 1));
                    ////bivariate.Add((double) (prevPrice/curPrice)-1,(double) (prevIndex/curIndex)-1);
                    double[] db = new double[2];
                    db[0] = caChange;
                    db[1] = revChange;
                    if (db[0] != 0 || db[1] != 0)
                        mvCA.Add(db);

                    db = new double[2];
                    db[0] = clChange;
                    db[1] = revChange;
                    if (db[0] != 0 || db[1] != 0)
                        mvCL.Add(db);

                    db = new double[2];
                    db[0] = taChange;
                    db[1] = revChange;
                    if (db[0] != 0 || db[1] != 0)
                        mvTA.Add(db);

                    db = new double[2];
                    db[0] = tlChange;
                    db[1] = revChange;
                    if (db[0] != 0 || db[1] != 0)
                        mvTL.Add(db);

                    //DateTime dt = finDataAdapter.PriceDataDao.PriceDatas[i].PriceDate;

                    //MessageBox.Show(finDataAdapter.PriceDataDao.PriceDatas[i].AdjClose + " " +
                    //                dt.ToShortDateString());
                    //MessageBox.Show(finDataAdapter.PriceDataDao.GetClosePrice(dt, finDataAdapter.PriceDataDao.IndexDatas)[0].ToString());
                }
                k++;
            }

            // peab vähemalt olema 3 vaatlust
            if (mvCA.Count > 2)
            {
                //FitResult fitResult = bivariate.LinearRegression();

                FitResult fitResult = mvCA.LinearRegression(0);

                dcfInput.TotalCurrentAssetsBeta = fitResult.Parameter(1).Value;
                dcfInput.TotalCurrentAssetsAlpha = fitResult.Parameter(0).Value;

                fitResult = mvCL.LinearRegression(0);
                dcfInput.TotalCurrentLiabilitiesBeta = fitResult.Parameter(1).Value;
                dcfInput.TotalCurrentLiabilitiesAlpha = fitResult.Parameter(0).Value;

                fitResult = mvTA.LinearRegression(0);
                dcfInput.TotalAssetsBeta = fitResult.Parameter(1).Value;
                dcfInput.TotalAssetsAlpha = fitResult.Parameter(0).Value;

                fitResult = mvTL.LinearRegression(0);
                dcfInput.TotalLiabilitiesBeta = fitResult.Parameter(1).Value;
                dcfInput.TotalLiabilitiesAlpha = fitResult.Parameter(0).Value;

                //MessageBox.Show("alfa: " + fitResult.Parameter(0).Value.ToString());
                //MessageBox.Show("beta: "+fitResult.Parameter(1).Value.ToString());
                //double[] pars = fitResult.Parameters();
                //foreach (var par in pars)
                //{
                //    MessageBox.Show(par.ToString());

                //}

                //MessageBox.Show(fitResult.CorrelationCoefficient(0,1).ToString());
                //double[] gfit = fitResult.
                //MessageBox.Show(fitResult.);

                //MessageBox.Show(fitResult.Parameter(2).ToString());
            }
        }
示例#6
0
        /// <summary>
        /// Siin täidetakse juba loodud DCFData objekte täiendavate andmetega ajalooliste andmete puhul ja kõigi andmetega 
        /// tuleviku prognoosi objektide puhul.
        /// </summary>
        /// <param name="dcfDatas">DCFData list</param>
        /// <param name="dcfInput">Arvutuste tegemiseks sisendi objekt</param>
        public static void CalculateQuaterlyForecasts(List<DcfData> dcfDatas, DcfInput dcfInput)
        {
            for (int i = 0; i < dcfDatas.Count; i++)
            {

                // hakata välja arvutama DcfData välju, mis varem täidetud ei ole
                // olenevalt sellest, kas IsPrognosis on true või false, tuleb erinevalt arvutada
                // kui IsPrognosis=true, siis tuleb kasutada eelduste klassis DcfInput olevat infot, juba toimunud kvartalite puhul tavaliselt mitte

                // tulevikuprognoosi spetsiifiline arvutus:
                if (dcfDatas[i].IsPrognosis)
                {

                    dcfDatas[i].Revenue = dcfDatas[i - 4].Revenue * (1 + dcfInput.GrowthRatePrognosis);
                    if (dcfInput.TotalAssetsAlpha != 0 && dcfInput.TotalAssetsBeta != 0 && dcfInput.ForecastMethod == DcfInput.ForecastingMethod.LinearRegression)
                    {
                        dcfDatas[i].TotalCurrentAssets = dcfInput.TotalAssetsAlpha +
                                                         dcfInput.TotalAssetsBeta * dcfDatas[i].Revenue;
                    }
                    else
                    {
                        dcfDatas[i].TotalAssets = dcfDatas[i - 1].Revenue * dcfInput.TotalAssetsPrcRevenue;
                    }

                    if (dcfInput.TotalCurrentAssetsAlpha != 0 && dcfInput.TotalCurrentAssetsBeta != 0 && dcfInput.ForecastMethod == DcfInput.ForecastingMethod.LinearRegression)
                    {
                        dcfDatas[i].TotalCurrentAssets = dcfInput.TotalCurrentAssetsAlpha +
                                                         dcfInput.TotalCurrentAssetsBeta * dcfDatas[i].Revenue;
                    }
                    else
                    {
                        dcfDatas[i].TotalCurrentAssets = dcfDatas[i - 1].Revenue * dcfInput.TotalCurrentAssetsPrcRevenue;
                    }

                    if (dcfInput.TotalLiabilitiesAlpha != 0 && dcfInput.TotalLiabilitiesBeta != 0 && dcfInput.ForecastMethod==DcfInput.ForecastingMethod.LinearRegression)
                    {
                        dcfDatas[i].TotalCurrentAssets = dcfInput.TotalLiabilitiesAlpha +
                                                         dcfInput.TotalLiabilitiesBeta * dcfDatas[i].Revenue;
                    }
                    else
                    {
                        dcfDatas[i].TotalLiabilities = dcfDatas[i - 1].Revenue * dcfInput.TotalLiabilitiesPrcRevenue;
                    }
                    if (dcfInput.TotalCurrentLiabilitiesAlpha != 0 && dcfInput.TotalCurrentLiabilitiesBeta != 0 && dcfInput.ForecastMethod == DcfInput.ForecastingMethod.LinearRegression)
                    {
                        dcfDatas[i].TotalCurrentAssets = dcfInput.TotalCurrentLiabilitiesAlpha +
                                                         dcfInput.TotalCurrentLiabilitiesBeta * dcfDatas[i].Revenue;
                    }
                    else
                    {
                        dcfDatas[i].TotalCurrentLiabilities = dcfDatas[i - 1].Revenue *
                                                              dcfInput.TotalCurrentLiabilitiesPrcRevenue;
                    }

                    dcfDatas[i].AllCosts = dcfDatas[i - 1].Revenue * dcfInput.AllCostsPrcRevenue;
                    dcfDatas[i].Depreciation = dcfDatas[i - 1].Revenue * dcfInput.DepreciationPrcRevenue;
                    dcfDatas[i].Ebit = dcfDatas[i - 1].Revenue * dcfInput.EbitPrcRevenue;
                    dcfDatas[i].Ebitda = dcfDatas[i - 1].Revenue * dcfInput.EbitdaPrcRevenue;

                }

                // koigil samasugune arvutus
                dcfDatas[i].NetWorkingCapital = dcfDatas[i].TotalCurrentAssets - dcfDatas[i].TotalCurrentLiabilities;
                dcfDatas[i].Ebiat = dcfDatas[i].Ebit * (1 - dcfInput.TaxRate); // ebit*(1-tax rate)
                dcfDatas[i].TaxRate = dcfInput.TaxRate;
                dcfDatas[i].AllCostsEbitda = dcfDatas[i].AllCosts - dcfDatas[i].Ebitda;

                if (i > 0)
                {

                    dcfDatas[i].NetWorkingCapitalChange = dcfDatas[i].NetWorkingCapital - dcfDatas[i - 1].NetWorkingCapital;
                    dcfDatas[i].TotalAssetsChange = dcfDatas[i].TotalAssets - dcfDatas[i - 1].TotalAssets;
                    dcfDatas[i].TotalLiabilitiesChange = dcfDatas[i].TotalLiabilities - dcfDatas[i - 1].TotalLiabilities;
                    dcfDatas[i].Capex = dcfDatas[i].TotalAssetsChange - dcfDatas[i].TotalLiabilitiesChange; // arvutatakse assets ja liabilities muutude vahena
                    dcfDatas[i].Capexdepreciation = dcfDatas[i].TotalAssetsChange - dcfDatas[i].TotalLiabilitiesChange - dcfDatas[i].Depreciation;
                    dcfDatas[i].Fcff = dcfDatas[i].Ebiat - dcfDatas[i].Capexdepreciation - dcfDatas[i].NetWorkingCapitalChange;
                    if (i >= 4)
                    {
                        try
                        {
                            dcfDatas[i].RevenueGrowth = dcfDatas[i].Revenue / dcfDatas[i - 4].Revenue - 1;
                        }
                        catch (InvalidOperationException) { }
                    }
                }

            }
        }
示例#7
0
文件: DcfVM.cs 项目: AFFA/Project
        public DcfVM(DcfInput dcfInput)
        {
            _dcfInput = dcfInput;

            _dcfInput.PropertyChanged += MyEventHandler;
        }