[Quantproject-developers] QuantProject/b7_Scripts/WalkForwardTesting/MSFTwalkForward RunMSFTwalkForw
Brought to you by:
glauco_1
|
From: <gla...@us...> - 2003-11-24 19:38:13
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/MSFTwalkForward
In directory sc8-pr-cvs1:/tmp/cvs-serv31021
Added Files:
RunMSFTwalkForward.cs TsMSFTwalkForward.cs
Log Message:
The MSFTwalkForward strategy has
been moved under the WalkForwardTesting folder.
--- NEW FILE: RunMSFTwalkForward.cs ---
/*
QuantProject - Quantitative Finance Library
RunMSFTsimpleTest.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.ADT.Histories;
using QuantProject.ADT.Optimizing;
using QuantProject.Business.Financial.Accounting;
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.Presentation.MicrosoftExcel;
namespace QuantProject.Scripts
{
/// <summary>
/// Summary description for runMSFTsimpleTest.
/// </summary>
public class RunMSFTwalkForward : Script
{
public RunMSFTwalkForward()
{
//
// TODO: Add constructor logic here
//
}
public override void Run()
{
DateTime startDateTime = new DateTime( 1995 , 1 , 1 );
DateTime endDateTime = new DateTime( 2003 , 9 , 1 );
QuoteCache.Add( new Instrument( "MSFT" ) , BarComponent.Open );
QuoteCache.Add( new Instrument( "MSFT" ) , BarComponent.Close );
QuoteCache.SetCache( startDateTime , endDateTime );
WalkForwardTester walkForwardTester = new WalkForwardTester();
walkForwardTester.StartDateTime = startDateTime;
walkForwardTester.EndDateTime = endDateTime;
walkForwardTester.InSampleWindowNumDays = 300;
walkForwardTester.OutOfSampleWindowNumDays = 60;
walkForwardTester.Parameters.Add( new Parameter( "SMAdays" , 3 , 50 , 2 ) );
walkForwardTester.Add( new TsMSFTsimpleTest() );
walkForwardTester.Account.AddCash(
new ExtendedDateTime( startDateTime , BarComponent.Open ) , 10000 );
walkForwardTester.Test();
AccountReport accountReport = walkForwardTester.Account.CreateReport( "MSFT" , 7 ,
new ExtendedDateTime( endDateTime , BarComponent.Close ) , "MSFT" );
ExcelManager.Add( accountReport );
ExcelManager.ShowReport();
}
}
}
--- NEW FILE: TsMSFTwalkForward.cs ---
/*
QuantProject - Quantitative Finance Library
TsMSFTsimpleTest.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 QuantProject.ADT;
using QuantProject.ADT.Histories;
using QuantProject.ADT.Optimizing;
using QuantProject.Business.Financial.Instruments;
using QuantProject.Business.Financial.Ordering;
using QuantProject.Business.Strategies;
namespace QuantProject.Scripts
{
/// <summary>
/// Summary description for tsMSFTsimpleTest.
/// </summary>
public class TsMSFTwalkForward : TradingSystem
{
public TsMSFTwalkForward()
{
//
// TODO: Add constructor logic here
//
}
private History microsoftCloseHistory;
private History microsoftCloseHistorySMA;
public override void InitializeData()
{
Parameter parameter = (Parameter) this.Parameters[ "SMAdays" ];
microsoftCloseHistory = QuoteCache.GetCloseHistory( "MSFT" );
microsoftCloseHistorySMA = microsoftCloseHistory.GetSimpleMovingAverage( (int) parameter.Value );
}
public override Signals GetSignals( ExtendedDateTime extendedDateTime )
{
Signals signals = new Signals();
if ( extendedDateTime.BarComponent == BarComponent.Close )
{
Signal signal = new Signal();
if ( microsoftCloseHistory.Cross( microsoftCloseHistorySMA ,
extendedDateTime.DateTime ) )
{
signal.Add( new Order( OrderType.MarketBuy , new Instrument( "MSFT" ) , 1 ,
new ExtendedDateTime( new Instrument( "MSFT" ).GetNextMarketDay( extendedDateTime.DateTime ) ,
BarComponent.Open ) ) );
signals.Add( signal );
}
else
{
if ( microsoftCloseHistorySMA.Cross( microsoftCloseHistory ,
extendedDateTime.DateTime ) )
{
signal.Add( new Order( OrderType.MarketSell , new Instrument( "MSFT" ) , 1 ,
new ExtendedDateTime(
new Instrument( "MSFT" ).GetNextMarketDay( extendedDateTime.DateTime ) ,
BarComponent.Open ) ) );
signals.Add( signal );
}
}
}
return signals;
}
}
}
|