[Quantproject-developers] QuantProject/b7_Scripts/SimpleTesting/MSFTSimpleTest_2 AsMSFTsimpleTest_2.
Brought to you by:
glauco_1
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/SimpleTesting/MSFTSimpleTest_2
In directory sc8-pr-cvs1:/tmp/cvs-serv12998/b7_Scripts/SimpleTesting/MSFTSimpleTest_2
Modified Files:
AsMSFTsimpleTest_2.cs RunMSFTsimpleTest_2.cs
TsMSFTsimpleTest_2.cs
Log Message:
Implemented the script, whose purpose is only to test the program's behaviour.
Index: AsMSFTsimpleTest_2.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/SimpleTesting/MSFTSimpleTest_2/AsMSFTsimpleTest_2.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** AsMSFTsimpleTest_2.cs 20 Dec 2003 18:31:36 -0000 1.1
--- AsMSFTsimpleTest_2.cs 11 Jan 2004 19:15:21 -0000 1.2
***************
*** 41,45 ****
//
}
! }
! //TODO: override of the base methods
}
--- 41,123 ----
//
}
! public override ArrayList GetOrdersForCurrentVirtualOrder( Order virtualOrder )
! {
! ArrayList orders = new ArrayList();
! switch(virtualOrder.Type)
! {
! case OrderType.MarketBuy:
! if(virtualOrder.Quantity != 0)
! {
! if ( this.account.Portfolio.IsShort( virtualOrder.Instrument ) )
! orders.Add( new Order( OrderType.MarketCover ,
! virtualOrder.Instrument ,
! (long) - ((Position)this.account.Portfolio[ virtualOrder.Instrument.Key ]).Quantity ,
! virtualOrder.ExtendedDateTime ) );
!
! if ( !this.account.Portfolio.IsLong( virtualOrder.Instrument ) )
! orders.Add( new Order( OrderType.MarketBuy ,
! virtualOrder.Instrument ,
! virtualOrder.Instrument.GetMaxBuyableQuantity(
! this.account.CashAmount +
! this.account.Portfolio.GetMarketValue( virtualOrder.ExtendedDateTime ) ,
! virtualOrder.ExtendedDateTime ) , virtualOrder.ExtendedDateTime ) );
! }
! else
! //it is a special order that acts in order to close any open position
! {
! if ( this.account.Portfolio.IsShort( virtualOrder.Instrument ) )
! orders.Add( new Order( OrderType.MarketCover ,
! virtualOrder.Instrument ,
! -(long) this.account.Portfolio.GetPosition( virtualOrder.Instrument ).Quantity ,
! virtualOrder.ExtendedDateTime ) );
!
! if ( this.account.Portfolio.IsLong( virtualOrder.Instrument ) )
! orders.Add( new Order( OrderType.MarketSell ,
! virtualOrder.Instrument ,
! (long) this.account.Portfolio.GetPosition( virtualOrder.Instrument ).Quantity ,
! virtualOrder.ExtendedDateTime ) );
! }
! break;
!
! case OrderType.MarketSell:
! if ( this.account.Portfolio.IsLong( virtualOrder.Instrument ) )
! orders.Add( new Order( OrderType.MarketSell ,
! virtualOrder.Instrument ,
! (long) this.account.Portfolio.GetPosition( virtualOrder.Instrument ).Quantity ,
! virtualOrder.ExtendedDateTime ) );
! if ( !this.account.Portfolio.IsShort( virtualOrder.Instrument ) )
! orders.Add( new Order( OrderType.MarketSellShort ,
! virtualOrder.Instrument ,
! virtualOrder.Instrument.GetMaxBuyableQuantity(
! this.account.CashAmount +
! this.account.Portfolio.GetMarketValue( virtualOrder.ExtendedDateTime ) ,
! virtualOrder.ExtendedDateTime ) ,
! virtualOrder.ExtendedDateTime ) );
! break;
! default:
! break;
! }
! return orders;
! }
!
! public override Orders GetOrders( Signal signal )
! {
! // This is the default account strategy. You may wish to override it.
! // It assumes the signal contains a single virtual order and it invests
! // all the available cash according to such virtual order. It assumes
! // the account will always contain a single position (long or short)
! // determined by the last signal.
! Orders orders = new Orders();
! foreach ( Order virtualOrder in signal )
! {
! ArrayList ordersForCurrentVirtualOrder =
! this.GetOrdersForCurrentVirtualOrder( virtualOrder );
! foreach( Order order in ordersForCurrentVirtualOrder )
! orders.Add( order );
! }
! return orders;
! }
!
! }
!
}
Index: RunMSFTsimpleTest_2.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/SimpleTesting/MSFTSimpleTest_2/RunMSFTsimpleTest_2.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** RunMSFTsimpleTest_2.cs 20 Dec 2003 18:43:50 -0000 1.2
--- RunMSFTsimpleTest_2.cs 11 Jan 2004 19:15:21 -0000 1.3
***************
*** 50,54 ****
{
DateTime startDateTime = new DateTime( 2000 , 1 , 1 );
! DateTime endDateTime = new DateTime( 2000 , 12 , 31 );
QuoteCache.Add( new Instrument( "MSFT" ) , BarComponent.Open );
QuoteCache.Add( new Instrument( "MSFT" ) , BarComponent.Close );
--- 50,54 ----
{
DateTime startDateTime = new DateTime( 2000 , 1 , 1 );
! DateTime endDateTime = new DateTime( 2000 , 12 , 29 );
QuoteCache.Add( new Instrument( "MSFT" ) , BarComponent.Open );
QuoteCache.Add( new Instrument( "MSFT" ) , BarComponent.Close );
Index: TsMSFTsimpleTest_2.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/SimpleTesting/MSFTSimpleTest_2/TsMSFTsimpleTest_2.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** TsMSFTsimpleTest_2.cs 20 Dec 2003 18:43:50 -0000 1.2
--- TsMSFTsimpleTest_2.cs 11 Jan 2004 19:15:21 -0000 1.3
***************
*** 45,99 ****
}
! private History microsoftCloseHistory;
! private History microsoftCloseHistorySimpleAverage;
! private History microsoftCloseHistoryStandardDeviation;
!
! public override void InitializeData()
! {
! microsoftCloseHistory = QuoteCache.GetCloseHistory( "MSFT" );
! microsoftCloseHistoryStandardDeviation =
! microsoftCloseHistory.GetFunctionHistory (Function.StandardDeviation,5,
! new DateTime(2000,1,1),
! new DateTime(2000,12,31));
! microsoftCloseHistorySimpleAverage =
! microsoftCloseHistory.GetFunctionHistory (Function.SimpleAverage,5,
! new DateTime(2000,1,1),
! new DateTime(2000,12,31));
! }
! public override Signals GetSignals( ExtendedDateTime extendedDateTime )
! {
! Signals signals = new Signals();
! if ( extendedDateTime.BarComponent == BarComponent.Close &&
! microsoftCloseHistoryStandardDeviation.IsDecreased(extendedDateTime.DateTime))
{
! Signal signal = new Signal();
! if ( this.microsoftCloseHistorySimpleAverage.IsDecreased(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 );
!
! }
! else
! {
! signal.Add( new Order( OrderType.MarketBuy , new Instrument( "MSFT" ) , 1 ,
! new ExtendedDateTime( new Instrument( "MSFT" ).GetNextMarketDay( extendedDateTime.DateTime ) ,
! BarComponent.Open ) ) );
! signals.Add( signal );
! }
}
! else
! //no signal given by the history of standard deviation
{
! // TODO:...
! //if there's an open position, return a signal to close it the next market day
}
-
- return signals;
- }
}
}
--- 45,104 ----
}
! private History microsoftCloseHistory;
! private History microsoftCloseHistorySimpleAverage;
! private History microsoftCloseHistoryStandardDeviation;
! public override void InitializeData()
{
! microsoftCloseHistory = QuoteCache.GetCloseHistory( "MSFT" );
!
! microsoftCloseHistoryStandardDeviation =
! microsoftCloseHistory.GetFunctionHistory (Function.StandardDeviation,5,
! (DateTime)this.microsoftCloseHistory.GetKey(0),
! (DateTime)this.microsoftCloseHistory.GetKey(this.microsoftCloseHistory.Count - 1));
! microsoftCloseHistorySimpleAverage =
! microsoftCloseHistory.GetFunctionHistory (Function.SimpleAverage,5,
! (DateTime)this.microsoftCloseHistory.GetKey(0),
! (DateTime)this.microsoftCloseHistory.GetKey(this.microsoftCloseHistory.Count - 1));
}
!
! public override Signals GetSignals( ExtendedDateTime extendedDateTime )
{
! Signals signals = new Signals();
! Signal signal = new Signal();
! if ( extendedDateTime.BarComponent == BarComponent.Close)
! {
! if(microsoftCloseHistoryStandardDeviation.IsDecreased(extendedDateTime.DateTime))
! {
! if ( this.microsoftCloseHistorySimpleAverage.IsDecreased(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 );
!
! }
! else
! {
! 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 no signal is given by the history of standard deviation
! //add a special signal to be managed by the account strategy
! {
! signal.Add( new Order( OrderType.MarketBuy , new Instrument( "MSFT" ) , 0 ,
! new ExtendedDateTime( new Instrument( "MSFT" ).GetNextMarketDay( extendedDateTime.DateTime ) ,
! BarComponent.Open ) ) );
! signals.Add( signal );
! }
! }
! return signals;
}
}
}
|