[Quantproject-developers] QuantProject/b7_Scripts/Funds AsFunds.cs,NONE,1.1 RunFunds.cs,NONE,1.1 TsF
Brought to you by:
glauco_1
|
From: <gla...@us...> - 2003-10-26 17:42:47
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/Funds
In directory sc8-pr-cvs1:/tmp/cvs-serv5112/b7_Scripts/Funds
Added Files:
AsFunds.cs RunFunds.cs TsFunds.cs
Log Message:
Added the Funds script
--- NEW FILE: AsFunds.cs ---
/*
QuantProject - Quantitative Finance Library
AsProfunds.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.Business.Financial.Ordering;
using QuantProject.Business.Financial.Accounting;
using QuantProject.Business.Strategies;
namespace QuantProject.Scripts
{
/// <summary>
/// Summary description for AsProfunds.
/// </summary>
public class AsFunds : AccountStrategy
{
public AsFunds( Account account ) : base( account )
{
//
// TODO: Add constructor logic here
//
}
public override ArrayList GetOrdersForCurrentVirtualOrder( Order virtualOrder )
{
ArrayList orders = new ArrayList();
switch(virtualOrder.Type)
{
case OrderType.MarketBuy:
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 ) );
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 ) );
break;
default:
break;
}
return orders;
}
}
}
--- NEW FILE: RunFunds.cs ---
/*
QuantProject - Quantitative Finance Library
RunProfunds.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.Financial.Testing;
using QuantProject.Business.Strategies;
using QuantProject.Business.Scripting;
using QuantProject.Presentation.MicrosoftExcel;
namespace QuantProject.Scripts
{
/// <summary>
/// Summary description for RunProfunds.
/// </summary>
public class RunFunds : Script
{
public RunFunds()
{
//
// TODO: Add constructor logic here
//
}
private void runForSingleTicker( string ticker )
{
//DateTime startDateTime = new DateTime( 2000 , 6 , 23 );
DateTime startDateTime = new DateTime( 2003 , 1 , 1 );
DateTime endDateTime = new DateTime( 2003 , 9 , 26 );
QuoteCache.Add( new Instrument( ticker ) , BarComponent.Open );
QuoteCache.Add( new Instrument( ticker ) , BarComponent.Close );
//QuoteCache.Add( new Instrument( "MSFT" ) , BarComponent.Close );
QuoteCache.SetCache( startDateTime , endDateTime );
TradingSystems tradingSystems = new TradingSystems();
TsFunds tsFunds = new TsFunds();
tsFunds.Ticker = ticker;
tradingSystems.Add( tsFunds );
Tester tester = new Tester(
new TestWindow( startDateTime , endDateTime ) ,
tradingSystems ,
10000 );
tester.Account.AccountStrategy = new AsProfunds( tester.Account );
//tester.Parameters.Add( new Parameter( "SMAdays" , 10 , 10 , 2 ) );
//tester.Optimize();
tester.Test();
//tester.Account.ReportToConsole( endDateTime );
((History)tester.Account.GetProfitNetLossHistory(
new ExtendedDateTime( endDateTime , BarComponent.Close ) ) ).ReportToConsole();
// tester.Account.AccountReport.ReportToExcel( "MSFT" ,
// new ExtendedDateTime( endDateTime , BarComponent.Close ) );
AccountReport accountReport = tester.Account.CreateReport( ticker , 7 ,
new ExtendedDateTime( endDateTime , BarComponent.Close ) );
ExcelManager.Add( accountReport );
ExcelManager.ShowReport();
}
public override void Run()
{
runForSingleTicker( "FSELX" );
}
}
}
--- NEW FILE: TsFunds.cs ---
/*
QuantProject - Quantitative Finance Library
TsProfunds.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 TsProfunds.
/// </summary>
public class TsFunds : TradingSystem
{
public string Ticker;
public TsFunds()
{
//
// TODO: Add constructor logic here
//
}
private History fund;
// private History microsoftCloseHistorySMA;
public override void InitializeData()
{
fund = QuoteCache.GetOpenHistory( Ticker );
// microsoftCloseHistorySMA = microsoftCloseHistory.GetSimpleMovingAverage( (int) parameter.Value );
}
public override Signals GetSignals( ExtendedDateTime extendedDateTime )
{
Signals signals = new Signals();
if ( !fund.IsLastKey( extendedDateTime.DateTime ) &&
( extendedDateTime.BarComponent == BarComponent.Close ) )
{
DateTime previousMarketDay = (DateTime)((History)fund).GetKey(
((History)fund).IndexOfKeyOrPrevious( extendedDateTime.DateTime ) );
DateTime nextMarketDay =
new Instrument( Ticker ).GetNextMarketDay( extendedDateTime.DateTime );
Signal signal = new Signal();
if ( (Single)fund[ nextMarketDay ] > (Single)fund[ previousMarketDay ] )
{
signal.Add( new Order( OrderType.MarketBuy , new Instrument( Ticker ) , 1 ,
new ExtendedDateTime( nextMarketDay , BarComponent.Open ) ) );
signals.Add( signal );
}
if ( (Single)fund[ nextMarketDay ] < (Single)fund[ previousMarketDay ] )
{
signal.Add( new Order( OrderType.MarketSell , new Instrument( Ticker ) , 1 ,
new ExtendedDateTime( nextMarketDay , BarComponent.Open ) ) );
signals.Add( signal );
}
}
return signals;
}
}
}
|