[Quantproject-developers] QuantProject/b7_Scripts/SimpleTesting/OneRank EndOfDayOneRank.cs,NONE,1.1
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2004-11-29 14:35:49
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/SimpleTesting/OneRank In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25717 Added Files: EndOfDayOneRank.cs Log Message: One rank strategy on a single ticker --- NEW FILE: EndOfDayOneRank.cs --- /* QuantProject - Quantitative Finance Library OneRank.cs Copyright (C) 2003 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; using QuantProject.Business.Financial.Instruments; using QuantProject.Business.Financial.Accounting; using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Timing; using QuantProject.Data.DataProviders; namespace QuantProject.Scripts.SimpleTesting { /// <summary> /// One rank strategy on a single ticker /// </summary> public class EndOfDayOneRank { private string ticker; private Account account; private void fiveMinutesBeforeMarketCloseHandler( Object sender , EndOfDayTimingEventArgs eventArgs ) { if ( this.account.GetMarketValue( this.ticker ) <= HistoricalDataProvider.GetMarketValue( this.ticker , this.account.EndOfDayTimer.GetCurrentTime().DateTime.AddDays( - 1 ) , BarComponent.Close ) ) { // today's closing value is lower or equal than yesterday's closing value if ( this.account.Portfolio.Contains( this.ticker ) ) this.account.ClosePosition( this.ticker ); } else { // today's closing value is higher than yesterday's closing value if ( !this.account.Portfolio.Contains( this.ticker ) ) { int maxBuyableQuantity = Convert.ToInt16( Math.Floor( this.account.CashAmount / this.account.GetMarketValue( this.ticker ))); this.account.AddOrder( new Order( OrderType.MarketBuy , new Instrument( ticker ) , maxBuyableQuantity ) ); } } } public EndOfDayOneRank( string ticker , Account account ) { this.ticker = ticker; this.account = account; this.account.AddCash( 10000 ); this.account.EndOfDayTimer.FiveMinutesBeforeMarketClose += new FiveMinutesBeforeMarketCloseEventHandler( this.fiveMinutesBeforeMarketCloseHandler ); } } } |