[Quantproject-developers] QuantProject/b7_Scripts/TechnicalAnalysisTesting/TrendFollowing/Immediate
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2008-01-14 23:38:40
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/TrendFollowing/ImmediateTrendFollower In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv21302/b7_Scripts/TechnicalAnalysisTesting/TrendFollowing/ImmediateTrendFollower Modified Files: GenomeManagerITF.cs Log Message: GenomeManagers have been updated (WeightedPositions have been used instead of CandidateProperties) Index: GenomeManagerITF.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/TrendFollowing/ImmediateTrendFollower/GenomeManagerITF.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** GenomeManagerITF.cs 17 Sep 2006 21:48:39 -0000 1.2 --- GenomeManagerITF.cs 14 Jan 2008 23:38:36 -0000 1.3 *************** *** 28,31 **** --- 28,36 ---- using QuantProject.Data; using QuantProject.Data.DataTables; + using QuantProject.Business.DataProviders; + using QuantProject.Business.Timing; + using QuantProject.Business.Strategies; + using QuantProject.Business.Strategies.ReturnsManagement; + using QuantProject.Business.Strategies.ReturnsManagement.Time; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; *************** *** 41,44 **** --- 46,50 ---- { private int numDaysForReturnCalculation; + private ReturnsManager returnsManager; public GenomeManagerITF(DataTable setOfInitialTickers, *************** *** 47,51 **** int numberOfTickersInPortfolio, int numDaysForReturnCalculation, ! PortfolioType portfolioType) : base(setOfInitialTickers, --- 53,58 ---- int numberOfTickersInPortfolio, int numDaysForReturnCalculation, ! PortfolioType portfolioType, ! string benchmark) : base(setOfInitialTickers, *************** *** 54,126 **** numberOfTickersInPortfolio, 0.0, ! portfolioType) { this.numDaysForReturnCalculation = numDaysForReturnCalculation; ! this.retrieveData(); } ! protected override float[] getArrayOfRatesOfReturn(string ticker) ! { ! float[] returnValue = null; ! Quotes tickerQuotes = new Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); ! returnValue = ExtendedDataTable.GetArrayOfFloatFromColumn(tickerQuotes, ! Quotes.AdjustedCloseToCloseRatio); ! for(int i = 0; i<returnValue.Length; i++) ! returnValue[i] = returnValue[i] - 1.0f; ! ! this.numberOfExaminedReturns = returnValue.Length; ! ! return returnValue; ! } ! ! ! //fitness is a sharpe-ratio based indicator for the equity line resulting ! //from applying the strategy ! public override double GetFitnessValue(Genome genome) { ! this.portfolioRatesOfReturn = this.getPortfolioRatesOfReturn(genome.Genes()); ! ! double[] equityLine = this.getFitnessValue_getEquityLineRates(); ! //return AdvancedFunctions.GetExpectancyScore(equityLine); ! return AdvancedFunctions.GetSharpeRatio(equityLine); } ! private double[] getFitnessValue_getEquityLineRates() ! { ! double[] returnValue = new double[this.PortfolioRatesOfReturn.Length]; ! double K;//initial capital invested at the beginning of the period ! for(int i = this.numDaysForReturnCalculation - 1; ! i<this.PortfolioRatesOfReturn.Length - this.numDaysForReturnCalculation; ! i += this.numDaysForReturnCalculation) { ! K = 1.0; ! for(int j=this.numDaysForReturnCalculation - 1; ! j > -1; j--) ! { ! K = K + K * this.PortfolioRatesOfReturn[i-j]; ! } ! ! for(int t=1;t<this.numDaysForReturnCalculation + 1;t++) ! { ! if(K < 1.0 && this.PortfolioType == PortfolioType.ShortAndLong) ! // if gain of first half period is negative and ! //positions can be reversed ! returnValue[i+t] = - this.PortfolioRatesOfReturn[i+t]; ! else if(K > 1.0) ! //if gain of first half period is positive ! returnValue[i+t] = this.PortfolioRatesOfReturn[i+t]; ! else if(K < 1.0 && this.PortfolioType != PortfolioType.ShortAndLong) ! //if gain of first half period is negative and ! //original positions can't be reversed ! returnValue[i+t] = 0.0;//out of the market ! } ! } return returnValue; ! } ! } - } --- 61,118 ---- numberOfTickersInPortfolio, 0.0, ! portfolioType, ! benchmark) { this.numDaysForReturnCalculation = numDaysForReturnCalculation; ! this.setReturnsManager(); } ! private void setReturnsManager() { ! EndOfDayDateTime firstEndOfDayDateTime = ! new EndOfDayDateTime(firstQuoteDate, EndOfDaySpecificTime.MarketClose); ! EndOfDayDateTime lastEndOfDayDateTime = ! new EndOfDayDateTime(lastQuoteDate, EndOfDaySpecificTime.MarketClose); ! this.returnsManager = ! new ReturnsManager( new CloseToCloseIntervals( ! firstEndOfDayDateTime, ! lastEndOfDayDateTime, ! this.benchmark, ! this.numDaysForReturnCalculation) , ! new HistoricalAdjustedQuoteProvider() ); } ! private float[] getStrategyReturns_getReturnsActually( ! float[] plainReturns) ! { ! float[] returnValue = new float[plainReturns.Length]; ! returnValue[0] = 0; //a the very first day the ! //first strategy return is equal to 0 because no position ! //has been entered ! float coefficient = 0; ! for(int i = 0; i < returnValue.Length - 1; i++) { ! if( plainReturns[i] > 0 ) ! coefficient = 1;//the strategy follows ... ! else if( plainReturns[i] <= 0 ) ! coefficient = - 1; ! ! returnValue[i + 1] = coefficient * plainReturns[i + 1]; } return returnValue; ! } ! ! protected override float[] getStrategyReturns() ! { ! EndOfDayDateTime firstEndOfDayDateTime = ! new EndOfDayDateTime(firstQuoteDate, EndOfDaySpecificTime.MarketClose); ! EndOfDayDateTime lastEndOfDayDateTime = ! new EndOfDayDateTime(lastQuoteDate, EndOfDaySpecificTime.MarketClose); ! float[] plainReturns = this.weightedPositionsFromGenome.GetReturns( ! this.returnsManager); ! return this.getStrategyReturns_getReturnsActually(plainReturns); ! } } } |