[Quantproject-developers] QuantProject/b4_Business/a2_Strategies/Eligibles ByMostDiscountedPrices.
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2011-01-16 18:34:30
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Eligibles In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv7575/a2_Strategies/Eligibles Modified Files: ByMostDiscountedPrices.cs Log Message: Updated ByMostDiscountedPrices IEligiblesSelectors Index: ByMostDiscountedPrices.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Eligibles/ByMostDiscountedPrices.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ByMostDiscountedPrices.cs 20 Nov 2010 18:55:41 -0000 1.1 --- ByMostDiscountedPrices.cs 16 Jan 2011 18:34:18 -0000 1.2 *************** *** 29,33 **** using QuantProject.Data.DataTables; using QuantProject.Data.Selectors; ! using QuantProject.Business.Financial.Fundamentals; namespace QuantProject.Business.Strategies.Eligibles --- 29,33 ---- using QuantProject.Data.DataTables; using QuantProject.Data.Selectors; ! using QuantProject.Business.Financial.Fundamentals.FairValueProviders; namespace QuantProject.Business.Strategies.Eligibles *************** *** 40,50 **** /// are returned depending on the time the selection is requested: /// the group SP 500 should be like that); ! /// -step 2: from tickers selected by step 1, the ones /// (not more than a given max number) that have ! /// the greatest (negative) relative difference between the current price ! /// and the fair price; /// </summary> [Serializable] ! public class ByMostDiscountedPrices : IEligiblesSelector { public event NewMessageEventHandler NewMessage; --- 40,54 ---- /// are returned depending on the time the selection is requested: /// the group SP 500 should be like that); ! /// -step 2: from tickers selected by step 1, only the ones ! /// that have incomes greater than a given minimum in the ! /// last given times, in a row ! /// -step 3: from tickers selected by step 2, the ones /// (not more than a given max number) that have ! /// the greatest relative difference between the fair price ! /// (provided by a IFairValueProvider) and the average price ! /// computed for a given number of days /// </summary> [Serializable] ! public class ByMostDiscountedPrices : IEligiblesSelector { public event NewMessageEventHandler NewMessage; *************** *** 55,58 **** --- 59,67 ---- private int numOfDaysForFundamentalAnalysis; private IFairValueProvider fairValueProvider; + private int numDaysForFundamentalDataAvailability; + private double minimumIncome; + private int numberOfMinGrowingIncomesInARowForTickers; + private double minimumRelativeDifferenceBetweenFairAndAverageMarketPrice; + private int numOfDaysForAverageMarketPriceComputation; public string Description *************** *** 68,72 **** public ByMostDiscountedPrices(IFairValueProvider fairValueProvider, string tickersGroupID , bool temporizedGroup, ! int maxNumberOfEligibleTickersToBeChosen, int numOfDaysForFundamentalAnalysis) { this.fairValueProvider = fairValueProvider; --- 77,85 ---- public ByMostDiscountedPrices(IFairValueProvider fairValueProvider, string tickersGroupID , bool temporizedGroup, ! int maxNumberOfEligibleTickersToBeChosen, int numOfDaysForFundamentalAnalysis, ! int numDaysForFundamentalDataAvailability, double minimumIncome, ! int numberOfMinGrowingIncomesInARowForTickers, ! double minimumRelativeDifferenceBetweenFairAndAverageMarketPrice, ! int numOfDaysForAverageMarketPriceComputation) { this.fairValueProvider = fairValueProvider; *************** *** 76,79 **** --- 89,101 ---- this.tickersGroupID = tickersGroupID; this.numOfDaysForFundamentalAnalysis = numOfDaysForFundamentalAnalysis; + this.numDaysForFundamentalDataAvailability = + numDaysForFundamentalDataAvailability; + this.minimumIncome = minimumIncome; + this.numberOfMinGrowingIncomesInARowForTickers = + numberOfMinGrowingIncomesInARowForTickers; + this.minimumRelativeDifferenceBetweenFairAndAverageMarketPrice = + minimumRelativeDifferenceBetweenFairAndAverageMarketPrice; + this.numOfDaysForAverageMarketPriceComputation = + numOfDaysForAverageMarketPriceComputation; } *************** *** 81,107 **** DataTable initialTableFromWhichToChooseTheMostDiscountedTickers, DateTime date ) { DataTable tableOfEligibleTickers; if(!initialTableFromWhichToChooseTheMostDiscountedTickers.Columns.Contains("FairPrice")) initialTableFromWhichToChooseTheMostDiscountedTickers.Columns.Add("FairPrice", System.Type.GetType("System.Double")); ! if(!initialTableFromWhichToChooseTheMostDiscountedTickers.Columns.Contains("MarketPrice")) ! initialTableFromWhichToChooseTheMostDiscountedTickers.Columns.Add("LastMonthAverageMarketPrice", System.Type.GetType("System.Double")); if(!initialTableFromWhichToChooseTheMostDiscountedTickers.Columns.Contains("RelativeDifferenceBetweenFairAndMarketPrice")) initialTableFromWhichToChooseTheMostDiscountedTickers.Columns.Add("RelativeDifferenceBetweenFairAndMarketPrice", System.Type.GetType("System.Double")); foreach(DataRow row in initialTableFromWhichToChooseTheMostDiscountedTickers.Rows) { ! row["FairPrice"] = ! this.fairValueProvider.GetFairValue( (string)row[0], ! date.AddDays(-this.numOfDaysForFundamentalAnalysis), ! date ); ! float[] lastMonthQuotes = ! Quotes.GetArrayOfAdjustedCloseQuotes((string)row[0], date.AddDays(-30), date); ! row["LastMonthAverageMarketPrice"] = ! ADT.Statistics.BasicFunctions.SimpleAverage(lastMonthQuotes); ! row["RelativeDifferenceBetweenFairAndMarketPrice"] = ! ((double)row["FairPrice"]-(double)row["LastMonthAverageMarketPrice"])/(double)row["FairPrice"]; } ! tableOfEligibleTickers = ExtendedDataTable.CopyAndSort(initialTableFromWhichToChooseTheMostDiscountedTickers, ! "RelativeDifferenceBetweenFairAndMarketPrice", true); ExtendedDataTable.DeleteRows(tableOfEligibleTickers, this.maxNumberOfEligibleTickersToBeChosen); --- 103,147 ---- DataTable initialTableFromWhichToChooseTheMostDiscountedTickers, DateTime date ) { + double signOfCurrentFairPrice; + double currentFairPrice; DataTable tableOfEligibleTickers; if(!initialTableFromWhichToChooseTheMostDiscountedTickers.Columns.Contains("FairPrice")) initialTableFromWhichToChooseTheMostDiscountedTickers.Columns.Add("FairPrice", System.Type.GetType("System.Double")); ! if(!initialTableFromWhichToChooseTheMostDiscountedTickers.Columns.Contains("AverageMarketPrice")) ! initialTableFromWhichToChooseTheMostDiscountedTickers.Columns.Add("AverageMarketPrice", System.Type.GetType("System.Double")); if(!initialTableFromWhichToChooseTheMostDiscountedTickers.Columns.Contains("RelativeDifferenceBetweenFairAndMarketPrice")) initialTableFromWhichToChooseTheMostDiscountedTickers.Columns.Add("RelativeDifferenceBetweenFairAndMarketPrice", System.Type.GetType("System.Double")); foreach(DataRow row in initialTableFromWhichToChooseTheMostDiscountedTickers.Rows) { ! try{ ! currentFairPrice = this.fairValueProvider.GetFairValue( (string)row[0], ! date.AddDays(-this.numOfDaysForFundamentalAnalysis), ! date ); ! row["FairPrice"] = currentFairPrice; ! double[] quotesForAveragePriceComputation = ! Quotes.GetDoubleArrayOfAdjustedCloseQuotes((string)row[0], date.AddDays(-this.numOfDaysForAverageMarketPriceComputation), date); ! row["AverageMarketPrice"] = ! ADT.Statistics.BasicFunctions.SimpleAverage(quotesForAveragePriceComputation); ! if(currentFairPrice < 0.0) ! signOfCurrentFairPrice = -1.0; ! else ! signOfCurrentFairPrice = 1.0; ! row["RelativeDifferenceBetweenFairAndMarketPrice"] = signOfCurrentFairPrice * ! ((double)row["FairPrice"]-(double)row["AverageMarketPrice"])/(double)row["AverageMarketPrice"]; ! } ! catch(Exception ex) ! { ! string s = ex.ToString(); ! } } ! string filterString = ! "AverageMarketPrice is not null AND FairPrice is not null AND " + ! "RelativeDifferenceBetweenFairAndMarketPrice >" + ! this.minimumRelativeDifferenceBetweenFairAndAverageMarketPrice.ToString(); ! ! tableOfEligibleTickers = ExtendedDataTable.CopyAndSort(initialTableFromWhichToChooseTheMostDiscountedTickers, ! filterString, ! "RelativeDifferenceBetweenFairAndMarketPrice", false); ExtendedDataTable.DeleteRows(tableOfEligibleTickers, this.maxNumberOfEligibleTickersToBeChosen); *************** *** 127,132 **** group = new SelectorByGroup(this.tickersGroupID); DataTable tickersFromGroup = group.GetTableOfSelectedTickers(); ! return this.getEligibleTickers_actually_getTableOfMostDiscountedTickers(tickersFromGroup, currentDate); } --- 167,179 ---- group = new SelectorByGroup(this.tickersGroupID); DataTable tickersFromGroup = group.GetTableOfSelectedTickers(); + SelectorByNumOfMinGrowingIncomesInARow selectorByMinimumGrowingIncomes = + new SelectorByNumOfMinGrowingIncomesInARow(tickersFromGroup, history.FirstDateTime, + history.LastDateTime, + this.minimumIncome, this.numberOfMinGrowingIncomesInARowForTickers, + 12, this.numDaysForFundamentalDataAvailability); + DataTable tickersWithPositiveGrowingIncomes = + selectorByMinimumGrowingIncomes.GetTableOfSelectedTickers(); ! return this.getEligibleTickers_actually_getTableOfMostDiscountedTickers(tickersWithPositiveGrowingIncomes, currentDate); } |