[Quantproject-developers] QuantProject/b4_Business/a1_Financial/a2_Accounting/h5_Reporting/Statisti
Brought to you by:
glauco_1
Update of /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a2_Accounting/h5_Reporting/StatisticsSummaryRows In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv16382/b4_Business/a1_Financial/a2_Accounting/h5_Reporting/StatisticsSummaryRows Added Files: AverageReturnOnDayOfWeekWithOpenPositions.cs AverageReturnOnDayWithOpenPositions.cs AverageReturnOnFridayWithOpenPositions.cs AverageReturnOnMondayWithOpenPositions.cs AverageReturnOnThursdayWithOpenPositions.cs AverageReturnOnTuesdayWithOpenPositions.cs AverageReturnOnWednesdayWithOpenPositions.cs Removed Files: AverageReturnOnMonday.cs Log Message: AverageReturnOnMonday has been replaced by AverageReturnOnMondayWithOpenPositions Added the classes for average return computation on days with open positions (with distinction by day of week) --- NEW FILE: AverageReturnOnThursdayWithOpenPositions.cs --- /* QuantProject - Quantitative Finance Library AverageReturnOnThursdayWithOpenPositions.cs Copyright (C) 2008 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.Accounting.Reporting.Tables; namespace QuantProject.Business.Financial.Accounting.Reporting.StatisticsSummaryRows { /// <summary> /// Summary row containing the average return of the strategy on Thursday /// </summary> [Serializable] public class AverageReturnOnThursdayWithOpenPositions : AverageReturnOnDayOfWeekWithOpenPositions { public AverageReturnOnThursdayWithOpenPositions( StatisticsSummary statisticsSummary ) : base( statisticsSummary ) { } protected override string getRowDescription() { return "Average % return on Thursday (with opened positions)"; } protected override DayOfWeek getSpecificDayOfWeek() { return DayOfWeek.Thursday; } } } --- AverageReturnOnMonday.cs DELETED --- --- NEW FILE: AverageReturnOnDayWithOpenPositions.cs --- /* QuantProject - Quantitative Finance Library AverageReturnOnDayWithOpenPositions.cs Copyright (C) 2008 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 System.Collections; using System.Data; using QuantProject.ADT.Histories; using QuantProject.ADT.Statistics; using QuantProject.Data.DataTables; using QuantProject.Business.Financial.Accounting.Reporting.Tables; using QuantProject.Business.Financial.Accounting.Reporting.SummaryRows; namespace QuantProject.Business.Financial.Accounting.Reporting.StatisticsSummaryRows { /// <summary> /// Summary row containing the average return of the strategy on each day /// with open positions /// </summary> [Serializable] public class AverageReturnOnDayWithOpenPositions : PercentageSummaryRow { private StatisticsSummary statisticsSummary; private object getRowValue( int totalNumberOfDaysWithOpenPositions , double sumOfReturnsOnDaysWithOpenPositions) { double averagePercentageReturn; averagePercentageReturn = 100.0 * sumOfReturnsOnDaysWithOpenPositions / (double)totalNumberOfDaysWithOpenPositions; string numOfDays = totalNumberOfDaysWithOpenPositions.ToString(); return averagePercentageReturn.ToString().Substring(0,4) + "#" + numOfDays.Substring(0,Math.Min(numOfDays.Length,4)); } private double getReturnForDate(DateTime date, DateTime previousDate) { double accountValueOnCloseForDate = (double)this.statisticsSummary.AccountReport.EquityLine.GetValue(date); double accountValueOnCloseForPreviousDate = (double)this.statisticsSummary.AccountReport.EquityLine.GetValue(previousDate); return (accountValueOnCloseForDate / accountValueOnCloseForPreviousDate) - 1.0; } private bool hasPositionsOnDate( DateTime date, DateTime previousDate ) { double accountValueOnCloseForDate = (double)this.statisticsSummary.AccountReport.EquityLine.GetValue(date); double accountValueOnCloseForPreviousDate = (double)this.statisticsSummary.AccountReport.EquityLine.GetValue(previousDate); return accountValueOnCloseForDate != accountValueOnCloseForPreviousDate; } public AverageReturnOnDayWithOpenPositions( StatisticsSummary statisticsSummary ) : base( ) { this.statisticsSummary = statisticsSummary; this.rowDescription = "Average % return on days with open positions "; History marketDays = Quotes.GetMarketDays( statisticsSummary.AccountReport.Benchmark, statisticsSummary.AccountReport.StartDateTime, statisticsSummary.AccountReport.EndDateTime.DateTime); DateTime date; DateTime previousDate; int totalNumberOfDaysWithOpenPositions = 0; double sumOfReturnsOnDaysWithOpenPositions = 0.0; for(int i = 1; i < marketDays.Count - 1; i++) { date = marketDays.GetDateTime( i ); previousDate = marketDays.GetDateTime( i - 1 ); if( this.hasPositionsOnDate( date, previousDate ) ) { totalNumberOfDaysWithOpenPositions++; sumOfReturnsOnDaysWithOpenPositions += this.getReturnForDate(date, previousDate); } } this.rowValue = this.getRowValue( totalNumberOfDaysWithOpenPositions , sumOfReturnsOnDaysWithOpenPositions); } } } --- NEW FILE: AverageReturnOnDayOfWeekWithOpenPositions.cs --- /* QuantProject - Quantitative Finance Library AverageReturnOnDayOfWeekWithOpenPositions.cs Copyright (C) 2008 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 System.Collections; using QuantProject.ADT.Histories; using QuantProject.ADT.Statistics; using QuantProject.Data.DataTables; using QuantProject.Business.Financial.Accounting.Reporting.Tables; using QuantProject.Business.Financial.Accounting.Reporting.SummaryRows; namespace QuantProject.Business.Financial.Accounting.Reporting.StatisticsSummaryRows { /// <summary> /// Summary row containing the average return of the strategy on a specific day of the week /// </summary> [Serializable] public abstract class AverageReturnOnDayOfWeekWithOpenPositions : PercentageSummaryRow { private StatisticsSummary statisticsSummary; private double getReturnForDate(DateTime date, DateTime previousDate) { double accountValueOnCloseForDate = (double)this.statisticsSummary.AccountReport.EquityLine.GetValue(date); double accountValueOnCloseForPreviousDate = (double)this.statisticsSummary.AccountReport.EquityLine.GetValue(previousDate); return (accountValueOnCloseForDate / accountValueOnCloseForPreviousDate) - 1.0; } private bool hasPositionsOnDate( DateTime date, DateTime previousDate ) { double accountValueOnCloseForDate = (double)this.statisticsSummary.AccountReport.EquityLine.GetValue(date); double accountValueOnCloseForPreviousDate = (double)this.statisticsSummary.AccountReport.EquityLine.GetValue(previousDate); return accountValueOnCloseForDate != accountValueOnCloseForPreviousDate; } protected abstract string getRowDescription(); protected abstract DayOfWeek getSpecificDayOfWeek(); private object getRowValue( int totalNumberOfSpecificDayOfWeek , double sumOfReturnsOnSpecificDayOfWeek) { double averagePercentageReturn; averagePercentageReturn = 100.0 * sumOfReturnsOnSpecificDayOfWeek / (double)totalNumberOfSpecificDayOfWeek; string numOfDays = totalNumberOfSpecificDayOfWeek.ToString(); return averagePercentageReturn.ToString().Substring(0,4) + "#" + numOfDays.Substring(0,Math.Min(numOfDays.Length,4)); } public AverageReturnOnDayOfWeekWithOpenPositions( StatisticsSummary statisticsSummary ) : base( ) { this.statisticsSummary = statisticsSummary; this.rowDescription = this.getRowDescription(); DayOfWeek specificDayOfWeek = this.getSpecificDayOfWeek(); History marketDays = Quotes.GetMarketDays( statisticsSummary.AccountReport.Benchmark, statisticsSummary.AccountReport.StartDateTime, statisticsSummary.AccountReport.EndDateTime.DateTime); DateTime date; DateTime previousDate; int totalNumberOfSpecificDayOfWeek = 0; double sumOfReturnsOnSpecificDayOfWeek = 0.0; for(int i = 1; i < marketDays.Count - 1; i++) { date = marketDays.GetDateTime( i ); previousDate = marketDays.GetDateTime( i - 1 ); if( date.DayOfWeek == specificDayOfWeek && this.hasPositionsOnDate( date, previousDate ) ) { totalNumberOfSpecificDayOfWeek++; sumOfReturnsOnSpecificDayOfWeek += this.getReturnForDate( date, previousDate ); } } this.rowValue = this.getRowValue(totalNumberOfSpecificDayOfWeek, sumOfReturnsOnSpecificDayOfWeek); } } } --- NEW FILE: AverageReturnOnFridayWithOpenPositions.cs --- /* QuantProject - Quantitative Finance Library AverageReturnOnFridayWithOpenPositions.cs Copyright (C) 2008 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.Accounting.Reporting.Tables; namespace QuantProject.Business.Financial.Accounting.Reporting.StatisticsSummaryRows { /// <summary> /// Summary row containing the average return of the strategy on Friday /// </summary> [Serializable] public class AverageReturnOnFridayWithOpenPositions : AverageReturnOnDayOfWeekWithOpenPositions { public AverageReturnOnFridayWithOpenPositions( StatisticsSummary statisticsSummary ) : base( statisticsSummary ) { } protected override string getRowDescription() { return "Average % return on Friday (with opened positions) "; } protected override DayOfWeek getSpecificDayOfWeek() { return DayOfWeek.Friday; } } } --- NEW FILE: AverageReturnOnTuesdayWithOpenPositions.cs --- /* QuantProject - Quantitative Finance Library AverageReturnOnTuesdayWithOpenPositions.cs Copyright (C) 2008 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.Accounting.Reporting.Tables; namespace QuantProject.Business.Financial.Accounting.Reporting.StatisticsSummaryRows { /// <summary> /// Summary row containing the average return of the strategy on Tuesday /// </summary> [Serializable] public class AverageReturnOnTuesdayWithOpenPositions : AverageReturnOnDayOfWeekWithOpenPositions { public AverageReturnOnTuesdayWithOpenPositions( StatisticsSummary statisticsSummary ) : base( statisticsSummary ) { } protected override string getRowDescription() { return "Average % return on Tuesday (with opened positions)"; } protected override DayOfWeek getSpecificDayOfWeek() { return DayOfWeek.Tuesday; } } } --- NEW FILE: AverageReturnOnWednesdayWithOpenPositions.cs --- /* QuantProject - Quantitative Finance Library AverageReturnOnWednesdayWithOpenPositions.cs Copyright (C) 2008 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.Accounting.Reporting.Tables; namespace QuantProject.Business.Financial.Accounting.Reporting.StatisticsSummaryRows { /// <summary> /// Summary row containing the average return of the strategy on Wednesday /// </summary> [Serializable] public class AverageReturnOnWednesdayWithOpenPositions : AverageReturnOnDayOfWeekWithOpenPositions { public AverageReturnOnWednesdayWithOpenPositions( StatisticsSummary statisticsSummary ) : base( statisticsSummary ) { } protected override string getRowDescription() { return "Average % return on Wednesday (with opened positions)"; } protected override DayOfWeek getSpecificDayOfWeek() { return DayOfWeek.Wednesday; } } } --- NEW FILE: AverageReturnOnMondayWithOpenPositions.cs --- /* QuantProject - Quantitative Finance Library AverageReturnOnMondayWithOpenPositions.cs Copyright (C) 2008 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.Accounting.Reporting.Tables; namespace QuantProject.Business.Financial.Accounting.Reporting.StatisticsSummaryRows { /// <summary> /// Summary row containing the average return of the strategy on Monday /// </summary> [Serializable] public class AverageReturnOnMondayWithOpenPositions : AverageReturnOnDayOfWeekWithOpenPositions { public AverageReturnOnMondayWithOpenPositions( StatisticsSummary statisticsSummary ) : base( statisticsSummary ) { } protected override string getRowDescription() { return "Average % return on Monday (with opened positions)"; } protected override DayOfWeek getSpecificDayOfWeek() { return DayOfWeek.Monday; } } } |