[Quantproject-developers] QuantProject/b4_Business/a1_Financial/a2_Accounting/h5_Reporting AccountRe
Brought to you by:
glauco_1
|
From: <gla...@us...> - 2003-11-02 18:26:07
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a2_Accounting/h5_Reporting
In directory sc8-pr-cvs1:/tmp/cvs-serv24939/b4_Business/a1_Financial/a2_Accounting/h5_Reporting
Modified Files:
AccountReport.cs
Log Message:
- Fixed %return in round trade table: as a consequence, the average
profit per trade now is fixed
- Added Buy and Hold percentage return to the report summary table
(this is an optional information, got by overriding
the create method)
Index: AccountReport.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a2_Accounting/h5_Reporting/AccountReport.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** AccountReport.cs 30 Oct 2003 22:06:51 -0000 1.3
--- AccountReport.cs 2 Nov 2003 18:26:04 -0000 1.4
***************
*** 29,33 ****
using QuantProject.ADT;
using QuantProject.ADT.Histories;
!
namespace QuantProject.Business.Financial.Accounting.Reporting
{
--- 29,33 ----
using QuantProject.ADT;
using QuantProject.ADT.Histories;
! using QuantProject.Business.Financial.Instruments;
namespace QuantProject.Business.Financial.Accounting.Reporting
{
***************
*** 39,44 ****
--- 39,47 ----
private Account account;
private Account accountCopy = new Account( "AccountCopy" );
+ private ExtendedDateTime endDateTime;
+ private string buyAndHoldTicker;
private double totalPnl;
private double finalAccountValue;
+ private double buyAndHoldPercentageReturn;
private long intervalDays;
private ReportTable transactionTable;
***************
*** 63,66 ****
--- 66,76 ----
get { return summary; }
}
+ public DateTime StartDateTime
+ {
+ get
+ {
+ return (DateTime) account.Transactions.GetKey( 0 );
+ }
+ }
/// <summary>
***************
*** 145,155 ****
addRowForPnl_actually( currentDate , detailedDataTable );
}
! private void setRows( int numDaysForInterval ,
! ExtendedDateTime endDateTime, System.Data.DataTable detailedDataTable )
{
DateTime currentDate = (DateTime) account.Transactions.GetKey( 0 );
try
{
! while ( currentDate < endDateTime.DateTime )
{
//addTransactionsToAccountCopy( currentDate );
--- 155,164 ----
addRowForPnl_actually( currentDate , detailedDataTable );
}
! private void setRows( int numDaysForInterval , System.Data.DataTable detailedDataTable )
{
DateTime currentDate = (DateTime) account.Transactions.GetKey( 0 );
try
{
! while ( currentDate < this.endDateTime.DateTime )
{
//addTransactionsToAccountCopy( currentDate );
***************
*** 168,177 ****
}
#endregion
! private System.Data.DataTable getDetailedDataTable( int numDaysForInterval ,
! ExtendedDateTime endDateTime )
{
System.Data.DataTable detailedDataTable = new System.Data.DataTable();
setColumns( detailedDataTable );
! setRows( numDaysForInterval , endDateTime , detailedDataTable );
return detailedDataTable;
}
--- 177,185 ----
}
#endregion
! private System.Data.DataTable getDetailedDataTable( int numDaysForInterval )
{
System.Data.DataTable detailedDataTable = new System.Data.DataTable();
setColumns( detailedDataTable );
! setRows( numDaysForInterval , detailedDataTable );
return detailedDataTable;
}
***************
*** 282,286 ****
roundTrade[ "ExitPrice" ] = dataRow[ "Price" ];
roundTrade[ "%chg" ] =
! ((double)roundTrade[ "ExitPrice" ] - (double)roundTrade[ "EntryPrice" ])/100;
roundTrade[ "%Profit" ] = - ((double)roundTrade[ "%chg" ]);
roundTrade[ "#bars" ] =
--- 290,295 ----
roundTrade[ "ExitPrice" ] = dataRow[ "Price" ];
roundTrade[ "%chg" ] =
! ((double)roundTrade[ "ExitPrice" ] - (double)roundTrade[ "EntryPrice" ])/
! ((double)roundTrade[ "EntryPrice" ])*100;
roundTrade[ "%Profit" ] = - ((double)roundTrade[ "%chg" ]);
roundTrade[ "#bars" ] =
***************
*** 303,307 ****
return roundTradeDataTable;
}
! public ReportTable getRoundTrades( string reportName )
{
DataTable roundTradeDataTable = getRoundTradeDataTable();
--- 312,316 ----
return roundTradeDataTable;
}
! private ReportTable getRoundTrades( string reportName )
{
DataTable roundTradeDataTable = getRoundTradeDataTable();
***************
*** 343,347 ****
return equityDataTable;
}
! public ReportTable getEquity( string reportName , DataTable detailedDataTable )
{
DataTable equityDataTable = getEquityDataTable( detailedDataTable );
--- 352,356 ----
return equityDataTable;
}
! private ReportTable getEquity( string reportName , DataTable detailedDataTable )
{
DataTable equityDataTable = getEquityDataTable( detailedDataTable );
***************
*** 369,372 ****
--- 378,397 ----
summary[ "Value" ] = this.totalPnl / ( this.finalAccountValue - this.totalPnl ) * 100;
}
+ private void getSummaryTable_setRow_BuyAndHoldPercentageReturn( DataRow summary )
+ {
+ if ( this.buyAndHoldTicker != "" )
+ {
+ // the report has to compare to a buy and hold benchmark
+ Instrument buyAndHoldInstrument = new Instrument( this.buyAndHoldTicker );
+ this.buyAndHoldPercentageReturn =
+ ( buyAndHoldInstrument.GetMarketValue( this.endDateTime ) -
+ buyAndHoldInstrument.GetMarketValue(
+ new ExtendedDateTime( this.StartDateTime , BarComponent.Open ) ) ) /
+ buyAndHoldInstrument.GetMarketValue(
+ new ExtendedDateTime( this.StartDateTime , BarComponent.Open ) ) * 100;
+ summary[ "Information" ] = "Buy & hold % return";
+ summary[ "Value" ] = this.buyAndHoldPercentageReturn;
+ }
+ }
private void getSummaryTable_setRow_AnnualSystemPercentageReturn( DataRow summary )
{
***************
*** 386,394 ****
private void getSummaryTable_setRow_NumberWinningTrades( DataRow summary )
{
- double totalROA = this.totalPnl / ( this.finalAccountValue - this.totalPnl );
summary[ "Information" ] = "Number winning trades";
DataRow[] DataRows = this.roundTrades.DataTable.Select( "([%Profit] > 0)" );
summary[ "Value" ] = DataRows.Length;
}
private void getSummary_setRow( DataTable summaryDataTable ,
getSummaryTable_setRow getSummaryTable_setRow_object )
--- 411,424 ----
private void getSummaryTable_setRow_NumberWinningTrades( DataRow summary )
{
summary[ "Information" ] = "Number winning trades";
DataRow[] DataRows = this.roundTrades.DataTable.Select( "([%Profit] > 0)" );
summary[ "Value" ] = DataRows.Length;
}
+ private void getSummaryTable_setRow_AverageTradePercentageReturn( DataRow summary )
+ {
+ summary[ "Information" ] = "Average trade % Return";
+ double avgReturn = (double) this.roundTrades.DataTable.Compute( "avg([%Profit])" , "true" );
+ summary[ "Value" ] = avgReturn;
+ }
private void getSummary_setRow( DataTable summaryDataTable ,
getSummaryTable_setRow getSummaryTable_setRow_object )
***************
*** 405,408 ****
--- 435,440 ----
new getSummaryTable_setRow( getSummaryTable_setRow_ReturnOnAccount ) );
getSummary_setRow( summaryDataTable ,
+ new getSummaryTable_setRow( getSummaryTable_setRow_BuyAndHoldPercentageReturn ) );
+ getSummary_setRow( summaryDataTable ,
new getSummaryTable_setRow( getSummaryTable_setRow_AnnualSystemPercentageReturn ) );
getSummary_setRow( summaryDataTable ,
***************
*** 410,413 ****
--- 442,447 ----
getSummary_setRow( summaryDataTable ,
new getSummaryTable_setRow( getSummaryTable_setRow_NumberWinningTrades ) );
+ getSummary_setRow( summaryDataTable ,
+ new getSummaryTable_setRow( getSummaryTable_setRow_AverageTradePercentageReturn ) );
}
#endregion
***************
*** 419,423 ****
return summaryDataTable;
}
! public ReportTable getSummary( string reportName )
{
this.totalPnl =
--- 453,457 ----
return summaryDataTable;
}
! private ReportTable getSummary( string reportName )
{
this.totalPnl =
***************
*** 435,441 ****
#endregion
public AccountReport Create( string reportName , int numDaysForInterval ,
! ExtendedDateTime endDateTime )
{
! DataTable detailedDataTable = getDetailedDataTable( numDaysForInterval , endDateTime );
this.transactionTable = getTransactionTable( reportName , detailedDataTable );
this.roundTrades = getRoundTrades( reportName );
--- 469,477 ----
#endregion
public AccountReport Create( string reportName , int numDaysForInterval ,
! ExtendedDateTime endDateTime , string buyAndHoldTicker )
{
! this.endDateTime = endDateTime;
! this.buyAndHoldTicker = buyAndHoldTicker;
! DataTable detailedDataTable = getDetailedDataTable( numDaysForInterval );
this.transactionTable = getTransactionTable( reportName , detailedDataTable );
this.roundTrades = getRoundTrades( reportName );
***************
*** 446,450 ****
#endregion
!
}
}
--- 482,490 ----
#endregion
! public AccountReport Create( string reportName , int numDaysForInterval ,
! ExtendedDateTime endDateTime )
! {
! return Create( reportName , numDaysForInterval , endDateTime , "" );
! }
}
}
|