[Quantproject-developers] QuantProject/b4_Business/a1_Financial/a2_Accounting/Slippage ZeroSlippageM
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2005-12-20 19:27:25
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a2_Accounting/Slippage In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15524 Added Files: ZeroSlippageManager.cs ISlippageManager.cs FixedPercentageSlippageManager.cs Log Message: Added classes for slippage management --- NEW FILE: FixedPercentageSlippageManager.cs --- /* QuantProject - Quantitative Finance Library FixedPercentageSlippageManager.cs Copyright (C) 2003 Marco Milletti 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.Business.Financial.Ordering; using QuantProject.Business.DataProviders; using QuantProject.Business.Timing; namespace QuantProject.Business.Financial.Accounting.Slippage { /// <summary> /// Slippage Manager for a slippage computed as a fixed percentage of price. /// </summary> [Serializable] public class FixedPercentageSlippageManager : ISlippageManager { private double percentage; private IHistoricalQuoteProvider quoteProvider; private IEndOfDayTimer endOfDayTimer; public FixedPercentageSlippageManager(IHistoricalQuoteProvider quoteProvider, IEndOfDayTimer endOfDayTimer, double percentage) { this.quoteProvider = quoteProvider; this.endOfDayTimer = endOfDayTimer; this.percentage = percentage; } public double GetSlippage(Order order) { double returnValue = 0.0; double marketPrice; if(order.Type == OrderType.LimitBuy || order.Type == OrderType.LimitCover || order.Type == OrderType.MarketBuy || order.Type == OrderType.MarketCover) { //it should be GetCurrentBid marketPrice = this.quoteProvider.GetMarketValue(order.Instrument.Key, endOfDayTimer.GetCurrentTime()); returnValue = percentage * marketPrice / 100.00; } else//sell type or sellShort type, limit or not { //it should be GetCurrentAsk marketPrice = this.quoteProvider.GetMarketValue(order.Instrument.Key, endOfDayTimer.GetCurrentTime()); returnValue = -percentage * marketPrice / 100.00; } return returnValue; } } } --- NEW FILE: ZeroSlippageManager.cs --- /* QuantProject - Quantitative Finance Library ZeroSlippageManager.cs Copyright (C) 2003 Marco Milletti 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; namespace QuantProject.Business.Financial.Accounting.Slippage { /// <summary> /// Slippage Manager for Zero value slippage. /// This is the slippage manager used by an Account /// if no ISlippageManager is specified. /// </summary> [Serializable] public class ZeroSlippageManager : ISlippageManager { public ZeroSlippageManager() { } public double GetSlippage( Ordering.Order order ) { return 0.0; } } } --- NEW FILE: ISlippageManager.cs --- /* QuantProject - Quantitative Finance Library ISlippageManager.cs Copyright (C) 2003 Marco Milletti 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; namespace QuantProject.Business.Financial.Accounting.Slippage { /// <summary> /// Interface to be implemented by slippage managers /// (for calculation of slippage) /// </summary> public interface ISlippageManager { double GetSlippage(Ordering.Order order); } } |