[Quantproject-developers] QuantProject/b7_Scripts/SimpleTesting/OneRank OneRank.cs,1.6,1.7
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2005-10-15 18:15:19
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/SimpleTesting/OneRank In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17267/b7_Scripts/SimpleTesting/OneRank Modified Files: OneRank.cs Log Message: Changed to handle short positions also Index: OneRank.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/SimpleTesting/OneRank/OneRank.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** OneRank.cs 9 Jan 2005 23:25:44 -0000 1.6 --- OneRank.cs 15 Oct 2005 18:15:06 -0000 1.7 *************** *** 57,64 **** // cash has not been added yet this.account.AddCash( 10000 ); } ! private void fiveMinutesBeforeMarketCloseEventHandler_withTickerExchangedNow() { long sharesToBeBought; double todayMarketValueAtClose = this.account.DataStreamer.GetCurrentBid( this.account.Key ); --- 57,82 ---- // cash has not been added yet this.account.AddCash( 10000 ); + if ( endOfDayTimingEventArgs.EndOfDayDateTime.DateTime > + this.lastDateTime ) + this.account.EndOfDayTimer.Stop(); } ! private void buyLongTicker() { long sharesToBeBought; + sharesToBeBought = MaxBuyableShares( this.account.Key , + this.account.CashAmount , this.account.DataStreamer ); + this.account.AddOrder( new Order( OrderType.MarketBuy , + new Instrument( this.account.Key ) , sharesToBeBought ) ); + } + private void sellShortTicker() + { + long sharesToBeSold; + sharesToBeSold = MaxBuyableShares( this.account.Key , + this.account.CashAmount , this.account.DataStreamer ); + this.account.AddOrder( new Order( OrderType.MarketSellShort , + new Instrument( this.account.Key ) , sharesToBeSold ) ); + } + private void fiveMinutesBeforeMarketCloseEventHandler_withTickerExchangedNow() + { double todayMarketValueAtClose = this.account.DataStreamer.GetCurrentBid( this.account.Key ); *************** *** 68,87 **** double yesterdayMarketValueAtClose = this.historicalQuoteProvider.GetMarketValue( this.account.Key , yesterdayAtClose ); ! if ( ( todayMarketValueAtClose > yesterdayMarketValueAtClose ) && ! ( !this.account.Contains( this.account.Key ) ) ) { ! // today close is higher than yesterday close and no position ! // is kept in portfolio, yet ! sharesToBeBought = MaxBuyableShares( this.account.Key , ! this.account.CashAmount , this.account.DataStreamer ); ! this.account.AddOrder( new Order( OrderType.MarketBuy , ! new Instrument( this.account.Key ) , sharesToBeBought ) ); } - if ( ( todayMarketValueAtClose < yesterdayMarketValueAtClose ) && - ( this.account.Contains( this.account.Key ) ) ) - this.account.ClosePosition( this.account.Key ); - if ( this.account.EndOfDayTimer.GetCurrentTime().DateTime > - this.lastDateTime ) - this.account.EndOfDayTimer.Stop(); } private void fiveMinutesBeforeMarketCloseEventHandler( --- 86,129 ---- double yesterdayMarketValueAtClose = this.historicalQuoteProvider.GetMarketValue( this.account.Key , yesterdayAtClose ); ! if ( ( todayMarketValueAtClose > yesterdayMarketValueAtClose ) ) { ! if ( this.account.Contains( this.account.Key ) ) ! { ! // today close is higher than yesterday close and ! // a position is already kept in portfolio ! if ( this.account.Portfolio.GetPosition( ! this.account.Key ).Type == PositionType.Short ) ! // today close is higher than yesterday close and ! // a short position is kept in portfolio ! { ! this.account.ClosePosition( this.account.Key ); ! this.buyLongTicker(); ! } ! } ! else ! // today close is higher than yesterday close and ! // no position is kept in portfolio ! this.buyLongTicker(); ! } ! if ( ( todayMarketValueAtClose < yesterdayMarketValueAtClose ) ) ! { ! if ( this.account.Contains( this.account.Key ) ) ! { ! // today close is lower than yesterday close and ! // a position is already kept in portfolio ! if ( this.account.Portfolio.GetPosition( ! this.account.Key ).Type == PositionType.Long ) ! // today close is lower than yesterday close and ! // a long position is kept in portfolio ! { ! this.account.ClosePosition( this.account.Key ); ! this.sellShortTicker(); ! } ! } ! else ! // today close is lower than yesterday close and ! // no position is kept in portfolio ! this.sellShortTicker(); } } private void fiveMinutesBeforeMarketCloseEventHandler( |