[Quantproject-developers] QuantProject/b7_Scripts/TickerSelectionTesting GenomeManagerForEfficient
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2008-01-14 23:38:40
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv21302/b7_Scripts/TickerSelectionTesting Modified Files: GenomeManagerForEfficientCTCPortfolio.cs GenomeManagerForEfficientCTOPortfolio.cs GenomeManagerForEfficientOTCCTOPortfolio.cs GenomeManagerForEfficientOTCPortfolio.cs GenomeManagerForEfficientPortfolio.cs GenomeManagerForWeightedEfficientPortfolio.cs Log Message: GenomeManagers have been updated (WeightedPositions have been used instead of CandidateProperties) Index: GenomeManagerForEfficientCTOPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientCTOPortfolio.cs,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** GenomeManagerForEfficientCTOPortfolio.cs 2 Jul 2006 19:57:34 -0000 1.19 --- GenomeManagerForEfficientCTOPortfolio.cs 14 Jan 2008 23:38:36 -0000 1.20 *************** *** 23,31 **** using System; using System.Data; ! using System.Collections; ! using QuantProject.ADT.Statistics; ! using QuantProject.ADT.Optimizing.Genetic; ! using QuantProject.Data; ! using QuantProject.Data.DataTables; --- 23,32 ---- using System; using System.Data; ! ! using QuantProject.Business.DataProviders; ! using QuantProject.Business.Timing; ! using QuantProject.Business.Strategies; ! using QuantProject.Business.Strategies.ReturnsManagement; ! using QuantProject.Business.Strategies.ReturnsManagement.Time; *************** *** 40,50 **** public class GenomeManagerForEfficientCTOPortfolio : GenomeManagerForEfficientPortfolio { ! private GenomeManagerForEfficientOTCPortfolio genManOTC; ! public GenomeManagerForEfficientCTOPortfolio(DataTable setOfInitialTickers, DateTime firstQuoteDate, DateTime lastQuoteDate, int numberOfTickersInPortfolio, double targetPerformance, ! PortfolioType portfolioType) :base(setOfInitialTickers, firstQuoteDate, --- 41,53 ---- public class GenomeManagerForEfficientCTOPortfolio : GenomeManagerForEfficientPortfolio { ! private ReturnsManager returnsManager; ! ! public GenomeManagerForEfficientCTOPortfolio(DataTable setOfInitialTickers, DateTime firstQuoteDate, DateTime lastQuoteDate, int numberOfTickersInPortfolio, double targetPerformance, ! PortfolioType portfolioType, ! string benchmark) :base(setOfInitialTickers, firstQuoteDate, *************** *** 52,156 **** numberOfTickersInPortfolio, targetPerformance, ! portfolioType) { ! this.retrieveData(); ! this.genManOTC = new GenomeManagerForEfficientOTCPortfolio(setOfInitialTickers, ! firstQuoteDate, ! lastQuoteDate, ! numberOfTickersInPortfolio, ! targetPerformance, ! portfolioType); ! } ! private float[] getArrayOfRatesOfReturn_getCloseToOpenRates(Quotes tickerQuotes) ! { ! float[] returnValue = new float[tickerQuotes.Rows.Count - 1]; ! for(int i = 0;i<tickerQuotes.Rows.Count - 1; i++) ! { ! returnValue[i] = ! ( (float)tickerQuotes.Rows[i+1]["quOpen"]* ! (float)tickerQuotes.Rows[i+1]["quAdjustedClose"]/ ! (float)tickerQuotes.Rows[i+1]["quClose"] ) ! /(float)tickerQuotes.Rows[i]["quAdjustedClose"] - 1; ! } ! return returnValue; ! } ! protected override float[] getArrayOfRatesOfReturn(string ticker) ! { ! float[] returnValue = null; ! Quotes tickerQuotes = new Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); ! returnValue = this.getArrayOfRatesOfReturn_getCloseToOpenRates(tickerQuotes); ! this.numberOfExaminedReturns = returnValue.Length; ! ! return returnValue; ! } ! public override double GetFitnessValue(Genome genome) ! { ! double returnValue = 0; ! this.portfolioRatesOfReturn = this.getPortfolioRatesOfReturn(genome.Genes()); ! double averagePortfolioRateOfReturn = ! BasicFunctions.SimpleAverage(this.portfolioRatesOfReturn); ! ! double portfolioVariance = ! BasicFunctions.Variance(this.portfolioRatesOfReturn); ! ! if(!Double.IsInfinity(portfolioVariance) && ! !Double.IsInfinity(averagePortfolioRateOfReturn) && ! !Double.IsNaN(portfolioVariance) && ! !Double.IsNaN(averagePortfolioRateOfReturn) && ! portfolioVariance > 0.0) ! //both variance and rate of return are ! //double values computed in the right way: ! // so it's possible to assign fitness ! { ! this.variance = portfolioVariance; ! this.rateOfReturn = averagePortfolioRateOfReturn; ! returnValue = this.getFitnessValue_calculate(); ! // returnValue = this.getFitnessValue_calculate() - ! // this.genManOTC.GetFitnessValue(genome); ! ! } ! ! return returnValue; ! } ! ! ! /*using LPM ! protected override double getFitnessValue_calculate() ! { ! double returnValue = 0; ! ! double a, b, c; ! a = 0.002; b = 2.0; c = 2.0; ! ! //returnValue = Math.Pow((a/this.Variance),b) * ! // Math.Pow((this.rateOfReturn - this.targetPerformance), ! // c); ! //this.lowerPartialMoment = AdvancedFunctions.LowerPartialMoment(this.portfolioRatesOfReturn, ! // BasicFunctions.SimpleAverage(this.portfolioRatesOfReturn), ! // 3.0); ! this.lowerPartialMoment = AdvancedFunctions.NegativeSemiVariance(this.portfolioRatesOfReturn); ! a = 1.0; ! returnValue = Math.Pow((a/this.lowerPartialMoment),b) * ! Math.Pow(Math.Max(0.0,(this.rateOfReturn - this.targetPerformance)), ! c); ! ! if(this.portfolioType == PortfolioType.OnlyShort) ! returnValue = - returnValue; ! ! if(Double.IsInfinity(returnValue) || Double.IsNaN(returnValue)) ! throw new Exception("Fitness value not computed correctly!"); ! ! return returnValue; } ! */ ! ! protected override double getFitnessValue_calculate() { ! return this.RateOfReturn/Math.Sqrt(this.Variance); } ! } - } --- 55,85 ---- numberOfTickersInPortfolio, targetPerformance, ! portfolioType, ! benchmark) { ! this.setReturnsManager(firstQuoteDate, lastQuoteDate); } ! ! private void setReturnsManager(DateTime firstQuoteDate, ! DateTime lastQuoteDate) { ! EndOfDayDateTime firstEndOfDayDateTime = ! new EndOfDayDateTime(firstQuoteDate, EndOfDaySpecificTime.MarketOpen); ! EndOfDayDateTime lastEndOfDayDateTime = ! new EndOfDayDateTime(lastQuoteDate, EndOfDaySpecificTime.MarketClose); ! this.returnsManager = ! new ReturnsManager( new CloseToOpenIntervals( ! firstEndOfDayDateTime, ! lastEndOfDayDateTime, ! this.benchmark), ! new HistoricalAdjustedQuoteProvider() ); } ! protected override float[] getStrategyReturns() ! { ! return this.weightedPositionsFromGenome.GetReturns(this.returnsManager); ! } ! } } Index: GenomeManagerForEfficientCTCPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientCTCPortfolio.cs,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** GenomeManagerForEfficientCTCPortfolio.cs 14 May 2006 18:36:37 -0000 1.13 --- GenomeManagerForEfficientCTCPortfolio.cs 14 Jan 2008 23:38:36 -0000 1.14 *************** *** 23,31 **** using System; using System.Data; ! using System.Collections; ! using QuantProject.ADT.Statistics; ! using QuantProject.ADT.Optimizing.Genetic; ! using QuantProject.Data; ! using QuantProject.Data.DataTables; --- 23,32 ---- using System; using System.Data; ! ! using QuantProject.Business.DataProviders; ! using QuantProject.Business.Timing; ! using QuantProject.Business.Strategies; ! using QuantProject.Business.Strategies.ReturnsManagement; ! using QuantProject.Business.Strategies.ReturnsManagement.Time; *************** *** 41,59 **** { private int numDaysForReturnCalculation; ! private double shiftedPortfolioRateOfReturn; ! private float[] shiftedPortfolioRatesOfReturn; ! //private double shiftedPortfolioVariance; ! //rate of return and variance of portfolio ! //shifted ahead of numDaysForReturnCalculation ! /// <summary> ! /// Rates of returns of the portfolio shifted ahead of numDaysForReturnCalculation ! /// </summary> ! public float[] ShiftedPortfolioRatesOfReturn ! { ! get{return this.shiftedPortfolioRatesOfReturn;} ! } ! ! public GenomeManagerForEfficientCTCPortfolio(DataTable setOfInitialTickers, DateTime firstQuoteDate, DateTime lastQuoteDate, --- 42,48 ---- { private int numDaysForReturnCalculation; ! private ReturnsManager returnsManager; ! public GenomeManagerForEfficientCTCPortfolio(DataTable setOfInitialTickers, DateTime firstQuoteDate, DateTime lastQuoteDate, *************** *** 61,65 **** int numDaysForReturnCalculation, double targetPerformance, ! PortfolioType portfolioType) : base(setOfInitialTickers, --- 50,55 ---- int numDaysForReturnCalculation, double targetPerformance, ! PortfolioType portfolioType, ! string benchmark) : base(setOfInitialTickers, *************** *** 68,185 **** numberOfTickersInPortfolio, targetPerformance, ! portfolioType) { ! this.numDaysForReturnCalculation = numDaysForReturnCalculation; ! this.retrieveData(); } ! // old implementation, where a "continuos" adjusted close to close ratio, ! // based on a particular fixed interval of days, is considered ! // In this case, there is no discontinuity between the returned ratesOfReturn ! // ! // protected override float[] getArrayOfRatesOfReturn(string ticker) ! // { ! // float[] returnValue = null; ! // Quotes tickerQuotes = new Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); ! // float[] allAdjValues = ExtendedDataTable.GetArrayOfFloatFromColumn(tickerQuotes, "quAdjustedClose"); ! // returnValue = new float[allAdjValues.Length/this.numDaysForReturnCalculation + 1]; ! // int i = 0; //index for ratesOfReturns array ! // for(int idx = 0; idx + this.numDaysForReturnCalculation < allAdjValues.Length; idx += this.numDaysForReturnCalculation ) ! // { ! // returnValue[i] = (allAdjValues[idx+this.numDaysForReturnCalculation]/ ! // allAdjValues[idx] - 1); ! // i++; ! // } ! // this.numberOfExaminedReturns = returnValue.Length; ! // ! // return returnValue; ! // } ! ! // new implementation, where a "discontinuos" adjusted close to close ratio, ! // based on a particular fixed interval of days, is considered ! // In this case, there is a discontinuity between each pair of ratesOfReturn, ! // equal to the given interval of days ! protected override float[] getArrayOfRatesOfReturn(string ticker) { ! this.calculateShiftedRateOfReturn(ticker); ! ! float[] returnValue = null; ! returnValue = ! QuantProject.Data.DataTables.Quotes.GetArrayOfCloseToCloseRatios(ticker, ! ref this.firstQuoteDate, ! this.lastQuoteDate, ! this.numDaysForReturnCalculation); ! ! this.numberOfExaminedReturns = returnValue.Length; ! ! return returnValue; ! } ! /*LPM as fitness ! protected override double getFitnessValue_calculate() ! { ! double returnValue = 0; ! ! double a, b, c; ! a = 0.002; b = 2.0; c = 2.0; ! ! //returnValue = Math.Pow((a/this.Variance),b) * ! // Math.Pow((this.rateOfReturn - this.targetPerformance), ! // c); ! //this.lowerPartialMoment = AdvancedFunctions.LowerPartialMoment(this.portfolioRatesOfReturn, ! // BasicFunctions.SimpleAverage(this.portfolioRatesOfReturn), ! // 3.0); ! this.lowerPartialMoment = AdvancedFunctions.NegativeSemiVariance(this.portfolioRatesOfReturn); ! a = 1.0; ! returnValue = Math.Pow((a/this.lowerPartialMoment),b) * ! Math.Pow((this.rateOfReturn - this.targetPerformance), ! c); ! ! if(this.portfolioType == PortfolioType.OnlyShort) ! returnValue = - returnValue; ! ! if(Double.IsInfinity(returnValue) || Double.IsNaN(returnValue)) ! throw new Exception("Fitness value not computed correctly!"); ! ! return returnValue; ! } ! */ ! private void calculateShiftedRateOfReturn(string ticker) ! { ! try ! { ! float[] closeToCloseRatios = Quotes.GetArrayOfCloseToCloseRatios(ticker, ref this.firstQuoteDate, ! this.lastQuoteDate, ! this.numDaysForReturnCalculation, ! this.numDaysForReturnCalculation); ! this.shiftedPortfolioRatesOfReturn = closeToCloseRatios; ! this.shiftedPortfolioRateOfReturn = ! BasicFunctions.SimpleAverage(closeToCloseRatios); ! //this.shiftedPortfolioVariance = ! //BasicFunctions.Variance(closeToCloseRatios); ! } ! catch(Exception ex) ! { ! ex = ex; ! } ! } ! ! protected override double getFitnessValue_calculate() ! { ! // return (this.RateOfReturn/Math.Sqrt(this.Variance))* ! // -this.shiftedPortfolioRateOfReturn * ! // -this.ShiftedPortfolioRatesOfReturn[this.ShiftedPortfolioRatesOfReturn.Length -1]; ! double sharpeRatioWaveUp = this.RateOfReturn/ ! Math.Sqrt(this.Variance); ! double sharpeRatioWaveDown = this.shiftedPortfolioRateOfReturn/ ! Math.Sqrt(BasicFunctions.Variance(this.shiftedPortfolioRatesOfReturn)); ! ! return sharpeRatioWaveUp - sharpeRatioWaveDown; ! ! } ! } - } --- 58,90 ---- numberOfTickersInPortfolio, targetPerformance, ! portfolioType, ! benchmark) { ! this.numDaysForReturnCalculation = numDaysForReturnCalculation; ! this.setReturnsManager(firstQuoteDate, lastQuoteDate); } ! ! private void setReturnsManager(DateTime firstQuoteDate, ! DateTime lastQuoteDate) { ! EndOfDayDateTime firstEndOfDayDateTime = ! new EndOfDayDateTime(firstQuoteDate, EndOfDaySpecificTime.MarketOpen); ! EndOfDayDateTime lastEndOfDayDateTime = ! new EndOfDayDateTime(lastQuoteDate, EndOfDaySpecificTime.MarketClose); ! this.returnsManager = ! new ReturnsManager( new CloseToCloseIntervals( ! firstEndOfDayDateTime, ! lastEndOfDayDateTime, ! this.benchmark, ! this.numDaysForReturnCalculation), ! new HistoricalAdjustedQuoteProvider() ); } ! protected override float[] getStrategyReturns() ! { ! return this.weightedPositionsFromGenome.GetReturns(this.returnsManager); ! } } } Index: GenomeManagerForEfficientOTCPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientOTCPortfolio.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** GenomeManagerForEfficientOTCPortfolio.cs 14 May 2006 18:36:37 -0000 1.2 --- GenomeManagerForEfficientOTCPortfolio.cs 14 Jan 2008 23:38:36 -0000 1.3 *************** *** 23,32 **** using System; using System.Data; - using System.Collections; - using QuantProject.ADT.Statistics; - using QuantProject.ADT.Optimizing.Genetic; - using QuantProject.Data; - using QuantProject.Data.DataTables; namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios --- 23,32 ---- using System; using System.Data; + using QuantProject.Business.DataProviders; + using QuantProject.Business.Timing; + using QuantProject.Business.Strategies; + using QuantProject.Business.Strategies.ReturnsManagement; + using QuantProject.Business.Strategies.ReturnsManagement.Time; namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios *************** *** 40,107 **** public class GenomeManagerForEfficientOTCPortfolio : GenomeManagerForEfficientPortfolio { ! ! public GenomeManagerForEfficientOTCPortfolio(DataTable setOfInitialTickers, DateTime firstQuoteDate, DateTime lastQuoteDate, int numberOfTickersInPortfolio, double targetPerformance, ! PortfolioType portfolioType) ! :base(setOfInitialTickers, ! firstQuoteDate, ! lastQuoteDate, ! numberOfTickersInPortfolio, ! targetPerformance, ! portfolioType) { ! this.retrieveData(); ! } ! ! protected override float[] getArrayOfRatesOfReturn(string ticker) ! { ! float[] returnValue = null; ! Quotes tickerQuotes = new Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); ! returnValue = ExtendedDataTable.GetRatesOfReturnsFromColumns(tickerQuotes, "quClose", "quOpen"); ! this.numberOfExaminedReturns = returnValue.Length; ! ! return returnValue; ! } ! /*using LPM ! protected override double getFitnessValue_calculate() ! { ! double returnValue = 0; ! ! double a, b, c; ! a = 0.002; b = 2.0; c = 2.0; ! ! //returnValue = Math.Pow((a/this.Variance),b) * ! // Math.Pow((this.rateOfReturn - this.targetPerformance), ! // c); ! //this.lowerPartialMoment = AdvancedFunctions.LowerPartialMoment(this.portfolioRatesOfReturn, ! // BasicFunctions.SimpleAverage(this.portfolioRatesOfReturn), ! // 3.0); ! this.lowerPartialMoment = AdvancedFunctions.NegativeSemiVariance(this.portfolioRatesOfReturn); ! a = 1.0; ! returnValue = Math.Pow((a/this.lowerPartialMoment),b) * ! Math.Pow(Math.Max(0.0,(this.rateOfReturn - this.targetPerformance)), ! c); ! ! if(this.portfolioType == PortfolioType.OnlyShort) ! returnValue = - returnValue; ! ! if(Double.IsInfinity(returnValue) || Double.IsNaN(returnValue)) ! throw new Exception("Fitness value not computed correctly!"); ! ! return returnValue; } - */ ! protected override double getFitnessValue_calculate() { ! return this.RateOfReturn/Math.Sqrt(this.Variance); } ! } - } --- 40,84 ---- public class GenomeManagerForEfficientOTCPortfolio : GenomeManagerForEfficientPortfolio { ! private ReturnsManager returnsManager; ! public GenomeManagerForEfficientOTCPortfolio(DataTable setOfInitialTickers, DateTime firstQuoteDate, DateTime lastQuoteDate, int numberOfTickersInPortfolio, double targetPerformance, ! PortfolioType portfolioType, ! string benchmark) ! :base(setOfInitialTickers, ! firstQuoteDate, ! lastQuoteDate, ! numberOfTickersInPortfolio, ! targetPerformance, ! portfolioType, ! benchmark) { ! this.setReturnsManager(firstQuoteDate, lastQuoteDate); } ! private void setReturnsManager(DateTime firstQuoteDate, ! DateTime lastQuoteDate) { ! EndOfDayDateTime firstEndOfDayDateTime = ! new EndOfDayDateTime(firstQuoteDate, EndOfDaySpecificTime.MarketOpen); ! EndOfDayDateTime lastEndOfDayDateTime = ! new EndOfDayDateTime(lastQuoteDate, EndOfDaySpecificTime.MarketClose); ! this.returnsManager = ! new ReturnsManager( ! new DailyOpenToCloseIntervals( ! firstEndOfDayDateTime, ! lastEndOfDayDateTime, ! this.benchmark ), ! new HistoricalRawQuoteProvider() ); } ! protected override float[] getStrategyReturns() ! { ! return ! this.weightedPositionsFromGenome.GetReturns(this.returnsManager); ! } } } Index: GenomeManagerForEfficientOTCCTOPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientOTCCTOPortfolio.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** GenomeManagerForEfficientOTCCTOPortfolio.cs 29 Aug 2007 09:56:00 -0000 1.5 --- GenomeManagerForEfficientOTCCTOPortfolio.cs 14 Jan 2008 23:38:36 -0000 1.6 *************** *** 23,31 **** using System; using System.Data; ! using System.Collections; ! using QuantProject.ADT.Statistics; ! using QuantProject.ADT.Optimizing.Genetic; ! using QuantProject.Data; ! using QuantProject.Data.DataTables; --- 23,32 ---- using System; using System.Data; ! ! using QuantProject.Business.DataProviders; ! using QuantProject.Business.Timing; ! using QuantProject.Business.Strategies; ! using QuantProject.Business.Strategies.ReturnsManagement; ! using QuantProject.Business.Strategies.ReturnsManagement.Time; *************** *** 38,44 **** /// </summary> [Serializable] ! public class GenomeManagerForEfficientOTCCTOPortfolio : GenomeManagerForWeightedEfficientPortfolio { ! public GenomeManagerForEfficientOTCCTOPortfolio(DataTable setOfInitialTickers, DateTime firstQuoteDate, --- 39,46 ---- /// </summary> [Serializable] ! public class GenomeManagerForEfficientOTCCTOPortfolio : GenomeManagerForEfficientPortfolio { ! private ReturnsManager returnsManager; ! public GenomeManagerForEfficientOTCCTOPortfolio(DataTable setOfInitialTickers, DateTime firstQuoteDate, *************** *** 46,50 **** int numberOfTickersInPortfolio, double targetPerformance, ! PortfolioType portfolioType) :base(setOfInitialTickers, firstQuoteDate, --- 48,53 ---- int numberOfTickersInPortfolio, double targetPerformance, ! PortfolioType portfolioType, ! string benchmark) :base(setOfInitialTickers, firstQuoteDate, *************** *** 52,95 **** numberOfTickersInPortfolio, targetPerformance, ! portfolioType) { ! this.retrieveData(); ! } ! ! protected override float[] getArrayOfRatesOfReturn(string ticker) ! { ! Quotes tickerQuotes = new Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); ! float[] returnValue = new float[2*tickerQuotes.Rows.Count - 1]; ! int j = 0; ! for(int i = 0;i<tickerQuotes.Rows.Count; i++) ! { ! //open to close ! returnValue[j] = (float)tickerQuotes.Rows[i]["quClose"]/ ! (float)tickerQuotes.Rows[i]["quOpen"] - 1; ! //close to open ! if(i<tickerQuotes.Rows.Count-1) ! { ! returnValue[j+1] = ! -(( (float)tickerQuotes.Rows[i+1]["quOpen"]* ! (float)tickerQuotes.Rows[i+1]["quAdjustedClose"]/ ! (float)tickerQuotes.Rows[i+1]["quClose"] ) ! /(float)tickerQuotes.Rows[i]["quAdjustedClose"] - 1); ! } ! j += 2 ; ! } ! this.numberOfExaminedReturns = returnValue.Length; ! return returnValue; } ! ! ! protected override double getFitnessValue_calculate() { ! return this.RateOfReturn/Math.Sqrt(this.Variance); ! //return AdvancedFunctions.GetExpectancyScore(this.PortfolioRatesOfReturn); } ! ! } - } --- 55,102 ---- numberOfTickersInPortfolio, targetPerformance, ! portfolioType, ! benchmark) { ! this.setReturnsManager(firstQuoteDate, lastQuoteDate); } ! //if the genome manager derives from genome manager without weights, ! //delete override key word ! protected ReturnIntervals getReturnIntervals(EndOfDayDateTime firstEndOfDayDateTime, ! EndOfDayDateTime lastEndOfDayDateTime) ! { ! return ! new OpenToCloseCloseToOpenIntervals( ! firstEndOfDayDateTime, ! lastEndOfDayDateTime, ! this.benchmark); ! } ! ! private void setReturnsManager(DateTime firstQuoteDate, ! DateTime lastQuoteDate) { ! EndOfDayDateTime firstEndOfDayDateTime = ! new EndOfDayDateTime(firstQuoteDate, EndOfDaySpecificTime.MarketOpen); ! EndOfDayDateTime lastEndOfDayDateTime = ! new EndOfDayDateTime(lastQuoteDate, EndOfDaySpecificTime.MarketClose); ! this.returnsManager = ! new ReturnsManager( this.getReturnIntervals(firstEndOfDayDateTime, ! lastEndOfDayDateTime), ! new HistoricalAdjustedQuoteProvider() ); } ! ! protected override float[] getStrategyReturns() ! { ! float[] returnValue; ! returnValue = this.weightedPositionsFromGenome.GetReturns( ! this.returnsManager ) ; ! for(int i = 0; i<returnValue.Length; i++) ! if(i%2 != 0) ! //returnValue[i] is a CloseToOpen return: ! //the strategy implies to reverse positions at night ! returnValue[i] = - returnValue[i]; ! ! return returnValue; ! } } } Index: GenomeManagerForWeightedEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForWeightedEfficientPortfolio.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** GenomeManagerForWeightedEfficientPortfolio.cs 29 Aug 2007 09:54:51 -0000 1.7 --- GenomeManagerForWeightedEfficientPortfolio.cs 14 Jan 2008 23:38:36 -0000 1.8 *************** *** 24,27 **** --- 24,28 ---- using System.Data; using System.Collections; + using QuantProject.ADT; using QuantProject.ADT.Statistics; *************** *** 29,33 **** using QuantProject.Data; using QuantProject.Data.DataTables; ! using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios --- 30,38 ---- 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; namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios *************** *** 38,43 **** /// </summary> [Serializable] ! public class GenomeManagerForWeightedEfficientPortfolio : GenomeManagerForEfficientPortfolio { public GenomeManagerForWeightedEfficientPortfolio(DataTable setOfInitialTickers, DateTime firstQuoteDate, --- 43,50 ---- /// </summary> [Serializable] ! public abstract class GenomeManagerForWeightedEfficientPortfolio : GenomeManagerForEfficientPortfolio { + private ReturnsManager returnsManager; + public GenomeManagerForWeightedEfficientPortfolio(DataTable setOfInitialTickers, DateTime firstQuoteDate, *************** *** 45,54 **** int numberOfTickersInPortfolio, double targetPerformance, ! PortfolioType portfolioType):base(setOfInitialTickers, firstQuoteDate, lastQuoteDate, numberOfTickersInPortfolio, targetPerformance, ! portfolioType) { --- 52,62 ---- int numberOfTickersInPortfolio, double targetPerformance, ! PortfolioType portfolioType, ! string benchmark):base(setOfInitialTickers, firstQuoteDate, lastQuoteDate, numberOfTickersInPortfolio, targetPerformance, ! portfolioType, benchmark) { *************** *** 56,99 **** //at even position the gene is used for finding //the coefficient for the ticker represented at the next odd position ! } ! ! #region override getPortfolioRatesOfReturn ! ! protected override double getTickerWeight(int[] genes, int tickerPositionInGenes) ! { ! double minimumWeight = (1.0 - ConstantsProvider.AmountOfVariableWeightToBeAssignedToTickers)/ ! (genes.Length / 2); ! double totalOfValuesForWeightsInGenes = 0.0; ! for(int j = 0; j<genes.Length; j++) ! { ! if(j%2==0) ! //ticker weight is contained in genes at even position ! totalOfValuesForWeightsInGenes += Math.Abs(genes[j]) + 1.0; ! //0 has to be avoided ! ! } ! double freeWeight = (Math.Abs(genes[tickerPositionInGenes-1]) + 1.0)/totalOfValuesForWeightsInGenes; ! return minimumWeight + freeWeight * (1.0 - minimumWeight * genes.Length / 2); ! } ! ! protected override double[] getPortfolioRatesOfReturn(int[] genes) { ! double[] returnValue = new double[this.numberOfExaminedReturns]; ! for(int i = 0; i<returnValue.Length; i++) ! { ! for(int j = 0; j<genes.Length; j++) ! { ! if(j%2==1) ! //ticker ID is contained in genes at odd position ! returnValue[i] += ! this.getPortfolioRatesOfReturn_getRateOfTickerToBeAddedToTheArray(genes,j,i); ! } ! } ! return returnValue; } ! ! #endregion ! #region override Decode public override object Decode(Genome genome) { --- 64,112 ---- //at even position the gene is used for finding //the coefficient for the ticker represented at the next odd position ! this.setReturnsManager(firstQuoteDate, lastQuoteDate); ! } ! ! protected abstract ReturnIntervals getReturnIntervals(EndOfDayDateTime firstEndOfDayDateTime, ! EndOfDayDateTime lastEndOfDayDateTime); ! ! private void setReturnsManager(DateTime firstQuoteDate, ! DateTime lastQuoteDate) { ! EndOfDayDateTime firstEndOfDayDateTime = ! new EndOfDayDateTime(firstQuoteDate, EndOfDaySpecificTime.MarketOpen); ! EndOfDayDateTime lastEndOfDayDateTime = ! new EndOfDayDateTime(lastQuoteDate, EndOfDaySpecificTime.MarketClose); ! this.returnsManager = ! new ReturnsManager( this.getReturnIntervals(firstEndOfDayDateTime, ! lastEndOfDayDateTime) , ! new HistoricalAdjustedQuoteProvider() ); } ! ! //this is a very generic implementation that will ! //be overriden by inherited classes specifying ! //the strategy and the type of returns ! protected override float[] getStrategyReturns() ! { ! return this.weightedPositionsFromGenome.GetReturns(this.returnsManager); ! } ! #region override Decode + protected override double getTickerWeight(int[] genes, int tickerPositionInGenes) + { + double minimumWeight = (1.0 - ConstantsProvider.AmountOfVariableWeightToBeAssignedToTickers)/ + (genes.Length / 2); + double totalOfValuesForWeightsInGenes = 0.0; + for(int j = 0; j<genes.Length; j++) + { + if(j%2==0) + //ticker weight is contained in genes at even position + totalOfValuesForWeightsInGenes += Math.Abs(genes[j]) + 1.0; + //0 has to be avoided ! + } + double freeWeight = (Math.Abs(genes[tickerPositionInGenes-1]) + 1.0)/totalOfValuesForWeightsInGenes; + return minimumWeight + freeWeight * (1.0 - minimumWeight * genes.Length / 2); + } + public override object Decode(Genome genome) { *************** *** 114,123 **** } GenomeMeaning meaning = new GenomeMeaning(arrayOfTickers, ! arrayOfTickersWeights, ! this.PortfolioRatesOfReturn[this.portfolioRatesOfReturn.Length - 1], ! this.RateOfReturn, ! this.Variance); return meaning; - } #endregion --- 127,132 ---- } GenomeMeaning meaning = new GenomeMeaning(arrayOfTickers, ! arrayOfTickersWeights); return meaning; } #endregion *************** *** 140,144 **** genome.GetMaxValueForGenes(genePosition) + 1); } - return returnValue; } --- 149,152 ---- *************** *** 190,196 **** geneValue + Convert.ToInt32(partOfGeneToSubtractOrAdd*geneValue)); } - return returnValue; - } --- 198,202 ---- *************** *** 245,248 **** } - } --- 251,253 ---- Index: GenomeManagerForEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientPortfolio.cs,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** GenomeManagerForEfficientPortfolio.cs 29 Aug 2007 09:56:00 -0000 1.28 --- GenomeManagerForEfficientPortfolio.cs 14 Jan 2008 23:38:36 -0000 1.29 *************** *** 31,36 **** using QuantProject.Data.DataTables; using QuantProject.Business.Strategies; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; - using QuantProject.Scripts.WalkForwardTesting.WalkForwardLag; namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios --- 31,36 ---- using QuantProject.Data.DataTables; using QuantProject.Business.Strategies; + using QuantProject.Business.Strategies.ReturnsManagement; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios *************** *** 41,122 **** /// </summary> [Serializable] ! public class GenomeManagerForEfficientPortfolio : IGenomeManager { protected int genomeSize; protected int minValueForGenes; protected int maxValueForGenes; ! ! protected DataTable setOfTickers;//used only for keeping ! //the same signature for ! //protected retrieveData() method ! protected CandidateProperties[] setOfCandidates; protected int originalNumOfTickers; protected DateTime firstQuoteDate; protected DateTime lastQuoteDate; protected double targetPerformance; ! protected double variance; ! //protected double lowerPartialMoment; ! protected double rateOfReturn; protected PortfolioType portfolioType; ! protected double[] portfolioRatesOfReturn; ! protected int numberOfExaminedReturns; protected GeneticOptimizer currentGeneticOptimizer; - //IGenomeManager implementation for properties public virtual int GenomeSize { get{return this.genomeSize;} } - public virtual int GetMinValueForGenes(int genePosition) { return this.minValueForGenes; } - public virtual int GetMaxValueForGenes(int genePosition) { return this.maxValueForGenes; } ! //end of implementation for properties ! ! public double Variance { ! get{return this.variance;} } ! ! public double RateOfReturn { ! get{return this.rateOfReturn;} } - public PortfolioType PortfolioType { get{return this.portfolioType;} - //set{this.portfolioType = value;} } ! ! public double[] PortfolioRatesOfReturn { ! get{return this.portfolioRatesOfReturn;} } - public DateTime FirstQuoteDate { get{return this.firstQuoteDate;} } - public DateTime LastQuoteDate { get{return this.lastQuoteDate;} } //setOfInitialTickers has to contain the //ticker's symbol in the first column ! - public GenomeManagerForEfficientPortfolio(DataTable setOfInitialTickers, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate, ! int numberOfTickersInPortfolio, ! double targetPerformance, ! PortfolioType portfolioType) { --- 41,108 ---- /// </summary> [Serializable] ! public abstract class GenomeManagerForEfficientPortfolio : IGenomeManager { protected int genomeSize; protected int minValueForGenes; protected int maxValueForGenes; ! protected DataTable setOfTickers; protected int originalNumOfTickers; protected DateTime firstQuoteDate; protected DateTime lastQuoteDate; protected double targetPerformance; ! protected double varianceOfStrategyReturns; ! protected double averageOfStrategyReturns; protected PortfolioType portfolioType; ! protected string benchmark; ! protected float[] strategyReturns; protected GeneticOptimizer currentGeneticOptimizer; + protected WeightedPositions weightedPositionsFromGenome; public virtual int GenomeSize { get{return this.genomeSize;} } public virtual int GetMinValueForGenes(int genePosition) { return this.minValueForGenes; } public virtual int GetMaxValueForGenes(int genePosition) { return this.maxValueForGenes; } ! public double VarianceOfStrategyReturns { ! get{return this.varianceOfStrategyReturns;} } ! public double AverageOfStrategyReturns { ! get{return this.averageOfStrategyReturns;} } public PortfolioType PortfolioType { get{return this.portfolioType;} } ! public float[] StrategyReturns { ! get{return this.strategyReturns;} } public DateTime FirstQuoteDate { get{return this.firstQuoteDate;} } public DateTime LastQuoteDate { get{return this.lastQuoteDate;} } + //setOfInitialTickers has to contain the //ticker's symbol in the first column ! public GenomeManagerForEfficientPortfolio(DataTable setOfInitialTickers, ! DateTime firstQuoteDate, ! DateTime lastQuoteDate, ! int numberOfTickersInPortfolio, ! double targetPerformance, ! PortfolioType portfolioType, ! string benchmark) { *************** *** 130,133 **** --- 116,120 ---- this.genomeSize = numberOfTickersInPortfolio; this.portfolioType = portfolioType; + this.benchmark = benchmark; this.setMinAndMaxValueForGenes(); GenomeManagement.SetRandomGenerator(QuantProject.ADT.ConstantsProvider.SeedForRandomGenerator); *************** *** 157,240 **** } - //this protected method has to be called by inherited genome - //managers (open to close or close to close) - //only after all initializations provided - //by their respective constructors - protected void retrieveData() - { - this.setOfCandidates = new CandidateProperties[setOfTickers.Rows.Count]; - for(int i = 0; i<setOfTickers.Rows.Count; i++) - { - string ticker = (string)setOfTickers.Rows[i][0]; - this.setOfCandidates[i] = new CandidateProperties(ticker, - this.getArrayOfRatesOfReturn(ticker)); - } - } - - //implementation of IGenomeManager - #region GetFitnessValue protected virtual double getFitnessValue_calculate() { ! double returnValue = 0; ! ! NormalDistribution normal = ! new NormalDistribution(this.rateOfReturn, ! Math.Sqrt(this.variance)); ! if(this.portfolioType == PortfolioType.OnlyLong || ! this.portfolioType == PortfolioType.ShortAndLong) ! //the genome fitness is evaluated as if ! //the portfolio was long ! //returnValue = normal.GetProbability(this.targetPerformance*0.75,this.targetPerformance*1.25); ! returnValue = 1.0 - normal.GetProbability(this.targetPerformance); ! else//only short orders are permitted ! //returnValue = normal.GetProbability(-this.targetPerformance*1.25,-this.targetPerformance*0.75); ! returnValue = normal.GetProbability(-this.targetPerformance); ! /*the following code has to be tested ! if(this.currentGeneticOptimizer.AverageRandomFitness != 0.0 && ! this.currentGeneticOptimizer.StandardDeviationOfRandomFitness != 0.0) ! //the two properties remain equal to 0.0 for the GeneticOptimizer ! //instance created in the Run method: the two properties are updated ! //effectively only for the GO instance calling the Run method ! returnValue = (returnValue - this.CurrentGeneticOptimizer.AverageRandomFitness)/ ! this.CurrentGeneticOptimizer.StandardDeviationOfRandomFitness; ! if(returnValue < 0.0) ! returnValue = 0.0; ! //fitness should be now pure positive number ! */ ! return returnValue; ! } public virtual double GetFitnessValue(Genome genome) { double returnValue = 0; ! this.portfolioRatesOfReturn = this.getPortfolioRatesOfReturn(genome.Genes()); ! double averagePortfolioRateOfReturn = ! BasicFunctions.SimpleAverage(this.portfolioRatesOfReturn); ! ! double portfolioVariance = ! BasicFunctions.Variance(this.portfolioRatesOfReturn); ! if(!Double.IsInfinity(portfolioVariance) && ! !Double.IsInfinity(averagePortfolioRateOfReturn) && ! !Double.IsNaN(portfolioVariance) && ! !Double.IsNaN(averagePortfolioRateOfReturn) && ! portfolioVariance > 0.0) ! //both variance and rate of return are //double values computed in the right way: // so it's possible to assign fitness { - this.variance = portfolioVariance; - this.rateOfReturn = averagePortfolioRateOfReturn; - SignedTickers signedTickers = - new SignedTickers( ((GenomeMeaning)genome.Meaning).Tickers ); - WeightedPositions weightedPositions = - new WeightedPositions( ((GenomeMeaning)genome.Meaning).TickersPortfolioWeights, - signedTickers ); if( this.portfolioType == PortfolioType.OnlyMixed && ! ( weightedPositions.NumberOfLongPositions == 0 || ! weightedPositions.NumberOfShortPositions == 0 ) ) // if both long and short positions have to be taken and // there aren't both long and short positions in portfolio --- 144,186 ---- } #region GetFitnessValue protected virtual double getFitnessValue_calculate() { ! return this.AverageOfStrategyReturns/Math.Sqrt(this.VarianceOfStrategyReturns); } + protected abstract float[] getStrategyReturns(); + + private void setWeightedPositionsFromGenome(Genome genome) + { + GenomeMeaning genomeMeaning = (GenomeMeaning)genome.Meaning; + this.weightedPositionsFromGenome = new WeightedPositions( + genomeMeaning.TickersPortfolioWeights, + new SignedTickers(genomeMeaning.Tickers) ); + } + public virtual double GetFitnessValue(Genome genome) { double returnValue = 0; ! this.setWeightedPositionsFromGenome(genome); ! this.strategyReturns = this.getStrategyReturns(); ! this.averageOfStrategyReturns = ! BasicFunctions.SimpleAverage(this.strategyReturns); ! this.varianceOfStrategyReturns = ! BasicFunctions.Variance(this.strategyReturns); ! if(!Double.IsInfinity(this.VarianceOfStrategyReturns) && ! !Double.IsInfinity(this.AverageOfStrategyReturns) && ! !Double.IsNaN(this.VarianceOfStrategyReturns) && ! !Double.IsNaN(this.AverageOfStrategyReturns) && ! this.VarianceOfStrategyReturns > 0.0) ! //both varianceOfStrate and rate of return are //double values computed in the right way: // so it's possible to assign fitness { if( this.portfolioType == PortfolioType.OnlyMixed && ! ( this.weightedPositionsFromGenome.NumberOfLongPositions == 0 || ! this.weightedPositionsFromGenome.NumberOfShortPositions == 0 ) ) // if both long and short positions have to be taken and // there aren't both long and short positions in portfolio *************** *** 244,278 **** returnValue = this.getFitnessValue_calculate(); } - return returnValue; } ! public virtual double GetFitnessValue(BruteForceOptimizableParameters bruteForceOptimizableParameters) ! { ! double returnValue = 0; ! this.portfolioRatesOfReturn = ! this.getPortfolioRatesOfReturn(bruteForceOptimizableParameters.GetValues()); ! double averagePortfolioRateOfReturn = ! BasicFunctions.SimpleAverage(this.portfolioRatesOfReturn); ! ! double portfolioVariance = ! BasicFunctions.Variance(this.portfolioRatesOfReturn); ! ! if(!Double.IsInfinity(portfolioVariance) && ! !Double.IsInfinity(averagePortfolioRateOfReturn) && ! !Double.IsNaN(portfolioVariance) && ! !Double.IsNaN(averagePortfolioRateOfReturn) && ! portfolioVariance > 0.0) ! //both variance and rate of return are ! //double values computed in the right way: ! // so it's possible to assign fitness ! { ! this.variance = portfolioVariance; ! this.rateOfReturn = averagePortfolioRateOfReturn; ! returnValue = this.getFitnessValue_calculate(); ! } ! ! return returnValue; ! } #endregion --- 190,223 ---- returnValue = this.getFitnessValue_calculate(); } return returnValue; } ! // public virtual double GetFitnessValue(BruteForceOptimizableParameters bruteForceOptimizableParameters) ! // { ! // double returnValue = 0; ! // this.portfolioRatesOfReturn = ! // this.getPortfolioRatesOfReturn(bruteForceOptimizableParameters.GetValues()); ! // double averagePortfolioRateOfReturn = ! // BasicFunctions.SimpleAverage(this.portfolioRatesOfReturn); ! // ! // double portfolioVariance = ! // BasicFunctions.Variance(this.portfolioRatesOfReturn); ! // ! // if(!Double.IsInfinity(portfolioVariance) && ! // !Double.IsInfinity(averagePortfolioRateOfReturn) && ! // !Double.IsNaN(portfolioVariance) && ! // !Double.IsNaN(averagePortfolioRateOfReturn) && ! // portfolioVariance > 0.0) ! // //both variance and rate of return are ! // //double values computed in the right way: ! // // so it's possible to assign fitness ! // { ! // this.variance = portfolioVariance; ! // this.rateOfReturn = averagePortfolioRateOfReturn; ! // returnValue = this.getFitnessValue_calculate(); ! // } ! // ! // return returnValue; ! // } #endregion *************** *** 289,300 **** // the others already stored in the given genome int returnValue = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePosition), ! genome.GetMaxValueForGenes(genePosition) + 1); while( GenomeManipulator.IsTickerContainedInGenome(returnValue,genome) ) //the portfolio can't have a long position and a short one for the same ticker { returnValue = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePosition), ! genome.GetMaxValueForGenes(genePosition) + 1); } - return returnValue; } --- 234,244 ---- // the others already stored in the given genome int returnValue = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePosition), ! genome.GetMaxValueForGenes(genePosition) + 1); while( GenomeManipulator.IsTickerContainedInGenome(returnValue,genome) ) //the portfolio can't have a long position and a short one for the same ticker { returnValue = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePosition), ! genome.GetMaxValueForGenes(genePosition) + 1); } return returnValue; } *************** *** 306,316 **** int genePositionToBeMutated = GenomeManagement.RandomGenerator.Next(genome.Size); int newValueForGene = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePositionToBeMutated), ! genome.GetMaxValueForGenes(genePositionToBeMutated) + 1); ! ! while( GenomeManipulator.IsTickerContainedInGenome(newValueForGene,genome) ) //the portfolio can't have a long position and a short one for the same ticker { newValueForGene = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePositionToBeMutated), ! genome.GetMaxValueForGenes(genePositionToBeMutated) + 1); } GenomeManagement.MutateOneGene(genome, genePositionToBeMutated, newValueForGene); --- 250,259 ---- int genePositionToBeMutated = GenomeManagement.RandomGenerator.Next(genome.Size); int newValueForGene = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePositionToBeMutated), ! genome.GetMaxValueForGenes(genePositionToBeMutated) + 1); ! while( GenomeManipulator.IsTickerContainedInGenome(newValueForGene,genome) ) //the portfolio can't have a long position and a short one for the same ticker { newValueForGene = GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePositionToBeMutated), ! genome.GetMaxValueForGenes(genePositionToBeMutated) + 1); } GenomeManagement.MutateOneGene(genome, genePositionToBeMutated, newValueForGene); *************** *** 319,323 **** #region Decode ! protected string decode_getTickerCodeForLongOrShortTrade(int geneValue) { string initialCharForTickerCode = ""; --- 262,266 ---- #region Decode ! protected virtual string decode_getTickerCodeForLongOrShortTrade(int geneValue) { string initialCharForTickerCode = ""; *************** *** 328,332 **** initialCharForTickerCode = "-"; } ! return initialCharForTickerCode + this.setOfCandidates[position].Ticker; } --- 271,275 ---- initialCharForTickerCode = "-"; } ! return initialCharForTickerCode + (string)setOfTickers.Rows[position][0]; } *************** *** 347,351 **** public virtual object Decode(Genome genome) { - string[] arrayOfTickers = new string[genome.Genes().Length]; int indexOfTicker; --- 290,293 ---- *************** *** 355,369 **** arrayOfTickers[index] = this.decode_getTickerCodeForLongOrShortTrade(indexOfTicker); } ! GenomeMeaning meaning = new GenomeMeaning(arrayOfTickers, ! this.PortfolioRatesOfReturn[this.portfolioRatesOfReturn.Length - 1], ! this.RateOfReturn, ! this.Variance); return meaning; - } #endregion - // end of implementation of IGenomeManager - #region old implementation for variance computation /* --- 297,305 ---- arrayOfTickers[index] = this.decode_getTickerCodeForLongOrShortTrade(indexOfTicker); } ! GenomeMeaning meaning = new GenomeMeaning(arrayOfTickers); return meaning; } #endregion #region old implementation for variance computation /* *************** *** 412,427 **** #endregion - - //this protected method must be overriden by inherited classes - //specifing the type of rates of return that have to - //be analyzed - protected virtual float[] getArrayOfRatesOfReturn(string ticker) - { - float[] returnValue = null; - this.numberOfExaminedReturns = returnValue.Length; - return returnValue; - - } - protected virtual double getTickerWeight(int[] genes, int tickerPositionInGenes) { --- 348,351 ---- *************** *** 429,473 **** //weights for tickers are all the same in this implementation } - - #region getPortfolioRatesOfReturn - - protected int getPortfolioRatesOfReturn_getRateOfTickerToBeAddedToTheArray_getPositionInSetOfCandidates(int geneValueForTickerIdx) - { - int position = geneValueForTickerIdx; - if(geneValueForTickerIdx < 0) - position = Math.Abs(geneValueForTickerIdx) - 1; - return position; - } - - protected float getPortfolioRatesOfReturn_getRateOfTickerToBeAddedToTheArray(int[] genes, - int tickerPositionInGenes, - int arrayElementPosition) - { - bool longReturns = false; - if(genes[tickerPositionInGenes] >= 0) - //genes[tickerPositionInGenes], the code for ticker, points to a ticker for which long returns are to be examined - longReturns = true; - int position = this.getPortfolioRatesOfReturn_getRateOfTickerToBeAddedToTheArray_getPositionInSetOfCandidates(genes[tickerPositionInGenes]); - this.setOfCandidates[position].LongRatesOfReturn = longReturns; - float[] arrayOfRatesOfReturn = this.setOfCandidates[position].ArrayOfRatesOfReturn; - double tickerWeight = this.getTickerWeight(genes,tickerPositionInGenes); - return (arrayOfRatesOfReturn[arrayElementPosition]*(float)tickerWeight); - } - - protected virtual double[] getPortfolioRatesOfReturn(int[] genes) - { - double[] returnValue = new double[this.numberOfExaminedReturns]; - for(int i = 0; i<returnValue.Length; i++) - { - for(int j=0; j<genes.Length; j++) - returnValue[i] += - this.getPortfolioRatesOfReturn_getRateOfTickerToBeAddedToTheArray(genes,j,i); - } - return returnValue; - } - - #endregion - } - } --- 353,356 ---- |