[Quantproject-developers] QuantProject/b3_Data/Selectors SelectorByNumberOfMinimumIncomesInARow.cs,
Brought to you by:
glauco_1
Update of /cvsroot/quantproject/QuantProject/b3_Data/Selectors In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv4883/Selectors Added Files: SelectorByNumberOfMinimumIncomesInARow.cs SelectorByNumOfMinGrowingIncomesInARow.cs SelectorByPriceAndFairValueComparison.cs Log Message: Added Selectors by (very simple, at the moment) fundamental analysis --- NEW FILE: SelectorByPriceAndFairValueComparison.cs --- /* QuantProject - Quantitative Finance Library SelectorByPriceAndFairValueComparison.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.Collections; using System.Data; using System.Windows.Forms; using QuantProject.DataAccess.Tables; using QuantProject.Data.DataTables; using QuantProject. namespace QuantProject.Data.Selectors { /// <summary> /// Class for selection on tickers by the relative difference /// between price and fair value computed by the given /// IFairValueProvider /// </summary> public class SelectorByPriceAndFairValueComparison : TickerSelector, ITickerSelector { private IFairValueProvider fairValueProvider; #region SelectorByPriceAndFairValueComparison Constructors /// <summary> /// ITickerSelector class for selecting tickers /// by the relative difference /// between price and fair value computed by the given /// IFairValueProvider /// </summary> /// <param name="fairValueProvider">IFairValueProvider object, /// which provides fair value computation for a given /// tickers at a given date</param> /// <param name="setOfTickersToBeSelected">DataTable containing /// tickers that have to be selected</param> /// <param name="orderInASCmode">If true, returned tickers /// are ordered in Ascending mode - from less to most. If false /// , returned tickers are ordered in descending mode - from most to less</param> /// <param name="firstDateForFundamentalAnalysis"></param> /// <param name="lastDateForFundamentalAnalysis"></param> /// <param name="maxNumOfReturnedTickers">Max number of selected /// tickers to be returned</param> /// <returns></returns> public SelectorByPriceAndFairValueComparison(IFairValueProvider fairValueProvider, DataTable setOfTickersToBeSelected, bool orderInASCmode, DateTime firstDateForFundamentalAnalysis, DateTime lastDateForFundamentalAnalysis, long maxNumOfReturnedTickers): base(setOfTickersToBeSelected, orderInASCmode, firstDateForFundamentalAnalysis, firstDateForFundamentalAnalysis, maxNumOfReturnedTickers) { this.fairValueProvider = fairValueProvider; } #endregion SelectorByLiquidityConstructors public DataTable GetTableOfSelectedTickers() { DataTable returnTickers; if(this.setOfTickersToBeSelected == null) { if ( this.minVolume > long.MinValue ) // a min volume value has been requested returnTickers = QuantProject.DataAccess.Tables.Quotes.GetTickersByLiquidity(this.isOrderedInASCMode, this.groupID, this.firstQuoteDate, this.lastQuoteDate, this.minVolume , this.maxNumOfReturnedTickers); else // a min volume value has not been requested returnTickers = QuantProject.DataAccess.Tables.Quotes.GetTickersByLiquidity(this.isOrderedInASCMode, this.groupID, this.firstQuoteDate, this.lastQuoteDate, this.maxNumOfReturnedTickers); } else//a set of tickers, not a group ID, //has been passed to the selector { if ( this.minVolume > long.MinValue ) // a min volume value has been requested returnTickers = QuantProject.Data.DataTables.Quotes.GetTickersByLiquidity(this.isOrderedInASCMode, this.setOfTickersToBeSelected, this.firstQuoteDate, this.lastQuoteDate, this.minVolume, this.maxNumOfReturnedTickers, this.numberOfTopRowsToDelete); else returnTickers = QuantProject.Data.DataTables.Quotes.GetTickersByLiquidity(this.isOrderedInASCMode, this.setOfTickersToBeSelected, this.firstQuoteDate, this.lastQuoteDate, this.maxNumOfReturnedTickers, this.numberOfTopRowsToDelete); } return returnTickers; } public void SelectAllTickers() { ; } } } --- NEW FILE: SelectorByNumberOfMinimumIncomesInARow.cs --- /* QuantProject - Quantitative Finance Library SelectorByNumberOfMinimumIncomesInARow.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.Collections; using System.Data; using System.Windows.Forms; using QuantProject.ADT.Histories; using QuantProject.DataAccess.Tables; using QuantProject.Data.DataTables; namespace QuantProject.Data.Selectors { /// <summary> /// Class for selection on tickers which have a given number of /// minimum incomes previously than a given date /// </summary> public class SelectorByNumberOfMinimumIncomesInARow : TickerSelector , ITickerSelector { private double minimumIncome; private int numberOfIncomes; private int incomePeriodLengthInMonths; private int numDaysForFundamentalDataAvailability; public SelectorByNumberOfMinimumIncomesInARow(DataTable setOfTickersToBeSelected, DateTime firstQuoteDate, DateTime lastQuoteDate, double minimumIncome, int numberOfIncomes, int incomePeriodLengthInMonths, int numDaysForFundamentalDataAvailability): base(setOfTickersToBeSelected, true, firstQuoteDate, lastQuoteDate, 500) { this.minimumIncome = minimumIncome; this.numberOfIncomes = numberOfIncomes; this.incomePeriodLengthInMonths = incomePeriodLengthInMonths; this.numDaysForFundamentalDataAvailability = numDaysForFundamentalDataAvailability; } #region GetTableOfSelectedTickers private bool getTableOfSelectedTickers_areIncomesAllGreaterThanMinimum(DataTable incomesForTicker) { bool returnValue = true; double currentIncome; for(int i = 0; i < incomesForTicker.Rows.Count; i++) { currentIncome = (double)incomesForTicker.Rows[i]["fvValue"]; if( currentIncome < this.minimumIncome ) returnValue = false; } return returnValue; } public DataTable GetTableOfSelectedTickers() { DataTable returnValue = new DataTable(); returnValue.Columns.Add("Ticker", System.Type.GetType("System.String")); object[] values = new object[1]; string currentTicker; DataTable incomesForCurrentTicker; for(int i = 0; i < this.setOfTickersToBeSelected.Rows.Count; i++) { currentTicker = (string)this.setOfTickersToBeSelected.Rows[i][0]; incomesForCurrentTicker = FinancialValues.GetLastFinancialValuesForTicker(currentTicker, 40, 12, this.lastQuoteDate.AddDays(-this.numDaysForFundamentalDataAvailability)); if( this.getTableOfSelectedTickers_areIncomesAllGreaterThanMinimum(incomesForCurrentTicker) ) { values[0] = currentTicker; returnValue.Rows.Add(values); } } return returnValue; } #endregion GetTableOfSelectedTickers public void SelectAllTickers() { ; } } } --- NEW FILE: SelectorByNumOfMinGrowingIncomesInARow.cs --- /* QuantProject - Quantitative Finance Library SelectorByNumOfMinGrowingIncomesInARow.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.Collections; using System.Data; using System.Windows.Forms; using QuantProject.ADT.Histories; using QuantProject.DataAccess.Tables; using QuantProject.Data.DataTables; namespace QuantProject.Data.Selectors { /// <summary> /// Class for selection on tickers which have a given number of /// minimum incomes, always growing, previously than a given date /// </summary> public class SelectorByNumOfMinGrowingIncomesInARow : TickerSelector , ITickerSelector { private double minimumIncome; private int numberOfIncomes; private int incomePeriodLengthInMonths; private int numDaysForFundamentalDataAvailability; public SelectorByNumOfMinGrowingIncomesInARow(DataTable setOfTickersToBeSelected, DateTime firstQuoteDate, DateTime lastQuoteDate, double minimumIncome, int numberOfIncomes, int incomePeriodLengthInMonths, int numDaysForFundamentalDataAvailability): base(setOfTickersToBeSelected, true, firstQuoteDate, lastQuoteDate, 500) { this.minimumIncome = minimumIncome; this.numberOfIncomes = numberOfIncomes; this.incomePeriodLengthInMonths = incomePeriodLengthInMonths; this.numDaysForFundamentalDataAvailability = numDaysForFundamentalDataAvailability; } #region GetTableOfSelectedTickers private bool getTableOfSelectedTickers_areIncomesAllGreaterThanMinimum(DataTable incomesForTicker) { bool returnValue = true; double previousIncome; double currentIncome = this.minimumIncome; for(int i = 0; i < incomesForTicker.Rows.Count; i++) { previousIncome = currentIncome; currentIncome = (double)incomesForTicker.Rows[i]["fvValue"]; if( currentIncome < this.minimumIncome || currentIncome < previousIncome ) returnValue = false; } return returnValue; } public DataTable GetTableOfSelectedTickers() { DataTable returnValue = new DataTable(); returnValue.Columns.Add("Ticker", System.Type.GetType("System.String")); object[] values = new object[1]; string currentTicker; DataTable incomesForCurrentTicker; for(int i = 0; i < this.setOfTickersToBeSelected.Rows.Count; i++) { currentTicker = (string)this.setOfTickersToBeSelected.Rows[i][0]; incomesForCurrentTicker = FinancialValues.GetLastFinancialValuesForTicker(currentTicker, 40, 12, this.lastQuoteDate.AddDays(-this.numDaysForFundamentalDataAvailability)); if( this.getTableOfSelectedTickers_areIncomesAllGreaterThanMinimum(incomesForCurrentTicker) ) { values[0] = currentTicker; returnValue.Rows.Add(values); } } return returnValue; } #endregion GetTableOfSelectedTickers public void SelectAllTickers() { ; } } } |