[Quantproject-developers] QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination LinearCombina
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2005-08-02 23:13:09
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14944/b7_Scripts/WalkForwardTesting/LinearCombination Modified Files: LinearCombinationTest.cs Log Message: - Added radio buttons to switch between daily and weekly strategy - Bug fixed: HistoricalAdjustedQuoteProvider is used for weekly strategies, now Index: LinearCombinationTest.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/LinearCombinationTest.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** LinearCombinationTest.cs 23 Jul 2005 17:57:01 -0000 1.1 --- LinearCombinationTest.cs 2 Aug 2005 23:12:59 -0000 1.2 *************** *** 28,31 **** --- 28,32 ---- using QuantProject.Business.Financial.Instruments; using QuantProject.Business.Financial.Ordering; + using QuantProject.Business.Strategies; using QuantProject.Business.Timing; using QuantProject.Presentation.Reporting.WindowsForm; *************** *** 43,107 **** private DateTime lastDate; private string[] signedTickers; ! private HistoricalRawQuoteProvider historicalQuoteProvider; private HistoricalEndOfDayTimer historicalEndOfDayTimer; private Account account; public LinearCombinationTest( DateTime firstDate , DateTime lastDate , ! string[] signedTickers ) { this.firstDate = firstDate; this.lastDate = lastDate; this.signedTickers = signedTickers; ! } ! private long marketOpenEventHandler_addOrder_getQuantity( ! string ticker ) ! { ! double accountValue = this.account.GetMarketValue(); ! double currentTickerAsk = ! this.account.DataStreamer.GetCurrentAsk( ticker ); ! double maxPositionValueForThisTicker = ! accountValue/this.signedTickers.Length; ! long quantity = Convert.ToInt64( Math.Floor( ! maxPositionValueForThisTicker / currentTickerAsk ) ); ! return quantity; ! } ! private void marketOpenEventHandler_addOrder( string signedTicker ) ! { ! OrderType orderType = GenomeRepresentation.GetOrderType( signedTicker ); ! string ticker = GenomeRepresentation.GetTicker( signedTicker ); ! long quantity = marketOpenEventHandler_addOrder_getQuantity( ticker ); ! Order order = new Order( orderType , new Instrument( ticker ) , ! quantity ); ! this.account.AddOrder( order ); ! } ! private void marketOpenEventHandler_addOrders() ! { ! foreach ( string signedTicker in this.signedTickers ) ! marketOpenEventHandler_addOrder( signedTicker ); ! } ! private void marketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) ! { ! if ( ( this.account.CashAmount == 0 ) && ! ( this.account.Transactions.Count == 0 ) ) ! // cash has not been added yet ! this.account.AddCash( 30000 ); ! marketOpenEventHandler_addOrders(); } - private void fiveMinutesBeforeMarketCloseEventHandler_closePositions() - { - ArrayList tickers = new ArrayList(); - foreach ( Position position in this.account.Portfolio.Positions ) - tickers.Add( position.Instrument.Key ); - foreach ( string ticker in tickers ) - this.account.ClosePosition( ticker ); - } - private void fiveMinutesBeforeMarketCloseEventHandler( Object sender , - EndOfDayTimingEventArgs endOfDayTimingEventArgs) - { - fiveMinutesBeforeMarketCloseEventHandler_closePositions(); - } private void oneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) --- 44,63 ---- private DateTime lastDate; private string[] signedTickers; + private bool openToCloseDaily; ! private IHistoricalQuoteProvider historicalQuoteProvider; private HistoricalEndOfDayTimer historicalEndOfDayTimer; private Account account; + private IEndOfDayStrategy endOfDayStrategy; public LinearCombinationTest( DateTime firstDate , DateTime lastDate , ! string[] signedTickers , bool openToCloseDaily ) { this.firstDate = firstDate; this.lastDate = lastDate; this.signedTickers = signedTickers; ! this.openToCloseDaily = openToCloseDaily; } private void oneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) *************** *** 112,115 **** --- 68,87 ---- } + private void run_setHistoricalQuoteProvider() + { + if ( this.openToCloseDaily ) + this.historicalQuoteProvider = new HistoricalRawQuoteProvider(); + else + this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); + } + private void run_setStrategy() + { + if ( this.openToCloseDaily ) + this.endOfDayStrategy = new OpenToCloseDailyStrategy( + this.account , this.signedTickers ); + else + this.endOfDayStrategy = new OpenToCloseWeeklyStrategy( + this.account , this.signedTickers ); + } public void Run() { *************** *** 118,123 **** new EndOfDayDateTime( this.firstDate , EndOfDaySpecificTime.MarketOpen ) , "DYN" ); ! this.historicalQuoteProvider = ! new HistoricalRawQuoteProvider(); this.account = new Account( "LinearCombination" , historicalEndOfDayTimer , new HistoricalEndOfDayDataStreamer( historicalEndOfDayTimer , --- 90,94 ---- new EndOfDayDateTime( this.firstDate , EndOfDaySpecificTime.MarketOpen ) , "DYN" ); ! run_setHistoricalQuoteProvider(); this.account = new Account( "LinearCombination" , historicalEndOfDayTimer , new HistoricalEndOfDayDataStreamer( historicalEndOfDayTimer , *************** *** 125,136 **** new HistoricalEndOfDayOrderExecutor( historicalEndOfDayTimer , this.historicalQuoteProvider ) ); // OneRank oneRank = new OneRank( account , // this.endDateTime ); this.historicalEndOfDayTimer.MarketOpen += new MarketOpenEventHandler( ! this.marketOpenEventHandler ); this.historicalEndOfDayTimer.FiveMinutesBeforeMarketClose += new FiveMinutesBeforeMarketCloseEventHandler( ! this.fiveMinutesBeforeMarketCloseEventHandler ); this.historicalEndOfDayTimer.OneHourAfterMarketClose += new OneHourAfterMarketCloseEventHandler( --- 96,108 ---- new HistoricalEndOfDayOrderExecutor( historicalEndOfDayTimer , this.historicalQuoteProvider ) ); + run_setStrategy(); // OneRank oneRank = new OneRank( account , // this.endDateTime ); this.historicalEndOfDayTimer.MarketOpen += new MarketOpenEventHandler( ! this.endOfDayStrategy.MarketOpenEventHandler ); this.historicalEndOfDayTimer.FiveMinutesBeforeMarketClose += new FiveMinutesBeforeMarketCloseEventHandler( ! this.endOfDayStrategy.FiveMinutesBeforeMarketCloseEventHandler ); this.historicalEndOfDayTimer.OneHourAfterMarketClose += new OneHourAfterMarketCloseEventHandler( |