[Quantproject-developers] QuantProject/b4_Business/a1_Financial/a4_Fundamentals/RatioProviders Ave
Brought to you by:
glauco_1
Update of /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a4_Fundamentals/RatioProviders In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv16924 Added Files: AverageAndDebtAdjustedGrowthRateProvider.cs LastAvailableGrowthRateProvider.cs LastAvailablePEProvider.cs Log Message: Added classes implementing IGrowthProvider and IRatioProvider_PE interfaces --- NEW FILE: AverageAndDebtAdjustedGrowthRateProvider.cs --- /* QuantProject - Quantitative Finance Library AverageAndDebtAdjustedGrowthRateProvider.cs Copyright (C) 2011 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.*/ using System; using System.Data; using QuantProject.DataAccess.Tables; using QuantProject.Business.DataProviders; using QuantProject.Business.Financial.Fundamentals; using QuantProject.Business.Financial.Fundamentals.RatioProviders; namespace QuantProject.Business.Financial.Fundamentals.RatioProviders { /// <summary> /// Class implementing IGrowthRateProvider Interface /// It provides an average growth rate, based on past /// incomes and then adjusted by the long term ratio level /// </summary> [Serializable] public class AverageAndDebtAdjustedGrowthRateProvider : FundamentalDataProvider, IGrowthRateProvider { protected double optimalDebtEquityRatio; protected int maximumNumberOfGrowthRatesToTakeIntoAccount; public AverageAndDebtAdjustedGrowthRateProvider( int daysForAvailabilityOfData, int maximumNumberOfGrowthRatesToTakeIntoAccount, double optimalDebtEquityRatio) : base( daysForAvailabilityOfData ) { this.optimalDebtEquityRatio = optimalDebtEquityRatio; this.maximumNumberOfGrowthRatesToTakeIntoAccount = maximumNumberOfGrowthRatesToTakeIntoAccount; } private double getGrowthRate_getLastAvailableDebtEquityRatio( string ticker , DateTime atDate ) { double returnValue = this.optimalDebtEquityRatio; //if not available the given optimalDebtEquityRatio is returned, //so not to bias the estimated average growth rate DateTime limitDateForEndingPeriodDate = atDate.AddDays(- this.daysForAvailabilityOfData); DataTable tableOfDebtEquityRatios = FinancialValues.GetLastFinancialValuesForTicker( ticker, 64, 12, limitDateForEndingPeriodDate);//64 CODE FOR DEBT EQUITY RATIO int numOfRows = tableOfDebtEquityRatios.Rows.Count; if( numOfRows > 0) returnValue = Math.Abs((double)tableOfDebtEquityRatios.Rows[ numOfRows - 1 ]["fvValue"]); return returnValue; } private double[] getGrowthRate_getAverageGrowthRate_getGrowthRates( double[] allAvailableGrowthRates ) { int numOfAvailableGrowthRates = allAvailableGrowthRates.Length; int numOfRatesToTakeIntoAccount = Math.Min(numOfAvailableGrowthRates, this.maximumNumberOfGrowthRatesToTakeIntoAccount); double[] returnValue = new double[numOfRatesToTakeIntoAccount]; for(int i = 0; i < numOfRatesToTakeIntoAccount; i++) { returnValue[i] = allAvailableGrowthRates[numOfAvailableGrowthRates - (numOfRatesToTakeIntoAccount - i)]; } return returnValue; } private double getGrowthRate_getAverageGrowthRate( DataTable tableOfEarnings ) { double returnValue; int numOfRows = tableOfEarnings.Rows.Count; double[] growthRates = new double[ numOfRows - 1 ]; for(int i = 0; i < growthRates.Length ; i++) { growthRates[i] = ( (double)tableOfEarnings.Rows[ i + 1 ]["fvValue"] - (double)tableOfEarnings.Rows[ i ]["fvValue"] ) / (double)tableOfEarnings.Rows[ i ]["fvValue"]; } double[] growthRatesToTakeIntoAccount = this.getGrowthRate_getAverageGrowthRate_getGrowthRates(growthRates); returnValue = ADT.Statistics.BasicFunctions.SimpleAverage(growthRatesToTakeIntoAccount); return returnValue; } public double GetGrowthRate( string ticker , DateTime atDate ) { double returnValue; DateTime limitDateForEndingPeriodDate = atDate.AddDays(- this.daysForAvailabilityOfData); //40 financial code for "net income" DataTable tableOfEarnings = FinancialValues.GetLastFinancialValuesForTicker( ticker, 40, 12, limitDateForEndingPeriodDate); double averageGrowthRate = this.getGrowthRate_getAverageGrowthRate(tableOfEarnings); double lastAvailableDebtEquityRatio = this.getGrowthRate_getLastAvailableDebtEquityRatio(ticker, atDate); returnValue = averageGrowthRate * Math.Min(1.0, (this.optimalDebtEquityRatio / lastAvailableDebtEquityRatio ) ); return returnValue; } } } --- NEW FILE: LastAvailablePEProvider.cs --- /* QuantProject - Quantitative Finance Library LastAvailablePEProvider.cs Copyright (C) 2010 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.*/ using System; using QuantProject.DataAccess.Tables; using QuantProject.Business.DataProviders; using QuantProject.Business.Financial.Fundamentals; using QuantProject.Business.Financial.Fundamentals.RatioProviders; namespace QuantProject.Business.Financial.Fundamentals.RatioProviders { /// <summary> /// Class implementing IRatioProvider_PE Interface /// It provides the last available PE, using the last available price /// and the last available Earnings. /// Instead of the last available price, /// the average of the last available prices can be used /// (it depends on how the class has been instatiated) /// </summary> [Serializable] public class LastAvailablePEProvider : FundamentalDataProvider, IRatioProvider_PE { private HistoricalMarketValueProvider historicalmarketValueProvider; public LastAvailablePEProvider(HistoricalMarketValueProvider historicalmarketValueProvider, int daysForAvailabilityOfData) : base(daysForAvailabilityOfData) { this.historicalmarketValueProvider = historicalmarketValueProvider; } private double getPERatio_getLastAvailableEarningsPerShare(string ticker , DateTime atDate) { double returnValue; DateTime limitDateForEndingPeriodDate = atDate.AddDays(- this.daysForAvailabilityOfData); //56 code for EPS; 12 months = length of period financial value refers to returnValue = FinancialValues.GetLastFinancialValueForTicker(ticker, 56, 12, limitDateForEndingPeriodDate); return returnValue; } public double GetPERatio( string ticker , DateTime atDate ) { double returnValue; double priceAtDate = this.historicalmarketValueProvider.GetMarketValue(ticker, atDate); double earningsPerShareAtDate = this.getPERatio_getLastAvailableEarningsPerShare(ticker , atDate); returnValue = priceAtDate / earningsPerShareAtDate; return returnValue; } } } --- NEW FILE: LastAvailableGrowthRateProvider.cs --- /* QuantProject - Quantitative Finance Library LastAvailableGrowthRateProvider.cs Copyright (C) 2010 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.*/ using System; using System.Data; using QuantProject.DataAccess.Tables; using QuantProject.Business.DataProviders; using QuantProject.Business.Financial.Fundamentals; using QuantProject.Business.Financial.Fundamentals.RatioProviders; namespace QuantProject.Business.Financial.Fundamentals.RatioProviders { /// <summary> /// Class implementing IGrowthRateProvider Interface /// It provides the last available growth rate (of earnings) /// </summary> [Serializable] public class LastAvailableGrowthRateProvider : FundamentalDataProvider, IGrowthRateProvider { public LastAvailableGrowthRateProvider( int daysForAvailabilityOfData ) : base( daysForAvailabilityOfData ) { } public double GetGrowthRate( string ticker , DateTime atDate ) { double returnValue; double lastEarnings; double previousEarnings; DateTime limitDateForEndingPeriodDate = atDate.AddDays(- this.daysForAvailabilityOfData); //40 financial code for "net income" DataTable tableOfEarnings = FinancialValues.GetLastFinancialValuesForTicker( ticker, 40, 12, limitDateForEndingPeriodDate); int numOfRows = tableOfEarnings.Rows.Count; previousEarnings = (double)tableOfEarnings.Rows[numOfRows - 2]["fvValue"]; lastEarnings = (double)tableOfEarnings.Rows[numOfRows - 1]["fvValue"]; returnValue = (lastEarnings - previousEarnings)/previousEarnings; return returnValue; } } } |