[Quantproject-developers] QuantProject/b7_Scripts/TickerSelectionTesting/DrivenBySharpeRatio Drive
Brought to you by:
glauco_1
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/DrivenBySharpeRatio
In directory vz-cvs-3.sog:/tmp/cvs-serv21636/TickerSelectionTesting/DrivenBySharpeRatio
Modified Files:
DrivenBySharpeRatioLogItem.cs DrivenBySharpeRatioMain.cs
DrivenBySharpeRatioStrategy.cs
Log Message:
Updated script files
Index: DrivenBySharpeRatioStrategy.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/DrivenBySharpeRatio/DrivenBySharpeRatioStrategy.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** DrivenBySharpeRatioStrategy.cs 16 Jan 2011 19:37:08 -0000 1.1
--- DrivenBySharpeRatioStrategy.cs 21 Aug 2011 14:22:07 -0000 1.2
***************
*** 47,50 ****
--- 47,52 ----
using QuantProject.Business.Strategies.Eligibles;
using QuantProject.Business.Strategies.Optimizing.Decoding;
+ using QuantProject.Business.Strategies.Optimizing.FitnessEvaluation;
+ using QuantProject.Business.Strategies.Optimizing.GenomeManagers;
using QuantProject.Data;
using QuantProject.Data.DataProviders;
***************
*** 52,59 ****
using QuantProject.Data.DataTables;
using QuantProject.ADT.Optimizing.Genetic;
! using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.InSampleChoosers;
! using QuantProject.Scripts.TickerSelectionTesting.OTC;
using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios;
- using QuantProject.Scripts.WalkForwardTesting.LinearCombination;
namespace QuantProject.Scripts.TickerSelectionTesting.DrivenBySharpeRatio
--- 54,59 ----
using QuantProject.Data.DataTables;
using QuantProject.ADT.Optimizing.Genetic;
! using QuantProject.Scripts.TickerSelectionTesting.DrivenBySharpeRatio.InSampleChoosers.Genetic;
using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios;
namespace QuantProject.Scripts.TickerSelectionTesting.DrivenBySharpeRatio
***************
*** 103,106 ****
--- 103,111 ----
protected double stopLoss;
protected double takeProfit;
+ protected string hedgingTicker;
+ protected double hedgingTickerWeight;
+ protected int popSizeForGeneticHedgingOptimization;
+ protected int genNumForGeneticHedgingOptimization;
+ protected IFitnessEvaluator fitnessEvaluatorForGeneticHedgingOptimization;
private string description_GetDescriptionForChooser()
***************
*** 155,164 ****
int minNumOfEligiblesForValidOptimization, IInSampleChooser inSampleChooser ,
int inSamplePeriodLengthInDays ,
! Benchmark benchmark , int numDaysBetweenEachOptimization ,
HistoricalMarketValueProvider historicalMarketValueProviderForInSample ,
HistoricalMarketValueProvider historicalMarketValueProviderForOutOfSample ,
PortfolioType portfolioType, double stopLoss,
double takeProfit)
{
this.drivenBySharpeRatioStrategy_commonInitialization(eligiblesSelector ,
minNumOfEligiblesForValidOptimization, inSampleChooser ,
--- 160,177 ----
int minNumOfEligiblesForValidOptimization, IInSampleChooser inSampleChooser ,
int inSamplePeriodLengthInDays ,
! Benchmark benchmark , string hedgingTicker , double hedgingTickerWeight,
! int numDaysBetweenEachOptimization ,
HistoricalMarketValueProvider historicalMarketValueProviderForInSample ,
HistoricalMarketValueProvider historicalMarketValueProviderForOutOfSample ,
+ int popSizeForGeneticHedgingOptimization, int genNumForGeneticHedgingOptimization,
+ IFitnessEvaluator fitnessEvaluatorForGeneticHedgingOptimization,
PortfolioType portfolioType, double stopLoss,
double takeProfit)
{
+ this.hedgingTicker = hedgingTicker;
+ this.hedgingTickerWeight = hedgingTickerWeight;
+ this.popSizeForGeneticHedgingOptimization = popSizeForGeneticHedgingOptimization;
+ this.genNumForGeneticHedgingOptimization = genNumForGeneticHedgingOptimization;
+ this.fitnessEvaluatorForGeneticHedgingOptimization = fitnessEvaluatorForGeneticHedgingOptimization;
this.drivenBySharpeRatioStrategy_commonInitialization(eligiblesSelector ,
minNumOfEligiblesForValidOptimization, inSampleChooser ,
***************
*** 215,223 ****
{
DateTime currentDateTime = this.now();
! if( allTickersAreExchanged( currentDateTime, AccountManager.GetTickersInOpenedPositions(this.account) ) )
! {
! AccountManager.ClosePositions( this.account );
! this.lastEntryTime = new DateTime(1900,1,1);
! }
}
#endregion newDateTimeEventHandler_closePositions
--- 228,236 ----
{
DateTime currentDateTime = this.now();
! // if( allTickersAreExchanged( currentDateTime, AccountManager.GetTickersInOpenedPositions(this.account) ) )
! // {
! AccountManager.ClosePositions( this.account );
! this.lastEntryTime = new DateTime(1900,1,1);
! // }
}
#endregion newDateTimeEventHandler_closePositions
***************
*** 321,325 ****
#region UpdateTestingPositions
!
protected void updateTestingPositions(DateTime currentDateTime)
{
--- 334,408 ----
#region UpdateTestingPositions
!
! #region updateTestingPositions_getPositionsHedgedOrNot
! protected EligibleTickers updateTestingPositions_getPositionsHedgedOrNot_getHedgedPositions_getEligibles(TestingPositions[] positionsToHedge)
! {
! EligibleTickers returnValue;
! ICollection<string> tickersNotHedged = new List<string>();
! foreach(WeightedPosition weightedPosition in positionsToHedge[0].WeightedPositions)
! tickersNotHedged.Add(weightedPosition.Ticker);
! returnValue = new EligibleTickers(tickersNotHedged);
! returnValue.AddAdditionalTicker(this.hedgingTicker);
!
! return returnValue;
! }
! protected IInSampleChooser updateTestingPositions_getPositionsHedgedOrNot_getChooserForHedgedPositions(int numOfPositionsToHedge)
! {
! IInSampleChooser returnValue;
! IDecoderForTestingPositions decoderWithWeights =
! new BasicDecoderForTestingPositionsWithWeights();
! returnValue =
! new DrivenBySharpeRatioInSampleChooserWithWeights(numOfPositionsToHedge + 1, 10 ,
! this.benchmark, decoderWithWeights, GenomeManagerType.OnlyLong, this.fitnessEvaluatorForGeneticHedgingOptimization,
! this.historicalMarketValueProviderForInSample, 0.90, 0.10, 0.001,
! this.popSizeForGeneticHedgingOptimization,
! this.genNumForGeneticHedgingOptimization, 30, false, 0.9);
!
! return returnValue;
! }
! private void updateTestingPositions_getPositionsHedgedOrNot_getHedgedPositions_setWeights(TestingPositions[] returnValue)
! {
! int numOfPositions = returnValue[0].WeightedPositions.Count;
! for(int i = 0; i < numOfPositions; i++)
! {
! if( returnValue[0].WeightedPositions[i].Ticker == this.hedgingTicker )
! returnValue[0].WeightedPositions[i].Weight = this.hedgingTickerWeight;
! else
! returnValue[0].WeightedPositions[i].Weight =
! (1.0-this.hedgingTickerWeight)/(numOfPositions - 1);
! }
! }
!
! protected TestingPositions[] updateTestingPositions_getPositionsHedgedOrNot_getHedgedPositions()
! {
! TestingPositions[] returnValue;
! TestingPositions[] positionsNotHedged =
! (TestingPositions[])inSampleChooser.AnalyzeInSample(this.currentEligibles, this.returnsManager);
! EligibleTickers chosenTickersWithHedgingTicker =
! this.updateTestingPositions_getPositionsHedgedOrNot_getHedgedPositions_getEligibles(positionsNotHedged);
! //set new insample chooser, with a decoder with weights
! IInSampleChooser chooserForHedgedPositions =
! this.updateTestingPositions_getPositionsHedgedOrNot_getChooserForHedgedPositions(positionsNotHedged[0].WeightedPositions.Count);
! returnValue =
! (TestingPositions[])chooserForHedgedPositions.AnalyzeInSample(chosenTickersWithHedgingTicker, this.returnsManager);
! //hedgingTickerWeight is directly determined
! // the other positions are given their weight consequently
! if(this.hedgingTickerWeight != 0.0)
! this.updateTestingPositions_getPositionsHedgedOrNot_getHedgedPositions_setWeights(returnValue);
! return returnValue;
! }
!
! protected TestingPositions[] updateTestingPositions_getPositionsHedgedOrNot()
! {
! TestingPositions[] returnValue;
! if(this.hedgingTicker == null)
! returnValue = (TestingPositions[])inSampleChooser.AnalyzeInSample(this.currentEligibles, this.returnsManager);
! else
! returnValue = this.updateTestingPositions_getPositionsHedgedOrNot_getHedgedPositions();
!
! return returnValue;
! }
! #endregion updateTestingPositions_getPositionsHedgedOrNot
!
protected void updateTestingPositions(DateTime currentDateTime)
{
***************
*** 342,346 ****
this.inSampleChooser != null ) )
{
! this.chosenPositions = (TestingPositions[])inSampleChooser.AnalyzeInSample(this.currentEligibles, this.returnsManager);
this.logOptimizationInfo(this.currentEligibles);
}
--- 425,429 ----
this.inSampleChooser != null ) )
{
! this.chosenPositions = this.updateTestingPositions_getPositionsHedgedOrNot();
this.logOptimizationInfo(this.currentEligibles);
}
***************
*** 395,399 ****
DrivenBySharpeRatioLogItem logItem =
new DrivenBySharpeRatioLogItem( this.now(),
! this.inSamplePeriodLengthInDays);
logItem.BestPositionsInSample =
this.chosenPositions;
--- 478,484 ----
DrivenBySharpeRatioLogItem logItem =
new DrivenBySharpeRatioLogItem( this.now(),
! this.inSamplePeriodLengthInDays,
! this.benchmark,
! this.historicalMarketValueProviderForInSample);
logItem.BestPositionsInSample =
this.chosenPositions;
Index: DrivenBySharpeRatioMain.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/DrivenBySharpeRatio/DrivenBySharpeRatioMain.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** DrivenBySharpeRatioMain.cs 16 Jan 2011 19:37:08 -0000 1.1
--- DrivenBySharpeRatioMain.cs 21 Aug 2011 14:22:07 -0000 1.2
***************
*** 31,34 ****
--- 31,35 ----
using QuantProject.ADT.Timing;
using QuantProject.Business.DataProviders;
+ using QuantProject.Business.DataProviders.VirtualQuotesProviding;
//using QuantProject.Data.DataProviders.Bars.Caching;
using QuantProject.Business.Strategies;
***************
*** 53,56 ****
--- 54,58 ----
using QuantProject.Scripts.General.Strategies.Optimizing.FitnessEvaluation;
using QuantProject.Scripts.TickerSelectionTesting.DrivenBySharpeRatio.InSampleChoosers.Genetic;
+ using QuantProject.Scripts.TickerSelectionTesting.DrivenBySharpeRatio.InSampleChoosers.BruteForce;
using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios;
//using QuantProject.Scripts.TickerSelectionTesting.OTC.InSampleChoosers.Genetic;
***************
*** 75,78 ****
--- 77,81 ----
private DateTime firstDateTime;
private DateTime lastDateTime;
+ private int numDaysBetweenEachOptimization;
private HistoricalMarketValueProvider historicalMarketValueProviderForInSample;
private HistoricalMarketValueProvider historicalMarketValueProviderForOutOfSample;
***************
*** 80,99 ****
private Timer timerForBackTester;
private GenomeManagerType genomeManagerType;
#region main
public DrivenBySharpeRatioMain()
{
! this.numberOfPortfolioPositions = 4;
! this.benchmark = new Benchmark( "^MIBTEL" );
! // this.benchmark = new Benchmark( "^GSPC" );
! this.portfolioType = PortfolioType.OnlyLong;//filter for out of sample
! this.genomeManagerType = GenomeManagerType.OnlyLong;//filter for the genetic chooser
// this.benchmark = new Benchmark( "ENI.MI" );
! this.firstDateTime = new DateTime( 2001 , 1 , 1 );
! this.lastDateTime = new DateTime( 2005 , 12 , 31 );
this.historicalMarketValueProviderForInSample =
// new HistoricalRawQuoteProvider();
new HistoricalAdjustedQuoteProvider();
this.historicalMarketValueProviderForOutOfSample =
this.historicalMarketValueProviderForInSample;
--- 83,120 ----
private Timer timerForBackTester;
private GenomeManagerType genomeManagerType;
+ private string hedgingTicker;
#region main
public DrivenBySharpeRatioMain()
{
! this.numberOfPortfolioPositions = 6;
! // this.benchmark = new Benchmark( "FTSEMIB.MI" );
! this.benchmark = new Benchmark( "^GSPC" );
! // this.hedgingTicker = "SH(FTSEMIB)";
! this.hedgingTicker = null;
! this.portfolioType = PortfolioType.ShortAndLong;//filter for out of sample
! this.genomeManagerType = GenomeManagerType.ShortAndLong;//filter for the genetic chooser
// this.benchmark = new Benchmark( "ENI.MI" );
! this.firstDateTime = new DateTime( 2003 , 1 , 1 );
! this.lastDateTime = new DateTime( 2009 , 12 , 31 );
! this.numDaysBetweenEachOptimization = 180;
+ HistoricalAdjustedQuoteProvider historicalAdjustedQuoteProvider =
+ new HistoricalAdjustedQuoteProvider();
+ List<DerivedVirtualTicker> virtualTickerList =
+ new List<DerivedVirtualTicker>();
+ DerivedVirtualTicker virtualTicker1 =
+ new DerivedVirtualTicker(this.hedgingTicker, this.benchmark.Ticker, 100);
+ virtualTickerList.Add(virtualTicker1);
+ ShortVirtualQuoteProvider shortVirtualQuoteProvider =
+ // new ShortVirtualQuoteProvider(virtualTickerList, historicalAdjustedQuoteProvider,
+ // 2 * this.numDaysBetweenEachOptimization);
+ new ShortVirtualQuoteProvider(virtualTickerList, historicalAdjustedQuoteProvider,
+ new DateTime(2003,6,1,16,0,0) );
this.historicalMarketValueProviderForInSample =
// new HistoricalRawQuoteProvider();
new HistoricalAdjustedQuoteProvider();
+ // new VirtualAndHistoricalAdjustedQuoteProvider(shortVirtualQuoteProvider);
+
this.historicalMarketValueProviderForOutOfSample =
this.historicalMarketValueProviderForInSample;
***************
*** 117,134 ****
protected override IEligiblesSelector getEligiblesSelector()
{
! this.maxNumberOfEligiblesToBeChosen = 200;
! // string tickersGroupId = "ticUSFin";
// string tickersGroupId = "USFunds";
// string tickersGroupId = "SP500";
! string tickersGroupId = "STOCKMI";
bool temporizedGroup = false;//Attenzione!
IEligiblesSelector eligiblesSelector =
// new ByGroup( tickersGroupId , temporizedGroup);
! new ByLiquidity ( tickersGroupId , temporizedGroup ,
! maxNumberOfEligiblesToBeChosen);
! // eligiblesSelector =
// new DummyEligibleSelector();
//
--- 138,199 ----
protected override IEligiblesSelector getEligiblesSelector()
{
! this.maxNumberOfEligiblesToBeChosen = 1000;
! string tickersGroupId = "ticUSFin";
// string tickersGroupId = "USFunds";
// string tickersGroupId = "SP500";
! // string tickersGroupId = "BLUECHIX";
! // string tickersGroupId = "ETFMI";
bool temporizedGroup = false;//Attenzione!
+ // by most discounted prices parameters
+ int numDaysForFundamentalDataAvailability = 60;
+ // int numDaysForFundamentalAnalysis = 365;
+ // double optimalDebtEquityRatioLevel = 0.1;
+ // int maxNumOfGrowthRatesToTakeIntoAccount = 4;
+ IGrowthRateProvider growthProvider =
+ // new AverageAndDebtAdjustedGrowthRateProvider(numDaysForFundamentalDataAvailability,
+ // maxNumOfGrowthRatesToTakeIntoAccount,
+ // optimalDebtEquityRatioLevel);
+ new LastAvailableGrowthRateProvider(numDaysForFundamentalDataAvailability);
+
+ IRatioProvider_PE PEProvider =
+ new LastAvailablePEProvider(this.historicalMarketValueProviderForInSample,
+ numDaysForFundamentalDataAvailability);
+ double fairPEGRatioLevel = 1.0;
+ IFairValueProvider fairValueProvider =
+ new PEGRatioFairValueProvider(fairPEGRatioLevel,PEProvider,
+ growthProvider,this.historicalMarketValueProviderForInSample);
+ // double minimumIncome = 1000000;
+ // int numOfMinIncomeInARow = 2;
+ // double minimumRelativeDifferenceBetweenFairAndAverageMarketPrice = 0.05;
+ // int numDaysForAveragePriceComputation = 90;
+
+ //end of by most discounted prices parameters
IEligiblesSelector eligiblesSelector =
// new ByGroup( tickersGroupId , temporizedGroup);
! // new ByLiquidity ( tickersGroupId , temporizedGroup ,
! // maxNumberOfEligiblesToBeChosen);
!
! new ByPriceMostLiquidAlwaysQuoted(tickersGroupId,
! temporizedGroup, maxNumberOfEligiblesToBeChosen,
! 6, 1.0, 5000.0);
!
! // new ByPriceLiquidityLowestPEQuotedAtAGivenPercentage(
! // tickersGroupId , temporizedGroup ,
! // maxNumberOfEligiblesToBeChosen ,
! // maxNumberOfEligiblesToBeChosen * 2,
! // numDaysForAveragePriceComputation,
! // 1, 1000, 10, 50, 0.9);
! // new ByMostDiscountedPrices( fairValueProvider ,
! // tickersGroupId , temporizedGroup ,
! // maxNumberOfEligiblesToBeChosen , numDaysForFundamentalAnalysis,
! // numDaysForFundamentalDataAvailability,
! // minimumIncome, numOfMinIncomeInARow,
! // minimumRelativeDifferenceBetweenFairAndAverageMarketPrice,
! // numDaysForAveragePriceComputation);
!
! // eligiblesSelector =
// new DummyEligibleSelector();
//
***************
*** 140,152 ****
protected override IInSampleChooser getInSampleChooser()
{
! int numberOfBestTestingPositionsToBeReturned = 5;
// parameters for the genetic optimizer
! double crossoverRate = 0.85;
! double mutationRate = 0.02;
! double elitismRate = 0.001;
! int populationSizeForGeneticOptimizer = 25000;
! int generationNumberForGeneticOptimizer = 25;
int seedForRandomGenerator =
QuantProject.ADT.ConstantsProvider.SeedForRandomGenerator;
BuyAndHoldFitnessEvaluator fitnessEvaluator =
--- 205,219 ----
protected override IInSampleChooser getInSampleChooser()
{
! int numberOfBestTestingPositionsToBeReturned = 10;
// parameters for the genetic optimizer
! double crossoverRate = 0.99;
! double mutationRate = 0.1;
! double elitismRate = 0.0;
! int populationSizeForGeneticOptimizer = 20000;
! int generationNumberForGeneticOptimizer = 35;
int seedForRandomGenerator =
QuantProject.ADT.ConstantsProvider.SeedForRandomGenerator;
+ bool keepOnRunningUntilConvergence = false;
+ double minConvergenceRate = 0.50;
BuyAndHoldFitnessEvaluator fitnessEvaluator =
***************
*** 163,167 ****
crossoverRate, mutationRate, elitismRate ,
populationSizeForGeneticOptimizer, generationNumberForGeneticOptimizer,
! seedForRandomGenerator);
return inSampleChooser;
--- 230,239 ----
crossoverRate, mutationRate, elitismRate ,
populationSizeForGeneticOptimizer, generationNumberForGeneticOptimizer,
! seedForRandomGenerator, keepOnRunningUntilConvergence,
! minConvergenceRate);
! // new DrivenBySharpeRatioBruteForceChooser(PortfolioType.OnlyLong,
! // this.numberOfPortfolioPositions, numberOfBestTestingPositionsToBeReturned,
! // this.benchmark, basicGenOptDecoder, fitnessEvaluator,
! // this.historicalMarketValueProviderForInSample);
return inSampleChooser;
***************
*** 172,177 ****
protected override IStrategyForBacktester getStrategyForBacktester()
{
! int numDaysBetweenEachOptimization = 60;
! int minNumOfEligiblesForValidOptimization = 15;
IStrategyForBacktester strategyForBacktester
--- 244,255 ----
protected override IStrategyForBacktester getStrategyForBacktester()
{
! // ConstantsProvider.AmountOfVariableWeightToBeAssignedToTickers = 0.5;
! int minNumOfEligiblesForValidOptimization = 10;
! int popSizeForGeneticHedgingOptimization = 10;
! int genNumForGeneticHedgingOptimization = 1;
! double weightForHedgingTicker = 0.40; //set 0.0 if you want
! //this weight be set by the genetic optimizer
! IFitnessEvaluator fitnessEvaluatorForGeneticHedgingOptimization =
! new BuyAndHoldFitnessEvaluator( new SharpeRatio() );
IStrategyForBacktester strategyForBacktester
***************
*** 179,185 ****
minNumOfEligiblesForValidOptimization, inSampleChooser ,
numDaysForInSample ,
! benchmark , numDaysBetweenEachOptimization ,
historicalMarketValueProviderForInSample ,
historicalMarketValueProviderForOutOfSample ,
this.portfolioType, this.stopLoss,
this.takeProfit);
--- 257,266 ----
minNumOfEligiblesForValidOptimization, inSampleChooser ,
numDaysForInSample ,
! benchmark , this.hedgingTicker, weightForHedgingTicker, numDaysBetweenEachOptimization ,
historicalMarketValueProviderForInSample ,
historicalMarketValueProviderForOutOfSample ,
+ popSizeForGeneticHedgingOptimization,
+ genNumForGeneticHedgingOptimization,
+ fitnessEvaluatorForGeneticHedgingOptimization,
this.portfolioType, this.stopLoss,
this.takeProfit);
Index: DrivenBySharpeRatioLogItem.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/DrivenBySharpeRatio/DrivenBySharpeRatioLogItem.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** DrivenBySharpeRatioLogItem.cs 16 Jan 2011 19:37:08 -0000 1.1
--- DrivenBySharpeRatioLogItem.cs 21 Aug 2011 14:22:07 -0000 1.2
***************
*** 52,57 ****
public class DrivenBySharpeRatioLogItem : LogItem
{
! protected DummyTesterForTestingPositions[]
! dummyTestersForBestTestingPositionsInSample;
protected TestingPositions[] bestPositionsInSample;
protected int numberOfEligibleTickers;
--- 52,57 ----
public class DrivenBySharpeRatioLogItem : LogItem
{
! protected BuyAndHoldTesterForTestingPositions[]
! buyAndHoldTestersForBestTestingPositionsInSample;
protected TestingPositions[] bestPositionsInSample;
protected int numberOfEligibleTickers;
***************
*** 60,63 ****
--- 60,65 ----
protected string tickers;
protected int inSamplePeriodLengthInDays;
+ protected Benchmark benchmark;
+ protected HistoricalMarketValueProvider historicalMarketValueProvider;
public TestingPositions[] BestPositionsInSample
***************
*** 108,112 ****
}
public DrivenBySharpeRatioLogItem(DateTime dateTime,
! int inSamplePeriodLengthInDays)
: base( dateTime )
{
--- 110,116 ----
}
public DrivenBySharpeRatioLogItem(DateTime dateTime,
! int inSamplePeriodLengthInDays,
! Benchmark benchmark,
! HistoricalMarketValueProvider historicalMarketValueProvider)
: base( dateTime )
{
***************
*** 114,129 ****
this.numberOfEligibleTickers = int.MinValue;
this.fitness = double.MinValue;
}
! #region runStrategyClickEventHandler
! protected virtual void runStrategyClickEventHandler(object sender, System.EventArgs e)
{
! // ;
! //general
DateTime firstDateTime = this.SimulatedCreationDateTime.AddDays(-this.inSamplePeriodLengthInDays);
DateTime lastDateTime = this.SimulatedCreationDateTime;
double maxRunningHours = 1;
- Benchmark benchmark = new Benchmark( "^GSPC" );
int numberOfPortfolioPositions = this.bestPositionsInSample[0].WeightedPositions.Count;
//cash and portfolio type
--- 118,218 ----
this.numberOfEligibleTickers = int.MinValue;
this.fitness = double.MinValue;
+ this.benchmark = benchmark;
+ this.historicalMarketValueProvider = historicalMarketValueProvider;
}
! #region runStrategyClickEventHandlerOnlyInSample
! protected virtual void runStrategyClickEventHandlerOnlyInSample(object sender, System.EventArgs e)
{
! DateTime firstDateTime = this.SimulatedCreationDateTime.AddDays(-this.inSamplePeriodLengthInDays);
! DateTime lastDateTime = this.SimulatedCreationDateTime;
! double maxRunningHours = 1;
! int numberOfPortfolioPositions = this.bestPositionsInSample[0].WeightedPositions.Count;
! //cash and portfolio type
! double cashToStart = 10000;
! HistoricalMarketValueProvider historicalQuoteProviderForBackTester,
! historicalQuoteProviderForInSampleChooser,
! historicalQuoteProviderForStrategy;
! historicalQuoteProviderForBackTester = this.historicalMarketValueProvider;
! historicalQuoteProviderForInSampleChooser = historicalQuoteProviderForBackTester;
! historicalQuoteProviderForStrategy = historicalQuoteProviderForInSampleChooser;
! //strategyParameters
! TestingPositions[] positionsToTest = this.BestPositionsInSample;
! DrivenBySharpeRatioStrategy strategy =
! new DrivenBySharpeRatioStrategy(positionsToTest,
! this.inSamplePeriodLengthInDays, this.benchmark,
! historicalQuoteProviderForBackTester,
! PortfolioType.OnlyLong);
!
! QuantProject.Business.Timing.Timer timer =
! new IndexBasedEndOfDayTimer( firstDateTime,
! lastDateTime,
! this.benchmark.Ticker);
!
! EndOfDayStrategyBackTester endOfDayStrategyBackTester =
! new EndOfDayStrategyBackTester(
! "BuyAndHold" , timer , strategy,
! historicalQuoteProviderForBackTester ,
! new SimpleAccountProvider(), firstDateTime ,
! lastDateTime ,
! this.benchmark , cashToStart , maxRunningHours );
!
! endOfDayStrategyBackTester.Run();
! BackTesterReportViewer.ShowReport( lastDateTime ,
! endOfDayStrategyBackTester );
! }
! #endregion runStrategyClickEventHandlerOnlyInSample
!
! #region runStrategyClickEventHandlerOnlyOutOfSample
! protected virtual void runStrategyClickEventHandlerOnlyOutOfSample(object sender, System.EventArgs e)
! {
! DateTime firstDateTime = this.SimulatedCreationDateTime;
! DateTime lastDateTime = this.SimulatedCreationDateTime.AddDays(this.inSamplePeriodLengthInDays);
! double maxRunningHours = 1;
! int numberOfPortfolioPositions = this.bestPositionsInSample[0].WeightedPositions.Count;
! //cash and portfolio type
! double cashToStart = 10000;
! HistoricalMarketValueProvider historicalQuoteProviderForBackTester,
! historicalQuoteProviderForInSampleChooser,
! historicalQuoteProviderForStrategy;
! historicalQuoteProviderForBackTester = this.historicalMarketValueProvider;
! historicalQuoteProviderForInSampleChooser = historicalQuoteProviderForBackTester;
! historicalQuoteProviderForStrategy = historicalQuoteProviderForInSampleChooser;
! //strategyParameters
! TestingPositions[] positionsToTest = this.BestPositionsInSample;
!
! DrivenBySharpeRatioStrategy strategy =
! new DrivenBySharpeRatioStrategy(positionsToTest,
! this.inSamplePeriodLengthInDays, this.benchmark,
! historicalQuoteProviderForBackTester,
! PortfolioType.OnlyLong);
!
! QuantProject.Business.Timing.Timer timer =
! new IndexBasedEndOfDayTimer( firstDateTime,
! lastDateTime,
! this.benchmark.Ticker);
!
! EndOfDayStrategyBackTester endOfDayStrategyBackTester =
! new EndOfDayStrategyBackTester(
! "BuyAndHold" , timer , strategy,
! historicalQuoteProviderForBackTester ,
! new SimpleAccountProvider(), firstDateTime ,
! lastDateTime ,
! this.benchmark , cashToStart , maxRunningHours );
!
! endOfDayStrategyBackTester.Run();
! BackTesterReportViewer.ShowReport( lastDateTime ,
! endOfDayStrategyBackTester );
!
! }
! #endregion runStrategyClickEventHandlerOnlyOutOfSample
!
! #region runStrategyClickEventHandlerInAndOutOfSample
! protected virtual void runStrategyClickEventHandlerInAndOutOfSample(object sender, System.EventArgs e)
! {
DateTime firstDateTime = this.SimulatedCreationDateTime.AddDays(-this.inSamplePeriodLengthInDays);
DateTime lastDateTime = this.SimulatedCreationDateTime;
double maxRunningHours = 1;
int numberOfPortfolioPositions = this.bestPositionsInSample[0].WeightedPositions.Count;
//cash and portfolio type
***************
*** 132,136 ****
historicalQuoteProviderForInSampleChooser,
historicalQuoteProviderForStrategy;
! historicalQuoteProviderForBackTester = new HistoricalAdjustedQuoteProvider();
historicalQuoteProviderForInSampleChooser = historicalQuoteProviderForBackTester;
historicalQuoteProviderForStrategy = historicalQuoteProviderForInSampleChooser;
--- 221,225 ----
historicalQuoteProviderForInSampleChooser,
historicalQuoteProviderForStrategy;
! historicalQuoteProviderForBackTester = this.historicalMarketValueProvider;
historicalQuoteProviderForInSampleChooser = historicalQuoteProviderForBackTester;
historicalQuoteProviderForStrategy = historicalQuoteProviderForInSampleChooser;
***************
*** 140,144 ****
DrivenBySharpeRatioStrategy strategy =
new DrivenBySharpeRatioStrategy(positionsToTest,
! this.inSamplePeriodLengthInDays, benchmark,
historicalQuoteProviderForBackTester,
PortfolioType.OnlyLong);
--- 229,233 ----
DrivenBySharpeRatioStrategy strategy =
new DrivenBySharpeRatioStrategy(positionsToTest,
! this.inSamplePeriodLengthInDays, this.benchmark,
historicalQuoteProviderForBackTester,
PortfolioType.OnlyLong);
***************
*** 147,151 ****
new IndexBasedEndOfDayTimer( firstDateTime,
lastDateTime.AddDays(this.inSamplePeriodLengthInDays),
! benchmark.Ticker);
EndOfDayStrategyBackTester endOfDayStrategyBackTester =
--- 236,240 ----
new IndexBasedEndOfDayTimer( firstDateTime,
lastDateTime.AddDays(this.inSamplePeriodLengthInDays),
! this.benchmark.Ticker);
EndOfDayStrategyBackTester endOfDayStrategyBackTester =
***************
*** 155,159 ****
new SimpleAccountProvider(), firstDateTime ,
lastDateTime.AddDays(this.inSamplePeriodLengthInDays) ,
! benchmark , cashToStart , maxRunningHours );
endOfDayStrategyBackTester.Run();
--- 244,248 ----
new SimpleAccountProvider(), firstDateTime ,
lastDateTime.AddDays(this.inSamplePeriodLengthInDays) ,
! this.benchmark , cashToStart , maxRunningHours );
endOfDayStrategyBackTester.Run();
***************
*** 162,185 ****
}
! #endregion runStrategyClickEventHandler
! private void showTestingPositionsClickEventHandler_setDummyTesters_setTester(
int currentIndex ,
TestingPositions testingPositions ,
DateTime simulatedCreationDateTime )
{
! this.dummyTestersForBestTestingPositionsInSample[ currentIndex ] =
! new DummyTesterForTestingPositions(
! testingPositions ,
this.inSamplePeriodLengthInDays ,
simulatedCreationDateTime );
}
! private void showTestingPositionsClickEventHandler_setDummyTesters()
{
! this.dummyTestersForBestTestingPositionsInSample =
! new DummyTesterForTestingPositions[this.BestPositionsInSample.Length];
! for ( int i = 0 ; i < BestPositionsInSample.Length; i++ )
! this.showTestingPositionsClickEventHandler_setDummyTesters_setTester(
i ,
BestPositionsInSample[ i ] ,
--- 251,276 ----
}
! #endregion runStrategyClickEventHandlerInAndOutOfSample
! private void showTestingPositionsClickEventHandler_setTesters_setTester(
int currentIndex ,
TestingPositions testingPositions ,
DateTime simulatedCreationDateTime )
{
! this.buyAndHoldTestersForBestTestingPositionsInSample[ currentIndex ] =
! new BuyAndHoldTesterForTestingPositions(this.historicalMarketValueProvider,
! this.benchmark, testingPositions ,
this.inSamplePeriodLengthInDays ,
simulatedCreationDateTime );
}
! private void showTestingPositionsClickEventHandler_setTesters()
{
! this.buyAndHoldTestersForBestTestingPositionsInSample =
! new BuyAndHoldTesterForTestingPositions[this.BestPositionsInSample.Length];
! for ( int i = 0 ;
! i < BestPositionsInSample.Length && this.BestPositionsInSample[ i ] != null;
! i++ )
! this.showTestingPositionsClickEventHandler_setTesters_setTester(
i ,
BestPositionsInSample[ i ] ,
***************
*** 189,196 ****
protected virtual void showTestingPositionsClickEventHandler(object sender, System.EventArgs e)
{
! this.showTestingPositionsClickEventHandler_setDummyTesters();
QuantProject.Presentation.ExecutablesListViewer executablesListViewer =
new ExecutablesListViewer(
! this.dummyTestersForBestTestingPositionsInSample );
executablesListViewer.Show();
}
--- 280,287 ----
protected virtual void showTestingPositionsClickEventHandler(object sender, System.EventArgs e)
{
! this.showTestingPositionsClickEventHandler_setTesters();
QuantProject.Presentation.ExecutablesListViewer executablesListViewer =
new ExecutablesListViewer(
! this.buyAndHoldTestersForBestTestingPositionsInSample );
executablesListViewer.Show();
}
***************
*** 198,207 ****
protected virtual void createAndShowContextMenu()
{
! MenuItem[] menuItems = new MenuItem[2];
! menuItems[0] = new MenuItem("Run Strategy");
! menuItems[1] = new MenuItem("Show TestingPositions");
menuItems[0].Click +=
! new System.EventHandler(this.runStrategyClickEventHandler);
menuItems[1].Click +=
new System.EventHandler(this.showTestingPositionsClickEventHandler);
ContextMenu contextMenu = new ContextMenu(menuItems);
--- 289,304 ----
protected virtual void createAndShowContextMenu()
{
! MenuItem[] menuItems = new MenuItem[4];
! menuItems[0] = new MenuItem("Run Strategy In Sample And Out of S.");
! menuItems[1] = new MenuItem("Run Strategy Only In Sample");
! menuItems[2] = new MenuItem("Run Strategy Only Out of S.");
! menuItems[3] = new MenuItem("Show TestingPositions");
menuItems[0].Click +=
! new System.EventHandler(this.runStrategyClickEventHandlerInAndOutOfSample);
menuItems[1].Click +=
+ new System.EventHandler(this.runStrategyClickEventHandlerOnlyInSample);
+ menuItems[2].Click +=
+ new System.EventHandler(this.runStrategyClickEventHandlerOnlyOutOfSample);
+ menuItems[3].Click +=
new System.EventHandler(this.showTestingPositionsClickEventHandler);
ContextMenu contextMenu = new ContextMenu(menuItems);
|