[Quantproject-developers] QuantProject/b4_Business/a1_Financial/a2_Accounting Account.cs,1.14,1.15
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2005-02-13 00:49:24
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a2_Accounting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20001/b4_Business/a1_Financial/a2_Accounting Modified Files: Account.cs Log Message: - a new constructor has been added, with an ICommissionManager parameter - now commissions are added when transactions are added Index: Account.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a2_Accounting/Account.cs,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Account.cs 6 Feb 2005 18:26:32 -0000 1.14 --- Account.cs 13 Feb 2005 00:49:14 -0000 1.15 *************** *** 49,65 **** /// ! [Serializable] ! public class Account : Keyed , IComparable ! { ! private double cashAmount; ! private AccountStrategy accountStrategy; private IEndOfDayTimer endOfDayTimer; private IDataStreamer dataStreamer; private IOrderExecutor orderExecutor; private ArrayList activeOrders; private AccountReport accountReport; ! public Portfolio Portfolio = new Portfolio(); ! //public AccountReport accountReport; public double CashAmount --- 49,66 ---- /// ! [Serializable] ! public class Account : Keyed , IComparable ! { ! private double cashAmount; ! private AccountStrategy accountStrategy; private IEndOfDayTimer endOfDayTimer; private IDataStreamer dataStreamer; private IOrderExecutor orderExecutor; + private ICommissionManager commissionManager; private ArrayList activeOrders; private AccountReport accountReport; ! public Portfolio Portfolio = new Portfolio(); ! //public AccountReport accountReport; public double CashAmount *************** *** 87,115 **** public AccountStrategy AccountStrategy ! { ! get { return accountStrategy; } ! set { accountStrategy = value; } ! } ! public TransactionHistory Transactions = new TransactionHistory(); ! public Account( string accountName ) : base ( accountName ) ! { ! this.initialize(); ! } ! private void initialize() ! { ! cashAmount = 0; this.activeOrders = new ArrayList(); ! accountStrategy = new AccountStrategy( this ); ! } ! public Account() : base ( "account" ) ! { ! this.initialize(); ! } ! public Account( string accountName , IEndOfDayTimer endOfDayTimer , ! IDataStreamer dataStreamer , IOrderExecutor orderExecutor ) : base( accountName ) { this.endOfDayTimer = endOfDayTimer; --- 88,116 ---- public AccountStrategy AccountStrategy ! { ! get { return accountStrategy; } ! set { accountStrategy = value; } ! } ! public TransactionHistory Transactions = new TransactionHistory(); ! public Account( string accountName ) : base ( accountName ) ! { ! this.initialize(); ! } ! private void initialize() ! { ! cashAmount = 0; this.activeOrders = new ArrayList(); ! accountStrategy = new AccountStrategy( this ); ! } ! public Account() : base ( "account" ) ! { ! this.initialize(); ! } ! private void initialize( IEndOfDayTimer endOfDayTimer , IDataStreamer dataStreamer , ! IOrderExecutor orderExecutor ) { this.endOfDayTimer = endOfDayTimer; *************** *** 118,121 **** --- 119,136 ---- this.orderExecutor.OrderFilled += new OrderFilledEventHandler( this.orderFilledEventHandler ); + } + public Account( string accountName , IEndOfDayTimer endOfDayTimer , + IDataStreamer dataStreamer , IOrderExecutor orderExecutor ) : base( accountName ) + { + this.initialize( endOfDayTimer , dataStreamer , orderExecutor ); + this.initialize(); + } + + public Account( string accountName , IEndOfDayTimer endOfDayTimer , + IDataStreamer dataStreamer , IOrderExecutor orderExecutor , + ICommissionManager commissionManager ) : base( accountName ) + { + this.initialize( endOfDayTimer , dataStreamer , orderExecutor ); + this.commissionManager = commissionManager; this.initialize(); } *************** *** 148,174 **** return returnValue; } ! public void Clear() ! { ! this.cashAmount = 0; ! this.Transactions.Clear(); ! this.Portfolio.Clear(); ! } ! public void AddCash( EndOfDayDateTime endOfDayDateTime , double moneyAmount ) ! { ! try ! { ! EndOfDayTransaction timedTransaction = ! new EndOfDayTransaction( TransactionType.AddCash , moneyAmount , endOfDayDateTime.Copy() ); ! this.Add( timedTransaction ); ! //Transactions.MultiAdd( extendedDateTime.DateTime , timedTransaction ); ! //cashAmount = cashAmount + moneyAmount; ! } ! catch (Exception exception) ! { exception = exception; // to avoid warning message ! /// TO DO!!! ! } ! } public void AddCash( double moneyAmount ) --- 163,189 ---- return returnValue; } ! public void Clear() ! { ! this.cashAmount = 0; ! this.Transactions.Clear(); ! this.Portfolio.Clear(); ! } ! public void AddCash( EndOfDayDateTime endOfDayDateTime , double moneyAmount ) ! { ! try ! { ! EndOfDayTransaction timedTransaction = ! new EndOfDayTransaction( TransactionType.AddCash , moneyAmount , endOfDayDateTime.Copy() ); ! this.Add( timedTransaction ); ! //Transactions.MultiAdd( extendedDateTime.DateTime , timedTransaction ); ! //cashAmount = cashAmount + moneyAmount; ! } ! catch (Exception exception) ! { exception = exception; // to avoid warning message ! /// TO DO!!! ! } ! } public void AddCash( double moneyAmount ) *************** *** 192,199 **** ! private void updateCash( Transaction transaction ) ! { ! cashAmount += transaction.CashFlow() - transaction.Commission.Value; ! } protected virtual Commission getCommission( Transaction transaction ) --- 207,216 ---- ! private void updateCash( Transaction transaction ) ! { ! cashAmount += transaction.CashFlow(); ! if ( transaction.Commission != null ) ! cashAmount -= transaction.Commission.Value; ! } protected virtual Commission getCommission( Transaction transaction ) *************** *** 201,225 **** return new Commission( transaction ); } ! public void Add( EndOfDayTransaction transaction ) ! { ! transaction.Commission = this.getCommission( transaction ); ! this.Transactions.Add( transaction ); ! this.updateCash( transaction ); ! this.Portfolio.Update( transaction ); ! //this.accountReport.AddRecord( this ); ! } ! // public void Add( Transaction transaction ) ! // { ! // this.Transactions.Add( transaction ); ! // this.updateCash( transaction ); ! // this.Portfolio.Update( transaction ); ! // //this.accountReport.AddRecord( this ); ! // } ! // ! // public double GetMarketValue( EndOfDayDateTime endOfDayDateTime ) ! // { ! // return this.CashAmount + this.Portfolio.GetMarketValue( endOfDayDateTime ); ! // } public double GetMarketValue( string ticker ) { --- 218,244 ---- return new Commission( transaction ); } ! public void Add( EndOfDayTransaction transaction ) ! { ! if ( this.commissionManager != null ) ! // an ICommissionManager has been passed to the constructor ! transaction.Commission = this.commissionManager.GetCommission( transaction ); ! this.Transactions.Add( transaction ); ! this.updateCash( transaction ); ! this.Portfolio.Update( transaction ); ! //this.accountReport.AddRecord( this ); ! } ! // public void Add( Transaction transaction ) ! // { ! // this.Transactions.Add( transaction ); ! // this.updateCash( transaction ); ! // this.Portfolio.Update( transaction ); ! // //this.accountReport.AddRecord( this ); ! // } ! // ! // public double GetMarketValue( EndOfDayDateTime endOfDayDateTime ) ! // { ! // return this.CashAmount + this.Portfolio.GetMarketValue( endOfDayDateTime ); ! // } public double GetMarketValue( string ticker ) { *************** *** 235,275 **** this.Portfolio.GetMarketValue( this.dataStreamer ); } ! // public double GetProfitNetLoss( EndOfDayDateTime endOfDayDateTime ) ! // { ! // return GetMarketValue( endOfDayDateTime ) + ! // this.Transactions.TotalWithdrawn - ! // this.Transactions.TotalAddedCash; ! // } ! // public History GetProfitNetLossHistory( EndOfDayDateTime finalDateTime ) ! // { ! // History history = new History(); ! // Account account = new Account( "ToGetProfitNetLossHistory" ); ! // foreach ( ArrayList arrayList in this.Transactions.Values ) ! // foreach ( EndOfDayTransaction transaction in arrayList ) ! // { ! // account.Add( transaction ); ! // history.MultiAdd( transaction.EndOfDayDateTime.DateTime , ! // account.GetProfitNetLoss( transaction.EndOfDayDateTime ) ); ! // } ! // history.MultiAdd( finalDateTime.DateTime , ! // account.GetProfitNetLoss( finalDateTime ) ); ! // return history; ! // } ! // ! public string ToString( DateTime dateTime ) ! { ! return ! "\nCashAmount : " + this.CashAmount + ! "\nPortfolioContent : " + this.Portfolio.ToString() + ! "\nPortfolioMarketValue : " + this.Portfolio.GetMarketValue( ! this.dataStreamer ); ! } ! // public AccountReport CreateReport( string reportName , ! // int numDaysForInterval , EndOfDayDateTime endDateTime ) ! // { ! // AccountReport accountReport = new AccountReport( this ); ! // return accountReport.Create( reportName , numDaysForInterval , endDateTime ); ! // } public AccountReport CreateReport( string reportName , int numDaysForInterval , EndOfDayDateTime endDateTime , string buyAndHoldTicker , --- 254,294 ---- this.Portfolio.GetMarketValue( this.dataStreamer ); } ! // public double GetProfitNetLoss( EndOfDayDateTime endOfDayDateTime ) ! // { ! // return GetMarketValue( endOfDayDateTime ) + ! // this.Transactions.TotalWithdrawn - ! // this.Transactions.TotalAddedCash; ! // } ! // public History GetProfitNetLossHistory( EndOfDayDateTime finalDateTime ) ! // { ! // History history = new History(); ! // Account account = new Account( "ToGetProfitNetLossHistory" ); ! // foreach ( ArrayList arrayList in this.Transactions.Values ) ! // foreach ( EndOfDayTransaction transaction in arrayList ) ! // { ! // account.Add( transaction ); ! // history.MultiAdd( transaction.EndOfDayDateTime.DateTime , ! // account.GetProfitNetLoss( transaction.EndOfDayDateTime ) ); ! // } ! // history.MultiAdd( finalDateTime.DateTime , ! // account.GetProfitNetLoss( finalDateTime ) ); ! // return history; ! // } ! // ! public string ToString( DateTime dateTime ) ! { ! return ! "\nCashAmount : " + this.CashAmount + ! "\nPortfolioContent : " + this.Portfolio.ToString() + ! "\nPortfolioMarketValue : " + this.Portfolio.GetMarketValue( ! this.dataStreamer ); ! } ! // public AccountReport CreateReport( string reportName , ! // int numDaysForInterval , EndOfDayDateTime endDateTime ) ! // { ! // AccountReport accountReport = new AccountReport( this ); ! // return accountReport.Create( reportName , numDaysForInterval , endDateTime ); ! // } public AccountReport CreateReport( string reportName , int numDaysForInterval , EndOfDayDateTime endDateTime , string buyAndHoldTicker , |