[Quantproject-developers] QuantProject/b7_Scripts/TickerSelectionTesting DataStreamerHandler.cs,NONE
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2004-09-05 13:51:48
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22726/b7_Scripts/TickerSelectionTesting Added Files: DataStreamerHandler.cs RunBestTwoIndipendent.cs Log Message: Added new script file with use of TickerSelectorClass --- NEW FILE: DataStreamerHandler.cs --- /* QuantProject - Quantitative Finance Library DataStreamerHandler.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 System.Data; using QuantProject.Business.Financial.Accounting; using QuantProject.Data.DataProviders; using QuantProject.ADT; using QuantProject.Data.Selectors; namespace QuantProject.Scripts.TickerSelectionTesting.BestTwoIndipendent { /// <summary> /// Implements NewQuoteEventHandler. This is the core strategy! /// </summary> public class DataStreamerHandler { private Account account; private ExtendedDateTime openAccountDate; public Account Account { get { return this.account; } } public DataStreamerHandler() { this.account = new Account( "Main" ); this.openAccountDate = new ExtendedDateTime(new DateTime(2002,1,1), BarComponent.Open); this.account.AddCash(this.openAccountDate, 10000); } private DataTable newQuoteEventHandler_getTickersToBuy(Quote encomingQuote) { TickerSelector liquidSelector = new TickerSelector(SelectionType.Liquidity, false, "NSDQ100", this.openAccountDate.DateTime, encomingQuote.ExtendedDataTable.DateTime,50); TickerSelector volatilityCTOselector = new TickerSelector(liquidSelector.GetTableOfSelectedTickers(), SelectionType.CloseToOpenVolatility, true, "", this.openAccountDate.DateTime, encomingQuote.ExtendedDataTable.DateTime, 40); TickerSelector avgCTOperformanceSelector = new TickerSelector(volatilityCTOselector.GetTableOfSelectedTickers(), SelectionType.AverageCloseToOpenPerformance, true, "", this.openAccountDate.DateTime, encomingQuote.ExtendedDataTable.DateTime, 20); TickerSelector correlationSelector = new TickerSelector(avgCTOperformanceSelector.GetTableOfSelectedTickers(), SelectionType.CloseToOpenLinearCorrelation, true, "", this.openAccountDate.DateTime, encomingQuote.ExtendedDataTable.DateTime, 2); return correlationSelector.GetTableOfSelectedTickers(); } public void NewQuoteEventHandler( Object sender , NewQuoteEventArgs eventArgs ) { Quote encomingQuote = eventArgs.Quote; if(this.openAccountDate.DateTime.AddDays(30).CompareTo(encomingQuote.ExtendedDataTable.DateTime)<0) //it has elasped enough time for a significant simulation of the strategy { DataTable tickersToBuy = this.newQuoteEventHandler_getTickersToBuy(encomingQuote); //the script has to be completed ... } } } } --- NEW FILE: RunBestTwoIndipendent.cs --- /* QuantProject - Quantitative Finance Library RunBestTwoIndipendent.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 System.Collections; using System.Data; using QuantProject.ADT; using QuantProject.Business.Financial.Accounting.Reporting; using QuantProject.Business.Financial.Instruments; using QuantProject.Business.Scripting; using QuantProject.Business.Strategies; using QuantProject.Business.Testing; using QuantProject.Data.DataTables; using QuantProject.Data.DataProviders; using QuantProject.Presentation.Reporting.WindowsForm; namespace QuantProject.Scripts.TickerSelectionTesting.BestTwoIndipendent { /// <summary> /// Script to test a strategy on many tickers inside a group, /// chosing the best two indipendent tickers /// when a fixed time span has elapsed. /// </summary> public class RunBestTwoIndipendent : Script { private string groupID; private ReportTable reportTable; private ExtendedDateTime startDateTime; private ExtendedDateTime endDateTime; //private int numIntervalDays; private HistoricalDataStreamer historicalDataStreamer; private DataStreamerHandler dataStreamerHandler = new DataStreamerHandler(); public RunBestTwoIndipendent() { this.reportTable = new ReportTable( "Summary_Reports" ); this.startDateTime = new ExtendedDateTime( new DateTime( 2002 , 1 , 1 ) , BarComponent.Open ); this.endDateTime = new ExtendedDateTime( new DateTime( 2002 , 12 , 31 ) , BarComponent.Close ); //this.numIntervalDays = 7; this.groupID = "NSDQ100"; } #region Run private void run_initializeHistoricalDataStreamer_addTickers() { Tickers_tickerGroups tickerInGroupID = new Tickers_tickerGroups(this.groupID); foreach(DataRow row in tickerInGroupID.Rows) { this.historicalDataStreamer.Add((string)row[Tickers_tickerGroups.Ticker]); } } private void run_initializeHistoricalDataStreamer() { this.historicalDataStreamer = new HistoricalDataStreamer(); this.historicalDataStreamer.StartDateTime = this.startDateTime; this.historicalDataStreamer.EndDateTime = this.endDateTime; this.run_initializeHistoricalDataStreamer_addTickers(); } public override void Run() { Report report; run_initializeHistoricalDataStreamer(); this.historicalDataStreamer.NewQuote += new NewQuoteEventHandler( this.dataStreamerHandler.NewQuoteEventHandler ); this.historicalDataStreamer.GoSimulate(); report = new Report( this.dataStreamerHandler.Account ); report.Show(); //???? //report.Show( "Best Two Indipendent" , this.numIntervalDays , this.startDateTime , "MSFT" ); } #endregion } } |