[Quantproject-developers] QuantProject/b4_Business/a07_DataProviders HistoricalMarketValueProvider.
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2008-09-29 21:03:00
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a07_DataProviders In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv5292/a07_DataProviders Added Files: HistoricalMarketValueProvider.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. --- NEW FILE: HistoricalMarketValueProvider.cs --- /* QuantProject - Quantitative Finance Library HistoricalMarketValueProvider.cs Copyright (C) 2007 Glauco Siliprandi 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.ADT.Histories; using QuantProject.Business.Strategies.Logging; using QuantProject.Business.Timing; using QuantProject.Data.DataProviders.Quotes; namespace QuantProject.Business.DataProviders { /// <summary> /// Abstract base class for historical market values providers /// </summary> [Serializable] public abstract class HistoricalMarketValueProvider : ILogDescriptor { public string Description { get { return "QtPrvdr_" + this.getDescription(); } } public HistoricalMarketValueProvider() { } protected abstract string getDescription(); public abstract double GetMarketValue( string ticker , DateTime dateTime ); /// <summary> /// True iif the given ticker was traded at the given DateTime /// </summary> /// <param name="ticker"></param> /// <param name="dateTime"></param> /// <returns></returns> public bool WasExchanged( string ticker , DateTime dateTime ) { bool wasExchanged = HistoricalQuotesProvider.WasExchanged( ticker , dateTime ); return wasExchanged; } #region GetQuotes #region addQuoteActually private double getMarketValue( string ticker , DateTime dateTime ) { double marketValue = this.GetMarketValue( ticker , dateTime ); return marketValue; } private void addQuoteActually( string ticker , DateTime dateTime , History quotes ) { double marketValue = this.getMarketValue( ticker , dateTime ); quotes.Add( dateTime , marketValue ); } #endregion addQuoteActually private void addMarketValue( string ticker , int historyIndex , History history , History quotes ) { DateTime currentDateTime = (DateTime)history.GetByIndex( historyIndex ); if ( this.WasExchanged( ticker , currentDateTime ) ) { this.addQuoteActually( ticker , currentDateTime , quotes ); } else throw new TickerNotExchangedException( ticker , currentDateTime ); } public History GetMarketValues( string ticker , History history ) { History quotes = new History(); for ( int i = 0 ; i < history.Count ; i++ ) this.addMarketValue( ticker , i , history , quotes ); return quotes; } #endregion GetQuotes } } |