[Quantproject-developers] QuantProject/b4_Business/a07_DataProviders HistoricalAdjustedBarProvider.
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2009-04-04 15:48:23
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a07_DataProviders In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv13461/b4_Business/a07_DataProviders Added Files: HistoricalAdjustedBarProvider.cs Log Message: Returns adjusted historical intraday market values --- NEW FILE: HistoricalAdjustedBarProvider.cs --- /* QuantProject - Quantitative Finance Library HistoricalAdjustedBarProvider.cs Copyright (C) 2009 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.Business.Timing; using QuantProject.Data.DataProviders.Bars; namespace QuantProject.Business.DataProviders { /// <summary> /// Returns adjusted historical intraday market values /// </summary> public class HistoricalAdjustedBarProvider : HistoricalMarketValueProvider { private HistoricalBarProvider historicalBarProvider; private HistoricalRawQuoteProvider historicalRawQuoteProvider; private HistoricalAdjustedQuoteProvider historicalAdjustedQuoteProvider; public HistoricalAdjustedBarProvider( HistoricalBarProvider historicalBarProvider , HistoricalRawQuoteProvider historicalRawQuoteProvider , HistoricalAdjustedQuoteProvider historicalAdjustedQuoteProvider ) { this.historicalBarProvider = historicalBarProvider; this.historicalRawQuoteProvider = historicalRawQuoteProvider; this.historicalAdjustedQuoteProvider = historicalAdjustedQuoteProvider; } protected override string getDescription() { return "adjustedBarProvider"; } #region GetMarketValue private double getAdjustmenFactor( string ticker , DateTime dateTime ) { DateTime marketCloseDateTime = HistoricalEndOfDayTimer.GetMarketClose( dateTime ); double rawClose = this.historicalRawQuoteProvider.GetMarketValue( ticker , marketCloseDateTime ); double adjustedClose = this.historicalAdjustedQuoteProvider.GetMarketValue( ticker , marketCloseDateTime ); double adjustmentFactor = adjustedClose / rawClose; return adjustmentFactor; } public override double GetMarketValue( string ticker , DateTime dateTime ) { double adjustmentFactor = this.getAdjustmenFactor( ticker , dateTime ); double marketValue = double.NaN; try { marketValue = this.historicalBarProvider.GetMarketValue( ticker , dateTime ) * adjustmentFactor; } catch( MissingBarException missingBarException ) { string forBreakPoint = missingBarException.Message; forBreakPoint += " "; throw new TickerNotExchangedException( ticker , dateTime ); } return marketValue; } #endregion GetMarketValue public override bool WasExchanged( string ticker, DateTime dateTime ) { bool wasExchanged = this.historicalBarProvider.WasExchanged( ticker , dateTime ); return wasExchanged; } } } |