quantproject-developers Mailing List for QuantProject (Page 52)
Brought to you by:
glauco_1
You can subscribe to this list here.
| 2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(7) |
Nov
(103) |
Dec
(67) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2004 |
Jan
(52) |
Feb
(9) |
Mar
(69) |
Apr
(53) |
May
(80) |
Jun
(23) |
Jul
(24) |
Aug
(112) |
Sep
(9) |
Oct
|
Nov
(58) |
Dec
(93) |
| 2005 |
Jan
(90) |
Feb
(93) |
Mar
(61) |
Apr
(56) |
May
(37) |
Jun
(61) |
Jul
(55) |
Aug
(68) |
Sep
(25) |
Oct
(46) |
Nov
(41) |
Dec
(37) |
| 2006 |
Jan
(33) |
Feb
(7) |
Mar
(19) |
Apr
(27) |
May
(73) |
Jun
(49) |
Jul
(83) |
Aug
(66) |
Sep
(45) |
Oct
(16) |
Nov
(15) |
Dec
(7) |
| 2007 |
Jan
(14) |
Feb
(33) |
Mar
|
Apr
(21) |
May
|
Jun
(34) |
Jul
(18) |
Aug
(100) |
Sep
(39) |
Oct
(55) |
Nov
(12) |
Dec
(2) |
| 2008 |
Jan
(120) |
Feb
(133) |
Mar
(129) |
Apr
(104) |
May
(42) |
Jun
(2) |
Jul
(52) |
Aug
(99) |
Sep
(134) |
Oct
|
Nov
(137) |
Dec
(48) |
| 2009 |
Jan
(48) |
Feb
(55) |
Mar
(61) |
Apr
(3) |
May
(2) |
Jun
(1) |
Jul
|
Aug
(51) |
Sep
|
Oct
(7) |
Nov
|
Dec
|
| 2010 |
Jan
(7) |
Feb
(1) |
Mar
(145) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(8) |
Dec
|
| 2011 |
Jan
(78) |
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(88) |
Sep
(6) |
Oct
(1) |
Nov
|
Dec
|
| 2012 |
Jan
|
Feb
(1) |
Mar
|
Apr
(6) |
May
(5) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
| 2013 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(2) |
| 2014 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: Marco M. <mi...@us...> - 2008-03-12 22:09:09
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv9863/TickerSelectionTesting Modified Files: EndOfDayTimerHandler.cs Log Message: Changed IEndOfDayStrategy interface Index: EndOfDayTimerHandler.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/EndOfDayTimerHandler.cs,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** EndOfDayTimerHandler.cs 14 Jan 2008 23:32:30 -0000 1.26 --- EndOfDayTimerHandler.cs 12 Mar 2008 22:09:05 -0000 1.27 *************** *** 76,82 **** public Account Account ! { ! get { return this.account; } ! } /// <summary> --- 76,83 ---- public Account Account ! { ! get { return this.account; } ! set { this.account = value; } ! } /// <summary> |
|
From: Marco M. <mi...@us...> - 2008-03-12 22:07:05
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv8738 Modified Files: b7_Scripts.csproj Scripts_SD.csproj Log Message: Updated sharp develop and VS net project's files Index: Scripts_SD.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/Scripts_SD.csproj,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** Scripts_SD.csproj 9 Mar 2008 23:28:37 -0000 1.16 --- Scripts_SD.csproj 12 Mar 2008 22:06:59 -0000 1.17 *************** *** 70,73 **** --- 70,75 ---- <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\InSampleChoosers\PVOCorrelationChooser.cs" /> <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\InSampleChoosers\PVOGeneticChooser.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\InSampleChoosers\PVO_CTCCorrelationChooser.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\InSampleChoosers\PVO_OTCCorrelationChooser.cs" /> <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVOGenomeManager.cs" /> <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVOLogItem.cs" /> *************** *** 76,79 **** --- 78,84 ---- <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVOPositionsStatus.cs" /> <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVOStrategy.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVO_OTCLogItem.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVO_OTCMain.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVO_OTCStrategy.cs" /> <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\EndOfDayTimerHandlerWeightedPVO.cs" /> <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\GenomeManagerWeightedPVO.cs" /> Index: b7_Scripts.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/b7_Scripts.csproj,v retrieving revision 1.87 retrieving revision 1.88 diff -C2 -d -r1.87 -r1.88 *** b7_Scripts.csproj 9 Mar 2008 23:30:10 -0000 1.87 --- b7_Scripts.csproj 12 Mar 2008 22:06:59 -0000 1.88 *************** *** 330,333 **** --- 330,348 ---- /> <File + RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVO_OTCLogItem.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVO_OTCMain.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVO_OTCStrategy.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVOGenomeManager.cs" SubType = "Code" *************** *** 395,398 **** --- 410,423 ---- /> <File + RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\InSampleChoosers\PVO_CTCCorrelationChooser.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\InSampleChoosers\PVO_OTCCorrelationChooser.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\InSampleChoosers\PVOCorrelationChooser.cs" SubType = "Code" |
|
From: Marco M. <mi...@us...> - 2008-03-12 22:06:14
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv8395 Modified Files: EndOfDayTimerHandlerPVO.cs Log Message: no message Index: EndOfDayTimerHandlerPVO.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/EndOfDayTimerHandlerPVO.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** EndOfDayTimerHandlerPVO.cs 14 Jan 2008 23:07:02 -0000 1.8 --- EndOfDayTimerHandlerPVO.cs 12 Mar 2008 22:06:05 -0000 1.9 *************** *** 71,75 **** protected bool overboughtMoreThanOversoldForFixedPortfolio; protected HistoricalAdjustedQuoteProvider historicalQuoteProvider; ! public EndOfDayTimerHandlerPVO(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, --- 71,75 ---- protected bool overboughtMoreThanOversoldForFixedPortfolio; protected HistoricalAdjustedQuoteProvider historicalQuoteProvider; ! public EndOfDayTimerHandlerPVO(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, |
|
From: Marco M. <mi...@us...> - 2008-03-12 22:05:38
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv8127 Modified Files: PVOLogItem.cs PVOMain.cs PVOStrategy.cs Log Message: Updated objects implementing the PVO strategy Index: PVOStrategy.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/PVOStrategy.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PVOStrategy.cs 9 Mar 2008 22:49:25 -0000 1.1 --- PVOStrategy.cs 12 Mar 2008 22:05:33 -0000 1.2 *************** *** 84,88 **** public Account Account { ! set { this.account = value; } } protected bool stopLossConditionReached; --- 84,89 ---- public Account Account { ! get { return this.account; } ! set { this.account = value; } } protected bool stopLossConditionReached; Index: PVOMain.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/PVOMain.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PVOMain.cs 9 Mar 2008 22:49:24 -0000 1.1 --- PVOMain.cs 12 Mar 2008 22:05:33 -0000 1.2 *************** *** 29,32 **** --- 29,33 ---- using QuantProject.Business.DataProviders; using QuantProject.Business.Strategies; + using QuantProject.Business.Financial.Accounting.AccountProviding; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.EquityEvaluation; *************** *** 100,125 **** return messageManager; } ! ! // TO DO check if you can add this to QuantProject.Presentation.Reporting.WindowsForm.Report ! // as a public method or as a new constructor ! // private void showReport( ! // DateTime lastDateTimeRequestedForTheScript , ! // EndOfDayStrategyBackTester endOfDayStrategyBackTester ) ! // { ! //// DateTime lastReportDateTime = ExtendedDateTime.Min( ! //// lastDateTimeRequestedForTheScript , ! //// endOfDayStrategyBackTester.EndOfDayTimer.GetCurrentTime().DateTime ); ! // DateTime lastReportDateTime = ! // endOfDayStrategyBackTester.ActualLastDateTime; ! // Report report = new Report( ! // endOfDayStrategyBackTester.AccountReport , ! // true ); ! // report.Create( endOfDayStrategyBackTester.DescriptionForLogFileName , 1 , ! // new EndOfDayDateTime( lastReportDateTime , ! // EndOfDaySpecificTime.OneHourAfterMarketClose ) , ! // endOfDayStrategyBackTester.Benchmark.Ticker ); ! // report.Show(); ! // } ! //Saves (in silent mode): //- a log file where the In Sample Analysis are --- 101,105 ---- return messageManager; } ! //Saves (in silent mode): //- a log file where the In Sample Analysis are *************** *** 153,157 **** //general DateTime firstDateTime = new DateTime( 2000 , 6 , 1 ); ! DateTime lastDateTime = new DateTime( 2000 , 7 , 31 ); double maxRunningHours = 5; Benchmark benchmark = new Benchmark( "^GSPC" ); --- 133,137 ---- //general DateTime firstDateTime = new DateTime( 2000 , 6 , 1 ); ! DateTime lastDateTime = new DateTime( 2001 , 6 , 1 ); double maxRunningHours = 5; Benchmark benchmark = new Benchmark( "^GSPC" ); *************** *** 164,184 **** // parameters for the in sample Chooser ! double crossoverRate = 0.85; ! double mutationRate = 0.02; ! double elitismRate = 0.001; ! int populationSizeForGeneticOptimizer = 500; ! int generationNumberForGeneticOptimizer = 10; int numberOfBestTestingPositionsToBeReturnedInSample = 5; int seedForRandomGenerator = QuantProject.ADT.ConstantsProvider.SeedForRandomGenerator; int numDaysBetweenEachOptimization = 15; ! int minLevelForOversoldThreshold = 50; ! int maxLevelForOversoldThreshold = 100; ! int minLevelForOverboughtThreshold = 50; ! int maxLevelForOverboughtThreshold = 100; int divisorForThresholdComputation = 10000; int numDaysForOscillatingPeriodForChooser = 1; //for genetic optimization bool symmetricalThresholds = true; ! bool overboughtMoreThanOversoldForFixedPortfolio = false; double maxAcceptableCloseToCloseDrawdown = 0.03; double minimumAcceptableGain = 0.008; --- 144,164 ---- // parameters for the in sample Chooser ! // double crossoverRate = 0.85; ! // double mutationRate = 0.02; ! // double elitismRate = 0.001; ! // int populationSizeForGeneticOptimizer = 500; ! // int generationNumberForGeneticOptimizer = 10; int numberOfBestTestingPositionsToBeReturnedInSample = 5; int seedForRandomGenerator = QuantProject.ADT.ConstantsProvider.SeedForRandomGenerator; int numDaysBetweenEachOptimization = 15; ! // int minLevelForOversoldThreshold = 50; ! // int maxLevelForOversoldThreshold = 100; ! // int minLevelForOverboughtThreshold = 50; ! // int maxLevelForOverboughtThreshold = 100; int divisorForThresholdComputation = 10000; int numDaysForOscillatingPeriodForChooser = 1; //for genetic optimization bool symmetricalThresholds = true; ! // bool overboughtMoreThanOversoldForFixedPortfolio = false; double maxAcceptableCloseToCloseDrawdown = 0.03; double minimumAcceptableGain = 0.008; *************** *** 195,210 **** historicalQuoteProviderForInSampleChooser = historicalQuoteProviderForBackTester; historicalQuoteProviderForStrategy = historicalQuoteProviderForInSampleChooser; ! IInSampleChooser inSampleChooser = ! new PVOGeneticChooser(numDaysForOscillatingPeriodForChooser , ! numberOfPortfolioPositions , numberOfBestTestingPositionsToBeReturnedInSample, ! benchmark, decoderForTestingPositions , fitnessEvaluator , ! historicalQuoteProviderForInSampleChooser , ! crossoverRate , mutationRate , elitismRate , ! populationSizeForGeneticOptimizer , generationNumberForGeneticOptimizer , ! seedForRandomGenerator , minLevelForOversoldThreshold , ! maxLevelForOversoldThreshold , minLevelForOverboughtThreshold , ! maxLevelForOverboughtThreshold , divisorForThresholdComputation , ! symmetricalThresholds , overboughtMoreThanOversoldForFixedPortfolio ); //parameters for eligiblesSelector bool temporizedGroup = true; --- 175,194 ---- historicalQuoteProviderForInSampleChooser = historicalQuoteProviderForBackTester; historicalQuoteProviderForStrategy = historicalQuoteProviderForInSampleChooser; ! ! // IInSampleChooser inSampleChooser = ! // new PVOGeneticChooser(numDaysForOscillatingPeriodForChooser , ! // numberOfPortfolioPositions , numberOfBestTestingPositionsToBeReturnedInSample, ! // benchmark, decoderForTestingPositions , fitnessEvaluator , ! // historicalQuoteProviderForInSampleChooser , ! // crossoverRate , mutationRate , elitismRate , ! // populationSizeForGeneticOptimizer , generationNumberForGeneticOptimizer , ! // seedForRandomGenerator , minLevelForOversoldThreshold , ! // maxLevelForOversoldThreshold , minLevelForOverboughtThreshold , ! // maxLevelForOverboughtThreshold , divisorForThresholdComputation , ! // symmetricalThresholds , overboughtMoreThanOversoldForFixedPortfolio ); ! IInSampleChooser inSampleChooser = ! new PVO_CTCCorrelationChooser(numberOfBestTestingPositionsToBeReturnedInSample, ! numDaysForOscillatingPeriodForChooser); //parameters for eligiblesSelector bool temporizedGroup = true; *************** *** 235,245 **** new EndOfDayStrategyBackTester( this.strategyIdentifier , strategy , ! historicalQuoteProviderForBackTester , firstDateTime , lastDateTime , benchmark , cashToStart , maxRunningHours ); - // TO DO check if you can do this assign in the EndOfDayStrategyBackTester - // constructor - strategy.Account = endOfDayStrategyBackTester.Account; - MessageManager messageManager = this.setMessageManager( eligiblesSelector , inSampleChooser , --- 219,226 ---- new EndOfDayStrategyBackTester( this.strategyIdentifier , strategy , ! historicalQuoteProviderForBackTester , ! new SimpleAccountProvider(), firstDateTime , lastDateTime , benchmark , cashToStart , maxRunningHours ); MessageManager messageManager = this.setMessageManager( eligiblesSelector , inSampleChooser , *************** *** 251,262 **** #endregion Run - public void Run1() - { - BackTestLog backTestLog = - LogArchiver.Load( System.Configuration.ConfigurationSettings.AppSettings["LogArchive"] ); - LogViewer logViewer = - new LogViewer( backTestLog ); - logViewer.Show(); - } } } --- 232,235 ---- Index: PVOLogItem.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/PVOLogItem.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PVOLogItem.cs 9 Mar 2008 22:49:24 -0000 1.1 --- PVOLogItem.cs 12 Mar 2008 22:05:33 -0000 1.2 *************** *** 25,28 **** --- 25,29 ---- using QuantProject.Business.DataProviders; using QuantProject.Business.Strategies; + using QuantProject.Business.Financial.Accounting.AccountProviding; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.InSample; *************** *** 45,59 **** public class PVOLogItem : LogItem { ! // static public Random rand = new Random(4676); ! private TestingPositions[] bestPVOPositionsInSample; ! private int numberOfEligibleTickers; ! private double fitnessOfFirstPVOPositionsInSample; ! private double fitnessOfLastPVOPositionsInSample; ! private int generationOfFirstPVOPositionsInSample; ! private int generationOfLastPVOPositionsInSample; ! private string thresholdsOfFirst; ! private string thresholdsOfLast; ! private string tickersOfFirst; ! private string tickersOfLast; public TestingPositions[] BestPVOPositionsInSample --- 46,59 ---- public class PVOLogItem : LogItem { ! protected TestingPositions[] bestPVOPositionsInSample; ! protected int numberOfEligibleTickers; ! protected double fitnessOfFirstPVOPositionsInSample; ! protected double fitnessOfLastPVOPositionsInSample; ! protected int generationOfFirstPVOPositionsInSample; ! protected int generationOfLastPVOPositionsInSample; ! protected string thresholdsOfFirst; ! protected string thresholdsOfLast; ! protected string tickersOfFirst; ! protected string tickersOfLast; public TestingPositions[] BestPVOPositionsInSample *************** *** 191,195 **** new EndOfDayStrategyBackTester( "PVO" , strategy , ! historicalQuoteProviderForBackTester , firstDateTime , lastDateTime , benchmark , cashToStart , maxRunningHours ); --- 191,196 ---- new EndOfDayStrategyBackTester( "PVO" , strategy , ! historicalQuoteProviderForBackTester , ! new SimpleAccountProvider(), firstDateTime , lastDateTime , benchmark , cashToStart , maxRunningHours ); |
|
From: Marco M. <mi...@us...> - 2008-03-12 22:05:36
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/InSampleChoosers In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv8127/InSampleChoosers Modified Files: PVOCorrelationChooser.cs Log Message: Updated objects implementing the PVO strategy Index: PVOCorrelationChooser.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/InSampleChoosers/PVOCorrelationChooser.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PVOCorrelationChooser.cs 9 Mar 2008 22:49:23 -0000 1.1 --- PVOCorrelationChooser.cs 12 Mar 2008 22:05:32 -0000 1.2 *************** *** 40,44 **** /// requested number of PVOPositions (positions for the PVO strategy) /// </summary> ! public class PVOCorrelationChooser : IInSampleChooser { public event NewProgressEventHandler NewProgress; --- 40,44 ---- /// requested number of PVOPositions (positions for the PVO strategy) /// </summary> ! public abstract class PVOCorrelationChooser : IInSampleChooser { public event NewProgressEventHandler NewProgress; *************** *** 47,52 **** protected CorrelationProvider correlationProvider; protected int numberOfBestTestingPositionsToBeReturned; - protected double oversoldThreshold; - protected double overboughtThreshold; protected int numDaysForOscillatingPeriod; --- 47,50 ---- *************** *** 55,60 **** get { ! string description = "PVOCorrelationChooser_" + ! this.correlationProvider.GetType().ToString(); return description; } --- 53,60 ---- get { ! string description = "CorrelationChooserType:\n" + ! this.correlationProvider.GetType().ToString() + "\n" + ! "NumOfTickersReturned:\n" + ! this.numberOfBestTestingPositionsToBeReturned.ToString(); return description; } *************** *** 75,84 **** /// </param> public PVOCorrelationChooser(int numberOfBestTestingPositionsToBeReturned, ! double oversoldThreshold, double overboughtThreshold, ! int numDaysForOscillatingPeriod) { this.numberOfBestTestingPositionsToBeReturned = numberOfBestTestingPositionsToBeReturned; - this.oversoldThreshold = oversoldThreshold; - this.overboughtThreshold = overboughtThreshold; this.numDaysForOscillatingPeriod = numDaysForOscillatingPeriod; } --- 75,81 ---- /// </param> public PVOCorrelationChooser(int numberOfBestTestingPositionsToBeReturned, ! int numDaysForOscillatingPeriod) { this.numberOfBestTestingPositionsToBeReturned = numberOfBestTestingPositionsToBeReturned; this.numDaysForOscillatingPeriod = numDaysForOscillatingPeriod; } *************** *** 95,109 **** } ! protected virtual void setCorrelationProvider(EligibleTickers eligibleTickers , ! ReturnsManager returnsManager) ! { ! this.correlationProvider = ! new OpenToCloseCorrelationProvider(eligibleTickers.Tickers, returnsManager, ! 0.0001f, 0.5f); ! } ! protected virtual PVOPositions getTestingPositions(WeightedPositions weightedPositions) { ! return new PVOPositions(weightedPositions, this.oversoldThreshold, this.overboughtThreshold, this.numDaysForOscillatingPeriod ); } --- 92,102 ---- } ! protected abstract void setCorrelationProvider(EligibleTickers eligibleTickers , ! ReturnsManager returnsManager); ! protected PVOPositions getTestingPositions(WeightedPositions weightedPositions) { ! return new PVOPositions(weightedPositions, 0.0, 0.0, ! this.numDaysForOscillatingPeriod ); } *************** *** 124,127 **** --- 117,122 ---- WeightedPositions weightedPositions = new WeightedPositions(signedTickers); bestTestingPositions[i] = this.getTestingPositions(weightedPositions); + ((PVOPositions)bestTestingPositions[i]).FitnessInSample = + correlations[correlations.Length - 1 -i].CorrelationValue; } return bestTestingPositions; |
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv7565 Added Files: PVO_OTCLogItem.cs PVO_OTCMain.cs PVO_OTCStrategy.cs Log Message: Added objects for the PVO implementation (OTC and CTC) --- NEW FILE: PVO_OTCLogItem.cs --- /* QuantProject - Quantitative Finance Library PVO_OTCLogItem.cs Copyright (C) 2008 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using QuantProject.Business.DataProviders; using QuantProject.Business.Strategies; using QuantProject.Business.Financial.Accounting.AccountProviding; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.InSample; using QuantProject.Business.Strategies.OutOfSample; using QuantProject.Business.Strategies.Logging; using QuantProject.Business.Strategies.ReturnsManagement.Time; using QuantProject.Business.Strategies.ReturnsManagement.Time.IntervalsSelectors; using QuantProject.Business.Timing; using QuantProject.Scripts.General.Reporting; namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator { /// <summary> /// LogItem for the PVO_OTC strategy /// portfolio value oscillator strategy /// </summary> [Serializable] public class PVO_OTCLogItem : PVOLogItem { public PVO_OTCLogItem(EndOfDayDateTime endOfDayDateTime ) : base( endOfDayDateTime ) { } public override void Run() { //general int inSampleDays = 120; DateTime firstDateTime = this.SimulatedCreationTime.DateTime.AddDays(-inSampleDays); DateTime lastDateTime = this.SimulatedCreationTime.DateTime; double maxRunningHours = 1; Benchmark benchmark = new Benchmark( "^GSPC" ); // definition for the Fitness Evaluator (for // objects that use it) int numberOfPortfolioPositions = this.BestPVOPositionsInSample[0].WeightedPositions.Count; //cash and portfolio type double cashToStart = 30000; HistoricalQuoteProvider historicalQuoteProviderForBackTester, historicalQuoteProviderForInSampleChooser, historicalQuoteProviderForStrategy; historicalQuoteProviderForBackTester = new HistoricalAdjustedQuoteProvider(); historicalQuoteProviderForInSampleChooser = historicalQuoteProviderForBackTester; historicalQuoteProviderForStrategy = historicalQuoteProviderForInSampleChooser; IEligiblesSelector eligiblesSelector = new DummyEligibleSelector(); //strategyParameters TestingPositions[] positionsToTest = new TestingPositions[this.bestPVOPositionsInSample.Length]; positionsToTest = this.bestPVOPositionsInSample; PVO_OTCStrategy strategy = new PVO_OTCStrategy(eligiblesSelector, positionsToTest, inSampleDays, benchmark , int.MaxValue , ((PVOPositions)positionsToTest[0]).OversoldThreshold, ((PVOPositions)positionsToTest[0]).OverboughtThreshold, historicalQuoteProviderForStrategy); EndOfDayStrategyBackTester endOfDayStrategyBackTester = new EndOfDayStrategyBackTester( "PVO_OTC" , strategy , historicalQuoteProviderForBackTester , new SimpleAccountProvider(), firstDateTime , lastDateTime , benchmark , cashToStart , maxRunningHours ); // TO DO check if you can do this assign in the EndOfDayStrategyBackTester // constructor strategy.Account = endOfDayStrategyBackTester.Account; endOfDayStrategyBackTester.Run(); BackTesterReportViewer.ShowReport( lastDateTime , endOfDayStrategyBackTester ); } } } --- NEW FILE: PVO_OTCMain.cs --- /* QuantProject - Quantitative Finance Library PVO_OTCMain.cs Copyright (C) 2008 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections; using System.IO; using QuantProject.ADT; using QuantProject.ADT.FileManaging; using QuantProject.Business.DataProviders; using QuantProject.Business.Strategies; using QuantProject.Business.Financial.Accounting.AccountProviding; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.EquityEvaluation; using QuantProject.Business.Strategies.Logging; using QuantProject.Business.Strategies.Optimizing.Decoding; using QuantProject.Business.Strategies.Optimizing.FitnessEvaluation; using QuantProject.Business.Strategies.ReturnsManagement; using QuantProject.Business.Strategies.ReturnsManagement.Time; using QuantProject.Business.Strategies.ReturnsManagement.Time.IntervalsSelectors; using QuantProject.Business.Timing; using QuantProject.Presentation; using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.InSampleChoosers; using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.Decoding; using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.FitnessEvaluators; using QuantProject.Scripts.General.Logging; using QuantProject.Scripts.General.Reporting; namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator { /// <summary> /// Entry point for the PVO_OTC strategy. If any strategy /// parameter had to be changed, this is the place where it should /// be done /// </summary> public class PVO_OTCMain { private string strategyIdentifier; private string fileNameWithoutExt; private string dirNameWhereToSaveResults; public PVO_OTCMain() { this.strategyIdentifier = "PVO_OTC"; } private void setFileNamesAndDirectory(EndOfDayStrategyBackTester endOfDayStrategyBackTester) { if(this.fileNameWithoutExt == null) { this.fileNameWithoutExt = this.strategyIdentifier + "_" + DateTime.Now.Hour.ToString().PadLeft(2,'0') + "_" + DateTime.Now.Minute.ToString().PadLeft(2,'0') + "_" + DateTime.Now.Second.ToString().PadLeft(2,'0'); this.dirNameWhereToSaveResults = System.Configuration.ConfigurationSettings.AppSettings["LogArchive"] + "\\" + fileNameWithoutExt + "\\"; if( !Directory.Exists(dirNameWhereToSaveResults) ) Directory.CreateDirectory(dirNameWhereToSaveResults); } } #region Run private MessageManager setMessageManager( IEligiblesSelector eligiblesSelector , IInSampleChooser inSampleChooser , IEndOfDayStrategy endOfDayStrategy , EndOfDayStrategyBackTester endOfDayStrategyBackTester ) { this.setFileNamesAndDirectory(endOfDayStrategyBackTester); string fullPathFileNameForMessagesLog = dirNameWhereToSaveResults + this.fileNameWithoutExt + "LogMessages.txt"; MessageManager messageManager = new MessageManager( fullPathFileNameForMessagesLog ); messageManager.Monitor( eligiblesSelector ); messageManager.Monitor( inSampleChooser ); // messageManager.Monitor( endOfDayStrategy ); messageManager.Monitor( endOfDayStrategyBackTester ); return messageManager; } // TO DO check if you can add this to QuantProject.Presentation.Reporting.WindowsForm.Report // as a public method or as a new constructor // private void showReport( // DateTime lastDateTimeRequestedForTheScript , // EndOfDayStrategyBackTester endOfDayStrategyBackTester ) // { //// DateTime lastReportDateTime = ExtendedDateTime.Min( //// lastDateTimeRequestedForTheScript , //// endOfDayStrategyBackTester.EndOfDayTimer.GetCurrentTime().DateTime ); // DateTime lastReportDateTime = // endOfDayStrategyBackTester.ActualLastDateTime; // Report report = new Report( // endOfDayStrategyBackTester.AccountReport , // true ); // report.Create( endOfDayStrategyBackTester.DescriptionForLogFileName , 1 , // new EndOfDayDateTime( lastReportDateTime , // EndOfDaySpecificTime.OneHourAfterMarketClose ) , // endOfDayStrategyBackTester.Benchmark.Ticker ); // report.Show(); // } //Saves (in silent mode): //- a log file where the In Sample Analysis are // stored; //- a report; //- a txt file with a full description of the // strategy's features private void saveScriptResults( EndOfDayStrategyBackTester endOfDayStrategyBackTester ) { this.setFileNamesAndDirectory(endOfDayStrategyBackTester); string fullPathFileNameForLog = dirNameWhereToSaveResults + this.fileNameWithoutExt + ".qpL"; string fullPathFileNameForReport = dirNameWhereToSaveResults + this.fileNameWithoutExt + ".qpR"; string fullPathFileNameForParametersLog = dirNameWhereToSaveResults + this.fileNameWithoutExt + "_Parameters.txt"; ObjectArchiver.Archive(endOfDayStrategyBackTester.Log, fullPathFileNameForLog); ObjectArchiver.Archive(endOfDayStrategyBackTester.AccountReport, fullPathFileNameForReport); StreamWriter w = File.AppendText(fullPathFileNameForParametersLog); w.WriteLine ("\n---\r\n"); w.WriteLine ( endOfDayStrategyBackTester.Description ); w.WriteLine ("\n---\r\n"); w.Flush(); w.Close(); } public void Run() { //general DateTime firstDateTime = new DateTime( 2000 , 6 , 1 ); DateTime lastDateTime = new DateTime( 2005 , 12 , 31 ); double maxRunningHours = 1.5; Benchmark benchmark = new Benchmark( "^GSPC" ); // definition for the Fitness Evaluator (for // objects that use it) //IEquityEvaluator equityEvaluator = new SharpeRatio(); //cash and portfolio type double cashToStart = 30000; //int numberOfPortfolioPositions = 4; // parameters for the in sample Chooser //double crossoverRate = 0.85; //double mutationRate = 0.02; //double elitismRate = 0.001; //int populationSizeForGeneticOptimizer = 500; // int generationNumberForGeneticOptimizer = 10; int numberOfBestTestingPositionsToBeReturnedInSample = 8; // int seedForRandomGenerator = // QuantProject.ADT.ConstantsProvider.SeedForRandomGenerator; int numDaysBetweenEachOptimization = 15; // int minLevelForOversoldThreshold = 50; // int maxLevelForOversoldThreshold = 100; // int minLevelForOverboughtThreshold = 50; // int maxLevelForOverboughtThreshold = 100; // int divisorForThresholdComputation = 10000; // int numDaysForOscillatingPeriodForChooser = 1; //for genetic optimization // bool symmetricalThresholds = true; // bool overboughtMoreThanOversoldForFixedPortfolio = false; // double maxAcceptableCloseToCloseDrawdown = 0.03; // double minimumAcceptableGain = 0.008; // IDecoderForTestingPositions decoderForTestingPositions // = new BasicDecoderForPVOPositions(symmetricalThresholds, divisorForThresholdComputation , // numDaysForOscillatingPeriodForChooser); // IFitnessEvaluator fitnessEvaluator = // new PVOFitnessEvaluator( equityEvaluator ); HistoricalQuoteProvider historicalQuoteProviderForBackTester, historicalQuoteProviderForInSampleChooser, historicalQuoteProviderForStrategy; historicalQuoteProviderForBackTester = new HistoricalAdjustedQuoteProvider(); historicalQuoteProviderForInSampleChooser = historicalQuoteProviderForBackTester; historicalQuoteProviderForStrategy = historicalQuoteProviderForInSampleChooser; IInSampleChooser inSampleChooser = new PVO_OTCCorrelationChooser(numberOfBestTestingPositionsToBeReturnedInSample); //parameters for eligiblesSelector bool temporizedGroup = true; double minRawOpenPrice = 25; double maxRawOpenPrice = 500; int numDaysForAverageOpenRawPrice = 20; string tickersGroupId = "SP500"; int maxNumberOfEligiblesToBeChosen = 100; IEligiblesSelector eligiblesSelector = new ByPriceMostLiquidAlwaysQuoted( tickersGroupId , temporizedGroup, maxNumberOfEligiblesToBeChosen, numDaysForAverageOpenRawPrice , minRawOpenPrice , maxRawOpenPrice ); //strategyParameters double oversoldThreshold = 0.0075; double overboughtThreshold = 0.0075; int inSampleDays = 120; PVO_OTCStrategy strategy = new PVO_OTCStrategy(eligiblesSelector, inSampleChooser, inSampleDays, benchmark , numDaysBetweenEachOptimization , oversoldThreshold , overboughtThreshold , historicalQuoteProviderForStrategy ); EndOfDayStrategyBackTester endOfDayStrategyBackTester = new EndOfDayStrategyBackTester( this.strategyIdentifier , strategy , historicalQuoteProviderForBackTester , new SimpleAccountProvider(),firstDateTime , lastDateTime , benchmark , cashToStart , maxRunningHours ); MessageManager messageManager = this.setMessageManager( eligiblesSelector , inSampleChooser , strategy , endOfDayStrategyBackTester ); endOfDayStrategyBackTester.Run(); this.saveScriptResults(endOfDayStrategyBackTester); } #endregion Run } } --- NEW FILE: PVO_OTCStrategy.cs --- /* QuantProject - Quantitative Finance Library PVO_OTCStrategy.cs Copyright (C) 2008 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Data; using System.Collections; using QuantProject.ADT; using QuantProject.ADT.Messaging; using QuantProject.Business.Financial.Accounting; using QuantProject.Business.Financial.Instruments; using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Timing; using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.OutOfSample; using QuantProject.Business.Strategies.Logging; using QuantProject.Business.Strategies.ReturnsManagement; using QuantProject.Business.Strategies.ReturnsManagement.Time; using QuantProject.Business.DataProviders; using QuantProject.Business.Strategies.TickersRelationships; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.Optimizing.Decoding; using QuantProject.Data; using QuantProject.Data.DataProviders; using QuantProject.Data.Selectors; using QuantProject.Data.DataTables; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Scripts.WalkForwardTesting.LinearCombination; namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator { /// <summary> /// Implements MarketOpenEventHandler and MarketCloseEventHandler /// These handlers contain the core strategy for the Portfolio Value /// Oscillator /// </summary> [Serializable] public class PVO_OTCStrategy : IEndOfDayStrategyForBacktester { public event NewLogItemEventHandler NewLogItem; public event NewMessageEventHandler NewMessage; //initialized by the constructor protected int inSampleDays; protected int numDaysBetweenEachOptimization; protected IInSampleChooser inSampleChooser; protected IEligiblesSelector eligiblesSelector; protected Benchmark benchmark; protected HistoricalQuoteProvider historicalQuoteProvider; protected double oversoldThreshold; protected double overboughtThreshold; //initialized after constructor's call protected int numDaysElapsedSinceLastOptimization; protected ReturnsManager returnsManager; protected TestingPositions[] chosenPVOPositions; //chosen in sample: these are the eligible positions for out //of sample testing protected PVOPositions pvoPositionsForOutOfSample; protected DateTime lastCloseDate; protected Account account; public Account Account { get { return this.account; } set { this.account = value; } } private string description_GetDescriptionForChooser() { if(this.inSampleChooser == null) return "ConstantChooser"; else return this.inSampleChooser.Description; } public string Description { get { string description = "PVO_OTC\n" + "Tickers_" + "2\n" + "_inSampleDays_" + this.inSampleDays.ToString() + "\n" + this.eligiblesSelector.Description + "\n" + "oversoldThreshold_" + this.oversoldThreshold.ToString() + "\n" + "overboughtThreshold_" + this.overboughtThreshold.ToString() + "\n" + this.description_GetDescriptionForChooser() + "\n" + "Optimization each " + this.numDaysBetweenEachOptimization.ToString() + " days"; return description; } } public bool StopBacktestIfMaxRunningHoursHasBeenReached { get { return true; } } private void pvo_otcStrategy(IEligiblesSelector eligiblesSelector, int inSampleDays, Benchmark benchmark, int numDaysBetweenEachOptimization, double oversoldThreshold, double overboughtThreshold, HistoricalQuoteProvider historicalQuoteProvider) { this.eligiblesSelector = eligiblesSelector; this.inSampleDays = inSampleDays; this.benchmark = benchmark; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; this.oversoldThreshold = oversoldThreshold; this.overboughtThreshold = overboughtThreshold; this.historicalQuoteProvider = historicalQuoteProvider; } public PVO_OTCStrategy(IEligiblesSelector eligiblesSelector, IInSampleChooser inSampleChooser, int inSampleDays, Benchmark benchmark, int numDaysBetweenEachOptimization, double oversoldThreshold, double overboughtThreshold, HistoricalQuoteProvider historicalQuoteProvider) { this.pvo_otcStrategy(eligiblesSelector, inSampleDays , benchmark , numDaysBetweenEachOptimization , oversoldThreshold, overboughtThreshold, historicalQuoteProvider); this.inSampleChooser = inSampleChooser; } public PVO_OTCStrategy(IEligiblesSelector eligiblesSelector, TestingPositions[] chosenPVOPositions, int inSampleDays, Benchmark benchmark, int numDaysBetweenEachOptimization, double oversoldThreshold, double overboughtThreshold, HistoricalQuoteProvider historicalQuoteProvider) { this.pvo_otcStrategy(eligiblesSelector, inSampleDays , benchmark , numDaysBetweenEachOptimization , oversoldThreshold, overboughtThreshold, historicalQuoteProvider); this.chosenPVOPositions = chosenPVOPositions; } #region MarketOpenEventHandler protected virtual EndOfDayDateTime getBeginOfOscillatingPeriod(IndexBasedEndOfDayTimer timer) { return new EndOfDayDateTime( (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition-1]["quDate"], EndOfDaySpecificTime.MarketClose ); } private PVOPositionsStatus marketOpenEventHandler_openPositions_getStatus(IndexBasedEndOfDayTimer timer) { EndOfDayDateTime today = timer.GetCurrentTime(); EndOfDayDateTime beginOfOscillatingPeriod = this.getBeginOfOscillatingPeriod(timer); PVOPositionsStatus currentStatus = PVOPositionsStatus.InTheMiddle; for(int i = 0; i<this.chosenPVOPositions.Length; i++) { if(this.chosenPVOPositions[i] != null) currentStatus = ((PVOPositions)this.chosenPVOPositions[i]).GetStatus(beginOfOscillatingPeriod, today, this.benchmark.Ticker, this.historicalQuoteProvider); if(currentStatus == PVOPositionsStatus.Oversold || currentStatus == PVOPositionsStatus.Overbought ) { this.pvoPositionsForOutOfSample = (PVOPositions)this.chosenPVOPositions[i]; i = this.chosenPVOPositions.Length;//exit from for } } return currentStatus; } protected void marketOpenEventHandler_openPositions(IndexBasedEndOfDayTimer timer) { PVOPositionsStatus pvoPositionsStatus = PVOPositionsStatus.InTheMiddle; if(timer.CurrentDateArrayPosition >= 1) pvoPositionsStatus = this.marketOpenEventHandler_openPositions_getStatus(timer); switch (pvoPositionsStatus) { case PVOPositionsStatus.Overbought: { #region manage Overbought case this.pvoPositionsForOutOfSample.WeightedPositions.Reverse(); try { AccountManager.OpenPositions( this.pvoPositionsForOutOfSample.WeightedPositions, this.account ); } catch(Exception ex) { ex = ex; } finally { this.pvoPositionsForOutOfSample.WeightedPositions.Reverse(); } #endregion break; } case PVOPositionsStatus.Oversold: { AccountManager.OpenPositions( this.pvoPositionsForOutOfSample.WeightedPositions, this.account ); break; } case PVOPositionsStatus.InTheMiddle://that is { //pvoPositionsForOutOfSample has not been set break; } default: { //it should never been reached break; } } } public virtual void MarketOpenEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if ( this.account.Portfolio.Count == 0 && this.chosenPVOPositions != null ) //portfolio is empty and optimization has //been already launched { try{ this.marketOpenEventHandler_openPositions( (IndexBasedEndOfDayTimer)sender ); } catch(TickerNotExchangedException ex) {ex=ex;} } } #endregion public void FiveMinutesBeforeMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { } private EndOfDayDateTime now() { return this.account.EndOfDayTimer.GetCurrentTime(); } public virtual void MarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if(this.account.Portfolio.Count > 0) AccountManager.ClosePositions(this.account); } #region OneHourAfterMarketCloseEventHandler protected virtual void updateReturnsManager(EndOfDayDateTime firstEndOfDayDateTime, EndOfDayDateTime lastEndOfDayDateTime) { this.returnsManager = new ReturnsManager( new DailyOpenToCloseIntervals(firstEndOfDayDateTime, lastEndOfDayDateTime, this.benchmark.Ticker ) , this.historicalQuoteProvider); } private PVO_OTCLogItem getLogItem( EligibleTickers eligibleTickers ) { PVO_OTCLogItem logItem = new PVO_OTCLogItem( this.now() ); logItem.BestPVOPositionsInSample = this.chosenPVOPositions; logItem.NumberOfEligibleTickers = eligibleTickers.Count; logItem.FitnessOfFirst = this.chosenPVOPositions[0].FitnessInSample; logItem.FitnessOfLast = this.chosenPVOPositions[this.chosenPVOPositions.Length - 1].FitnessInSample; // logItem.GenerationOfFirst = // ((IGeneticallyOptimizable)this.chosenPVOPositions[0]).Generation; // logItem.GenerationOfLast = // ((IGeneticallyOptimizable)this.chosenPVOPositions[this.chosenPVOPositions.Length - 1]).Generation; logItem.ThresholdsOfFirst = ((PVOPositions)this.chosenPVOPositions[0]).OversoldThreshold.ToString() + ";" + ((PVOPositions)this.chosenPVOPositions[0]).OverboughtThreshold.ToString(); logItem.ThresholdsOfLast = ((PVOPositions)this.chosenPVOPositions[this.chosenPVOPositions.Length - 1]).OversoldThreshold.ToString() + ";" + ((PVOPositions)this.chosenPVOPositions[this.chosenPVOPositions.Length - 1]).OverboughtThreshold.ToString(); logItem.TickersOfFirst = this.chosenPVOPositions[0].HashCodeForTickerComposition; logItem.TickersOfLast = this.chosenPVOPositions[this.chosenPVOPositions.Length - 1].HashCodeForTickerComposition; return logItem; } private void raiseNewLogItem( EligibleTickers eligibleTickers ) { PVO_OTCLogItem logItem = this.getLogItem( eligibleTickers ); NewLogItemEventArgs newLogItemEventArgs = new NewLogItemEventArgs( logItem ); this.NewLogItem( this , newLogItemEventArgs ); } private void notifyMessage( EligibleTickers eligibleTickers ) { string message = "Number of Eligible tickers: " + eligibleTickers.Count; NewMessageEventArgs newMessageEventArgs = new NewMessageEventArgs( message ); if ( this.NewMessage != null ) this.NewMessage( this , newMessageEventArgs ); } private void logOptimizationInfo( EligibleTickers eligibleTickers ) { this.raiseNewLogItem( eligibleTickers ); this.notifyMessage( eligibleTickers ); } private void updateTestingPositions_updateThresholds() { for(int i = 0; i<this.chosenPVOPositions.Length; i++) { ((PVOPositions)this.chosenPVOPositions[i]).OversoldThreshold = this.oversoldThreshold; ((PVOPositions)this.chosenPVOPositions[i]).OverboughtThreshold = this.overboughtThreshold; } } protected virtual void updateTestingPositions(DateTime currentDate) { EndOfDayHistory endOfDayHistory = this.benchmark.GetEndOfDayHistory( new EndOfDayDateTime(currentDate.AddDays(-this.inSampleDays), EndOfDaySpecificTime.MarketOpen), new EndOfDayDateTime(currentDate, EndOfDaySpecificTime.MarketClose)); EligibleTickers eligibles = this.eligiblesSelector.GetEligibleTickers(endOfDayHistory); this.updateReturnsManager(endOfDayHistory.FirstEndOfDayDateTime, endOfDayHistory.LastEndOfDayDateTime); if(this.inSampleChooser != null) this.chosenPVOPositions = (TestingPositions[])inSampleChooser.AnalyzeInSample(eligibles, this.returnsManager); this.updateTestingPositions_updateThresholds(); this.logOptimizationInfo(eligibles); } /// <summary> /// Handles a "One hour after market close" event. /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> public virtual void OneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { this.lastCloseDate = endOfDayTimingEventArgs.EndOfDayDateTime.DateTime; this.numDaysElapsedSinceLastOptimization++; if((this.numDaysElapsedSinceLastOptimization == this.numDaysBetweenEachOptimization)) //num days without optimization has elapsed { this.updateTestingPositions(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime); //sets tickers to be chosen next Market Close event this.numDaysElapsedSinceLastOptimization = 0; } } #endregion } } |
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/InSampleChoosers In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv7565/InSampleChoosers Added Files: PVO_CTCCorrelationChooser.cs PVO_OTCCorrelationChooser.cs Log Message: Added objects for the PVO implementation (OTC and CTC) --- NEW FILE: PVO_OTCCorrelationChooser.cs --- /* QuantProject - Quantitative Finance Library PVO_OTCCorrelationChooser.cs Copyright (C) 2008 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections; using QuantProject.ADT; using QuantProject.ADT.Messaging; using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.TickersRelationships; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.ReturnsManagement; using QuantProject.Business.Strategies.OutOfSample; using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.InSampleChoosers; namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.InSampleChoosers { /// <summary> /// PVO_OTCCorrelationChooser to be used for /// in sample optimization /// By means of correlation, the AnalyzeInSample method returns the /// requested number of PVOPositions (positions for the PVO strategy) /// </summary> public class PVO_OTCCorrelationChooser : PVOCorrelationChooser { /// <summary> /// PVO_OTCCorrelationChooser to be used for /// in sample optimization /// </summary> /// <param name="numberOfBestTestingPositionsToBeReturned"> /// The number of PVOPositions that the /// AnalyzeInSample method will return /// </param> public PVO_OTCCorrelationChooser(int numberOfBestTestingPositionsToBeReturned) : base(numberOfBestTestingPositionsToBeReturned,1) { } protected override void setCorrelationProvider(EligibleTickers eligibleTickers , ReturnsManager returnsManager) { this.correlationProvider = new OpenToCloseCorrelationProvider(eligibleTickers.Tickers, returnsManager, 0.0001f, 0.5f); } } } --- NEW FILE: PVO_CTCCorrelationChooser.cs --- /* QuantProject - Quantitative Finance Library PVO_CTCCorrelationChooser.cs Copyright (C) 2008 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections; using QuantProject.ADT; using QuantProject.ADT.Messaging; using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.TickersRelationships; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.ReturnsManagement; using QuantProject.Business.Strategies.OutOfSample; using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.InSampleChoosers; namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.InSampleChoosers { /// <summary> /// PVO_CTCCorrelationChooser to be used for /// in sample optimization /// By means of correlation, the AnalyzeInSample method returns the /// requested number of PVOPositions (positions for the PVO strategy) /// </summary> public class PVO_CTCCorrelationChooser : PVOCorrelationChooser { /// <summary> /// PVO_CTCCorrelationChooser to be used for /// in sample optimization /// </summary> /// <param name="numberOfBestTestingPositionsToBeReturned"> /// The number of PVOPositions that the /// AnalyzeInSample method will return /// </param> public PVO_CTCCorrelationChooser(int numberOfBestTestingPositionsToBeReturned, int closeToCloseReturnIntervalLength) : base(numberOfBestTestingPositionsToBeReturned, closeToCloseReturnIntervalLength) { } protected override void setCorrelationProvider(EligibleTickers eligibleTickers , ReturnsManager returnsManager) { DateTime firstDate = returnsManager.ReturnIntervals[0].Begin.DateTime; DateTime lastDate = returnsManager.ReturnIntervals.LastEndOfDayDateTime.DateTime; this.correlationProvider = new CloseToCloseCorrelationProvider(eligibleTickers.Tickers, firstDate, lastDate, this.numDaysForOscillatingPeriod, 0.0001f, 0.5f, "^GSPC"); } } } |
|
From: Marco M. <mi...@us...> - 2008-03-12 22:02:14
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv6068/a2_Strategies Modified Files: EndOfDayStrategyBackTester.cs Log Message: The strategy's account is set directly in the backtester constructor; the account is initialized by a IAccountProvider object Index: EndOfDayStrategyBackTester.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/EndOfDayStrategyBackTester.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** EndOfDayStrategyBackTester.cs 7 Mar 2008 23:27:13 -0000 1.6 --- EndOfDayStrategyBackTester.cs 12 Mar 2008 22:02:06 -0000 1.7 *************** *** 29,32 **** --- 29,33 ---- using QuantProject.Business.Financial.Accounting; using QuantProject.Business.Financial.Accounting.Reporting; + using QuantProject.Business.Financial.Accounting.AccountProviding; using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Strategies.Logging; *************** *** 50,54 **** private double cashToStart; private double maxRunningHours; ! private DateTime startingTimeForScript; private IEndOfDayTimer endOfDayTimer; --- 51,55 ---- private double cashToStart; private double maxRunningHours; ! private IAccountProvider accountProvider; private DateTime startingTimeForScript; private IEndOfDayTimer endOfDayTimer; *************** *** 123,130 **** "_to_" + ExtendedDateTime.GetShortDescriptionForFileName( this.actualLastDateTime ) + ! "_annlRtrn_" + this.AccountReport.Summary.AnnualSystemPercentageReturn.FormattedValue + ! "_maxDD_" + this.AccountReport.Summary.MaxEquityDrawDown.FormattedValue + ! "_" + this.historicalQuoteProvider.Description + ! "_" + this.endOfDayStrategy.Description; return description; } --- 124,131 ---- "_to_" + ExtendedDateTime.GetShortDescriptionForFileName( this.actualLastDateTime ) + ! "\n_annlRtrn_" + this.AccountReport.Summary.AnnualSystemPercentageReturn.FormattedValue + ! "\n_maxDD_" + this.AccountReport.Summary.MaxEquityDrawDown.FormattedValue + ! "\nHistoricalQuoteProviderForBackTester_" + this.historicalQuoteProvider.Description + ! "\n_" + this.endOfDayStrategy.Description; return description; } *************** *** 142,145 **** --- 143,147 ---- IEndOfDayStrategyForBacktester endOfDayStrategy , IHistoricalQuoteProvider historicalQuoteProvider , + IAccountProvider accountProvider, DateTime firstDateTime , DateTime lastDateTime , Benchmark benchmark , *************** *** 150,153 **** --- 152,156 ---- this.endOfDayStrategy = endOfDayStrategy; this.historicalQuoteProvider = historicalQuoteProvider; + this.accountProvider = accountProvider; this.firstDateTime = firstDateTime; this.lastDateTime = lastDateTime; *************** *** 157,161 **** this.initialize_endOfDayTimer(); ! this.initialize_account(); this.backTestLog = new BackTestLog( backTestID , firstDateTime , lastDateTime , benchmark ); --- 160,166 ---- this.initialize_endOfDayTimer(); ! this.account = this.accountProvider.GetAccount(this.endOfDayTimer, ! this.historicalQuoteProvider); ! this.endOfDayStrategy.Account = this.account; this.backTestLog = new BackTestLog( backTestID , firstDateTime , lastDateTime , benchmark ); *************** *** 173,186 **** this.benchmark.Ticker ); } ! private void initialize_account() ! { ! this.account = new Account( this.backTestID , this.endOfDayTimer , ! new HistoricalEndOfDayDataStreamer( this.endOfDayTimer , ! this.historicalQuoteProvider ) , ! new HistoricalEndOfDayOrderExecutor( this.endOfDayTimer , ! this.historicalQuoteProvider ) ); ! } ! ! #region Run #region run_addEventHandlers --- 178,182 ---- this.benchmark.Ticker ); } ! #region Run #region run_addEventHandlers |
|
From: Marco M. <mi...@us...> - 2008-03-12 22:00:46
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv4561/a2_Strategies Modified Files: IEndOfDayStrategy.cs Log Message: Added Account property (get;set;) to the interface, in order to set the account of the object implementing an IEndOfDayStrategy to the account created by the EndOfDayStrategyBacktester (directly in the constructor of the Backtester) Glauco, please check your main files (the "external" account assignement) Index: IEndOfDayStrategy.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/IEndOfDayStrategy.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** IEndOfDayStrategy.cs 19 Jan 2008 19:07:05 -0000 1.2 --- IEndOfDayStrategy.cs 12 Mar 2008 22:00:34 -0000 1.3 *************** *** 23,26 **** --- 23,27 ---- using System; + using QuantProject.Business.Financial.Accounting; using QuantProject.Business.Financial.Accounting.Transactions; using QuantProject.Business.Strategies.Logging; *************** *** 46,49 **** --- 47,51 ---- void OneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ); + Account Account{get;set;} } } |
|
From: Marco M. <mi...@us...> - 2008-03-12 21:56:16
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/TickersRelationships In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv1509/a2_Strategies/TickersRelationships Modified Files: CloseToCloseCorrelationProvider.cs CorrelationProvider.cs Log Message: Fixed minor bug in CorrelationProvider objects Index: CloseToCloseCorrelationProvider.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/TickersRelationships/CloseToCloseCorrelationProvider.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CloseToCloseCorrelationProvider.cs 14 Jan 2008 23:02:30 -0000 1.1 --- CloseToCloseCorrelationProvider.cs 12 Mar 2008 21:56:07 -0000 1.2 *************** *** 62,66 **** string benchmark) : base(tickersToAnalyze, ! startDate, endDate, minimumAbsoluteReturnValue, maximumAbsoluteReturnValue, benchmark) --- 62,66 ---- string benchmark) : base(tickersToAnalyze, ! startDate, endDate, closeToCloseIntervalLength, minimumAbsoluteReturnValue, maximumAbsoluteReturnValue, benchmark) Index: CorrelationProvider.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/TickersRelationships/CorrelationProvider.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CorrelationProvider.cs 30 Jan 2008 23:11:32 -0000 1.2 --- CorrelationProvider.cs 12 Mar 2008 21:56:08 -0000 1.3 *************** *** 49,54 **** --- 49,67 ---- protected EndOfDayDateTime firstEndOfDayDateTime; protected EndOfDayDateTime lastEndOfDayDateTime; + protected int returnIntervalLength; protected string benchmark; + + private void correlationProvider_commonInitialization(string[] tickersToAnalyze, + float minimumAbsoluteReturnValue, float maximumAbsoluteReturnValue) + { + this.tickers = tickersToAnalyze; + this.minimumAbsoluteReturnValue = minimumAbsoluteReturnValue; + this.maximumAbsoluteReturnValue = maximumAbsoluteReturnValue; + this.numOfCombinationTwoByTwo = + (int)((Math.Pow(this.tickers.Length, 2) - this.tickers.Length ) / 2); + } + + /// <summary> /// Creates the correlation provider *************** *** 65,83 **** /// of returns</param> public CorrelationProvider(string[] tickersToAnalyze, ! DateTime startDate, DateTime endDate, float minimumAbsoluteReturnValue, float maximumAbsoluteReturnValue, string benchmark) { ! this.tickers = tickersToAnalyze; ! this.setEndOfDayDatesTime(startDate, endDate); ! this.minimumAbsoluteReturnValue = minimumAbsoluteReturnValue; ! this.maximumAbsoluteReturnValue = maximumAbsoluteReturnValue; this.benchmark = benchmark; - - this.numOfCombinationTwoByTwo = - (int)((Math.Pow(this.tickers.Length, 2) - this.tickers.Length ) / 2); - this.setReturnsManager(); } /// <summary> /// Creates the correlation provider --- 78,104 ---- /// of returns</param> public CorrelationProvider(string[] tickersToAnalyze, ! DateTime startDate, DateTime endDate, int returnIntervalLength, float minimumAbsoluteReturnValue, float maximumAbsoluteReturnValue, string benchmark) { ! this.correlationProvider_commonInitialization(tickersToAnalyze, ! minimumAbsoluteReturnValue, maximumAbsoluteReturnValue); ! this.setEndOfDayDatesTime(startDate,endDate); ! this.returnIntervalLength = returnIntervalLength; this.benchmark = benchmark; } + public CorrelationProvider(string[] tickersToAnalyze, + DateTime startDate, DateTime endDate, + float minimumAbsoluteReturnValue, float maximumAbsoluteReturnValue, + string benchmark) + { + this.correlationProvider_commonInitialization(tickersToAnalyze, + minimumAbsoluteReturnValue, maximumAbsoluteReturnValue); + this.setEndOfDayDatesTime(startDate,endDate); + this.returnIntervalLength = 1; + this.benchmark = benchmark; + } + /// <summary> /// Creates the correlation provider *************** *** 94,106 **** float minimumAbsoluteReturnValue, float maximumAbsoluteReturnValue ) { ! this.tickers = tickersToAnalyze; this.returnsManager = returnsManager; - this.minimumAbsoluteReturnValue = minimumAbsoluteReturnValue; - this.maximumAbsoluteReturnValue = maximumAbsoluteReturnValue; - - this.numOfCombinationTwoByTwo = - (int)((Math.Pow(this.tickers.Length, 2) - this.tickers.Length ) / 2); } ! protected abstract void setEndOfDayDatesTime(DateTime startDate, DateTime endDate); protected abstract void setReturnsManager(); --- 115,125 ---- float minimumAbsoluteReturnValue, float maximumAbsoluteReturnValue ) { ! this.correlationProvider_commonInitialization(tickersToAnalyze, ! minimumAbsoluteReturnValue, maximumAbsoluteReturnValue); this.returnsManager = returnsManager; } ! ! ! protected abstract void setEndOfDayDatesTime(DateTime startDate, DateTime endDate); protected abstract void setReturnsManager(); *************** *** 154,157 **** --- 173,178 ---- protected void getOrderedTickersPearsonCorrelations_setCorrelations() { + if(this.returnsManager == null) + this.setReturnsManager(); this.pearsonCorrelations = new TickersPearsonCorrelation[ this.numOfCombinationTwoByTwo ]; |
|
From: Marco M. <mi...@us...> - 2008-03-12 21:55:21
|
Update of /cvsroot/quantproject/QuantProject/b4_Business In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv860 Modified Files: b4_Business.csproj Business_SD.csproj Log Message: Added: - IAccountProvider interface; - InteractiveBrokerAccountProvider; -SimpleAccountProvider Index: Business_SD.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/Business_SD.csproj,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** Business_SD.csproj 7 Mar 2008 23:27:12 -0000 1.16 --- Business_SD.csproj 12 Mar 2008 21:55:13 -0000 1.17 *************** *** 61,64 **** --- 61,65 ---- <Compile Include="a07_DataProviders\HistoricalQuoteProvider.cs" /> <Compile Include="a07_DataProviders\TickerNotExchangedException.cs" /> + <Compile Include="a1_Financial\a2_Accounting\AccountProviding\IAccountProvider.cs" /> <Compile Include="a1_Financial\a2_Accounting\h5_Reporting\StatisticsSummaryRows\AverageReturnOnMonday.cs" /> <Compile Include="a1_Financial\a2_Accounting\h5_Reporting\SummaryRows\AverageNumberOfTransactionsPerDay.cs" /> *************** *** 232,235 **** --- 233,237 ---- <Name>b3_Data</Name> </ProjectReference> + <Folder Include="a1_Financial\a2_Accounting\AccountProviding" /> <Folder Include="a1_Financial\a2_Accounting\h5_Reporting\StatisticsSummaryRows" /> <Folder Include="a2_Strategies\EndOfDayStrategies" /> Index: b4_Business.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/b4_Business.csproj,v retrieving revision 1.58 retrieving revision 1.59 diff -C2 -d -r1.58 -r1.59 *** b4_Business.csproj 7 Mar 2008 23:27:12 -0000 1.58 --- b4_Business.csproj 12 Mar 2008 21:55:13 -0000 1.59 *************** *** 328,331 **** --- 328,346 ---- /> <File + RelPath = "a1_Financial\a2_Accounting\AccountProviding\IAccountProvider.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "a1_Financial\a2_Accounting\AccountProviding\InteractiveBrokerAccountProvider.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "a1_Financial\a2_Accounting\AccountProviding\SimpleAccountProvider.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "a1_Financial\a2_Accounting\Commissions\Commission.cs" SubType = "Code" |
Update of /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a2_Accounting/AccountProviding In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv32742 Added Files: IAccountProvider.cs InteractiveBrokerAccountProvider.cs SimpleAccountProvider.cs Log Message: Added: - IAccountProvider interface; - InteractiveBrokerAccountProvider; -SimpleAccountProvider --- NEW FILE: IAccountProvider.cs --- /* QuantProject - Quantitative Finance Library IAccountProvider.cs Copyright (C) 2008 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using QuantProject.Business.DataProviders; using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Strategies.Logging; using QuantProject.Business.Timing; namespace QuantProject.Business.Financial.Accounting.AccountProviding { /// <summary> /// Interface to be implemented by objects /// that provide a new account through the /// GetAccount method. /// These objects are used at the moment /// by the EndOfDaysStrategyBackTester /// </summary> public interface IAccountProvider : ILogDescriptor { /// <summary> /// Returns a new account /// </summary> /// <param name="instrumentKey">instrument identifier</param> /// <param name="endOfDayDateTime">end of day date time for the market evaluation</param> /// <returns></returns> Account GetAccount( IEndOfDayTimer timer , IHistoricalQuoteProvider historicalQuoteProvider ); } } --- NEW FILE: InteractiveBrokerAccountProvider.cs --- /* QuantProject - Quantitative Finance Library InteractiveBrokerAccountProvider.cs Copyright (C) 2008 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using QuantProject.ADT; using QuantProject.Business.DataProviders; using QuantProject.Business.Financial.Accounting.Commissions; using QuantProject.Business.Financial.Accounting.Slippage; using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Timing; namespace QuantProject.Business.Financial.Accounting.AccountProviding { /// <summary> /// IAccountProvider object that provides a typical account /// with Interactive Broker for individual traders, /// where commissions are managed and slippage can be simulated /// through a fixed percentage amount (on stock-price) /// lost at each stock-transaction /// </summary> public class InteractiveBrokerAccountProvider : IAccountProvider { private double slippageFixedPercentage; public InteractiveBrokerAccountProvider() { this.slippageFixedPercentage = 0.0; } public InteractiveBrokerAccountProvider(double slippageFixedPercentage) { if( slippageFixedPercentage < 0.0 || slippageFixedPercentage > 100.0 ) throw new OutOfRangeException(slippageFixedPercentage, 0.0, 100.0); this.slippageFixedPercentage = slippageFixedPercentage; } private ISlippageManager getAccount_getSlippageManager(IEndOfDayTimer timer , IHistoricalQuoteProvider historicalQuoteProvider) { ISlippageManager slippageManager; if(this.slippageFixedPercentage == 0.0) slippageManager = new ZeroSlippageManager(); else//this.slippageFixedPercentage > 0.0 slippageManager = new FixedPercentageSlippageManager( historicalQuoteProvider , timer , this.slippageFixedPercentage ); return slippageManager; } public Account GetAccount( IEndOfDayTimer timer , IHistoricalQuoteProvider historicalQuoteProvider ) { Account account = new Account( "IBAccount" , timer , new HistoricalEndOfDayDataStreamer( timer , historicalQuoteProvider ) , new HistoricalEndOfDayOrderExecutor( timer , historicalQuoteProvider , this.getAccount_getSlippageManager( timer , historicalQuoteProvider ) ), new IBCommissionManager() ); return account; } public string Description { get { string description = "IBAccountForIndividualTraders"; return description; } } } } --- NEW FILE: SimpleAccountProvider.cs --- /* QuantProject - Quantitative Finance Library SimpleAccountProvider.cs Copyright (C) 2008 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using QuantProject.Business.DataProviders; using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Timing; namespace QuantProject.Business.Financial.Accounting.AccountProviding { /// <summary> /// IAccountProvider object that provides an account /// with no commissions and slippage /// on orders /// </summary> public class SimpleAccountProvider : IAccountProvider { public SimpleAccountProvider() { } public Account GetAccount( IEndOfDayTimer timer , IHistoricalQuoteProvider historicalQuoteProvider ) { Account account = new Account( "SimpleAccount" , timer , new HistoricalEndOfDayDataStreamer( timer , historicalQuoteProvider ) , new HistoricalEndOfDayOrderExecutor( timer , historicalQuoteProvider ) ); return account; } public string Description { get { string description = "SimpleAccount_NoComm_NoSlippage"; return description; } } } } |
|
From: Marco M. <mi...@us...> - 2008-03-12 21:53:25
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a2_Accounting/AccountProviding In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv32039/AccountProviding Log Message: Directory /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a2_Accounting/AccountProviding added to the repository |
|
From: Marco M. <mi...@us...> - 2008-03-12 21:51:44
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv30900 Modified Files: ADT_SD.csproj b1_ADT.csproj Added Files: OutOfRangeException.cs Log Message: Added OutOfRangeException, the exception that should be thrown when a given number does not fit the expected range --- NEW FILE: OutOfRangeException.cs --- /* QuantProject - Quantitative Finance Library OutOfRangeException.cs Copyright (C) 2008 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; namespace QuantProject.ADT { /// <summary> /// It should be thrown when a given number /// is out of the desired range /// </summary> public class OutOfRangeException : Exception { private double outOfRangeNumber; private double minimumForValidRange; private double maximumForValidRange; public override string Message { get { return this.outOfRangeNumber.ToString() + "is out of range! It should be between " + this.minimumForValidRange.ToString() + " and " + this.maximumForValidRange.ToString(); } } public OutOfRangeException( double outOfRangeNumber, double minimumForValidRange, double maximumForValidRange) { this.outOfRangeNumber = outOfRangeNumber; this.minimumForValidRange = minimumForValidRange; this.maximumForValidRange = maximumForValidRange; } } } Index: ADT_SD.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/ADT_SD.csproj,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ADT_SD.csproj 19 Jan 2008 18:19:54 -0000 1.5 --- ADT_SD.csproj 12 Mar 2008 21:51:34 -0000 1.6 *************** *** 53,56 **** --- 53,57 ---- <Compile Include="ExtendedDateTime.cs" /> <Compile Include="HashProvider.cs" /> + <Compile Include="OutOfRangeException.cs" /> <Compile Include="IProgressNotifier.cs" /> <Compile Include="Keyed.cs" /> Index: b1_ADT.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/b1_ADT.csproj,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** b1_ADT.csproj 19 Jan 2008 18:20:26 -0000 1.27 --- b1_ADT.csproj 12 Mar 2008 21:51:35 -0000 1.28 *************** *** 148,151 **** --- 148,156 ---- /> <File + RelPath = "OutOfRangeException.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "RecursiveHashtable.cs" SubType = "Code" |
|
From: Marco M. <mi...@us...> - 2008-03-09 23:30:27
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv12013 Modified Files: b7_Scripts.csproj Log Message: Updated VS NET project's file Index: b7_Scripts.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/b7_Scripts.csproj,v retrieving revision 1.86 retrieving revision 1.87 diff -C2 -d -r1.86 -r1.87 *** b7_Scripts.csproj 9 Mar 2008 23:28:36 -0000 1.86 --- b7_Scripts.csproj 9 Mar 2008 23:30:10 -0000 1.87 *************** *** 330,338 **** /> <File - RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVO_OTCStrategy.cs" - SubType = "Code" - BuildAction = "Compile" - /> - <File RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVOGenomeManager.cs" SubType = "Code" --- 330,333 ---- |
|
From: Marco M. <mi...@us...> - 2008-03-09 23:28:43
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv10136 Modified Files: b7_Scripts.csproj Scripts_SD.csproj Log Message: Updated vs net and sharp develop project's files Index: Scripts_SD.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/Scripts_SD.csproj,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** Scripts_SD.csproj 6 Mar 2008 20:07:48 -0000 1.15 --- Scripts_SD.csproj 9 Mar 2008 23:28:37 -0000 1.16 *************** *** 49,52 **** --- 49,53 ---- <Compile Include="ArbitrageTesting\OverReactionHypothesis\DoubleOverReaction_OTC\RunDOR_OTC.cs" /> <Compile Include="AssemblyInfo.cs" /> + <Compile Include="EvaluatingOptimizationTechnique\TechnicalAnalysis\RunTestingOptimizationExtremeCounterTrend.cs" /> <Compile Include="General\Logging\LogArchiver.cs" /> <Compile Include="General\Logging\LogViewer.cs" /> *************** *** 59,65 **** --- 60,85 ---- <Compile Include="SimpleTesting\ShortTest\EndOfDayTimerHandler.cs" /> <Compile Include="SimpleTesting\ShortTest\RunShortTest.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\ExtremeCounterTrend\EndOfDayTimerHandlerECT.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\ExtremeCounterTrend\GenomeManagerECT.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\ExtremeCounterTrend\RunExtremeCounterTrend.cs" /> <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\EndOfDayTimerHandlerBiasedPVO_OTC.cs" /> <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\RunBiasedPVO_OTC.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\Decoding\BasicDecoderForPVOPositions.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\FitnessEvaluators\PVOFitnessEvaluator.cs" /> <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\GenomeManagerPVO_OTC.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\InSampleChoosers\PVOCorrelationChooser.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\InSampleChoosers\PVOGeneticChooser.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVOGenomeManager.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVOLogItem.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVOMain.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVOPositions.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVOPositionsStatus.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVOStrategy.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\EndOfDayTimerHandlerWeightedPVO.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\GenomeManagerWeightedPVO.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\RunWeightedPVO.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\WeightedBalancedPVO\EndOfDayTimerHandlerWeightedBalancedPVO.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\WeightedBalancedPVO\GenomeManagerWeightedBalancedPVO.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\WeightedBalancedPVO\RunWeightedBalancedPVO.cs" /> <Compile Include="TickerSelectionTesting\EndOfDayTimerHandlerCTC.cs" /> <Compile Include="TickerSelectionTesting\EndOfDayTimerHandlerCTO.cs" /> *************** *** 69,72 **** --- 89,93 ---- <Compile Include="TickerSelectionTesting\RunEfficientCTCPortfolio.cs" /> <Compile Include="TickerSelectionTesting\RunEfficientCTOPortfolio.cs" /> + <Compile Include="WalkForwardTesting\FixedLengthTwoPhases\FixedLengthTwoPhasesLogItem.cs" /> <Compile Include="WalkForwardTesting\FixedLengthTwoPhases\FixedLengthTwoPhasesMain.cs" /> <Compile Include="WalkForwardTesting\FixedLengthTwoPhases\FixedLengthTwoPhasesStrategy.cs" /> *************** *** 167,171 **** <Compile Include="ArbitrageTesting\PairTrading\SimplePairTrading\InSample\RunSimplePairTradingIS.cs" /> <Compile Include="EvaluatingOptimizationTechnique\EfficientPortfolio\RunTestingOptimizationOpenToCloseFitnessCombined.cs" /> - <Compile Include="EvaluatingOptimizationTechnique\TechnicalAnalysis\RunTestingOptimizationExtremeCounterTrend.cs" /> <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedPeriodOscillators\RunFPOscillatorCTC.cs" /> <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedPeriodOscillators\EndOfDayTimerHandlerFPOscillatorCTC.cs" /> --- 188,191 ---- *************** *** 188,194 **** <Compile Include="ArbitrageTesting\PairTrading\SimplePairTrading\InSample\GenomeRepresentation.cs" /> <Compile Include="ArbitrageTesting\PairTrading\SimplePairTrading\InSample\OptimizationOutput.cs" /> - <Compile Include="TechnicalAnalysisTesting\Oscillators\ExtremeCounterTrend\RunExtremeCounterTrend.cs" /> - <Compile Include="TechnicalAnalysisTesting\Oscillators\ExtremeCounterTrend\EndOfDayTimerHandlerECT.cs" /> - <Compile Include="TechnicalAnalysisTesting\Oscillators\ExtremeCounterTrend\GenomeManagerECT.cs" /> <Compile Include="WalkForwardTesting\LinearCombination\ExtremeCounterTrendStrategy.cs" /> <Compile Include="WalkForwardTesting\LinearCombination\FixedPeriodOscillatorStrategy.cs" /> --- 208,211 ---- *************** *** 220,229 **** <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\EndOfDayTimerHandlerBiasedPVO.cs" /> <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\RunBiasedPVO.cs" /> - <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\EndOfDayTimerHandlerWeightedPVO.cs" /> - <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\GenomeManagerWeightedPVO.cs" /> - <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\RunWeightedPVO.cs" /> - <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\WeightedBalancedPVO\EndOfDayTimerHandlerWeightedBalancedPVO.cs" /> - <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\WeightedBalancedPVO\GenomeManagerWeightedBalancedPVO.cs" /> - <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\WeightedBalancedPVO\RunWeightedBalancedPVO.cs" /> <Compile Include="WalkForwardTesting\LinearCombination\FixedLevelOscillatorBiasedPVOStrategy.cs" /> <Compile Include="WalkForwardTesting\WalkForwardLag\WFLagNewChosenPositionsEventArgs.cs" /> --- 237,240 ---- *************** *** 249,255 **** --- 260,273 ---- <Folder Include="EvaluatingOptimizationTechnique\" /> <Folder Include="EvaluatingOptimizationTechnique\EfficientPortfolio\" /> + <Folder Include="BackTesting" /> + <Folder Include="TechnicalAnalysisTesting\Oscillators\ExtremeCounterTrend" /> + <Folder Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\Decoding" /> <Folder Include="General" /> <Folder Include="General\Logging" /> <Folder Include="General\Reporting" /> + <Folder Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\FitnessEvaluators" /> + <Folder Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\InSampleChoosers" /> + <Folder Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO" /> + <Folder Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\WeightedBalancedPVO" /> <Folder Include="TickerSelectionTesting\SimpleSelection\" /> <Folder Include="WalkForwardTesting\FixedLengthTwoPhases" /> *************** *** 269,273 **** <Folder Include="TechnicalAnalysisTesting\Oscillators\" /> <Folder Include="TechnicalAnalysisTesting\Oscillators\FixedPeriodOscillators\" /> - <Folder Include="TechnicalAnalysisTesting\Oscillators\ExtremeCounterTrend\" /> <ProjectReference Include="..\b1_ADT\ADT_SD.csproj"> <Project>{6A426DC3-013E-4D38-A1AE-7BE128BF2DD7}</Project> --- 287,290 ---- *************** *** 299,304 **** <Folder Include="WalkForwardTesting\WalkForwardLag\GeneticOptimizerTesting" /> <Folder Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO" /> - <Folder Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO" /> - <Folder Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\WeightedBalancedPVO" /> <Folder Include="WalkForwardTesting\WalkForwardLag\WeightedPositionsChoosers" /> <Folder Include="ArbitrageTesting\OverReactionHypothesis" /> --- 316,319 ---- Index: b7_Scripts.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/b7_Scripts.csproj,v retrieving revision 1.85 retrieving revision 1.86 diff -C2 -d -r1.85 -r1.86 *** b7_Scripts.csproj 6 Mar 2008 20:04:18 -0000 1.85 --- b7_Scripts.csproj 9 Mar 2008 23:28:36 -0000 1.86 *************** *** 254,262 **** /> <File - RelPath = "General\Logging\LogViewer.resx" - DependentUpon = "LogViewer.cs" - BuildAction = "EmbeddedResource" - /> - <File RelPath = "General\Reporting\BackTesterReportViewer.cs" SubType = "Code" --- 254,257 ---- *************** *** 335,338 **** --- 330,368 ---- /> <File + RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVO_OTCStrategy.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVOGenomeManager.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVOLogItem.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVOMain.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVOPositions.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVOPositionsStatus.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\PVOStrategy.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\RunPVO.cs" SubType = "Code" *************** *** 360,363 **** --- 390,413 ---- /> <File + RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\Decoding\BasicDecoderForPVOPositions.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\FitnessEvaluators\PVOFitnessEvaluator.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\InSampleChoosers\PVOCorrelationChooser.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\InSampleChoosers\PVOGeneticChooser.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\EndOfDayTimerHandlerWeightedPVO.cs" SubType = "Code" |
|
From: Marco M. <mi...@us...> - 2008-03-09 22:49:28
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv6639/Oscillators/FixedLevelOscillators/PortfolioValueOscillator Added Files: PVOGenomeManager.cs PVOLogItem.cs PVOMain.cs PVOPositions.cs PVOPositionsStatus.cs PVOStrategy.cs Log Message: Added a new implementation for the PVO strategy (now common objects recently added at business layer by Glauco are used). At the moment, these files perform a PVO strategy using close to close returns, on a multiday - minimum 1 day - basis. Take profit and stop loss levels can be set. --- NEW FILE: PVOStrategy.cs --- /* QuantProject - Quantitative Finance Library PVOStrategy.cs Copyright (C) 2008 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Data; using System.Collections; using QuantProject.ADT; using QuantProject.ADT.Messaging; using QuantProject.Business.Financial.Accounting; using QuantProject.Business.Financial.Instruments; using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Timing; using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.OutOfSample; using QuantProject.Business.Strategies.Logging; using QuantProject.Business.Strategies.ReturnsManagement; using QuantProject.Business.Strategies.ReturnsManagement.Time; using QuantProject.Business.DataProviders; using QuantProject.Business.Strategies.TickersRelationships; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.Optimizing.Decoding; using QuantProject.Data; using QuantProject.Data.DataProviders; using QuantProject.Data.Selectors; using QuantProject.Data.DataTables; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Scripts.WalkForwardTesting.LinearCombination; namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator { /// <summary> /// Implements MarketOpenEventHandler and MarketCloseEventHandler /// These handlers contain the core strategy for the Portfolio Value /// Oscillator /// </summary> [Serializable] public class PVOStrategy : IEndOfDayStrategyForBacktester { public event NewLogItemEventHandler NewLogItem; public event NewMessageEventHandler NewMessage; //initialized by the constructor protected int numberOfTickersToBeChosen; protected int inSampleDays; protected int numDaysBetweenEachOptimization; protected IInSampleChooser inSampleChooser; protected IEligiblesSelector eligiblesSelector; protected Benchmark benchmark; protected HistoricalQuoteProvider historicalQuoteProvider; protected double maxAcceptableCloseToCloseDrawdown; protected double minimumAcceptableGain; protected int numDaysForOscillatingPeriod; //initialized after constructor's call protected int numDaysElapsedSinceLastOptimization; protected ReturnsManager returnsManager; protected TestingPositions[] chosenPVOPositions; //chosen in sample: these are the eligible positions for out //of sample testing protected PVOPositions pvoPositionsForOutOfSample; protected DateTime lastCloseDate; protected bool portfolioHasBeenOverbought; protected bool portfolioHasBeenOversold; protected Account account; public Account Account { set { this.account = value; } } protected bool stopLossConditionReached; protected bool takeProfitConditionReached; protected double currentAccountValue; protected double previousAccountValue; private string description_GetDescriptionForChooser() { if(this.inSampleChooser == null) return "ConstantChooser"; else return this.inSampleChooser.Description; } public string Description { get { string description = "PVO_" + "nmbrTckrs_" + this.numberOfTickersToBeChosen.ToString() + "_inSmplDays_" + this.inSampleDays.ToString() + "_" + this.eligiblesSelector.Description + "_" + this.description_GetDescriptionForChooser(); return description; } } public bool StopBacktestIfMaxRunningHoursHasBeenReached { get { return true; } } private void pvoStrategy(IEligiblesSelector eligiblesSelector, int inSampleDays, int numDaysForOscillatingPeriod, int numberOfTickersToBeChosen, Benchmark benchmark, int numDaysBetweenEachOptimization, HistoricalQuoteProvider historicalQuoteProvider, double maxAcceptableCloseToCloseDrawdown, double minimumAcceptableGain) { this.eligiblesSelector = eligiblesSelector; this.inSampleDays = inSampleDays; this.numDaysForOscillatingPeriod = numDaysForOscillatingPeriod; this.numberOfTickersToBeChosen = numberOfTickersToBeChosen; this.benchmark = benchmark; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; this.historicalQuoteProvider = historicalQuoteProvider; this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; this.minimumAcceptableGain = minimumAcceptableGain; this.stopLossConditionReached = false; this.currentAccountValue = 0.0; this.previousAccountValue = 0.0; this.portfolioHasBeenOverbought = false; this.portfolioHasBeenOversold = false; } public PVOStrategy(IEligiblesSelector eligiblesSelector, IInSampleChooser inSampleChooser, int inSampleDays, int numDaysForOscillatingPeriod, int numberOfTickersToBeChosen, Benchmark benchmark, int numDaysBetweenEachOptimization, HistoricalQuoteProvider historicalQuoteProvider, double maxAcceptableCloseToCloseDrawdown, double minimumAcceptableGain) { this.pvoStrategy(eligiblesSelector, inSampleDays , numDaysForOscillatingPeriod , numberOfTickersToBeChosen , benchmark , numDaysBetweenEachOptimization , historicalQuoteProvider , maxAcceptableCloseToCloseDrawdown , minimumAcceptableGain ); this.inSampleChooser = inSampleChooser; } public PVOStrategy(IEligiblesSelector eligiblesSelector, TestingPositions[] chosenPVOPositions, int inSampleDays, int numDaysForOscillatingPeriod, int numberOfTickersToBeChosen, Benchmark benchmark, int numDaysBetweenEachOptimization, HistoricalQuoteProvider historicalQuoteProvider, double maxAcceptableCloseToCloseDrawdown, double minimumAcceptableGain) { this.pvoStrategy(eligiblesSelector, inSampleDays , numDaysForOscillatingPeriod , numberOfTickersToBeChosen , benchmark , numDaysBetweenEachOptimization , historicalQuoteProvider , maxAcceptableCloseToCloseDrawdown , minimumAcceptableGain ); this.chosenPVOPositions = chosenPVOPositions; } public virtual void MarketOpenEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ; } public void FiveMinutesBeforeMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { } private EndOfDayDateTime now() { return this.account.EndOfDayTimer.GetCurrentTime(); } #region MarketCloseEventHandler //forOutOfSampleTesting protected virtual EndOfDayDateTime getBeginOfOscillatingPeriod(IndexBasedEndOfDayTimer timer) { return new EndOfDayDateTime( (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition-this.numDaysForOscillatingPeriod]["quDate"], EndOfDaySpecificTime.MarketClose ); } private void marketCloseEventHandler_reverseIfNeeded_reverse(PVOPositionsStatus currentStatus) { if(currentStatus == PVOPositionsStatus.Overbought) { this.portfolioHasBeenOversold = false; this.portfolioHasBeenOverbought = true; } else if(currentStatus == PVOPositionsStatus.Oversold) { this.portfolioHasBeenOversold = true; this.portfolioHasBeenOverbought = false; } AccountManager.ReversePositions(this.account); this.previousAccountValue = this.account.GetMarketValue(); } private void marketCloseEventHandler_reverseIfNeeded(IndexBasedEndOfDayTimer timer) { EndOfDayDateTime today = timer.GetCurrentTime(); EndOfDayDateTime beginOfOscillatingPeriod = this.getBeginOfOscillatingPeriod(timer); PVOPositionsStatus pvoPositionsStatus = this.pvoPositionsForOutOfSample.GetStatus(beginOfOscillatingPeriod, today , this.benchmark.Ticker, this.historicalQuoteProvider); if(pvoPositionsStatus == PVOPositionsStatus.Overbought && this.portfolioHasBeenOversold) //open positions derive from an overSold period but now //the overbought threshold has been reached this.marketCloseEventHandler_reverseIfNeeded_reverse(pvoPositionsStatus); if(pvoPositionsStatus == PVOPositionsStatus.Oversold && this.portfolioHasBeenOverbought) //open positions derive from an overBought period but now //the overSold threshold has been reached this.marketCloseEventHandler_reverseIfNeeded_reverse(pvoPositionsStatus); } private PVOPositionsStatus marketCloseEventHandler_openPositions_getStatus(IndexBasedEndOfDayTimer timer) { EndOfDayDateTime today = timer.GetCurrentTime(); EndOfDayDateTime beginOfOscillatingPeriod = this.getBeginOfOscillatingPeriod(timer); PVOPositionsStatus currentStatus = PVOPositionsStatus.InTheMiddle; for(int i = 0; i<this.chosenPVOPositions.Length; i++) { if(this.chosenPVOPositions[i] != null) currentStatus = ((PVOPositions)this.chosenPVOPositions[i]).GetStatus(beginOfOscillatingPeriod, today, this.benchmark.Ticker, this.historicalQuoteProvider); if(currentStatus == PVOPositionsStatus.Oversold || currentStatus == PVOPositionsStatus.Overbought ) { this.pvoPositionsForOutOfSample = (PVOPositions)this.chosenPVOPositions[i]; i = this.chosenPVOPositions.Length;//exit from for } } return currentStatus; } protected void marketCloseEventHandler_openPositions(IndexBasedEndOfDayTimer timer) { PVOPositionsStatus pvoPositionsStatus = PVOPositionsStatus.InTheMiddle; if(timer.CurrentDateArrayPosition >= this.numDaysForOscillatingPeriod) pvoPositionsStatus = this.marketCloseEventHandler_openPositions_getStatus(timer); switch (pvoPositionsStatus){ case PVOPositionsStatus.Overbought: { #region manage Overbought case this.pvoPositionsForOutOfSample.WeightedPositions.Reverse(); try{ AccountManager.OpenPositions( this.pvoPositionsForOutOfSample.WeightedPositions, this.account ); this.portfolioHasBeenOverbought = true; this.portfolioHasBeenOversold = false; this.previousAccountValue = this.account.GetMarketValue(); } catch(Exception ex){ ex = ex; } finally{ this.pvoPositionsForOutOfSample.WeightedPositions.Reverse(); } #endregion break; } case PVOPositionsStatus.Oversold: { #region manage Oversold case AccountManager.OpenPositions( this.pvoPositionsForOutOfSample.WeightedPositions, this.account ); this.portfolioHasBeenOverbought = false; this.portfolioHasBeenOversold = true; this.previousAccountValue = this.account.GetMarketValue(); #endregion break; } case PVOPositionsStatus.InTheMiddle://that is { //pvoPositionsForOutOfSample has not been set this.previousAccountValue = this.account.GetMarketValue(); break; } default: { //it should never been reached this.previousAccountValue = this.account.GetMarketValue(); break; } } } protected virtual void marketCloseEventHandler_closePositionsIfNeeded() { if(this.stopLossConditionReached || this.takeProfitConditionReached || this.numDaysElapsedSinceLastOptimization + 1 == this.numDaysBetweenEachOptimization ) { AccountManager.ClosePositions(this.account); this.portfolioHasBeenOverbought = false; this.portfolioHasBeenOversold = false; } } protected virtual void marketCloseEventHandler_updateStopLossAndTakeProfitConditions() { //this.previousAccountValue has been set at opening positions this.stopLossConditionReached = false; this.takeProfitConditionReached = false; this.currentAccountValue = this.account.GetMarketValue(); double portfolioGainOrLoss = (this.currentAccountValue - this.previousAccountValue) /this.previousAccountValue; if(!double.IsInfinity(portfolioGainOrLoss) && portfolioGainOrLoss <= -this.maxAcceptableCloseToCloseDrawdown ) { this.stopLossConditionReached = true; this.takeProfitConditionReached = false; } else if (!double.IsInfinity(portfolioGainOrLoss) && portfolioGainOrLoss >= this.minimumAcceptableGain ) { this.stopLossConditionReached = false; this.takeProfitConditionReached = true; } } public virtual void MarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { try{ this.marketCloseEventHandler_updateStopLossAndTakeProfitConditions(); this.marketCloseEventHandler_closePositionsIfNeeded(); if( this.chosenPVOPositions != null ) //PVOPositions have been chosen by the chooser { if(this.account.Portfolio.Count == 0) this.marketCloseEventHandler_openPositions((IndexBasedEndOfDayTimer)sender); //positions are opened only if thresholds are reached else//there are some opened positions this.marketCloseEventHandler_reverseIfNeeded((IndexBasedEndOfDayTimer)sender); } } catch(TickerNotExchangedException ex) {ex=ex;} } #endregion #region OneHourAfterMarketCloseEventHandler protected virtual void updateReturnsManager(EndOfDayDateTime firstEndOfDayDateTime, EndOfDayDateTime lastEndOfDayDateTime) { this.returnsManager = new ReturnsManager(new CloseToCloseIntervals(firstEndOfDayDateTime, lastEndOfDayDateTime, this.benchmark.Ticker, this.numDaysForOscillatingPeriod), this.historicalQuoteProvider); } private PVOLogItem getLogItem( EligibleTickers eligibleTickers ) { PVOLogItem logItem = new PVOLogItem( this.now() ); logItem.BestPVOPositionsInSample = this.chosenPVOPositions; logItem.NumberOfEligibleTickers = eligibleTickers.Count; logItem.FitnessOfFirst = this.chosenPVOPositions[0].FitnessInSample; logItem.FitnessOfLast = this.chosenPVOPositions[this.chosenPVOPositions.Length - 1].FitnessInSample; logItem.GenerationOfFirst = ((IGeneticallyOptimizable)this.chosenPVOPositions[0]).Generation; logItem.GenerationOfLast = ((IGeneticallyOptimizable)this.chosenPVOPositions[this.chosenPVOPositions.Length - 1]).Generation; logItem.ThresholdsOfFirst = ((PVOPositions)this.chosenPVOPositions[0]).OversoldThreshold.ToString() + ";" + ((PVOPositions)this.chosenPVOPositions[0]).OverboughtThreshold.ToString(); logItem.ThresholdsOfLast = ((PVOPositions)this.chosenPVOPositions[this.chosenPVOPositions.Length - 1]).OversoldThreshold.ToString() + ";" + ((PVOPositions)this.chosenPVOPositions[this.chosenPVOPositions.Length - 1]).OverboughtThreshold.ToString(); logItem.TickersOfFirst = this.chosenPVOPositions[0].HashCodeForTickerComposition; logItem.TickersOfLast = this.chosenPVOPositions[this.chosenPVOPositions.Length - 1].HashCodeForTickerComposition; return logItem; } private void raiseNewLogItem( EligibleTickers eligibleTickers ) { PVOLogItem logItem = this.getLogItem( eligibleTickers ); NewLogItemEventArgs newLogItemEventArgs = new NewLogItemEventArgs( logItem ); this.NewLogItem( this , newLogItemEventArgs ); } private void notifyMessage( EligibleTickers eligibleTickers ) { string message = "Number of Eligible tickers: " + eligibleTickers.Count; NewMessageEventArgs newMessageEventArgs = new NewMessageEventArgs( message ); if ( this.NewMessage != null ) this.NewMessage( this , newMessageEventArgs ); } private void logOptimizationInfo( EligibleTickers eligibleTickers ) { this.raiseNewLogItem( eligibleTickers ); this.notifyMessage( eligibleTickers ); } protected virtual void updateTestingPositions(DateTime currentDate) { EndOfDayHistory endOfDayHistory = this.benchmark.GetEndOfDayHistory( new EndOfDayDateTime(currentDate.AddDays(-this.inSampleDays), EndOfDaySpecificTime.MarketClose), new EndOfDayDateTime(currentDate, EndOfDaySpecificTime.MarketClose)); EligibleTickers eligibles = this.eligiblesSelector.GetEligibleTickers(endOfDayHistory); this.updateReturnsManager(endOfDayHistory.FirstEndOfDayDateTime, endOfDayHistory.LastEndOfDayDateTime); if(this.inSampleChooser != null) this.chosenPVOPositions = (TestingPositions[])inSampleChooser.AnalyzeInSample(eligibles, this.returnsManager ); this.logOptimizationInfo(eligibles); } /// <summary> /// Handles a "One hour after market close" event. /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> public virtual void OneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { this.lastCloseDate = endOfDayTimingEventArgs.EndOfDayDateTime.DateTime; this.numDaysElapsedSinceLastOptimization++; if((this.numDaysElapsedSinceLastOptimization == this.numDaysBetweenEachOptimization)) //num days without optimization has elapsed { this.updateTestingPositions(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime); //sets tickers to be chosen next Market Close event this.numDaysElapsedSinceLastOptimization = 0; } } #endregion } } --- NEW FILE: PVOLogItem.cs --- /* QuantProject - Quantitative Finance Library PVOLogItem.cs Copyright (C) 2008 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using QuantProject.Business.DataProviders; using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.InSample; using QuantProject.Business.Strategies.OutOfSample; using QuantProject.Business.Strategies.Logging; using QuantProject.Business.Strategies.ReturnsManagement.Time; using QuantProject.Business.Strategies.ReturnsManagement.Time.IntervalsSelectors; using QuantProject.Business.Timing; using QuantProject.Scripts.General.Reporting; namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator { /// <summary> /// LogItem for the PVO strategy /// portfolio value oscillator strategy /// </summary> [Serializable] public class PVOLogItem : LogItem { // static public Random rand = new Random(4676); private TestingPositions[] bestPVOPositionsInSample; private int numberOfEligibleTickers; private double fitnessOfFirstPVOPositionsInSample; private double fitnessOfLastPVOPositionsInSample; private int generationOfFirstPVOPositionsInSample; private int generationOfLastPVOPositionsInSample; private string thresholdsOfFirst; private string thresholdsOfLast; private string tickersOfFirst; private string tickersOfLast; public TestingPositions[] BestPVOPositionsInSample { get { if ( this.bestPVOPositionsInSample == null ) throw new Exception( "This property has not " + "been assigned yet! If you are loading the LogItem from " + "a log, this property was not set before logging the LogItem." ); return this.bestPVOPositionsInSample; } set { this.bestPVOPositionsInSample = value; } } public int NumberOfEligibleTickers { get { if ( this.numberOfEligibleTickers == int.MinValue ) throw new Exception( "This property has not " + "been assigned yet! If you are loading the LogItem from " + "a log, this property was not set before logging the LogItem." ); return this.numberOfEligibleTickers; } set { this.numberOfEligibleTickers = value; } } public double FitnessOfFirst { get { if ( this.fitnessOfFirstPVOPositionsInSample == double.MinValue ) throw new Exception( "This property has not " + "been assigned yet! If you are loading the LogItem from " + "a log, this property was not set before logging the LogItem." ); return this.fitnessOfFirstPVOPositionsInSample; } set { this.fitnessOfFirstPVOPositionsInSample = value; } } public double FitnessOfLast { get { if ( this.fitnessOfLastPVOPositionsInSample == double.MinValue ) throw new Exception( "This property has not " + "been assigned yet! If you are loading the LogItem from " + "a log, this property was not set before logging the LogItem." ); return this.fitnessOfLastPVOPositionsInSample; } set { this.fitnessOfLastPVOPositionsInSample = value; } } public int GenerationOfFirst { get{return this.generationOfFirstPVOPositionsInSample;} set{this.generationOfFirstPVOPositionsInSample = value;} } public int GenerationOfLast { get{return this.generationOfLastPVOPositionsInSample;} set{this.generationOfLastPVOPositionsInSample = value;} } public string ThresholdsOfFirst { get{return this.thresholdsOfFirst;} set{this.thresholdsOfFirst = value;} } public string ThresholdsOfLast { get{return this.thresholdsOfLast;} set{this.thresholdsOfLast = value;} } public string TickersOfFirst { get{return this.tickersOfFirst;} set{this.tickersOfFirst = value;} } public string TickersOfLast { get{return this.tickersOfLast;} set{this.tickersOfLast = value;} } public PVOLogItem(EndOfDayDateTime endOfDayDateTime ) : base( endOfDayDateTime ) { this.numberOfEligibleTickers = int.MinValue; this.fitnessOfFirstPVOPositionsInSample = double.MinValue; this.fitnessOfLastPVOPositionsInSample = double.MinValue; } public override void Run() { //general int inSampleDays = 120; DateTime firstDateTime = this.SimulatedCreationTime.DateTime.AddDays(-inSampleDays); DateTime lastDateTime = this.SimulatedCreationTime.DateTime; double maxRunningHours = 1; Benchmark benchmark = new Benchmark( "^GSPC" ); // definition for the Fitness Evaluator (for // objects that use it) int numDaysForOscillatingPeriodForChooser = ((PVOPositions)this.BestPVOPositionsInSample[0]).NumDaysForOscillatingPeriod; int numberOfPortfolioPositions = this.BestPVOPositionsInSample[0].WeightedPositions.Count; //cash and portfolio type double cashToStart = 30000; double maxAcceptableCloseToCloseDrawdown = 0.02; double minimumAcceptableGain = 0.007; HistoricalQuoteProvider historicalQuoteProviderForBackTester, historicalQuoteProviderForInSampleChooser, historicalQuoteProviderForStrategy; historicalQuoteProviderForBackTester = new HistoricalAdjustedQuoteProvider(); historicalQuoteProviderForInSampleChooser = historicalQuoteProviderForBackTester; historicalQuoteProviderForStrategy = historicalQuoteProviderForInSampleChooser; IEligiblesSelector eligiblesSelector = new DummyEligibleSelector(); //strategyParameters int numDaysForOscillatingPeriodForOutOfSample = numDaysForOscillatingPeriodForChooser; TestingPositions[] positionsToTest = new TestingPositions[1]; // int idx = PVOLogItem.rand.Next(bestPVOPositionsInSample.Length); positionsToTest[0] = this.bestPVOPositionsInSample[0]; PVOStrategy strategy = new PVOStrategy(eligiblesSelector, positionsToTest, inSampleDays, numDaysForOscillatingPeriodForOutOfSample, numberOfPortfolioPositions , benchmark , int.MaxValue , historicalQuoteProviderForStrategy , maxAcceptableCloseToCloseDrawdown , minimumAcceptableGain ); EndOfDayStrategyBackTester endOfDayStrategyBackTester = new EndOfDayStrategyBackTester( "PVO" , strategy , historicalQuoteProviderForBackTester , firstDateTime , lastDateTime , benchmark , cashToStart , maxRunningHours ); // TO DO check if you can do this assign in the EndOfDayStrategyBackTester // constructor strategy.Account = endOfDayStrategyBackTester.Account; endOfDayStrategyBackTester.Run(); BackTesterReportViewer.ShowReport( lastDateTime , endOfDayStrategyBackTester ); } } } --- NEW FILE: PVOPositionsStatus.cs --- /* QuantProject - Quantitative Finance Library PVOPositionsStatus.cs Copyright (C) 2008 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator { /// <summary> /// Specifies in which status a given PVOPositions /// is /// </summary> [Serializable] public enum PVOPositionsStatus { Oversold, InTheMiddle, Overbought, TooDistantFromThresholds } } --- NEW FILE: PVOMain.cs --- /* QuantProject - Quantitative Finance Library PVOMain.cs Copyright (C) 2008 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections; using System.IO; using QuantProject.ADT; using QuantProject.ADT.FileManaging; using QuantProject.Business.DataProviders; using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.EquityEvaluation; using QuantProject.Business.Strategies.Logging; using QuantProject.Business.Strategies.Optimizing.Decoding; using QuantProject.Business.Strategies.Optimizing.FitnessEvaluation; using QuantProject.Business.Strategies.ReturnsManagement; using QuantProject.Business.Strategies.ReturnsManagement.Time; using QuantProject.Business.Strategies.ReturnsManagement.Time.IntervalsSelectors; using QuantProject.Business.Timing; using QuantProject.Presentation; using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.InSampleChoosers; using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.Decoding; using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.FitnessEvaluators; using QuantProject.Scripts.General.Logging; using QuantProject.Scripts.General.Reporting; namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator { /// <summary> /// Entry point for the PVO strategy. If any strategy /// parameter had to be changed, this is the place where it should /// be done /// </summary> public class PVOMain { private string strategyIdentifier; private string fileNameWithoutExt; private string dirNameWhereToSaveResults; public PVOMain() { this.strategyIdentifier = "PVO"; } private void setFileNamesAndDirectory(EndOfDayStrategyBackTester endOfDayStrategyBackTester) { if(this.fileNameWithoutExt == null) { this.fileNameWithoutExt = this.strategyIdentifier + "_" + DateTime.Now.Hour.ToString().PadLeft(2,'0') + "_" + DateTime.Now.Minute.ToString().PadLeft(2,'0') + "_" + DateTime.Now.Second.ToString().PadLeft(2,'0'); this.dirNameWhereToSaveResults = System.Configuration.ConfigurationSettings.AppSettings["LogArchive"] + "\\" + fileNameWithoutExt + "\\"; if( !Directory.Exists(dirNameWhereToSaveResults) ) Directory.CreateDirectory(dirNameWhereToSaveResults); } } #region Run private MessageManager setMessageManager( IEligiblesSelector eligiblesSelector , IInSampleChooser inSampleChooser , IEndOfDayStrategy endOfDayStrategy , EndOfDayStrategyBackTester endOfDayStrategyBackTester ) { this.setFileNamesAndDirectory(endOfDayStrategyBackTester); string fullPathFileNameForMessagesLog = dirNameWhereToSaveResults + this.fileNameWithoutExt + "LogMessages.txt"; MessageManager messageManager = new MessageManager( fullPathFileNameForMessagesLog ); messageManager.Monitor( eligiblesSelector ); messageManager.Monitor( inSampleChooser ); // messageManager.Monitor( endOfDayStrategy ); messageManager.Monitor( endOfDayStrategyBackTester ); return messageManager; } // TO DO check if you can add this to QuantProject.Presentation.Reporting.WindowsForm.Report // as a public method or as a new constructor // private void showReport( // DateTime lastDateTimeRequestedForTheScript , // EndOfDayStrategyBackTester endOfDayStrategyBackTester ) // { //// DateTime lastReportDateTime = ExtendedDateTime.Min( //// lastDateTimeRequestedForTheScript , //// endOfDayStrategyBackTester.EndOfDayTimer.GetCurrentTime().DateTime ); // DateTime lastReportDateTime = // endOfDayStrategyBackTester.ActualLastDateTime; // Report report = new Report( // endOfDayStrategyBackTester.AccountReport , // true ); // report.Create( endOfDayStrategyBackTester.DescriptionForLogFileName , 1 , // new EndOfDayDateTime( lastReportDateTime , // EndOfDaySpecificTime.OneHourAfterMarketClose ) , // endOfDayStrategyBackTester.Benchmark.Ticker ); // report.Show(); // } //Saves (in silent mode): //- a log file where the In Sample Analysis are // stored; //- a report; //- a txt file with a full description of the // strategy's features private void saveScriptResults( EndOfDayStrategyBackTester endOfDayStrategyBackTester ) { this.setFileNamesAndDirectory(endOfDayStrategyBackTester); string fullPathFileNameForLog = dirNameWhereToSaveResults + this.fileNameWithoutExt + ".qpL"; string fullPathFileNameForReport = dirNameWhereToSaveResults + this.fileNameWithoutExt + ".qpR"; string fullPathFileNameForParametersLog = dirNameWhereToSaveResults + this.fileNameWithoutExt + "_Parameters.txt"; ObjectArchiver.Archive(endOfDayStrategyBackTester.Log, fullPathFileNameForLog); ObjectArchiver.Archive(endOfDayStrategyBackTester.AccountReport, fullPathFileNameForReport); StreamWriter w = File.AppendText(fullPathFileNameForParametersLog); w.WriteLine ("\n---\r\n"); w.WriteLine ( endOfDayStrategyBackTester.Description ); w.WriteLine ("\n---\r\n"); w.Flush(); w.Close(); } public void Run() { //general DateTime firstDateTime = new DateTime( 2000 , 6 , 1 ); DateTime lastDateTime = new DateTime( 2000 , 7 , 31 ); double maxRunningHours = 5; Benchmark benchmark = new Benchmark( "^GSPC" ); // definition for the Fitness Evaluator (for // objects that use it) IEquityEvaluator equityEvaluator = new SharpeRatio(); //cash and portfolio type double cashToStart = 30000; int numberOfPortfolioPositions = 4; // parameters for the in sample Chooser double crossoverRate = 0.85; double mutationRate = 0.02; double elitismRate = 0.001; int populationSizeForGeneticOptimizer = 500; int generationNumberForGeneticOptimizer = 10; int numberOfBestTestingPositionsToBeReturnedInSample = 5; int seedForRandomGenerator = QuantProject.ADT.ConstantsProvider.SeedForRandomGenerator; int numDaysBetweenEachOptimization = 15; int minLevelForOversoldThreshold = 50; int maxLevelForOversoldThreshold = 100; int minLevelForOverboughtThreshold = 50; int maxLevelForOverboughtThreshold = 100; int divisorForThresholdComputation = 10000; int numDaysForOscillatingPeriodForChooser = 1; //for genetic optimization bool symmetricalThresholds = true; bool overboughtMoreThanOversoldForFixedPortfolio = false; double maxAcceptableCloseToCloseDrawdown = 0.03; double minimumAcceptableGain = 0.008; IDecoderForTestingPositions decoderForTestingPositions = new BasicDecoderForPVOPositions(symmetricalThresholds, divisorForThresholdComputation , numDaysForOscillatingPeriodForChooser); IFitnessEvaluator fitnessEvaluator = new PVOFitnessEvaluator( equityEvaluator ); HistoricalQuoteProvider historicalQuoteProviderForBackTester, historicalQuoteProviderForInSampleChooser, historicalQuoteProviderForStrategy; historicalQuoteProviderForBackTester = new HistoricalAdjustedQuoteProvider(); historicalQuoteProviderForInSampleChooser = historicalQuoteProviderForBackTester; historicalQuoteProviderForStrategy = historicalQuoteProviderForInSampleChooser; IInSampleChooser inSampleChooser = new PVOGeneticChooser(numDaysForOscillatingPeriodForChooser , numberOfPortfolioPositions , numberOfBestTestingPositionsToBeReturnedInSample, benchmark, decoderForTestingPositions , fitnessEvaluator , historicalQuoteProviderForInSampleChooser , crossoverRate , mutationRate , elitismRate , populationSizeForGeneticOptimizer , generationNumberForGeneticOptimizer , seedForRandomGenerator , minLevelForOversoldThreshold , maxLevelForOversoldThreshold , minLevelForOverboughtThreshold , maxLevelForOverboughtThreshold , divisorForThresholdComputation , symmetricalThresholds , overboughtMoreThanOversoldForFixedPortfolio ); //parameters for eligiblesSelector bool temporizedGroup = true; double minRawOpenPrice = 25; double maxRawOpenPrice = 500; int numDaysForAverageOpenRawPrice = 20; string tickersGroupId = "SP500"; int maxNumberOfEligiblesToBeChosen = 100; IEligiblesSelector eligiblesSelector = new ByPriceMostLiquidAlwaysQuoted( tickersGroupId , temporizedGroup, maxNumberOfEligiblesToBeChosen, numDaysForAverageOpenRawPrice , minRawOpenPrice , maxRawOpenPrice ); //strategyParameters int inSampleDays = 120; int numDaysForOscillatingPeriodForOutOfSampleChoosing = numDaysForOscillatingPeriodForChooser; PVOStrategy strategy = new PVOStrategy(eligiblesSelector, inSampleChooser, inSampleDays, numDaysForOscillatingPeriodForOutOfSampleChoosing, numberOfPortfolioPositions , benchmark , numDaysBetweenEachOptimization , historicalQuoteProviderForStrategy , maxAcceptableCloseToCloseDrawdown , minimumAcceptableGain ); EndOfDayStrategyBackTester endOfDayStrategyBackTester = new EndOfDayStrategyBackTester( this.strategyIdentifier , strategy , historicalQuoteProviderForBackTester , firstDateTime , lastDateTime , benchmark , cashToStart , maxRunningHours ); // TO DO check if you can do this assign in the EndOfDayStrategyBackTester // constructor strategy.Account = endOfDayStrategyBackTester.Account; MessageManager messageManager = this.setMessageManager( eligiblesSelector , inSampleChooser , strategy , endOfDayStrategyBackTester ); endOfDayStrategyBackTester.Run(); this.saveScriptResults(endOfDayStrategyBackTester); } #endregion Run public void Run1() { BackTestLog backTestLog = LogArchiver.Load( System.Configuration.ConfigurationSettings.AppSettings["LogArchive"] ); LogViewer logViewer = new LogViewer( backTestLog ); logViewer.Show(); } } } --- NEW FILE: PVOPositions.cs --- /* QuantProject - Quantitative Finance Library PVOPositions.cs Copyright (C) 2008 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.OutOfSample; using QuantProject.Business.Strategies.ReturnsManagement; using QuantProject.Business.Strategies.ReturnsManagement.Time; using QuantProject.Business.Timing; using QuantProject.Business.DataProviders; namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator { /// <summary> /// This is the class representing a TestingPositions for the /// portfolio value oscillator strategy /// </summary> [Serializable] public class PVOPositions : TestingPositions, IGeneticallyOptimizable { private double oversoldThreshold; private double overboughtThreshold; private int numDaysForOscillatingPeriod; private int generation; private static ReturnsManager returnsManager; public double OversoldThreshold { get{return this.oversoldThreshold;} set{this.oversoldThreshold = value;} } public double OverboughtThreshold { get{return this.overboughtThreshold;} set{this.overboughtThreshold = value;} } public int NumDaysForOscillatingPeriod { get{return this.numDaysForOscillatingPeriod;} } //explicit interface implementation //the property can be used only by a interface //instance or through a cast to the interface int IGeneticallyOptimizable.Generation { get{return this.generation;} set{this.generation = value;} } public PVOPositions Copy() { return new PVOPositions(this.WeightedPositions,this.OversoldThreshold, this.overboughtThreshold, this.numDaysForOscillatingPeriod); } public PVOPositions(WeightedPositions weightedPositions, double oversoldThreshold, double overboughtThreshold, int numDaysForOscillatingPeriod) : base(weightedPositions) { this.oversoldThreshold = oversoldThreshold; this.overboughtThreshold = overboughtThreshold; this.numDaysForOscillatingPeriod = numDaysForOscillatingPeriod; this.generation = -1; } private void setReturnsManager(EndOfDayDateTime beginOfPeriod, EndOfDayDateTime endOfPeriod, string benchmark, HistoricalQuoteProvider quoteProvider) { if(PVOPositions.returnsManager == null || PVOPositions.returnsManager.ReturnIntervals[0].Begin != beginOfPeriod || PVOPositions.returnsManager.ReturnIntervals[0].End != endOfPeriod) //if a returnsManager has not been set yet or a different one has to be set //for a different returnInterval PVOPositions.returnsManager = new ReturnsManager(new ReturnIntervals( new ReturnInterval( beginOfPeriod, endOfPeriod ) ) , quoteProvider ); } private double getOscillatingPeriodReturn(EndOfDayDateTime beginOfPeriod, EndOfDayDateTime endOfPeriod, string benchmark, HistoricalQuoteProvider quoteProvider) { this.setReturnsManager(beginOfPeriod, endOfPeriod, benchmark, quoteProvider); return this.WeightedPositions.GetReturn(0, PVOPositions.returnsManager); } public PVOPositionsStatus GetStatus(EndOfDayDateTime beginOfPeriod, EndOfDayDateTime endOfPeriod, string benchmark, HistoricalQuoteProvider quoteProvider, double maxCoefficientOfCrossingThresholds) { PVOPositionsStatus returnValue; double oscillatingPeriodReturn = double.NaN; oscillatingPeriodReturn = this.getOscillatingPeriodReturn(beginOfPeriod, endOfPeriod, benchmark, quoteProvider); if(oscillatingPeriodReturn >= this.overboughtThreshold && oscillatingPeriodReturn <= maxCoefficientOfCrossingThresholds*this.overboughtThreshold) returnValue = PVOPositionsStatus.Overbought; else if(oscillatingPeriodReturn <= -this.oversoldThreshold && Math.Abs(oscillatingPeriodReturn)<=maxCoefficientOfCrossingThresholds*this.oversoldThreshold) returnValue = PVOPositionsStatus.Oversold; else if ( Math.Abs(oscillatingPeriodReturn) > maxCoefficientOfCrossingThresholds*this.oversoldThreshold || oscillatingPeriodReturn > maxCoefficientOfCrossingThresholds*this.overboughtThreshold ) returnValue = PVOPositionsStatus.TooDistantFromThresholds; else returnValue = PVOPositionsStatus.InTheMiddle; return returnValue; } public PVOPositionsStatus GetStatus(EndOfDayDateTime beginOfPeriod, EndOfDayDateTime endOfPeriod, string benchmark, HistoricalQuoteProvider quoteProvider) { return this.GetStatus(beginOfPeriod, endOfPeriod , benchmark, quoteProvider, 10000.0); //a very high maxCoefficientOfCrossingThresholds is given: //so the status TooDistantFromThresholds should never been reached } public bool AreAllTickersMovingTogetherUpOrDown(EndOfDayDateTime beginOfPeriod, EndOfDayDateTime endOfPeriod, string benchmark, HistoricalQuoteProvider quoteProvider) { bool returnValue = true; SignedTickers signedTickers = this.WeightedPositions.SignedTickers; float returnOfCurrentTicker, returnOfNextTicker; this.setReturnsManager(beginOfPeriod, endOfPeriod, benchmark, quoteProvider); for( int i = 0; signedTickers.Count > 1 && i < signedTickers.Count - 1 && returnValue == true; i++ ) { returnOfCurrentTicker = PVOPositions.returnsManager.GetReturn(signedTickers[ i ].Ticker, 0); returnOfNextTicker = PVOPositions.returnsManager.GetReturn(signedTickers[ i+1 ].Ticker, 0); if( (returnOfCurrentTicker > 0 && returnOfNextTicker < 0) || (returnOfCurrentTicker < 0 && returnOfNextTicker > 0) ) returnValue = false; } return returnValue; } } } --- NEW FILE: PVOGenomeManager.cs --- /* QuantProject - Quantitative Finance Library PVOGenomeManager.cs Copyright (C) 2008 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Data; using System.Collections; using QuantProject.ADT; using QuantProject.ADT.Statistics; using QuantProject.ADT.Optimizing.Genetic; 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.Business.Strategies.TickersRelationships; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.Optimizing.FitnessEvaluation; using QuantProject.Business.Strategies.Optimizing.Decoding; using QuantProject.Business.Strategies.Optimizing.GenomeManagers; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator { /// <summary> /// Implements what needed to use the Genetic Optimizer /// for finding the portfolio that best suites /// the Portfolio Value Oscillator strategy /// </summary> [Serializable] public class PVOGenomeManager : BasicGenomeManager { protected int minLevelForOversoldThreshold; protected int maxLevelForOversoldThreshold; protected int minLevelForOverboughtThreshold; protected int maxLevelForOverboughtThreshold; protected int divisorForThresholdComputation; protected bool symmetricalThresholds; protected bool overboughtMoreThanOversoldForFixedPortfolio; protected int numOfGenesDedicatedToThresholds; protected int numDaysForOscillatingPeriod; protected CorrelationProvider correlationProvider;//used for experimental //tests using 2 tickers and PearsonCorrelationCoefficient as fitness private void genomeManagerPVO_checkParametersForThresholdsComputation() { if(this.maxLevelForOverboughtThreshold < this.minLevelForOverboughtThreshold || this.maxLevelForOversoldThreshold < this.minLevelForOversoldThreshold || this.divisorForThresholdComputation < this.maxLevelForOverboughtThreshold || this.divisorForThresholdComputation < this.maxLevelForOversoldThreshold || (this.symmetricalThresholds && (this.minLevelForOversoldThreshold != this.minLevelForOverboughtThreshold || this.maxLevelForOversoldThreshold != this.maxLevelForOverboughtThreshold) ) || (this.overboughtMoreThanOversoldForFixedPortfolio && (this.minLevelForOverboughtThreshold > Convert.ToInt32(Convert.ToDouble(this.minLevelForOversoldThreshold)* Convert.ToDouble(this.divisorForThresholdComputation) / (Convert.ToDouble(this.divisorForThresholdComputation) - Convert.ToDouble(this.minLevelForOversoldThreshold) ) ) || this.maxLevelForOverboughtThreshold < Convert.ToInt32(Convert.ToDouble(this.maxLevelForOversoldThreshold) * Convert.ToDouble(this.divisorForThresholdComputation) / (Convert.ToDouble(this.divisorForThresholdComputation) - Convert.ToDouble(this.maxLevelForOversoldThreshold) ) ) ) ) ) throw new Exception("Bad parameters for thresholds computation!"); } public PVOGenomeManager(EligibleTickers eligibleTickers, int numberOfTickersInPortfolio, int numDaysForOscillatingPeriod, int minLevelForOversoldThreshold, int maxLevelForOversoldThreshold, int minLevelForOverboughtThreshold, int maxLevelForOverboughtThreshold, int divisorForThresholdComputation, IDecoderForTestingPositions decoderForTestingPositions, IFitnessEvaluator fitnessEvaluator, bool symmetricalThresholds, bool overboughtMoreThanOversoldForFixedPortfolio, GenomeManagerType genomeManagerType, ReturnsManager returnsManager, int seedForRandomGenerator) : base(eligibleTickers, numberOfTickersInPortfolio, decoderForTestingPositions, fitnessEvaluator, genomeManagerType, returnsManager, seedForRandomGenerator) { this.numDaysForOscillatingPeriod = numDaysForOscillatingPeriod; this.divisorForThresholdComputation = divisorForThresholdComputation; this.decoderForTestingPositions = decoderForTestingPositions; this.minLevelForOversoldThreshold = minLevelForOversoldThreshold; this.maxLevelForOversoldThreshold = maxLevelForOversoldThreshold; this.minLevelForOverboughtThreshold = minLevelForOverboughtThreshold; this.maxLevelForOverboughtThreshold = maxLevelForOverboughtThreshold; this.symmetricalThresholds = symmetricalThresholds; this.overboughtMoreThanOversoldForFixedPortfolio = overboughtMoreThanOversoldForFixedPortfolio; if(this.symmetricalThresholds)//value for thresholds must be unique numOfGenesDedicatedToThresholds = 1; else numOfGenesDedicatedToThresholds = 2; this.genomeManagerPVO_checkParametersForThresholdsComputation(); } public override int GenomeSize { get{return this.genomeSize + this.numOfGenesDedicatedToThresholds;} } #region Get Min and Max Value private int getMinValueForGenes_getMinValueForTicker() { int returnValue; switch (this.genomeManagerType) { case GenomeManagerType.OnlyLong : returnValue = 0; break; default://For ShortAndLong or OnlyShort portfolios returnValue = - this.eligibleTickers.Count; break; } return returnValue; } public override int GetMinValueForGenes(int genePosition) { int returnValue; switch (genePosition) { case 0 ://gene for oversold threshold returnValue = this.minLevelForOversoldThreshold; break; case 1 ://gene for overbought threshold if(this.numOfGenesDedicatedToThresholds == 2) returnValue = this.minLevelForOverboughtThreshold; else returnValue = this.getMinValueForGenes_getMinValueForTicker(); break; default://gene for ticker returnValue = this.getMinValueForGenes_getMinValueForTicker(); break; } return returnValue; } private int getMaxValueForGenes_getMaxValueForTicker() { int returnValue; switch (this.genomeManagerType) { case GenomeManagerType.OnlyShort : returnValue = - 1; break; default ://For ShortAndLong or OnlyLong portfolios returnValue = this.eligibleTickers.Count - 1; break; } return returnValue; } public override int GetMaxValueForGenes(int genePosition) { int returnValue; switch (genePosition) { case 0 ://gene for oversold threshold returnValue = this.maxLevelForOversoldThreshold; break; case 1 ://gene for overbought threshold if(this.numOfGenesDedicatedToThresholds == 2) returnValue = this.maxLevelForOverboughtThreshold; else returnValue = this.getMaxValueForGenes_getMaxValueForTicker(); break; default://gene for ticker returnValue = this.getMaxValueForGenes_getMaxValueForTicker(); break; } return returnValue; } #endregion public override Genome[] GetChilds(Genome parent1, Genome parent2) { //in this simple implementation //child have the tickers of one parent //and the thresholds of the other Genome[] childs = new Genome[2]; childs[0] = parent1.Clone(); childs[1] = parent2.Clone(); //exchange of genes coding thresholds if(this.symmetricalThresholds)//unique value for thresholds { childs[0].SetGeneValue(parent2.GetGeneValue(0),0); childs[1].SetGeneValue(parent1.GetGeneValue(0),0); } else//two different values for thresholds { childs[0].SetGeneValue(parent2.GetGeneValue(0),0); childs[1].SetGeneValue(parent1.GetGeneValue(0),0); childs[0].SetGeneValue(parent2.GetGeneValue(1),1); childs[1].SetGeneValue(parent1.GetGeneValue(1),1); } return childs; } public override int GetNewGeneValue(Genome genome, int genePosition) { // in this implementation only new gene values pointing to tickers // must be different from the others already stored int minValueForGene = genome.GetMinValueForGenes(genePosition); int maxValueForGene = genome.GetMaxValueForGenes(genePosition); int returnValue = GenomeManagement.RandomGenerator.Next(minValueForGene, maxValueForGene + 1); if(this.numOfGenesDedicatedToThresholds == 2 && this.overboughtMoreThanOversoldForFixedPortfolio && genePosition == 1) //genePosition points to overbought threshold, //dipendent from the oversold one such that the portfolio tends to be fix returnValue = Convert.ToInt32(Convert.ToDouble(genome.GetGeneValue(0)) * Convert.ToDouble(this.divisorForThresholdComputation) / (Convert.ToDouble(this.divisorForThresholdComputation) - Convert.ToDouble(genome.GetGeneValue(0)))); while(genePosition > this.numOfGenesDedicatedToThresholds - 1 && GenomeManipulator.IsTickerContainedInGenome(returnValue, genome, this.numOfGenesDedicatedToThresholds, genome.Size - 1)) //while in the given position has to be stored //a new gene pointing to a ticker and //the proposed returnValue points to a ticker //already stored in the given genome returnValue = GenomeManagement.RandomGenerator.Next(minValueForGene, maxValueForGene + 1); return returnValue; } public override void Mutate(Genome genome) { // in this implementation only one gene is mutated int genePositionToBeMutated = GenomeManagement.RandomGenerator.Next(genome.Size); int minValueForGene = genome.GetMinValueForGenes(genePositionToBeMutated); int maxValueForGene = genome.GetMaxValueForGenes(genePositionToBeMutated); int newValueForGene = GenomeManagement.RandomGenerator.Next(minValueForGene, maxValueForGene +1); while(genePositionToBeMutated > this.numOfGenesDedicatedToThresholds - 1 && GenomeManipulator.IsTickerContainedInGenome(newValueForGene, genome, this.numOfGenesDedicatedToThresholds, genome.Size - 1)) //while in the proposed genePositionToBeMutated has to be stored //a new gene pointing to a ticker and //the proposed newValueForGene points to a ticker //already stored in the given genome newValueForGene = GenomeManagement.RandomGenerator.Next(minValueForGene, maxValueForGene +1); //TODO add if when it is mutated a threshold //(just a single threshold or the pair of thresholds) if(genePositionToBeMutated > this.numOfGenesDedicatedToThresholds - 1) GenomeManagement.MutateOneGene(genome, genePositionToBeMutated, newValueForGene); } } } |
|
From: Marco M. <mi...@us...> - 2008-03-09 22:49:28
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/Decoding In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv6639/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/Decoding Added Files: BasicDecoderForPVOPositions.cs Log Message: Added a new implementation for the PVO strategy (now common objects recently added at business layer by Glauco are used). At the moment, these files perform a PVO strategy using close to close returns, on a multiday - minimum 1 day - basis. Take profit and stop loss levels can be set. --- NEW FILE: BasicDecoderForPVOPositions.cs --- /* QuantProject - Quantitative Finance Library BasicDecoderForPVOPositions.cs Copyright (C) 2008 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using QuantProject.ADT.Collections; using QuantProject.ADT.Optimizing.Decoding; using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.OutOfSample; using QuantProject.Business.Strategies.Optimizing.Decoding; namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.Decoding { /// <summary> /// Decodes optimization candidates to a /// PVOPositions /// In this implementation, only tickers and thresholds are decoded /// </summary> public class BasicDecoderForPVOPositions : BasicDecoderForTestingPositions { protected int numOfGenesDedicatedToThresholds; protected int numDaysForOscillatingPeriod; protected double oversoldThreshold; protected double overboughtThreshold; protected int divisorForThresholdComputation; public BasicDecoderForPVOPositions(bool symmetricalThresholds, int divisorForThresholdComputation, int numDaysForOscillatingPeriod) : base() { if(symmetricalThresholds) this.numOfGenesDedicatedToThresholds = 1; else this.numOfGenesDedicatedToThresholds = 2; this.divisorForThresholdComputation = divisorForThresholdComputation; this.numDaysForOscillatingPeriod = numDaysForOscillatingPeriod; } private void decodeDecodable_setThresholds() { if(this.numOfGenesDedicatedToThresholds == 1) //symmetrical thresholds { this.oversoldThreshold = Convert.ToDouble(this.encoded[0])/Convert.ToDouble(this.divisorForThresholdComputation); this.overboughtThreshold = this.oversoldThreshold; } else//different thresholds, that is this.numOfGenesDedicatedToThresholds == 1 { this.oversoldThreshold = Convert.ToDouble(this.encoded[0])/Convert.ToDouble(this.divisorForThresholdComputation); this.overboughtThreshold = Convert.ToDouble(this.encoded[1])/Convert.ToDouble(this.divisorForThresholdComputation); } } protected override TestingPositions decodeDecodable() { SignedTickers signedTickers = this.decodeSignedTickers(); this.decodeDecodable_setThresholds(); PVOPositions pvoPositions = new PVOPositions( new WeightedPositions( this.getWeights(), signedTickers), this.oversoldThreshold, this.overboughtThreshold, this.numDaysForOscillatingPeriod); return pvoPositions; } protected override string getDescription() { return "PVO_Dcdr_NoWghts"; } protected override void setTickerRelatedGeneValues() { this.tickerRelatedGeneValues = IntArrayManager.SubArray(this.encoded, this.numOfGenesDedicatedToThresholds, this.encoded.Length - this.numOfGenesDedicatedToThresholds); } } } |
|
From: Marco M. <mi...@us...> - 2008-03-09 22:49:27
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/FitnessEvaluators In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv6639/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/FitnessEvaluators Added Files: PVOFitnessEvaluator.cs Log Message: Added a new implementation for the PVO strategy (now common objects recently added at business layer by Glauco are used). At the moment, these files perform a PVO strategy using close to close returns, on a multiday - minimum 1 day - basis. Take profit and stop loss levels can be set. --- NEW FILE: PVOFitnessEvaluator.cs --- /* QuantProject - Quantitative Finance Library PVOFitnessEvaluator.cs Copyright (C) 2008 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using QuantProject.ADT; using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.OutOfSample; using QuantProject.Business.Strategies.Optimizing.FitnessEvaluation; using QuantProject.Business.Strategies.EquityEvaluation; using QuantProject.Business.Strategies.ReturnsManagement; namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.FitnessEvaluators { /// <summary> /// Evaluates (in sample) the fitness for a given TestingPositions /// </summary> public class PVOFitnessEvaluator : IFitnessEvaluator { private IEquityEvaluator strategyEquityEvaluator; public string Description { get { string description = "FitnessEvaluatedWith_" + this.strategyEquityEvaluator.GetType().ToString(); return description; } } public PVOFitnessEvaluator(IEquityEvaluator strategyEquityEvaluator) { this.strategyEquityEvaluator = strategyEquityEvaluator; } #region GetFitnessValue //returns true if the strategy gets effective positions on //the market for at least half the market days private bool getFitnessValue_getFitnessValueActually_strategyGetsSufficientPositions(float[] strategyReturns) { int daysOnTheMarket = 0; foreach(float strategyReturn in strategyReturns) if(strategyReturn != 0) //the applied strategy gets positions on the market daysOnTheMarket++; return daysOnTheMarket >= strategyReturns.Length / 2; } private float getFitnessValue_getFitnessValueActually( TestingPositions testingPositions, ReturnsManager returnsManager ) { float fitnessValue = -0.5f; PVOPositions pvoPositions = (PVOPositions)testingPositions; float oversoldThreshold = Convert.ToSingle(pvoPositions.OversoldThreshold); float overboughtThreshold = Convert.ToSingle(pvoPositions.OverboughtThreshold); float[] plainWeightedPositionsReturns = testingPositions.WeightedPositions.GetReturns(returnsManager); float[] strategyReturns = new float[ plainWeightedPositionsReturns.Length ]; strategyReturns[0] = 0; //a the very first day the //strategy return is equal to 0 because no position //has been entered float coefficient = 0; for(int i = 0; i < strategyReturns.Length - 1; i++) { if( plainWeightedPositionsReturns[i] >= overboughtThreshold ) //portfolio has been overbought coefficient = -1; else if( plainWeightedPositionsReturns[i] <= - oversoldThreshold ) //portfolio has been oversold coefficient = 1; //else the previous coeff is kept or, if no threshold has been //reached, then no positions will be opened (coefficient = 0) strategyReturns[i + 1] = coefficient * plainWeightedPositionsReturns[i + 1]; } if(this.getFitnessValue_getFitnessValueActually_strategyGetsSufficientPositions(strategyReturns)) fitnessValue = this.strategyEquityEvaluator.GetReturnsEvaluation(strategyReturns); return fitnessValue; } public double GetFitnessValue(object meaning , ReturnsManager returnsManager ) { float fitnessValue = -0.5f; TestingPositions testingPositions = (TestingPositions)meaning; if(testingPositions.WeightedPositions != null) fitnessValue = this.getFitnessValue_getFitnessValueActually( testingPositions, returnsManager ); return fitnessValue; } #endregion } } |
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/InSampleChoosers In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv6639/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/InSampleChoosers Added Files: PVOCorrelationChooser.cs PVOGeneticChooser.cs Log Message: Added a new implementation for the PVO strategy (now common objects recently added at business layer by Glauco are used). At the moment, these files perform a PVO strategy using close to close returns, on a multiday - minimum 1 day - basis. Take profit and stop loss levels can be set. --- NEW FILE: PVOCorrelationChooser.cs --- /* QuantProject - Quantitative Finance Library PVOCorrelationChooser.cs Copyright (C) 2008 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections; using QuantProject.ADT; using QuantProject.ADT.Messaging; using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.TickersRelationships; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.ReturnsManagement; using QuantProject.Business.Strategies.OutOfSample; namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.InSampleChoosers { /// <summary> /// PVOCorrelationChooser to be used for /// in sample optimization /// By means of correlation, the AnalyzeInSample method returns the /// requested number of PVOPositions (positions for the PVO strategy) /// </summary> public class PVOCorrelationChooser : IInSampleChooser { public event NewProgressEventHandler NewProgress; public event NewMessageEventHandler NewMessage; protected CorrelationProvider correlationProvider; protected int numberOfBestTestingPositionsToBeReturned; protected double oversoldThreshold; protected double overboughtThreshold; protected int numDaysForOscillatingPeriod; public virtual string Description { get { string description = "PVOCorrelationChooser_" + this.correlationProvider.GetType().ToString(); return description; } } /// <summary> /// PVOCorrelationChooser to be used for /// in sample optimization /// </summary> /// <param name="numberOfBestTestingPositionsToBeReturned"> /// The number of PVOPositions that the /// AnalyzeInSample method will return /// </param> /// /// <param name="numDaysForOscillatingPeriod"> /// Interval's length of the return for the PVOPosition /// to be checked out of sample, in order to update the /// status for the PVOPosition itself /// </param> public PVOCorrelationChooser(int numberOfBestTestingPositionsToBeReturned, double oversoldThreshold, double overboughtThreshold, int numDaysForOscillatingPeriod) { this.numberOfBestTestingPositionsToBeReturned = numberOfBestTestingPositionsToBeReturned; this.oversoldThreshold = oversoldThreshold; this.overboughtThreshold = overboughtThreshold; this.numDaysForOscillatingPeriod = numDaysForOscillatingPeriod; } #region AnalyzeInSample private void analyzeInSample_checkParameters( EligibleTickers eligibleTickers , ReturnsManager returnsManager ) { if ( eligibleTickers.Count < 2 ) throw new Exception( "Eligible tickers for driving positions contains " + "only " + eligibleTickers.Count + " elements, while NumberOfDrivingPositions is 2"); } protected virtual void setCorrelationProvider(EligibleTickers eligibleTickers , ReturnsManager returnsManager) { this.correlationProvider = new OpenToCloseCorrelationProvider(eligibleTickers.Tickers, returnsManager, 0.0001f, 0.5f); } protected virtual PVOPositions getTestingPositions(WeightedPositions weightedPositions) { return new PVOPositions(weightedPositions, this.oversoldThreshold, this.overboughtThreshold, this.numDaysForOscillatingPeriod ); } private TestingPositions[] getBestTestingPositionsInSample( EligibleTickers eligibleTickers , ReturnsManager returnsManager ) { this.setCorrelationProvider(eligibleTickers , returnsManager); TestingPositions[] bestTestingPositions = new TestingPositions[this.numberOfBestTestingPositionsToBeReturned]; TickersPearsonCorrelation[] correlations = this.correlationProvider.GetOrderedTickersPearsonCorrelations(); for(int i = 0; i<this.numberOfBestTestingPositionsToBeReturned; i++) { SignedTickers signedTickers = new SignedTickers("-"+correlations[correlations.Length - 1 -i].FirstTicker + ";" + correlations[correlations.Length - 1 -i].SecondTicker); WeightedPositions weightedPositions = new WeightedPositions(signedTickers); bestTestingPositions[i] = this.getTestingPositions(weightedPositions); } return bestTestingPositions; } /// <summary> /// Returns the best TestingPositions with respect to the in sample data /// </summary> /// <param name="eligibleTickers"></param> /// <returns></returns> public object AnalyzeInSample( EligibleTickers eligibleTickers , ReturnsManager returnsManager ) { if ( this.NewMessage != null ) this.NewMessage( this , new NewMessageEventArgs( "New Correlation Analysis" ) ); if ( this.NewProgress != null ) this.NewProgress( this , new NewProgressEventArgs( 1 , 1 ) ); this.analyzeInSample_checkParameters( eligibleTickers , returnsManager ); TestingPositions[] bestTestingPositionsInSample = this.getBestTestingPositionsInSample( eligibleTickers , returnsManager ); return bestTestingPositionsInSample; } #endregion } } --- NEW FILE: PVOGeneticChooser.cs --- /* QuantProject - Quantitative Finance Library PVOGeneticChooser.cs Copyright (C) 2008 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Business.Strategies; using QuantProject.Business.DataProviders; using QuantProject.Business.Strategies.Optimizing.FitnessEvaluation; using QuantProject.Business.Strategies.Optimizing.Decoding; using QuantProject.Business.Strategies.Eligibles; using QuantProject.Business.Strategies.InSample; using QuantProject.Business.Strategies.ReturnsManagement; using QuantProject.Business.Strategies.OutOfSample; using QuantProject.Business.Strategies.Optimizing.GenomeManagers; namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.InSampleChoosers { /// <summary> /// In sample genetic analyzer for the Portfolio Value Oscillator /// </summary> public class PVOGeneticChooser : GeneticChooser { protected int numDaysForOscillatingPeriod; protected int minLevelForOversoldThreshold; protected int maxLevelForOversoldThreshold; protected int minLevelForOverboughtThreshold; protected int maxLevelForOverboughtThreshold; protected int divisorForThresholdComputation; protected bool symmetricalThresholds; protected bool overboughtMoreThanOversoldForFixedPortfolio; public PVOGeneticChooser( int numDaysForOscillatingPeriod, int numberOfPortfolioPositions , int numberOfBestTestingPositionsToBeReturned , Benchmark benchmark , IDecoderForTestingPositions decoderForTestingPositions , IFitnessEvaluator fitnessEvaluator , IHistoricalQuoteProvider historicalQuoteProvider , double crossoverRate , double mutationRate , double elitismRate , int populationSizeForGeneticOptimizer , int generationNumberForGeneticOptimizer , int seedForRandomGenerator, int minLevelForOversoldThreshold , int maxLevelForOversoldThreshold, int minLevelForOverboughtThreshold , int maxLevelForOverboughtThreshold, int divisorForThresholdComputation, bool symmetricalThresholds , bool overboughtMoreThanOversoldForFixedPortfolio) : base(numberOfPortfolioPositions, numberOfBestTestingPositionsToBeReturned, benchmark , decoderForTestingPositions , fitnessEvaluator , historicalQuoteProvider , crossoverRate , mutationRate , elitismRate , populationSizeForGeneticOptimizer , generationNumberForGeneticOptimizer , seedForRandomGenerator ) { this.numDaysForOscillatingPeriod = numDaysForOscillatingPeriod; this.minLevelForOversoldThreshold = minLevelForOversoldThreshold; this.maxLevelForOversoldThreshold = maxLevelForOversoldThreshold; this.minLevelForOverboughtThreshold = minLevelForOverboughtThreshold; this.maxLevelForOverboughtThreshold = maxLevelForOverboughtThreshold; this.divisorForThresholdComputation = divisorForThresholdComputation; this.symmetricalThresholds = symmetricalThresholds; this.overboughtMoreThanOversoldForFixedPortfolio = overboughtMoreThanOversoldForFixedPortfolio; } protected override string getHashCodeForGenome(QuantProject.ADT.Optimizing.Genetic.Genome genome) { string returnValue = ((TestingPositions)genome.Meaning).HashCodeForTickerComposition; return returnValue; } protected override IGenomeManager getGenomeManager(EligibleTickers eligibleTickers , ReturnsManager returnsManager) { return new PVOGenomeManager(eligibleTickers, this.numberOfPortfolioPositions, this.numDaysForOscillatingPeriod , this.minLevelForOversoldThreshold, this.maxLevelForOversoldThreshold, this.minLevelForOverboughtThreshold, this.maxLevelForOverboughtThreshold, this.divisorForThresholdComputation, this.decoderForTestingPositions, this.fitnessEvaluator, this.symmetricalThresholds, this.overboughtMoreThanOversoldForFixedPortfolio, GenomeManagerType.ShortAndLong, returnsManager, this.seedForRandomGenerator); } } } |
|
From: Marco M. <mi...@us...> - 2008-03-09 22:40:55
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/BiasedPVO In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv1495/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/BiasedPVO Modified Files: EndOfDayTimerHandlerBiasedPVO.cs EndOfDayTimerHandlerBiasedPVO_OTC.cs RunBiasedPVO.cs RunBiasedPVO_OTC.cs Log Message: Updated old implementation of the PVO_OTC strategy Index: EndOfDayTimerHandlerBiasedPVO_OTC.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/BiasedPVO/EndOfDayTimerHandlerBiasedPVO_OTC.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** EndOfDayTimerHandlerBiasedPVO_OTC.cs 14 Jan 2008 22:58:11 -0000 1.1 --- EndOfDayTimerHandlerBiasedPVO_OTC.cs 9 Mar 2008 22:40:51 -0000 1.2 *************** *** 138,145 **** // UPDATE WITH DailyOpenToCloseIntervals // ReturnsManager returnsManager = new ReturnsManager( ! // new CloseToCloseIntervals(new EndOfDayDateTime(today.AddDays(-this.numDaysForThresholdsReComputation), EndOfDaySpecificTime.MarketClose), ! // new EndOfDayDateTime(today, EndOfDaySpecificTime.MarketClose), ! // this.benchmark, ! // this.numDaysForOscillatingPeriod), // new HistoricalAdjustedQuoteProvider() ); // //double returnsAverage; --- 138,144 ---- // UPDATE WITH DailyOpenToCloseIntervals // ReturnsManager returnsManager = new ReturnsManager( ! // new CloseToOpenIntervals(new EndOfDayDateTime(today.AddDays(-this.numDaysForThresholdsReComputation), EndOfDaySpecificTime.MarketClose), ! // new EndOfDayDateTime(today, EndOfDaySpecificTime.MarketOpen), ! // this.benchmark), // new HistoricalAdjustedQuoteProvider() ); // //double returnsAverage; Index: EndOfDayTimerHandlerBiasedPVO.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/BiasedPVO/EndOfDayTimerHandlerBiasedPVO.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** EndOfDayTimerHandlerBiasedPVO.cs 14 Jan 2008 23:07:03 -0000 1.4 --- EndOfDayTimerHandlerBiasedPVO.cs 9 Mar 2008 22:40:51 -0000 1.5 *************** *** 353,357 **** //positions that have just been closed { ! AccountManager.OpenPositions(weightedPositions, this.account); this.portfolioHasBeenOverbought = overboughtPortfolio; this.portfolioHasBeenOversold = !overboughtPortfolio; --- 353,357 ---- //positions that have just been closed { ! AccountManager.OpenPositions(weightedPositions, this.account, 30000); this.portfolioHasBeenOverbought = overboughtPortfolio; this.portfolioHasBeenOversold = !overboughtPortfolio; Index: RunBiasedPVO.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/BiasedPVO/RunBiasedPVO.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RunBiasedPVO.cs 14 Jan 2008 23:07:03 -0000 1.3 --- RunBiasedPVO.cs 9 Mar 2008 22:40:51 -0000 1.4 *************** *** 177,181 **** ! private void saveScriptResults_saveScriptFeaturesToLogFile(string nameForScriptFiles) { string pathFile = System.Configuration.ConfigurationSettings.AppSettings["ReportsArchive"] + --- 177,181 ---- ! protected void saveScriptResults_saveScriptFeaturesToLogFile(string nameForScriptFiles) { string pathFile = System.Configuration.ConfigurationSettings.AppSettings["ReportsArchive"] + Index: RunBiasedPVO_OTC.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/BiasedPVO/RunBiasedPVO_OTC.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RunBiasedPVO_OTC.cs 14 Jan 2008 22:58:11 -0000 1.1 --- RunBiasedPVO_OTC.cs 9 Mar 2008 22:40:51 -0000 1.2 *************** *** 115,122 **** } ! // protected override void run_initializeHistoricalQuoteProvider() ! // { ! // this.historicalQuoteProvider = new HistoricalRawQuoteProvider(); ! // } protected override void run_initializeAccount() --- 115,122 ---- } ! protected override void run_initializeHistoricalQuoteProvider() ! { ! this.historicalQuoteProvider = new HistoricalRawQuoteProvider(); ! } protected override void run_initializeAccount() *************** *** 171,174 **** --- 171,216 ---- this.minimumAcceptableGain); } + + public override void SaveScriptResults() + { + string fileName = DateTime.Now.Hour.ToString().PadLeft(2,'0') + "_" + + DateTime.Now.Minute.ToString().PadLeft(2,'0') + "_" + + DateTime.Now.Second.ToString().PadLeft(2,'0') + "_" + + this.scriptName + "GenOS_" + this.numOfDifferentGenomesToEvaluateOutOfSample + + "_From_" + this.tickerGroupID + "_" + this.numberOfEligibleTickers + + "_DaysForOpt" + this.numDaysForOptimizationPeriod + "Tick" + + this.numberOfTickersToBeChosen + "GenN°" + + this.generationNumberForGeneticOptimizer + + "PopSize" + this.populationSizeForGeneticOptimizer + + Convert.ToString(this.portfolioType); + string dirNameWhereToSaveReports = System.Configuration.ConfigurationSettings.AppSettings["ReportsArchive"] + + "\\" + this.ScriptName + "\\"; + string dirNameWhereToSaveTransactions = System.Configuration.ConfigurationSettings.AppSettings["TransactionsArchive"] + + "\\" + this.ScriptName + "\\"; + string dirNameWhereToSaveBestGenomes = System.Configuration.ConfigurationSettings.AppSettings["GenomesArchive"] + + "\\" + this.ScriptName + "\\"; + + this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveBestGenomes); + if( this.PathOfFileContainingGenomes == null ) + { + OptimizationOutput optimizationOutput = new OptimizationOutput(); + foreach(GenomeRepresentation genomeRepresentation in this.endOfDayTimerHandler.BestGenomes) + optimizationOutput.Add(genomeRepresentation); + ObjectArchiver.Archive(optimizationOutput, + dirNameWhereToSaveBestGenomes + + fileName + ".bgn"); + } + this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveReports); + AccountReport accountReport = this.account.CreateReport(fileName,1, + this.endOfDayTimer.GetCurrentTime(), + this.benchmark, + this.historicalQuoteProvider); + ObjectArchiver.Archive(accountReport, + dirNameWhereToSaveReports + + fileName + ".qPr"); + this.saveScriptResults_saveScriptFeaturesToLogFile(fileName); + this.endOfDayTimer.Stop(); + } + } } |
|
From: Marco M. <mi...@us...> - 2008-03-09 22:34:37
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/InSampleChoosers In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv30670/InSampleChoosers Log Message: Directory /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/InSampleChoosers added to the repository |
|
From: Marco M. <mi...@us...> - 2008-03-09 22:34:24
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/FitnessEvaluators In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv30644/FitnessEvaluators Log Message: Directory /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/FitnessEvaluators added to the repository |
|
From: Marco M. <mi...@us...> - 2008-03-09 22:34:11
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/Decoding In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv30477/Decoding Log Message: Directory /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/Decoding added to the repository |
|
From: Marco M. <mi...@us...> - 2008-03-09 21:42:27
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/InSample In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv30434 Modified Files: GeneticChooser.cs Log Message: Fixed bug in AnalyzeInSample method: now a new TestingPositions object is returnes Index: GeneticChooser.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/InSample/GeneticChooser.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** GeneticChooser.cs 7 Mar 2008 23:27:13 -0000 1.8 --- GeneticChooser.cs 9 Mar 2008 21:42:21 -0000 1.9 *************** *** 55,59 **** //the method that returns the hash code for genome //is virtual) ! protected TestingPositions[] bestTestingPositions; protected Benchmark benchmark; protected IDecoderForTestingPositions decoderForTestingPositions; --- 55,59 ---- //the method that returns the hash code for genome //is virtual) ! // protected TestingPositions[] bestTestingPositions; protected Benchmark benchmark; protected IDecoderForTestingPositions decoderForTestingPositions; *************** *** 104,110 **** this.numberOfPortfolioPositions = numberOfPortfolioPositions; this.numberOfBestTestingPositionsToBeReturned = numberOfBestTestingPositionsToBeReturned; - // this.choosePositionsWithAtLeastOneDifferentTicker = - // choosePositionsWithAtLeastOneDifferentTicker; - this.bestTestingPositions = new TestingPositions[numberOfBestTestingPositionsToBeReturned]; this.benchmark = benchmark; this.decoderForTestingPositions = decoderForTestingPositions; --- 104,107 ---- *************** *** 186,191 **** ! private void setBestTestingPositions() { GeneticOptimizer GO = this.geneticOptimizer; int addedTestingPositions = 0; --- 183,189 ---- ! private TestingPositions[] getBestTestingPositionsInSample_getTestingPositionsActually() { + TestingPositions[] bestTestingPositions = new TestingPositions[numberOfBestTestingPositionsToBeReturned]; GeneticOptimizer GO = this.geneticOptimizer; int addedTestingPositions = 0; *************** *** 201,209 **** if( counter == 0 || !genomesCollector.ContainsKey(currentGenomeHashcode) ) { ! this.bestTestingPositions[addedTestingPositions] = (TestingPositions)currentGenome.Meaning; ! ((TestingPositions)this.bestTestingPositions[addedTestingPositions]).FitnessInSample = currentGenome.Fitness; ! ((IGeneticallyOptimizable)this.bestTestingPositions[addedTestingPositions]).Generation = currentGenome.Generation; genomesCollector.Add(currentGenomeHashcode, null); --- 199,207 ---- if( counter == 0 || !genomesCollector.ContainsKey(currentGenomeHashcode) ) { ! bestTestingPositions[addedTestingPositions] = (TestingPositions)currentGenome.Meaning; ! ((TestingPositions)bestTestingPositions[addedTestingPositions]).FitnessInSample = currentGenome.Fitness; ! ((IGeneticallyOptimizable)bestTestingPositions[addedTestingPositions]).Generation = currentGenome.Generation; genomesCollector.Add(currentGenomeHashcode, null); *************** *** 211,215 **** } counter ++ ; ! } } --- 209,214 ---- } counter ++ ; ! } ! return bestTestingPositions; } *************** *** 235,241 **** new NewGenerationEventHandler( this.newGenerationEventHandler ); this.geneticOptimizer.Run( false ); ! this.setBestTestingPositions(); ! ! return this.bestTestingPositions; } --- 234,239 ---- new NewGenerationEventHandler( this.newGenerationEventHandler ); this.geneticOptimizer.Run( false ); ! ! return this.getBestTestingPositionsInSample_getTestingPositionsActually(); } |