[Quantproject-developers] QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOs
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2007-08-29 09:50:31
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv13724/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator Modified Files: EndOfDayTimerHandlerPVO.cs Log Message: Code has been re-organized in a more logical and Object Oriented way: - WeightedPositions class has been used. - Some static methods have been deleted from SignedTicker class. They have been moved to WeightedPositions. - Basic orders'management has been moved to the primitive base class EndOfDayTimerHandler and to AccountManager class Index: EndOfDayTimerHandlerPVO.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/EndOfDayTimerHandlerPVO.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** EndOfDayTimerHandlerPVO.cs 9 Apr 2007 18:08:04 -0000 1.5 --- EndOfDayTimerHandlerPVO.cs 29 Aug 2007 09:50:20 -0000 1.6 *************** *** 57,65 **** protected double currentOverboughtThreshold; protected double maxAcceptableCloseToCloseDrawdown; - protected bool stopLossConditionReached; - protected double currentAccountValue; - protected double previousAccountValue; - protected int numDaysBetweenEachOptimization; - protected int numDaysElapsedSinceLastOptimization; protected DateTime lastCloseDate; protected IGenomeManager iGenomeManager; --- 57,60 ---- *************** *** 118,133 **** this.previousAccountValue = this.currentAccountValue; this.currentAccountValue = this.account.GetMarketValue(); ! if((this.currentAccountValue - this.previousAccountValue) ! /this.previousAccountValue < -this.maxAcceptableCloseToCloseDrawdown) ! { this.stopLossConditionReached = true; - } else - { this.stopLossConditionReached = false; - } } ! protected virtual double getCurrentChosenTickersValue(IndexBasedEndOfDayTimer timer) { double returnValue = 999.0; --- 113,124 ---- this.previousAccountValue = this.currentAccountValue; this.currentAccountValue = this.account.GetMarketValue(); ! if( (this.currentAccountValue - this.previousAccountValue)/ ! this.previousAccountValue < -this.maxAcceptableCloseToCloseDrawdown ) this.stopLossConditionReached = true; else this.stopLossConditionReached = false; } ! protected virtual double getCurrentChosenWeightedPositionsValue(IndexBasedEndOfDayTimer timer) { double returnValue = 999.0; *************** *** 141,147 **** (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition]["quDate"]; returnValue = ! SignedTicker.GetCloseToClosePortfolioReturn( ! this.chosenTickers, this.chosenTickersPortfolioWeights, ! initialDate,finalDate) + 1.0; } catch(MissingQuotesException ex) --- 132,137 ---- (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition]["quDate"]; returnValue = ! this.chosenWeightedPositions.GetCloseToCloseReturn( initialDate, ! finalDate) + 1.0; } catch(MissingQuotesException ex) *************** *** 154,160 **** private void marketCloseEventHandler_reverseIfNeeded(IndexBasedEndOfDayTimer timer) { ! double currentChosenTickersValue = ! this.getCurrentChosenTickersValue(timer); ! if(currentChosenTickersValue != 999.0) //currentChosenTickersValue has been properly computed { --- 144,150 ---- private void marketCloseEventHandler_reverseIfNeeded(IndexBasedEndOfDayTimer timer) { ! double currentChosenWeightedPositionsTickersValue = ! this.getCurrentChosenWeightedPositionsValue(timer); ! if(currentChosenWeightedPositionsTickersValue != 999.0) //currentChosenTickersValue has been properly computed { *************** *** 162,166 **** //it is possible to reverse positions { ! if(currentChosenTickersValue >= 1.0 + currentOverboughtThreshold && this.portfolioHasBeenOversold) //open positions derive from an overSold period but now --- 152,156 ---- //it is possible to reverse positions { ! if(currentChosenWeightedPositionsTickersValue >= 1.0 + currentOverboughtThreshold && this.portfolioHasBeenOversold) //open positions derive from an overSold period but now *************** *** 171,175 **** this.portfolioHasBeenOverbought = true; } ! if(currentChosenTickersValue <= 1.0 - currentOversoldThreshold && this.portfolioHasBeenOverbought) //open positions derive from an overSold period but now --- 161,165 ---- this.portfolioHasBeenOverbought = true; } ! if(currentChosenWeightedPositionsTickersValue <= 1.0 - currentOversoldThreshold && this.portfolioHasBeenOverbought) //open positions derive from an overSold period but now *************** *** 184,203 **** } ! private void marketCloseEventHandler_openPositions(IndexBasedEndOfDayTimer timer) { ! double currentChosenTickersValue = ! this.getCurrentChosenTickersValue(timer); ! if(currentChosenTickersValue != 999.0) //currentChosenTickersValue has been properly computed { ! if(currentChosenTickersValue >= 1.0 + currentOverboughtThreshold && this.portfolioType == PortfolioType.ShortAndLong) { ! SignedTicker.ChangeSignOfEachTicker(this.chosenTickers); ! ! //short the portfolio try { ! base.openPositions(this.chosenTickers); this.portfolioHasBeenOverbought = true; this.portfolioHasBeenOversold = false; --- 174,194 ---- } ! protected void marketCloseEventHandler_openPositions(IndexBasedEndOfDayTimer timer) { ! if(this.account.CashAmount == 0.0 && this.account.Transactions.Count == 0) ! this.account.AddCash(15000); ! double currentChosenWeightedPositionsValue = ! this.getCurrentChosenWeightedPositionsValue(timer); ! if(currentChosenWeightedPositionsValue != 999.0) //currentChosenTickersValue has been properly computed { ! if(currentChosenWeightedPositionsValue >= 1.0 + currentOverboughtThreshold && this.portfolioType == PortfolioType.ShortAndLong) { ! this.chosenWeightedPositions.Reverse(); try { ! AccountManager.OpenPositions( this.chosenWeightedPositions, ! this.account ); this.portfolioHasBeenOverbought = true; this.portfolioHasBeenOversold = false; *************** *** 209,218 **** finally { ! SignedTicker.ChangeSignOfEachTicker(this.chosenTickers); } } ! else if (currentChosenTickersValue <= 1.0 - currentOversoldThreshold) { ! base.openPositions(this.chosenTickers); this.portfolioHasBeenOverbought = false; this.portfolioHasBeenOversold = true; --- 200,210 ---- finally { ! this.chosenWeightedPositions.Reverse(); } } ! else if (currentChosenWeightedPositionsValue <= 1.0 - currentOversoldThreshold) { ! AccountManager.OpenPositions( this.chosenWeightedPositions, ! this.account ); this.portfolioHasBeenOverbought = false; this.portfolioHasBeenOversold = true; *************** *** 226,232 **** this.numDaysElapsedSinceLastOptimization + 1 == this.numDaysBetweenEachOptimization ) { ! base.closePositions(); //a new optimization is needed, now ! this.chosenTickers[0] = null; //when positions are closed, these parameters //have to be reset to false --- 218,224 ---- this.numDaysElapsedSinceLastOptimization + 1 == this.numDaysBetweenEachOptimization ) { ! AccountManager.ClosePositions(this.account); //a new optimization is needed, now ! this.chosenWeightedPositions = null; //when positions are closed, these parameters //have to be reset to false *************** *** 241,245 **** //this.marketCloseEventHandler_updateStopLossCondition(); this.marketCloseEventHandler_closePositionsIfNeeded(); ! if(this.chosenTickers[0] != null) //tickers to buy have been chosen by the optimizer { --- 233,237 ---- //this.marketCloseEventHandler_updateStopLossCondition(); this.marketCloseEventHandler_closePositionsIfNeeded(); ! if(this.chosenWeightedPositions != null) //tickers to buy have been chosen by the optimizer { *************** *** 248,252 **** //positions are opened only if thresholds are reached else//there are some opened positions ! this.marketCloseEventHandler_reverseIfNeeded((IndexBasedEndOfDayTimer)sender);; } --- 240,244 ---- //positions are opened only if thresholds are reached else//there are some opened positions ! this.marketCloseEventHandler_reverseIfNeeded((IndexBasedEndOfDayTimer)sender); } *************** *** 320,324 **** { DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); ! if(setOfTickersToBeOptimized.Rows.Count > this.chosenTickers.Length*2) //the optimization process is meaningful only if the initial set of tickers is //larger than the number of tickers to be chosen --- 312,316 ---- { DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); ! if(setOfTickersToBeOptimized.Rows.Count > this.numberOfTickersToBeChosen*2) //the optimization process is meaningful only if the initial set of tickers is //larger than the number of tickers to be chosen *************** *** 347,352 **** GO.Run(false); ! this.chosenTickers = ((GenomeMeaningPVO)GO.BestGenome.Meaning).Tickers; ! this.chosenTickersPortfolioWeights = ((GenomeMeaningPVO)GO.BestGenome.Meaning).TickersPortfolioWeights; this.currentOversoldThreshold = ((GenomeMeaningPVO)GO.BestGenome.Meaning).OversoldThreshold; this.currentOverboughtThreshold = ((GenomeMeaningPVO)GO.BestGenome.Meaning).OverboughtThreshold; --- 339,344 ---- GO.Run(false); ! this.chosenWeightedPositions = new WeightedPositions( ((GenomeMeaningPVO)GO.BestGenome.Meaning).TickersPortfolioWeights, ! new SignedTickers( ((GenomeMeaningPVO)GO.BestGenome.Meaning).Tickers) ); this.currentOversoldThreshold = ((GenomeMeaningPVO)GO.BestGenome.Meaning).OversoldThreshold; this.currentOverboughtThreshold = ((GenomeMeaningPVO)GO.BestGenome.Meaning).OverboughtThreshold; *************** *** 371,375 **** this.seedForRandomGenerator++; this.numDaysElapsedSinceLastOptimization++; - this.orders.Clear(); if((this.numDaysElapsedSinceLastOptimization == this.numDaysBetweenEachOptimization)) --- 363,366 ---- |