[Quantproject-developers] QuantProject/b4_Business/a2_Strategies/returnsManagement/time OpenToClos
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2007-09-23 21:46:36
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/returnsManagement/time In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv27047 Added Files: OpenToCloseCloseToOpenIntervals.cs Log Message: Added OpenToCloseCloseToOpenIntervals for computation of OpenToClose CloseToOpen returns (returns where an open to close return is followed by the next close to open return, and this is followed by the next open to close return, and so on) --- NEW FILE: OpenToCloseCloseToOpenIntervals.cs --- /* QuantProject - Quantitative Finance Library OpenToCloseCloseToOpenIntervals.cs Copyright (C) 2007 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.ADT.Histories; using QuantProject.Business.Timing; namespace QuantProject.Business.Strategies.ReturnsManagement.Time { /// <summary> /// Open to Close - Close to Open intervals, to be used /// to compute returns where an open to close return is followed /// by the next close to open return, and this is followed /// by the next open to close return, and so on /// </summary> public class OpenToCloseCloseToOpenIntervals : ReturnIntervals { /// <summary> /// Creates the OTC-CTO intervals for the given benchmark, from /// the first EndOfDayDateTime to the last EndOfDayDateTime /// </summary> /// <param name="firstEndOfDayDateTime"></param> /// <param name="lastEndOfDayDateTime"></param> /// <param name="benchmark"></param> public OpenToCloseCloseToOpenIntervals( EndOfDayDateTime firstEndOfDayDateTime , EndOfDayDateTime lastEndOfDayDateTime , string benchmark ) : base( firstEndOfDayDateTime , lastEndOfDayDateTime , benchmark ) { } #region setIntervals private void addInterval( History marketDaysForBenchmark , int i ) { //adds the open to close interval DateTime dateTimeForOTC = (DateTime)marketDaysForBenchmark.GetKey( i ); ReturnInterval returnOTCInterval = new ReturnInterval( new EndOfDayDateTime( dateTimeForOTC , EndOfDaySpecificTime.MarketOpen ) , new EndOfDayDateTime( dateTimeForOTC , EndOfDaySpecificTime.MarketClose ) ); this.Add( returnOTCInterval ); //adds the following close to open interval DateTime dateTimeForCTOEnd = (DateTime)marketDaysForBenchmark.GetKey( i + 1 ); ReturnInterval returnCTOInterval = new ReturnInterval( new EndOfDayDateTime( dateTimeForOTC , EndOfDaySpecificTime.MarketClose ) , new EndOfDayDateTime( dateTimeForCTOEnd , EndOfDaySpecificTime.MarketOpen ) ); this.Add( returnCTOInterval ); } private void setIntervals( History marketDaysForBenchmark ) { for( int i = 0 ; i < marketDaysForBenchmark.Count - 1 ; i++ ) this.addInterval( marketDaysForBenchmark , i ); } protected override void setIntervals() { History marketDaysForBenchmark = QuantProject.Data.DataTables.Quotes.GetMarketDays( this.benchmark , firstEndOfDayDateTime.DateTime , lastEndOfDayDateTime.DateTime ); this.setIntervals( marketDaysForBenchmark ); } #endregion setIntervals } } |