[Quantproject-developers] QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes EndOfDayT
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2006-07-02 19:57:37
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv15028/b7_Scripts/TickerSelectionTesting/TestingOTCTypes Modified Files: EndOfDayTimerHandlerOTCTypes.cs Log Message: Updated strategies based on OTC and CTO behaviours. Minor changes. Index: EndOfDayTimerHandlerOTCTypes.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes/EndOfDayTimerHandlerOTCTypes.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** EndOfDayTimerHandlerOTCTypes.cs 7 Jan 2006 10:28:56 -0000 1.2 --- EndOfDayTimerHandlerOTCTypes.cs 2 Jul 2006 19:57:34 -0000 1.3 *************** *** 29,32 **** --- 29,33 ---- using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Timing; + using QuantProject.Business.Strategies; using QuantProject.Data.DataProviders; using QuantProject.Data.Selectors; *************** *** 49,53 **** private int seedForRandomGenerator; private Account[] accounts; ! //private ArrayList[] ordersForAccounts; public EndOfDayTimerHandlerOTCTypes(string tickerGroupID, int numberOfEligibleTickers, --- 50,56 ---- private int seedForRandomGenerator; private Account[] accounts; ! private string[,] lastOrderedTickersForTheAccount; ! int numOfClosesWithOpenPositionsFor2DaysStrategy; ! public EndOfDayTimerHandlerOTCTypes(string tickerGroupID, int numberOfEligibleTickers, *************** *** 69,104 **** this.seedForRandomGenerator = ConstantsProvider.SeedForRandomGenerator; this.accounts = accounts; ! //for(int i = 0; i<this.accounts.Length;i++) ! //ordersForAccounts[i] = new ArrayList(); } ! ! // protected override void addChosenTickersToOrderList() ! // { ! // for(int i = 0; i<this.accounts.Length; i++) ! // { ! // if(i==0)//OTC daily ! // {} ! // if(i==1) ! // {} ! // if(i==2) ! // {} ! // for(int j = 0; j<this.numberOfTickersToBeChosen; j++) ! // { ! // string ticker = this.chosenTickersForAccounts[i,j]; ! // if( ticker != null) ! // { ! // this.addOrderForTickerForEachAccount(i, ticker ); ! // this.lastOrderedTickersForAccounts[i,j] = ! // GenomeManagerForEfficientPortfolio.GetCleanTickerCode(ticker); ! // } ! // } ! // } ! // } ! private void openPositions_openWhenPortfolioIsEmpty(int accountNumber) { if(this.accounts[accountNumber].Portfolio.Count == 0) { ! foreach(object item in this.orders) ! this.accounts[accountNumber].AddOrder((Order)item); } } --- 72,91 ---- this.seedForRandomGenerator = ConstantsProvider.SeedForRandomGenerator; this.accounts = accounts; ! this.lastOrderedTickersForTheAccount = new string[this.accounts.Length, ! this.numberOfTickersToBeChosen]; } ! ! private void openPositionsForTheAccountWhenPortfolioIsEmpty(int accountNumber) { if(this.accounts[accountNumber].Portfolio.Count == 0) { ! this.orders.Clear(); ! this.addChosenTickersToOrderListForTheGivenAccount(accountNumber); ! for(int i = 0; i<this.orders.Count;i++) ! { ! this.accounts[accountNumber].AddOrder((Order)this.orders[i]); ! this.lastOrderedTickersForTheAccount[accountNumber, i] = ! SignedTicker.GetTicker(((Order)this.orders[i]).Instrument.Key); ! } } } *************** *** 123,126 **** --- 110,114 ---- this.orders.Add(order); } + protected void addChosenTickersToOrderListForTheGivenAccount(int accountNumber) { *************** *** 128,178 **** { if(this.chosenTickers[i] != null) - { this.addOrderForTickerForTheGivenAccount( i, accountNumber ); - this.lastOrderedTickers[i] = - GenomeManagerForEfficientPortfolio.GetCleanTickerCode(this.chosenTickers[i]); - } - } - } - protected override void openPositions() - { - - for(int i = 0; i<this.accounts.Length; i++) - { - //add cash first for each account - if(this.orders.Count == 0 && this.accounts[i].Transactions.Count == 0) - this.accounts[i].AddCash(30000); - - if(i<=1)//daily classical, and multiday - { - this.orders.Clear(); - this.addChosenTickersToOrderListForTheGivenAccount(i); - this.openPositions_openWhenPortfolioIsEmpty(i); - } - else if(i==2)//for the CTO OTC - { - this.closePositions_close(i); - this.orders.Clear(); - this.addChosenTickersToOrderListForTheGivenAccount(i); - foreach(object item in this.orders) - this.accounts[i].AddOrder((Order)item); - } - else if(i==3)//for the CTO, no position is opened - //at market open. Any open position is closed, instead - { - this.closePositions_close(i); - } } } ! ! private void closePositions_close(int accountNumber) { string ticker; if(this.accounts[accountNumber].Portfolio.Count >0) { ! for(int j = 0; j<this.lastOrderedTickers.Length; j++) { ! ticker = this.lastOrderedTickers[j]; if( ticker != null) { --- 116,132 ---- { if(this.chosenTickers[i] != null) this.addOrderForTickerForTheGivenAccount( i, accountNumber ); } } + ! private void closePositionsForTheAccount(int accountNumber) { string ticker; if(this.accounts[accountNumber].Portfolio.Count >0) { ! for(int j = 0; j<this.numberOfTickersToBeChosen; j++) { ! ticker = this.lastOrderedTickersForTheAccount[accountNumber, j]; if( ticker != null) { *************** *** 184,245 **** } ! ! ! protected override void closePositions() { ! for(int i=0; i<this.accounts.Length; i++) { ! if(i==0)//OTC daily account ! this.closePositions_close(i); ! if(i==1)//OTC 2 days ! { ! if(this.numDaysElapsedSinceLastOptimization == ! this.numDaysBetweenEachOptimization - 1) ! this.closePositions_close(i); ! } ! if(i==2)//OTC-CTO ! { ! this.closePositions_close(i); ! if(this.numDaysElapsedSinceLastOptimization < ! this.numDaysBetweenEachOptimization - 1) ! //open reverse positions at night ! { ! this.reverseSignOfChosenTickers(); ! this.orders.Clear(); ! this.addChosenTickersToOrderListForTheGivenAccount(i); ! this.openPositions_openWhenPortfolioIsEmpty(i); ! this.reverseSignOfChosenTickers(); ! this.orders.Clear(); ! } ! } ! if(i==3)//CTO, only at night ! { ! // this.closePositions_close(i); ! if(this.numDaysElapsedSinceLastOptimization < ! this.numDaysBetweenEachOptimization - 1) ! //open reverse positions at night ! { ! this.reverseSignOfChosenTickers(); ! this.orders.Clear(); ! this.addChosenTickersToOrderListForTheGivenAccount(i); ! this.openPositions_openWhenPortfolioIsEmpty(i); ! this.reverseSignOfChosenTickers(); ! this.orders.Clear(); ! } ! } } ! } ! private void reverseSignOfChosenTickers() ! { ! for(int i = 0; i<this.chosenTickers.Length; i++) { ! if(this.chosenTickers[i] != null) ! { ! if(this.chosenTickers[i].StartsWith("-")) ! this.chosenTickers[i] = ! GenomeManagerForEfficientPortfolio.GetCleanTickerCode(this.chosenTickers[i]); ! else ! this.chosenTickers[i] = "-" + this.chosenTickers[i]; ! } } } --- 138,156 ---- } ! private void marketCloseEventHandler_reversePositionsForTheAccount(int accountNumber) { ! this.closePositionsForTheAccount(accountNumber); ! SignedTicker.ChangeSignOfEachTicker(this.chosenTickers); ! try { ! this.openPositionsForTheAccountWhenPortfolioIsEmpty(accountNumber); } ! catch(Exception ex) { ! ex = ex; ! } ! finally ! { ! SignedTicker.ChangeSignOfEachTicker(this.chosenTickers); } } *************** *** 253,271 **** Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! //temporarily the if condition ! //if(this.numDaysElapsedSinceLastOptimization == 0) ! this.openPositions(); } ! ! public override void MarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! ! //temporarily ! //if(this.numDaysElapsedSinceLastOptimization == ! // this.numDaysBetweenEachOptimization) ! this.closePositions(); ! } --- 164,210 ---- Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! for(int i = 0; i<this.accounts.Length; i++) ! { ! //add cash first for each account ! if(this.orders.Count == 0 && this.accounts[i].Transactions.Count == 0) ! this.accounts[i].AddCash(30000); ! ! if(i<=1)//daily classical and multiday ! this.openPositionsForTheAccountWhenPortfolioIsEmpty(i); ! ! if(i==2)//for the CTO OTC ! { ! this.closePositionsForTheAccount(i); ! this.openPositionsForTheAccountWhenPortfolioIsEmpty(i); ! } ! if(i==3)//for the CTO, no position is opened ! //at market open. Any open position is closed, instead ! this.closePositionsForTheAccount(i); ! } } ! public override void MarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! if(this.accounts[1].Portfolio.Count > 0) ! numOfClosesWithOpenPositionsFor2DaysStrategy++; ! ! for(int i=0; i<this.accounts.Length; i++) ! { ! if(i==0)//OTC daily account ! this.closePositionsForTheAccount(i); ! ! if(i==1)//OTC 2 days ! { ! if(this.numOfClosesWithOpenPositionsFor2DaysStrategy == 2) ! { ! this.closePositionsForTheAccount(i); ! this.numOfClosesWithOpenPositionsFor2DaysStrategy = 0; ! } ! } ! ! if(i>=2)//for the OTC-CTO and CTO ! this.marketCloseEventHandler_reversePositionsForTheAccount(i); ! } } *************** *** 276,313 **** protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) { ! /* ! SelectorByAverageRawOpenPrice selectorByOpenPrice = ! new SelectorByAverageRawOpenPrice(this.tickerGroupID, false, ! currentDate.AddDays(-this.numDaysForLiquidity), currentDate, ! this.numberOfEligibleTickers, this.minPriceForMinimumCommission, ! this.maxPriceForMinimumCommission, 0, 2); ! DataTable tickersByPrice = selectorByOpenPrice.GetTableOfSelectedTickers(); ! */ ! ! SelectorByGroup temporizedGroup = new SelectorByGroup(this.tickerGroupID, currentDate); ! SelectorByOpenCloseCorrelationToBenchmark lessCorrelatedFromTemporizedGroup = ! new SelectorByOpenCloseCorrelationToBenchmark(temporizedGroup.GetTableOfSelectedTickers(), ! this.benchmark,true, ! currentDate.AddDays(-this.numDaysForOptimizationPeriod ), ! currentDate, ! this.numberOfEligibleTickers); ! this.eligibleTickers = lessCorrelatedFromTemporizedGroup.GetTableOfSelectedTickers(); ! SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromEligible = ! new SelectorByQuotationAtEachMarketDay( this.eligibleTickers, ! false, currentDate.AddDays(-this.numDaysForOptimizationPeriod), ! currentDate, this.numberOfEligibleTickers, this.benchmark); ! //SelectorByWinningOpenToClose winners = ! // new SelectorByWinningOpenToClose(quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(), ! // false, currentDate.AddDays(-2), ! // currentDate, this.numberOfEligibleTickers/4); ! //return winners.GetTableOfSelectedTickers(); ! //SelectorByOpenCloseCorrelationToBenchmark lessCorrelated = ! // new SelectorByOpenCloseCorrelationToBenchmark(quotedAtEachMarketDayFromEligible.GetTableOfSelectedTickers(), ! // this.benchmark, true, ! // currentDate.AddDays(-this.numDaysForLiquidity), ! // currentDate, this.numberOfEligibleTickers/2); ! return quotedAtEachMarketDayFromEligible.GetTableOfSelectedTickers(); ! //return lessCorrelated.GetTableOfSelectedTickers(); } --- 215,239 ---- protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) { ! SelectorByGroup temporizedGroup = new SelectorByGroup(this.tickerGroupID, currentDate); ! DataTable tickersFromGroup = temporizedGroup.GetTableOfSelectedTickers(); ! SelectorByAverageRawOpenPrice byPrice = ! new SelectorByAverageRawOpenPrice(tickersFromGroup,false,currentDate, ! currentDate.AddDays(-30), ! tickersFromGroup.Rows.Count, ! 30,500, 0.0001,100); ! ! ! SelectorByLiquidity mostLiquidSelector = ! new SelectorByLiquidity(byPrice.GetTableOfSelectedTickers(), ! false,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, ! this.numberOfEligibleTickers); ! ! SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromMostLiquid = ! new SelectorByQuotationAtEachMarketDay(mostLiquidSelector.GetTableOfSelectedTickers(), ! false, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, ! this.numberOfEligibleTickers, this.benchmark); ! ! return quotedAtEachMarketDayFromMostLiquid.GetTableOfSelectedTickers(); } *************** *** 323,327 **** { IGenomeManager genManEfficientOTCTypes = ! new GenomeManagerForEfficientOTCTypes(setOfTickersToBeOptimized, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, --- 249,253 ---- { IGenomeManager genManEfficientOTCTypes = ! new GenomeManagerForEfficientOTCCTOPortfolio(setOfTickersToBeOptimized, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, *************** *** 348,360 **** } - protected void oneHourAfterMarketCloseEventHandler_updatePrices() - { - //min price for minimizing commission amount - //according to IB Broker's commission scheme - this.minPriceForMinimumCommission = this.account.CashAmount/(this.numberOfTickersToBeChosen*100); - this.maxPriceForMinimumCommission = this.maxPriceForMinimumCommission; - //just to avoid warning message - } - /// <summary> /// Handles a "One hour after market close" event. --- 274,277 ---- *************** *** 367,371 **** this.seedForRandomGenerator++; this.orders.Clear(); - //this.oneHourAfterMarketCloseEventHandler_updatePrices(); if(this.numDaysElapsedSinceLastOptimization == this.numDaysBetweenEachOptimization - 1) --- 284,287 ---- |