quantproject-developers Mailing List for QuantProject (Page 83)
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...> - 2006-08-03 21:18:43
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/ExtremeCounterTrend In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv15341/b7_Scripts/TechnicalAnalysisTesting/Oscillators/ExtremeCounterTrend Modified Files: RunExtremeCounterTrend.cs Log Message: Enriched the name for the output file. Index: RunExtremeCounterTrend.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/ExtremeCounterTrend/RunExtremeCounterTrend.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RunExtremeCounterTrend.cs 2 Jul 2006 19:41:46 -0000 1.2 --- RunExtremeCounterTrend.cs 3 Aug 2006 21:18:40 -0000 1.3 *************** *** 73,77 **** portfolioType, maxRunningHours) { ! this.ScriptName = "ExtremeCounterTrendScriptWithExpScoreWeighted"; this.numDaysForReturnCalculation = numDaysForReturnCalculation; this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; --- 73,77 ---- portfolioType, maxRunningHours) { ! this.ScriptName = "ExtremeCounterTrendScriptWithSharpeRatio"; this.numDaysForReturnCalculation = numDaysForReturnCalculation; this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; *************** *** 116,120 **** public override void SaveScriptResults() { ! string fileName = "From"+ this.tickerGroupID + "_" + this.numberOfEligibleTickers + "_DaysForOpt" + this.numDaysForOptimizationPeriod + "Tickers" + this.numberOfTickersToBeChosen + "GenNum" + --- 116,120 ---- public override void SaveScriptResults() { ! string fileName = this.scriptName + "_From_" + this.tickerGroupID + "_" + this.numberOfEligibleTickers + "_DaysForOpt" + this.numDaysForOptimizationPeriod + "Tickers" + this.numberOfTickersToBeChosen + "GenNum" + |
|
From: Marco M. <mi...@us...> - 2006-08-03 21:17:25
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/Selectors In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv14898/b3_Data/Selectors Modified Files: SelectorByCloseToCloseCorrelationToBenchmark.cs Log Message: Update XLM remarks (for documentation) Index: SelectorByCloseToCloseCorrelationToBenchmark.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/Selectors/SelectorByCloseToCloseCorrelationToBenchmark.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SelectorByCloseToCloseCorrelationToBenchmark.cs 2 Jul 2006 19:31:18 -0000 1.3 --- SelectorByCloseToCloseCorrelationToBenchmark.cs 3 Aug 2006 21:17:16 -0000 1.4 *************** *** 71,84 **** /// Creates a new instance of the selector /// </summary> ! /// <param name="groupID">The group ID containing the tickers that have to be ordered</param> ! /// <param name="benchmark">Benchmark</param> /// <param name="orderInASCmode">Ordering mode</param> /// <param name="firstQuoteDate">The first date for the interval</param> /// <param name="lastQuoteDate">The last date for the interval</param> /// <param name="maxNumOfReturnedTickers">Max number of tickers to be returned</param> ! /// <param name="numDaysBetweenEachClose">Number of days between closes to be studied. NOTE that ! /// close values are grouped in pairs and the first close value in each group is ! /// not the last close in the previous group. There is, in other words, a discontinuity ! /// between each group, with length equal to the group's length </param> public SelectorByCloseToCloseCorrelationToBenchmark(string groupID, string benchmark, --- 71,84 ---- /// Creates a new instance of the selector /// </summary> ! /// <param name="groupID">The group ID containing the tickers that have to be ordered by Pearson ! /// correlation coefficient to a given benchmark</param> ! /// <param name="benchmark">Benchmark to be used for computation of correlation coefficient</param> /// <param name="orderInASCmode">Ordering mode</param> /// <param name="firstQuoteDate">The first date for the interval</param> /// <param name="lastQuoteDate">The last date for the interval</param> /// <param name="maxNumOfReturnedTickers">Max number of tickers to be returned</param> ! /// <param name="addBenchmarkToTheGivenSetOfTickers">If TRUE, the benchmark is added to ! /// output table (with correlation ! /// equal to 1) </param> public SelectorByCloseToCloseCorrelationToBenchmark(string groupID, string benchmark, |
|
From: Marco M. <mi...@us...> - 2006-08-03 21:16:00
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv14164/b7_Scripts/WalkForwardTesting/LinearCombination Modified Files: TestDisplayer.cs StrategyType.cs MainForm.cs LinearCombinationTest.cs Log Message: Added ImmediateTrendFollower strategy to the project. ITF strategy is just the reversal of the ECT (ExtremeCounterTrend strategy). Index: LinearCombinationTest.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/LinearCombinationTest.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** LinearCombinationTest.cs 2 Jul 2006 19:22:12 -0000 1.7 --- LinearCombinationTest.cs 3 Aug 2006 21:15:57 -0000 1.8 *************** *** 92,99 **** private void run_setStrategy() { ! string[] signedTickers = GenomeRepresentation.GetSignedTickers( ! this.genomeRepresentation.SignedTickers ); ! double[] weightsForSignedTickers = GenomeRepresentation.GetWeightsForSignedTickers( ! this.genomeRepresentation.SignedTickers ); switch (this.strategyType) { --- 92,98 ---- private void run_setStrategy() { ! string[] signedTickers = genomeRepresentation.SignedTickers.Split(";".ToCharArray()); ! double[] weightsForSignedTickers = ! GenomeRepresentation.GetWeightsArray(this.genomeRepresentation.WeightsForSignedTickers); switch (this.strategyType) { *************** *** 128,131 **** --- 127,135 ---- this.account , signedTickers , weightsForSignedTickers, this.numDaysForOscillatorStrategy ); break; + + case StrategyType.ImmediateTrendFollower: + this.endOfDayStrategy = new ImmediateTrendFollowerStrategy( + this.account , signedTickers , weightsForSignedTickers, this.numDaysForOscillatorStrategy ); + break; } } Index: MainForm.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/MainForm.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** MainForm.cs 7 Jan 2006 10:45:07 -0000 1.9 --- MainForm.cs 3 Aug 2006 21:15:57 -0000 1.10 *************** *** 109,151 **** private void InitializeComponent() { ! this.mainMenu1 = new System.Windows.Forms.MainMenu(); ! this.menuItem1 = new System.Windows.Forms.MenuItem(); ! this.menuItem2 = new System.Windows.Forms.MenuItem(); ! this.menuItem3 = new System.Windows.Forms.MenuItem(); ! // ! // mainMenu1 ! // ! this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { ! this.menuItem1}); ! // ! // menuItem1 ! // ! this.menuItem1.Index = 0; ! this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { ! this.menuItem2, ! this.menuItem3}); ! this.menuItem1.Text = "File"; ! // ! // menuItem2 ! // ! this.menuItem2.Index = 0; ! this.menuItem2.Text = "Create Optimized Genomes"; ! this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click); ! // ! // menuItem3 ! // ! this.menuItem3.Index = 1; ! this.menuItem3.Text = "Test Optimized Genomes"; ! this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click); ! // ! // MainForm ! // ! this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); ! this.ClientSize = new System.Drawing.Size(292, 273); ! this.Menu = this.mainMenu1; ! this.Name = "MainForm"; ! this.Text = "MainForm"; ! } #endregion --- 109,151 ---- private void InitializeComponent() { ! this.mainMenu1 = new System.Windows.Forms.MainMenu(); ! this.menuItem1 = new System.Windows.Forms.MenuItem(); ! this.menuItem2 = new System.Windows.Forms.MenuItem(); ! this.menuItem3 = new System.Windows.Forms.MenuItem(); ! // ! // mainMenu1 ! // ! this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { ! this.menuItem1}); ! // ! // menuItem1 ! // ! this.menuItem1.Index = 0; ! this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { ! this.menuItem2, ! this.menuItem3}); ! this.menuItem1.Text = "File"; ! // ! // menuItem2 ! // ! this.menuItem2.Index = 0; ! this.menuItem2.Text = "Create Optimized Genomes"; ! this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click); ! // ! // menuItem3 ! // ! this.menuItem3.Index = 1; ! this.menuItem3.Text = "Test Optimized Genomes"; ! this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click); ! // ! // MainForm ! // ! this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); ! this.ClientSize = new System.Drawing.Size(292, 273); ! this.Menu = this.mainMenu1; ! this.Name = "MainForm"; ! this.Text = "MainForm"; ! } #endregion *************** *** 280,284 **** TestDisplayer testDisplayer = new TestDisplayer( this.firstDate , this.lastDate , this.optimizationOutput ); ! this.optimizationOutput = null; testDisplayer.Show(); } --- 280,284 ---- TestDisplayer testDisplayer = new TestDisplayer( this.firstDate , this.lastDate , this.optimizationOutput ); ! this.optimizationOutput = null;//why this? testDisplayer.Show(); } Index: StrategyType.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/StrategyType.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** StrategyType.cs 2 Jul 2006 19:22:12 -0000 1.3 --- StrategyType.cs 3 Aug 2006 21:15:57 -0000 1.4 *************** *** 35,39 **** OpenToCloseCloseToOpenDaily, FixedPeriodOscillator, ! ExtremeCounterTrend } } --- 35,40 ---- OpenToCloseCloseToOpenDaily, FixedPeriodOscillator, ! ExtremeCounterTrend, ! ImmediateTrendFollower } } Index: TestDisplayer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/TestDisplayer.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** TestDisplayer.cs 2 Jul 2006 19:22:12 -0000 1.8 --- TestDisplayer.cs 3 Aug 2006 21:15:57 -0000 1.9 *************** *** 38,42 **** private System.Windows.Forms.RadioButton radioButtonFixedPeriodOscillator; private System.Windows.Forms.RadioButton radioButtonOpenToCloseDaily; - private System.Windows.Forms.RadioButton radioButtonReversalOneRank; private System.Windows.Forms.DateTimePicker dtpLastDate; private System.Windows.Forms.Label label1; --- 38,41 ---- *************** *** 55,58 **** --- 54,59 ---- private GenomeRepresentation lastSelectedGenomeRepresentation; private System.Windows.Forms.RadioButton radioButtonOTCCTODaily; + private System.Windows.Forms.RadioButton radioButtonExtremeCounterTrend; + private System.Windows.Forms.RadioButton radioButtonImmediateTrendFollower; private StrategyType selectedStrategyType = StrategyType.OpenToCloseDaily; *************** *** 60,63 **** --- 61,106 ---- { this.dgBestGenomes.DataSource = this.bestGenomes; + DataGridTableStyle ts = new DataGridTableStyle(); + ts.MappingName = this.dgBestGenomes.DataSource.GetType().Name; + + DataGridTextBoxColumn signedTickersBox = new DataGridTextBoxColumn(); + signedTickersBox.MappingName ="SignedTickers"; + signedTickersBox.HeaderText = "Tickers"; + ts.GridColumnStyles.Add(signedTickersBox); + + DataGridTextBoxColumn weights = new DataGridTextBoxColumn(); + weights.MappingName ="WeightsForSignedTickers"; + weights.HeaderText = "Weights"; + ts.GridColumnStyles.Add(weights); + + DataGridTextBoxColumn fitness = new DataGridTextBoxColumn(); + fitness.MappingName ="Fitness"; + fitness.HeaderText = "Fitness"; + ts.GridColumnStyles.Add(fitness); + + DataGridTextBoxColumn firstDate = new DataGridTextBoxColumn(); + firstDate.MappingName ="FirstOptimizationDate"; + firstDate.HeaderText = "FirstOptimizationDate"; + ts.GridColumnStyles.Add(firstDate); + + DataGridTextBoxColumn lastDate = new DataGridTextBoxColumn(); + lastDate.MappingName ="LastOptimizationDate"; + lastDate.HeaderText = "LastOptimizationDate"; + ts.GridColumnStyles.Add(lastDate); + + DataGridTextBoxColumn genNumber = new DataGridTextBoxColumn(); + genNumber.MappingName ="GenerationCounter"; + genNumber.HeaderText = "GenNum"; + ts.GridColumnStyles.Add(genNumber); + + DataGridTextBoxColumn eligible = new DataGridTextBoxColumn(); + eligible.MappingName ="EligibleTickers"; + eligible.HeaderText = "EligibleTickers"; + ts.GridColumnStyles.Add(eligible); + + this.dgBestGenomes.TableStyles.Clear(); + ts.AllowSorting = true; + this.dgBestGenomes.TableStyles.Add(ts); + this.dgBestGenomes.AllowSorting = true; } public TestDisplayer( DateTime firstDate , DateTime lastDate , *************** *** 111,119 **** this.label1 = new System.Windows.Forms.Label(); this.dtpLastDate = new System.Windows.Forms.DateTimePicker(); ! this.radioButtonReversalOneRank = new System.Windows.Forms.RadioButton(); this.radioButtonOpenToCloseDaily = new System.Windows.Forms.RadioButton(); this.radioButtonFixedPeriodOscillator = new System.Windows.Forms.RadioButton(); this.labelDays = new System.Windows.Forms.Label(); this.radioButtonOTCCTODaily = new System.Windows.Forms.RadioButton(); ((System.ComponentModel.ISupportInitialize)(this.dgBestGenomes)).BeginInit(); this.SuspendLayout(); --- 154,163 ---- this.label1 = new System.Windows.Forms.Label(); this.dtpLastDate = new System.Windows.Forms.DateTimePicker(); ! this.radioButtonExtremeCounterTrend = new System.Windows.Forms.RadioButton(); this.radioButtonOpenToCloseDaily = new System.Windows.Forms.RadioButton(); this.radioButtonFixedPeriodOscillator = new System.Windows.Forms.RadioButton(); this.labelDays = new System.Windows.Forms.Label(); this.radioButtonOTCCTODaily = new System.Windows.Forms.RadioButton(); + this.radioButtonImmediateTrendFollower = new System.Windows.Forms.RadioButton(); ((System.ComponentModel.ISupportInitialize)(this.dgBestGenomes)).BeginInit(); this.SuspendLayout(); *************** *** 150,154 **** // textBoxDaysFPOscillatorAndRevOneRank // ! this.textBoxDaysFPOscillatorAndRevOneRank.Location = new System.Drawing.Point(320, 152); this.textBoxDaysFPOscillatorAndRevOneRank.Name = "textBoxDaysFPOscillatorAndRevOneRank"; this.textBoxDaysFPOscillatorAndRevOneRank.Size = new System.Drawing.Size(56, 20); --- 194,198 ---- // textBoxDaysFPOscillatorAndRevOneRank // ! this.textBoxDaysFPOscillatorAndRevOneRank.Location = new System.Drawing.Point(320, 176); this.textBoxDaysFPOscillatorAndRevOneRank.Name = "textBoxDaysFPOscillatorAndRevOneRank"; this.textBoxDaysFPOscillatorAndRevOneRank.Size = new System.Drawing.Size(56, 20); *************** *** 178,189 **** this.dtpLastDate.TabIndex = 2; // ! // radioButtonReversalOneRank // ! this.radioButtonReversalOneRank.Location = new System.Drawing.Point(232, 120); ! this.radioButtonReversalOneRank.Name = "radioButtonReversalOneRank"; ! this.radioButtonReversalOneRank.Size = new System.Drawing.Size(192, 24); ! this.radioButtonReversalOneRank.TabIndex = 10; ! this.radioButtonReversalOneRank.Text = "Extreme counter trend"; ! this.radioButtonReversalOneRank.CheckedChanged += new System.EventHandler(this.radioButtonReversalOneRank_CheckedChanged); // // radioButtonOpenToCloseDaily --- 222,233 ---- this.dtpLastDate.TabIndex = 2; // ! // radioButtonExtremeCounterTrend // ! this.radioButtonExtremeCounterTrend.Location = new System.Drawing.Point(232, 120); ! this.radioButtonExtremeCounterTrend.Name = "radioButtonExtremeCounterTrend"; ! this.radioButtonExtremeCounterTrend.Size = new System.Drawing.Size(192, 24); ! this.radioButtonExtremeCounterTrend.TabIndex = 10; ! this.radioButtonExtremeCounterTrend.Text = "Extreme counter trend"; ! this.radioButtonExtremeCounterTrend.CheckedChanged += new System.EventHandler(this.radioButtonExtremeCounterTrend_CheckedChanged); // // radioButtonOpenToCloseDaily *************** *** 207,211 **** // labelDays // ! this.labelDays.Location = new System.Drawing.Point(272, 152); this.labelDays.Name = "labelDays"; this.labelDays.Size = new System.Drawing.Size(40, 16); --- 251,255 ---- // labelDays // ! this.labelDays.Location = new System.Drawing.Point(272, 176); this.labelDays.Name = "labelDays"; this.labelDays.Size = new System.Drawing.Size(40, 16); *************** *** 221,224 **** --- 265,277 ---- this.radioButtonOTCCTODaily.Text = "OTC - CTO Daily"; // + // radioButtonImmediateTrendFollower + // + this.radioButtonImmediateTrendFollower.Location = new System.Drawing.Point(232, 144); + this.radioButtonImmediateTrendFollower.Name = "radioButtonImmediateTrendFollower"; + this.radioButtonImmediateTrendFollower.Size = new System.Drawing.Size(192, 24); + this.radioButtonImmediateTrendFollower.TabIndex = 12; + this.radioButtonImmediateTrendFollower.Text = "Immediate Trend Follower"; + this.radioButtonImmediateTrendFollower.CheckedChanged += new System.EventHandler(this.radioButtonImmediateTrendFollower_CheckedChanged); + // // TestDisplayer // *************** *** 226,231 **** this.ClientSize = new System.Drawing.Size(584, 373); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.radioButtonOTCCTODaily, ! this.radioButtonReversalOneRank, this.labelDays, this.textBoxDaysFPOscillatorAndRevOneRank, --- 279,285 ---- this.ClientSize = new System.Drawing.Size(584, 373); this.Controls.AddRange(new System.Windows.Forms.Control[] { + this.radioButtonImmediateTrendFollower, this.radioButtonOTCCTODaily, ! this.radioButtonExtremeCounterTrend, this.labelDays, this.textBoxDaysFPOscillatorAndRevOneRank, *************** *** 288,293 **** this.dgBestGenomes_MouseUp_getClickedGenomeRepresentation( sender , e ); dgBestGenomes_MouseUp_rightButton_updateDates( genomeRepresentation ); ! string[] signedTickers = GenomeRepresentation.GetSignedTickers( ! genomeRepresentation.SignedTickers ); LinearCombinationTest linearCombinationTest = new LinearCombinationTest( this.dtpFirstDate.Value , --- 342,346 ---- this.dgBestGenomes_MouseUp_getClickedGenomeRepresentation( sender , e ); dgBestGenomes_MouseUp_rightButton_updateDates( genomeRepresentation ); ! string[] signedTickers = genomeRepresentation.SignedTickers.Split(";".ToCharArray()); LinearCombinationTest linearCombinationTest = new LinearCombinationTest( this.dtpFirstDate.Value , *************** *** 334,341 **** else if(this.radioButtonFixedPeriodOscillator.Checked) this.selectedStrategyType = StrategyType.FixedPeriodOscillator; ! else if(this.radioButtonReversalOneRank.Checked) this.selectedStrategyType = StrategyType.ExtremeCounterTrend; else if(this.radioButtonOTCCTODaily.Checked) this.selectedStrategyType = StrategyType.OpenToCloseCloseToOpenDaily; } --- 387,396 ---- else if(this.radioButtonFixedPeriodOscillator.Checked) this.selectedStrategyType = StrategyType.FixedPeriodOscillator; ! else if(this.radioButtonExtremeCounterTrend.Checked) this.selectedStrategyType = StrategyType.ExtremeCounterTrend; else if(this.radioButtonOTCCTODaily.Checked) this.selectedStrategyType = StrategyType.OpenToCloseCloseToOpenDaily; + else if(this.radioButtonImmediateTrendFollower.Checked) + this.selectedStrategyType = StrategyType.ImmediateTrendFollower; } *************** *** 360,367 **** } ! private void radioButtonReversalOneRank_CheckedChanged(object sender, System.EventArgs e) { this.update_selectedStrategyType(); } } } --- 415,428 ---- } ! private void radioButtonExtremeCounterTrend_CheckedChanged(object sender, System.EventArgs e) { this.update_selectedStrategyType(); } + + private void radioButtonImmediateTrendFollower_CheckedChanged(object sender, System.EventArgs e) + { + this.update_selectedStrategyType(); + } + } } |
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/TrendFollowing/ImmediateTrendFollower In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv13669/b7_Scripts/TechnicalAnalysisTesting/TrendFollowing/ImmediateTrendFollower Added Files: RunImmediateTrendFollower.cs GenomeManagerITF.cs EndOfDayTimerHandlerITF.cs Log Message: Added ImmediateTrendFollower strategy to the project. ITF strategy is just the reversal of the ECT (ExtremeCounterTrend strategy). --- NEW FILE: GenomeManagerITF.cs --- /* QuantProject - Quantitative Finance Library GenomeManagerITF.cs Copyright (C) 2003 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.Statistics; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Data; using QuantProject.Data.DataTables; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.TechnicalAnalysisTesting.TrendFollowing.ImmediateTrendFollower { /// <summary> /// Implements what needed to use the Genetic Optimizer /// for finding the portfolio that best suites /// the immediate trend follower strategy /// </summary> [Serializable] public class GenomeManagerITF : GenomeManagerForEfficientPortfolio { private int numDaysForReturnCalculation; public GenomeManagerITF(DataTable setOfInitialTickers, DateTime firstQuoteDate, DateTime lastQuoteDate, int numberOfTickersInPortfolio, int numDaysForReturnCalculation, PortfolioType portfolioType) : base(setOfInitialTickers, firstQuoteDate, lastQuoteDate, numberOfTickersInPortfolio, 0.0, portfolioType) { this.numDaysForReturnCalculation = numDaysForReturnCalculation; this.retrieveData(); } protected override float[] getArrayOfRatesOfReturn(string ticker) { float[] returnValue = null; Quotes tickerQuotes = new Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); returnValue = ExtendedDataTable.GetArrayOfFloatFromColumn(tickerQuotes, Quotes.AdjustedCloseToCloseRatio); for(int i = 0; i<returnValue.Length; i++) returnValue[i] = returnValue[i] - 1.0f; this.numberOfExaminedReturns = returnValue.Length; return returnValue; } //fitness is a sharpe-ratio based indicator for the equity line resulting //from applying the strategy public override double GetFitnessValue(Genome genome) { this.portfolioRatesOfReturn = this.getPortfolioRatesOfReturn(genome.Genes()); double[] equityLine = this.getFitnessValue_getEquityLineRates(); //return AdvancedFunctions.GetExpectancyScore(equityLine); return AdvancedFunctions.GetSharpeRatio(equityLine); } private double[] getFitnessValue_getEquityLineRates() { double[] returnValue = new double[this.PortfolioRatesOfReturn.Length]; double gainForTheLastHalfPeriod = 0.0; for(int i = this.numDaysForReturnCalculation - 1; i<this.PortfolioRatesOfReturn.Length - this.numDaysForReturnCalculation; i += this.numDaysForReturnCalculation) { gainForTheLastHalfPeriod = 0.0; for(int j=this.numDaysForReturnCalculation - 1; j > -1; j--) { gainForTheLastHalfPeriod = (1.0+gainForTheLastHalfPeriod) * this.PortfolioRatesOfReturn[i-j]; } for(int t=1;t<this.numDaysForReturnCalculation + 1;t++) { if(gainForTheLastHalfPeriod<0.0) // if gain of first half period is negative returnValue[i+t] = - this.PortfolioRatesOfReturn[i+t]; //return of the next half period is still negative else// if gain of first half period is positive returnValue[i+t] = this.PortfolioRatesOfReturn[i+t]; //return of the next half period is still positive } } return returnValue; } } } --- NEW FILE: EndOfDayTimerHandlerITF.cs --- /* QuantProject - Quantitative Finance Library EndOfDayTimerHandlerITF.cs Copyright (C) 2003 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.Business.Financial.Accounting; using QuantProject.Business.Financial.Instruments; using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Timing; using QuantProject.Business.Strategies; 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; namespace QuantProject.Scripts.TechnicalAnalysisTesting.TrendFollowing.ImmediateTrendFollower { /// <summary> /// Implements MarketOpenEventHandler and MarketCloseEventHandler /// These handlers contain the core strategy for the extreme /// counter trend strategy! /// </summary> [Serializable] public class EndOfDayTimerHandlerITF : EndOfDayTimerHandler { private int numDaysForReturnCalculation; private double maxAcceptableCloseToCloseDrawdown; private bool stopLossConditionReached; private double currentAccountValue; private double previousAccountValue; private int numDaysBetweenEachOptimization; private int numDaysElapsedSinceLastOptimization; private int daysCounterWithPositions; private DateTime lastCloseDate; private IGenomeManager iGenomeManager; public EndOfDayTimerHandlerITF(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, Account account, int generationNumberForGeneticOptimizer, int populationSizeForGeneticOptimizer, string benchmark, int numDaysForReturnCalculation, int numDaysBetweenEachOptimization, PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, account, generationNumberForGeneticOptimizer, populationSizeForGeneticOptimizer, benchmark, 0.0, portfolioType) { this.numDaysForReturnCalculation = numDaysForReturnCalculation; this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; this.stopLossConditionReached = false; this.currentAccountValue = 0.0; this.previousAccountValue = 0.0; // this.numDaysBetweenEachOptimization = 2* numDaysForReturnCalculation; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; } #region MarketCloseEventHandler protected void marketCloseEventHandler_updateStopLossCondition() { this.previousAccountValue = this.currentAccountValue; this.currentAccountValue = this.account.GetMarketValue(); if((this.currentAccountValue - this.previousAccountValue) /this.previousAccountValue < -this.maxAcceptableCloseToCloseDrawdown) { this.stopLossConditionReached = true; } else { this.stopLossConditionReached = false; } } private double marketCloseEventHandler_openPositions_getLastHalfPeriodGain(IndexBasedEndOfDayTimer timer) { double returnValue = 999.0; try { DateTime initialDateForHalfPeriod = (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition - this.numDaysForReturnCalculation + 1]["quDate"]; DateTime finalDateForHalfPeriod = (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition]["quDate"]; returnValue = SignedTicker.GetCloseToClosePortfolioReturn( this.chosenTickers, this.chosenTickersPortfolioWeights, initialDateForHalfPeriod,finalDateForHalfPeriod); } catch(MissingQuotesException ex) { ex = ex; } return returnValue; } private void marketCloseEventHandler_openPositions(IndexBasedEndOfDayTimer timer) { double lastHalfPeriodGain = this.marketCloseEventHandler_openPositions_getLastHalfPeriodGain(timer); if(lastHalfPeriodGain != 999.0) //last half period gain has been properly computed { if(lastHalfPeriodGain > 0.0) base.openPositions(); else//the last HalfPeriodGain has been negative { SignedTicker.ChangeSignOfEachTicker(this.chosenTickers); //short the portfolio try{ base.openPositions(); } catch(Exception ex){ ex = ex; } finally{SignedTicker.ChangeSignOfEachTicker(this.chosenTickers);} } } } private void marketCloseEventHandler_closePositions() { this.daysCounterWithPositions++; if(this.daysCounterWithPositions == this.numDaysForReturnCalculation || this.stopLossConditionReached) { //Close if halfPeriod has elapsed or stop loss condition reached base.closePositions(); this.daysCounterWithPositions = 0; } } public override void MarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { //this.marketCloseEventHandler_updateStopLossCondition(); this.marketCloseEventHandler_closePositions(); if(this.chosenTickers[0] != null) //tickers to buy have been chosen { if(this.account.Portfolio.Count == 0) this.marketCloseEventHandler_openPositions((IndexBasedEndOfDayTimer)sender); } } #endregion #region OneHourAfterMarketCloseEventHandler protected DataTable getSetOfTickersToBeOptimized(DateTime currentDate) { SelectorByGroup temporizedGroup = new SelectorByGroup(this.tickerGroupID, currentDate); DataTable tickersFromGroup = temporizedGroup.GetTableOfSelectedTickers(); int numOfTickersInGroupAtCurrentDate = tickersFromGroup.Rows.Count; SelectorByAverageRawOpenPrice byPrice = new SelectorByAverageRawOpenPrice(tickersFromGroup,false,currentDate, currentDate.AddDays(-30), numOfTickersInGroupAtCurrentDate, 30,500, 0.0001,100); // SelectorByLiquidity mostLiquidSelector = // new SelectorByLiquidity(byPrice.GetTableOfSelectedTickers(), // false,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, // this.numberOfEligibleTickers); SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromByPrice = new SelectorByQuotationAtEachMarketDay(byPrice.GetTableOfSelectedTickers(), false, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, numOfTickersInGroupAtCurrentDate, this.benchmark); SelectorByCloseToCloseVolatility lessVolatile = new SelectorByCloseToCloseVolatility(quotedAtEachMarketDayFromByPrice.GetTableOfSelectedTickers(), true,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, this.numberOfEligibleTickers); return lessVolatile.GetTableOfSelectedTickers(); //OLD for etf // SelectorByGroup temporizedGroup = new SelectorByGroup(this.tickerGroupID, // currentDate); // // SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromTemporized = // new SelectorByQuotationAtEachMarketDay(temporizedGroup.GetTableOfSelectedTickers(), // false, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, // 600, this.benchmark); // // filter to be used with plain stocks // DataTable tickersQuotedAtEachMarketDay = quotedAtEachMarketDayFromTemporized.GetTableOfSelectedTickers(); // SelectorByLiquidity mostLiquid = // new SelectorByLiquidity(tickersQuotedAtEachMarketDay, // false,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, // tickersQuotedAtEachMarketDay.Rows.Count/2); // // DataTable mostLiquidTickers = mostLiquid.GetTableOfSelectedTickers(); // // SelectorByCloseToCloseVolatility lessVolatile = // new SelectorByCloseToCloseVolatility(mostLiquidTickers, // true,currentDate.AddDays(-30), currentDate, // Math.Min(this.numberOfEligibleTickers, mostLiquidTickers.Rows.Count/2)); ////// return mostLiquid.GetTableOfSelectedTickers(); // return lessVolatile.GetTableOfSelectedTickers(); // // //// return quotedAtEachMarketDayFromTemporized.GetTableOfSelectedTickers(); } protected virtual void setTickers(DateTime currentDate, bool setGenomeCounter) { DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); if(setOfTickersToBeOptimized.Rows.Count > this.chosenTickers.Length*2) //the optimization process is meaningful only if the initial set of tickers is //larger than the number of tickers to be chosen { this.iGenomeManager = new GenomeManagerITF(setOfTickersToBeOptimized, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, this.numberOfTickersToBeChosen, this.numDaysForReturnCalculation, this.portfolioType); GeneticOptimizer GO = new GeneticOptimizer(this.iGenomeManager, this.populationSizeForGeneticOptimizer, this.generationNumberForGeneticOptimizer, ConstantsProvider.SeedForRandomGenerator); if(setGenomeCounter) this.genomeCounter = new GenomeCounter(GO); GO.Run(false); this.addGenomeToBestGenomes(GO.BestGenome,((GenomeManagerForEfficientPortfolio)this.iGenomeManager).FirstQuoteDate, ((GenomeManagerForEfficientPortfolio)this.iGenomeManager).LastQuoteDate, setOfTickersToBeOptimized.Rows.Count); this.chosenTickers = ((GenomeMeaning)GO.BestGenome.Meaning).Tickers; this.chosenTickersPortfolioWeights = ((GenomeMeaning)GO.BestGenome.Meaning).TickersPortfolioWeights; } //else it will be buyed again the previous optimized portfolio //that's it the actual chosenTickers member } /// <summary> /// Handles a "One hour after market close" event. /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> public override void OneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { this.lastCloseDate = endOfDayTimingEventArgs.EndOfDayDateTime.DateTime; ConstantsProvider.SeedForRandomGenerator++; this.numDaysElapsedSinceLastOptimization++; this.orders.Clear(); if((this.numDaysElapsedSinceLastOptimization - 1 == this.numDaysBetweenEachOptimization)) //|| this.isTheFirstClose ) //num days without optimization has elapsed or //it is the first close (OLD IMPLEMENTATION) { this.setTickers(endOfDayTimingEventArgs.EndOfDayDateTime.DateTime, false); //sets tickers to be chosen next Market Close event this.numDaysElapsedSinceLastOptimization = 0; } } #endregion } } --- NEW FILE: RunImmediateTrendFollower.cs --- /* QuantProject - Quantitative Finance Library RunImmediateTrendFollower.cs Copyright (C) 2003 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.Data; using QuantProject.ADT; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Business.DataProviders; using QuantProject.Business.Financial.Accounting; using QuantProject.Business.Financial.Accounting.Reporting; using QuantProject.Business.Financial.Instruments; using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Scripting; using QuantProject.Business.Strategies; using QuantProject.Business.Testing; using QuantProject.Business.Timing; using QuantProject.Data.DataProviders; using QuantProject.Data.Selectors; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Presentation.Reporting.WindowsForm; using QuantProject.ADT.FileManaging; using QuantProject.Scripts.WalkForwardTesting.LinearCombination; namespace QuantProject.Scripts.TechnicalAnalysisTesting.TrendFollowing.ImmediateTrendFollower { /// <summary> /// Script that implements the immediate trend follower strategy, /// for finding tickers that tend to /// earn (lose) from previous gains (losses), using efficient portfolios /// </summary> [Serializable] public class RunImmediateTrendFollower : RunEfficientPortfolio { private int numDaysForReturnCalculation; private double maxAcceptableCloseToCloseDrawdown; private int numDaysBetweenEachOptimization; public RunImmediateTrendFollower(string tickerGroupID, int maxNumOfEligibleTickersForOptimization, int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, int generationNumberForGeneticOptimizer, int populationSizeForGeneticOptimizer, string benchmark, DateTime startDate, DateTime endDate, int numDaysForReturnCalculation, int numDaysBetweenEachOptimization, PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown, double maxRunningHours): base(tickerGroupID, maxNumOfEligibleTickersForOptimization, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, generationNumberForGeneticOptimizer, populationSizeForGeneticOptimizer, benchmark, startDate, endDate, 0.0, portfolioType, maxRunningHours) { this.ScriptName = "ITF_Fitness_SR_NoWeights"; this.numDaysForReturnCalculation = numDaysForReturnCalculation; this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; } #region auxiliary overriden methods for Run protected override void run_initializeEndOfDayTimerHandler() { this.endOfDayTimerHandler = new EndOfDayTimerHandlerITF(this.tickerGroupID, this.numberOfEligibleTickers, this.numberOfTickersToBeChosen, this.numDaysForOptimizationPeriod, this.account, this.generationNumberForGeneticOptimizer, this.populationSizeForGeneticOptimizer, this.benchmark, this.numDaysForReturnCalculation, this.numDaysBetweenEachOptimization, this.portfolioType, this.maxAcceptableCloseToCloseDrawdown); } protected override void run_initializeHistoricalQuoteProvider() { this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); } protected override void run_addEventHandlers() { this.endOfDayTimer.MarketClose += new MarketCloseEventHandler( this.endOfDayTimerHandler.MarketCloseEventHandler); this.endOfDayTimer.MarketClose += new MarketCloseEventHandler( this.checkDateForReport); this.endOfDayTimer.OneHourAfterMarketClose += new OneHourAfterMarketCloseEventHandler( this.endOfDayTimerHandler.OneHourAfterMarketCloseEventHandler); } public override void SaveScriptResults() { string fileName = this.scriptName + "_From_"+ this.tickerGroupID + "_" + this.numberOfEligibleTickers + "_DaysForOpt" + this.numDaysForOptimizationPeriod + "Tickers" + this.numberOfTickersToBeChosen + "GenNum" + this.generationNumberForGeneticOptimizer + "PopSize" + this.populationSizeForGeneticOptimizer + "HalfPeriodDays" + Convert.ToString(this.numDaysForReturnCalculation) + 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 + "\\"; //default report with numIntervalDays = 1 AccountReport accountReport = this.account.CreateReport(fileName,1, this.endOfDayTimer.GetCurrentTime(), this.benchmark, new HistoricalAdjustedQuoteProvider()); this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveReports); ObjectArchiver.Archive(accountReport, dirNameWhereToSaveReports + fileName + ".qPr"); // // this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveTransactions); // ObjectArchiver.Archive(this.account.Transactions, // dirNameWhereToSaveTransactions + // fileName + ".qPt"); // this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveBestGenomes); OptimizationOutput optimizationOutput = new OptimizationOutput(); foreach(GenomeRepresentation genomeRepresentation in this.endOfDayTimerHandler.BestGenomes) optimizationOutput.Add(genomeRepresentation); ObjectArchiver.Archive(optimizationOutput, dirNameWhereToSaveBestGenomes + fileName + ".bgn"); this.endOfDayTimer.Stop(); } #endregion } } |
|
From: Marco M. <mi...@us...> - 2006-08-03 21:14:17
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv13669/b7_Scripts/WalkForwardTesting/LinearCombination Added Files: ImmediateTrendFollowerStrategy.cs Log Message: Added ImmediateTrendFollower strategy to the project. ITF strategy is just the reversal of the ECT (ExtremeCounterTrend strategy). --- NEW FILE: ImmediateTrendFollowerStrategy.cs --- /* QuantProject - Quantitative Finance Library ImmediateTrendFollowerStrategy.cs Copyright (C) 2003 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.Data; using QuantProject.Data.DataTables; using QuantProject.Business.Financial.Accounting; using QuantProject.Business.Financial.Instruments; using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Strategies; using QuantProject.Business.Timing; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.WalkForwardTesting.LinearCombination { /// <summary> /// Immediate Trend Follower Strategy (it's just the /// reversal of the ExtremeCounterTrend strategy /// </summary> [Serializable] public class ImmediateTrendFollowerStrategy : IEndOfDayStrategy { private Account account; private string[] signedTickers; private double[] weightsForSignedTickers; private int numDaysForReturnCalculation; private int numOfClosesElapsed = 0; private int numOfDaysWithOpenPosition = 0; public ImmediateTrendFollowerStrategy( Account account , string[] signedTickers, double[] weightsForSignedTickers, int numDaysForReturnCalculation) { this.account = account; this.signedTickers = signedTickers; this.weightsForSignedTickers = weightsForSignedTickers; this.numDaysForReturnCalculation = numDaysForReturnCalculation; } public void MarketOpenEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { } public void FiveMinutesBeforeMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs) { } private long marketCloseEventHandler_addOrder_getQuantity( int indexForSignedTicker) { double accountValue = this.account.GetMarketValue(); double currentTickerAsk = this.account.DataStreamer.GetCurrentAsk( SignedTicker.GetTicker(this.signedTickers[indexForSignedTicker]) ); double maxPositionValueForThisTicker = accountValue*this.weightsForSignedTickers[indexForSignedTicker]; long quantity = Convert.ToInt64( Math.Floor( maxPositionValueForThisTicker / currentTickerAsk ) ); return quantity; } private void marketCloseEventHandler_addOrder( int indexForSignedTicker ) { OrderType orderType = GenomeRepresentation.GetOrderType( this.signedTickers[indexForSignedTicker] ); string ticker = GenomeRepresentation.GetTicker( this.signedTickers[indexForSignedTicker] ); long quantity = marketCloseEventHandler_addOrder_getQuantity( indexForSignedTicker ); Order order = new Order( orderType , new Instrument( ticker ) , quantity ); this.account.AddOrder( order ); } private void marketCloseEventHandler_addOrders() { for(int i = 0; i<this.signedTickers.Length; i++) marketCloseEventHandler_addOrder( i ); } private double marketCloseEventHandler_openPositions_getLastHalfPeriodGain(IndexBasedEndOfDayTimer timer) { double returnValue = 999.0; try { DateTime initialDateForHalfPeriod = (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition - this.numDaysForReturnCalculation + 1]["quDate"]; DateTime finalDateForHalfPeriod = (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition]["quDate"]; returnValue = SignedTicker.GetCloseToClosePortfolioReturn( this.signedTickers,initialDateForHalfPeriod,finalDateForHalfPeriod); } catch(MissingQuotesException ex) { ex = ex; } return returnValue; } private void marketCloseEventHandler_openPositions(IndexBasedEndOfDayTimer timer) { double lastHalfPeriodGain = this.marketCloseEventHandler_openPositions_getLastHalfPeriodGain(timer); if(lastHalfPeriodGain != 999.0) //last half period gain has been properly computed { if(lastHalfPeriodGain > 0.0) //the portfolio had a gain for the last half period this.marketCloseEventHandler_addOrders(); else//the portfolio had a loss for the last half period { SignedTicker.ChangeSignOfEachTicker(this.signedTickers); //short the portfolio try{this.marketCloseEventHandler_addOrders();} catch(Exception ex){ex = ex;} finally{SignedTicker.ChangeSignOfEachTicker(this.signedTickers);} } } } private void marketCloseEventHandler_closePositions() { ArrayList tickers = new ArrayList(); foreach ( Position position in this.account.Portfolio.Positions ) tickers.Add( position.Instrument.Key ); foreach ( string ticker in tickers ) this.account.ClosePosition( ticker ); this.numOfDaysWithOpenPosition = 0; } public void MarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if(this.account.Transactions.Count == 0) this.account.AddCash(30000); if(this.account.Portfolio.Count > 0) this.numOfDaysWithOpenPosition++; if(this.numOfDaysWithOpenPosition == this.numDaysForReturnCalculation) this.marketCloseEventHandler_closePositions(); if(this.account.Portfolio.Count == 0 && (this.numOfClosesElapsed + 1) >= this.numDaysForReturnCalculation) //portfolio is empty and previous closes can be now checked if(this.account.Portfolio.Count == 0) this.marketCloseEventHandler_openPositions((IndexBasedEndOfDayTimer)sender); this.numOfClosesElapsed++; } public void OneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs) { } } } |
|
From: Marco M. <mi...@us...> - 2006-08-03 21:10:27
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/TrendFollowing/ImmediateTrendFollower In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv12071/ImmediateTrendFollower Log Message: Directory /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/TrendFollowing/ImmediateTrendFollower added to the repository |
|
From: Marco M. <mi...@us...> - 2006-08-03 21:09:52
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/TrendFollowing In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv11688/TrendFollowing Log Message: Directory /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/TrendFollowing added to the repository |
|
From: Marco M. <mi...@us...> - 2006-08-02 21:55:47
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv1350/b1_ADT/Optimizing/Genetic Modified Files: Genome.cs Log Message: Fixed bug in Clone() method: field "generation" is now properly initialized to the value of the genome that has to be cloned Index: Genome.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/Genome.cs,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Genome.cs 30 Jul 2006 14:00:28 -0000 1.11 --- Genome.cs 2 Aug 2006 21:55:42 -0000 1.12 *************** *** 158,161 **** --- 158,162 ---- returnValue.Fitness = this.Fitness; returnValue.Meaning = this.Meaning; + returnValue.generation = this.Generation; returnValue.hasBeenCloned = true; |
|
From: Marco M. <mi...@us...> - 2006-08-02 17:19:37
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv10406/b1_ADT/Optimizing/Genetic Modified Files: GenomeManagement.cs Log Message: Fixed bug in setMaskForChildsForAlternateFixedCrossover method. Index: GenomeManagement.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/GenomeManagement.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** GenomeManagement.cs 2 Jul 2006 19:51:36 -0000 1.8 --- GenomeManagement.cs 2 Aug 2006 17:19:30 -0000 1.9 *************** *** 142,155 **** private static void setMaskForChildsForAlternateFixedCrossover() { ! for(int childIndex = 0; childIndex < 2; childIndex++) { ! for(int genePos = 0; genePos < genomeSize; genePos++) { ! if(genePos%2 == 0) ! //gene position is even ! maskForChilds[childIndex, genePos] = 1; ! else ! // gene position is odd ! maskForChilds[childIndex, genePos] = 2; } } --- 142,158 ---- private static void setMaskForChildsForAlternateFixedCrossover() { ! for(int genePos = 0; genePos < genomeSize; genePos++) { ! if(genePos%2 == 0) ! //gene position is even ! { ! maskForChilds[0, genePos] = 1; ! maskForChilds[1, genePos] = 2; ! } ! else ! // gene position is odd { ! maskForChilds[0, genePos] = 2; ! maskForChilds[1, genePos] = 1; } } |
|
From: Glauco S. <gla...@us...> - 2006-07-31 16:42:32
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv7185/b7_Scripts/WalkForwardTesting/WalkForwardLag Added Files: WeightedPositions.cs Log Message: WeightedPositions.cs has been moved from the b7_Scripts.csproj project to the b4_Business.csproj project. It has been moved from a2_Strategies\WeightedPositions.cs to WalkForwardTesting\WalkForwardLag\WeightedPositions.cs It has been moved from the namespace QuantProject.Business.Strategies to the namespace QuantProject.Scripts.WalkForwardTesting.WalkForwardLag This move was needed because I need to deserialize some QuantProject.Scripts.WalkForwardTesting.WalkForwardLag.WeightedPositions objects, but I believe the proper namespace should be QuantProject.Business.Strategies So, it may be a good idea to move it there, when possible, in the future. --- NEW FILE: WeightedPositions.cs --- /* QuantProject - Quantitative Finance Library WeightedPositions.cs Copyright (C) 2003 Glauco Siliprandi 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.Business.DataProviders; using QuantProject.Business.Financial.Accounting; using QuantProject.Business.Strategies; using QuantProject.Business.Timing; namespace QuantProject.Scripts.WalkForwardTesting.WalkForwardLag { [Serializable] /// <summary> /// Consistent group of weighted positions: weights are /// checked to sum up to 1. /// </summary> public class WeightedPositions : SortedList { /// <summary> /// returns the type for this class /// </summary> public static System.Type Type { get { return getType(); } } public WeightedPositions( double[] normalizedWeightValues , string[] tickers ) { this.checkParameters( normalizedWeightValues , tickers ); for ( int i=0 ; i < tickers.Length ; i++ ) { string ticker = tickers[ i ]; double weight = normalizedWeightValues[ i ]; if ( !this.ContainsKey( ticker ) ) this.Add( ticker , new WeightedPosition( weight , ticker ) ); else ((WeightedPosition)this[ ticker ]).Weight += weight; } } private void checkParameters( double[] normalizedWeightValues , string[] tickers ) { if ( normalizedWeightValues.Length != tickers.Length ) throw new Exception( "The number of normalized weights is " + "different from the number of tickers. They should be the same " + "number!" ); double totalWeight = ADT.Statistics.BasicFunctions.SumOfAbs( normalizedWeightValues ); if ( ( totalWeight < 0.999 ) || ( totalWeight > 1.001 ) ) throw new Exception( "The total of (absolute) weights " + "should sum up to 1, " + "but it sums up to " + totalWeight.ToString() ); } public WeightedPosition GetWeightedPosition( string ticker ) { return (WeightedPosition)this[ ticker ]; } public WeightedPosition GetWeightedPosition( int i ) { return (WeightedPosition)this.GetByIndex( i ); } #region GetEquityLine /// <summary> /// Returns a virtual amount of quantities for each virtual ticker. /// Non integer values can be returned also, that's why we call /// them virtual quantities /// </summary> /// <returns></returns> private Hashtable getVirtualQuantities( double beginningCash , DateTime dateTime ) { Hashtable virtualQuantities = new Hashtable(); HistoricalAdjustedQuoteProvider historicalAdjustedQuoteProvider = new HistoricalAdjustedQuoteProvider(); EndOfDayDateTime endOfDayDateTime = new EndOfDayDateTime( dateTime , EndOfDaySpecificTime.MarketClose ); foreach( WeightedPosition weightedPosition in this.Values ) { string ticker = weightedPosition.Ticker; double valueForThisPosition = beginningCash * Math.Abs( weightedPosition.Weight ); double tickerQuote = historicalAdjustedQuoteProvider.GetMarketValue( ticker , endOfDayDateTime ); double virtualQuantityForThisPosition = valueForThisPosition / tickerQuote; if ( weightedPosition.IsShort ) virtualQuantityForThisPosition = -virtualQuantityForThisPosition; virtualQuantities.Add( ticker , virtualQuantityForThisPosition ); } return virtualQuantities; } private double getCash( double beginningCash , Hashtable virtualQuantities ) { double cash = beginningCash; foreach ( WeightedPosition weightedPosition in this.Values ) { double thisVirtualQuantity = (double)virtualQuantities[ weightedPosition.Ticker ]; double thisPositionValue = beginningCash * Math.Abs( weightedPosition.Weight ); if ( thisVirtualQuantity > 0 ) // long position cash -= thisPositionValue; else // virtualQuantity < 0 i.e. short position cash += thisPositionValue; } return cash; } private double getVirtualPortfolioValue( DateTime dateTime , Hashtable tickerVirtualQuantities ) { HistoricalAdjustedQuoteProvider historicalAdjustedQuoteProvider = new HistoricalAdjustedQuoteProvider(); double virtualPortfolioValue = 0; foreach( string ticker in tickerVirtualQuantities.Keys ) { EndOfDayDateTime endOfDayDateTime = new EndOfDayDateTime( dateTime , EndOfDaySpecificTime.MarketClose ); double tickerQuote = historicalAdjustedQuoteProvider.GetMarketValue( ticker , endOfDayDateTime ); double virtualQuantity = (double)tickerVirtualQuantities[ ticker ]; virtualPortfolioValue += virtualQuantity * tickerQuote; } return virtualPortfolioValue; } /// <summary> /// computes the equity line for this weighted positions. The equity line is virtual because /// quantities for each ticker can be non integer also (it is simulated an account where /// every single penny is always invested, so fractional quantities are simulated) /// </summary> /// <param name="beginningCash">cash amount when the simulated strategy begins</param> /// <param name="equityDates">an ordered list of DateTime(s) where the equity line has to be computed</param> /// <returns></returns> public EquityLine GetVirtualEquityLine( double beginningCash , SortedList equityDates ) { DateTime firstDate = (DateTime)equityDates.GetKey( 0 ); EquityLine equityLine = new EquityLine(); Hashtable virtualQuantities = this.getVirtualQuantities( beginningCash , firstDate ); double cash = this.getCash( beginningCash , virtualQuantities ); for( int i = 0 ; i < equityDates.Count ; i++ ) { DateTime dateTime = (DateTime)equityDates.GetKey( i ); equityLine.Add( dateTime , cash + this.getVirtualPortfolioValue( dateTime , virtualQuantities ) ); } return equityLine; } #endregion #region getType private static WeightedPositions getSimpleDummyInstance() { double[] weights = {1.0}; string[] tickers = {"DUMMY"}; WeightedPositions dummyInstance = new WeightedPositions( weights , tickers ); return dummyInstance; } private static System.Type getType() { WeightedPositions weightedPositions = WeightedPositions.getSimpleDummyInstance(); return weightedPositions.GetType(); } #endregion #region GetCloseToClosePortfolioReturns // private static double getCloseToCloseReturn( string ticker , // SortedList datesForReturnComputation , int i ) // { // DateTime previousDate = (DateTime)datesForReturnComputation.GetByIndex( i ); // DateTime currentDate = // (DateTime)datesForReturnComputation.GetByIndex( i + 1 ); // HistoricalAdjustedQuoteProvider historicalQuoteProvider = // new HistoricalAdjustedQuoteProvider(); // double previousQuote = historicalQuoteProvider.GetMarketValue( ticker , // new EndOfDayDateTime( previousDate , EndOfDaySpecificTime.MarketClose ) ); // double currentQuote = historicalQuoteProvider.GetMarketValue( ticker , // new EndOfDayDateTime( currentDate , EndOfDaySpecificTime.MarketClose ) ); // double closeToCloseReturn = currentQuote / previousQuote - 1.0; // return closeToCloseReturn; // } // private static double getMultiplier( string signedTicker ) // { // double multiplier = 1.0; // if ( IsShort( signedTicker ) ) // multiplier = -multiplier; // return multiplier; // } private double getCloseToClosePortfolioReturn( SortedList datesForReturnComputation , int i ) { DateTime dateTime = (DateTime)datesForReturnComputation.GetByIndex( i + 1 ); double dailyReturn = 0.0; foreach ( WeightedPosition weightedPosition in this.Values ) dailyReturn += weightedPosition.GetCloseToCloseDailyReturn( dateTime ); return dailyReturn; } private double[] getCloseToClosePortfolioReturns( SortedList datesForReturnComputation ) { // the return for first DateTime cannot be computed so the returned // array will have one element less the datesForReturnComputation double[] closeToClosePortfolioReturns = new double[ datesForReturnComputation.Count - 1 ]; for ( int i=0 ; i < closeToClosePortfolioReturns.Length ; i++ ) closeToClosePortfolioReturns[ i ] = this.getCloseToClosePortfolioReturn( datesForReturnComputation , i ); return closeToClosePortfolioReturns; } /// <summary> /// Gets portfolio's return (for this weighted positions) computed on the /// market days contained in commonMarketDays /// </summary> /// <param name="commonMarketDays">SortedList of DateTime objects: positions /// are assumed to be exchanged in all such market days, otherwise /// an exception should be thrown</param> /// <returns></returns> public double[] GetCloseToClosePortfolioReturns( SortedList commonMarketDays ) { // TO DO check parameter: check if each position is exchanged in each common market day return getCloseToClosePortfolioReturns( commonMarketDays ); } #endregion } } |
|
From: Glauco S. <gla...@us...> - 2006-07-31 16:42:14
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv7065/b4_Business/a2_Strategies Removed Files: WeightedPositions.cs Log Message: WeightedPositions.cs has been moved from the b7_Scripts.csproj project to the b4_Business.csproj project. It has been moved from a2_Strategies\WeightedPositions.cs to WalkForwardTesting\WalkForwardLag\WeightedPositions.cs It has been moved from the namespace QuantProject.Business.Strategies to the namespace QuantProject.Scripts.WalkForwardTesting.WalkForwardLag This move was needed because I need to deserialize some QuantProject.Scripts.WalkForwardTesting.WalkForwardLag.WeightedPositions objects, but I believe the proper namespace should be QuantProject.Business.Strategies So, it may be a good idea to move it there, when possible, in the future. --- WeightedPositions.cs DELETED --- |
|
From: Glauco S. <gla...@us...> - 2006-07-31 16:39:58
|
Update of /cvsroot/quantproject/QuantProject/b4_Business In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv5318/b4_Business Modified Files: b4_Business.csproj Log Message: WeightedPositions.cs has been moved from the b7_Scripts.csproj project to the b4_Business.csproj project. It has been moved from a2_Strategies\WeightedPositions.cs to WalkForwardTesting\WalkForwardLag\WeightedPositions.cs It has been moved from the namespace QuantProject.Business.Strategies to the namespace QuantProject.Scripts.WalkForwardTesting.WalkForwardLag This move was needed because I need to deserialize some QuantProject.Scripts.WalkForwardTesting.WalkForwardLag.WeightedPositions objects, but I believe the proper namespace should be QuantProject.Business.Strategies So, it may be a good idea to move it there, when possible, in the future. Index: b4_Business.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/b4_Business.csproj,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** b4_Business.csproj 30 Jul 2006 12:57:34 -0000 1.35 --- b4_Business.csproj 31 Jul 2006 16:39:47 -0000 1.36 *************** *** 620,628 **** /> <File - RelPath = "a2_Strategies\WeightedPositions.cs" - SubType = "Code" - BuildAction = "Compile" - /> - <File RelPath = "a3_Testing\BackTester.cs" SubType = "Code" --- 620,623 ---- |
|
From: Glauco S. <gla...@us...> - 2006-07-31 16:39:58
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv5318/b7_Scripts Modified Files: b7_Scripts.csproj Log Message: WeightedPositions.cs has been moved from the b7_Scripts.csproj project to the b4_Business.csproj project. It has been moved from a2_Strategies\WeightedPositions.cs to WalkForwardTesting\WalkForwardLag\WeightedPositions.cs It has been moved from the namespace QuantProject.Business.Strategies to the namespace QuantProject.Scripts.WalkForwardTesting.WalkForwardLag This move was needed because I need to deserialize some QuantProject.Scripts.WalkForwardTesting.WalkForwardLag.WeightedPositions objects, but I believe the proper namespace should be QuantProject.Business.Strategies So, it may be a good idea to move it there, when possible, in the future. Index: b7_Scripts.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/b7_Scripts.csproj,v retrieving revision 1.58 retrieving revision 1.59 diff -C2 -d -r1.58 -r1.59 *** b7_Scripts.csproj 30 Jul 2006 13:05:18 -0000 1.58 --- b7_Scripts.csproj 31 Jul 2006 16:39:47 -0000 1.59 *************** *** 589,592 **** --- 589,597 ---- /> <File + RelPath = "WalkForwardTesting\WalkForwardLag\WeightedPositions.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "WalkForwardTesting\WalkForwardLag\WFLagCandidates.cs" SubType = "Code" |
|
From: Glauco S. <gla...@us...> - 2006-07-30 14:16:35
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Statistics In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv24287/b1_ADT/Statistics Modified Files: BasicFunctions.cs Log Message: - the public method SumOfAbs has been added - the public method MultiplyBy has been added Index: BasicFunctions.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Statistics/BasicFunctions.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** BasicFunctions.cs 2 Jul 2006 19:29:52 -0000 1.7 --- BasicFunctions.cs 30 Jul 2006 14:16:31 -0000 1.8 *************** *** 98,101 **** --- 98,120 ---- } + static public double SumOfAbs( double[] data ) + { + double sum = 0; + for( int i = 0; i < data.Length ; i ++ ) + { + sum += Math.Abs( data[ i ] ); + } + return sum; + } + static public double[] MultiplyBy( double[] data , double multiplier ) + { + double[] returnData = new double[ data.Length ]; + for( int i = 0; i < data.Length ; i ++ ) + { + returnData[ i ] = data[ i ] * multiplier; + } + return returnData; + } + static public double SimpleAverage( double[] data ) { |
|
From: Glauco S. <gla...@us...> - 2006-07-30 14:00:32
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv17615/b1_ADT/Optimizing/Genetic Modified Files: Genome.cs Log Message: - now, an exception is thrown if Fitness is required, but Fitness is not a number (in such a case, probably it is requested before it is computed) Index: Genome.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/Genome.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Genome.cs 8 Nov 2005 18:32:25 -0000 1.10 --- Genome.cs 30 Jul 2006 14:00:28 -0000 1.11 *************** *** 63,67 **** public double Fitness { ! get{return this.fitness;} set{this.fitness = value;} } --- 63,73 ---- public double Fitness { ! get ! { ! if ( double.IsNaN( this.fitness ) ) ! throw new Exception( ! "The fitness for this genome is not a number!" ); ! return this.fitness; ! } set{this.fitness = value;} } |
|
From: Glauco S. <gla...@us...> - 2006-07-30 13:58:29
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/FileManaging In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv16800/b1_ADT/FileManaging Modified Files: ObjectArchiver.cs Log Message: - a try catch structure has been cut out Index: ObjectArchiver.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/FileManaging/ObjectArchiver.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ObjectArchiver.cs 8 Jun 2006 18:43:57 -0000 1.3 --- ObjectArchiver.cs 30 Jul 2006 13:58:26 -0000 1.4 *************** *** 64,69 **** object returnValue = null; ! try ! { ObjectArchiver.stream = new FileStream( fullPath, --- 64,69 ---- object returnValue = null; ! // try ! // { ObjectArchiver.stream = new FileStream( fullPath, *************** *** 72,85 **** FileShare.None); returnValue = ObjectArchiver.formatter.Deserialize(stream); ! } ! catch( Exception ex ) ! { ! string stringForBreakpoint = ex.Message; ! stringForBreakpoint = stringForBreakpoint; ! } ! finally ! { ObjectArchiver.stream.Close(); ! } return returnValue; } --- 72,85 ---- FileShare.None); returnValue = ObjectArchiver.formatter.Deserialize(stream); ! // } ! // catch( Exception ex ) ! // { ! // string stringForBreakpoint = ex.Message; ! // stringForBreakpoint = stringForBreakpoint; ! // } ! // finally ! // { ObjectArchiver.stream.Close(); ! // } return returnValue; } |
|
From: Glauco S. <gla...@us...> - 2006-07-30 13:57:10
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a2_Accounting In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv16245/b4_Business/a1_Financial/a2_Accounting Modified Files: Position.cs Log Message: - the IsLong property has been added - the IsShort propery has been added Index: Position.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a2_Accounting/Position.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Position.cs 15 Oct 2005 18:19:22 -0000 1.2 --- Position.cs 30 Jul 2006 13:57:06 -0000 1.3 *************** *** 64,67 **** --- 64,75 ---- } } + public bool IsLong + { + get { return ( this.Quantity >= 0 ); } + } + public bool IsShort + { + get { return ( !this.IsLong ); } + } public Position( Instrument instrument , long quantity ) { |
|
From: Glauco S. <gla...@us...> - 2006-07-30 13:55:42
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataTables In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv15565/b3_Data/DataTables Modified Files: Quotes.cs Log Message: The removeNonContainedDates private method has been fixed (to say the truth, never used yet, so it may still require some tuning...) Index: Quotes.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/DataTables/Quotes.cs,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** Quotes.cs 22 Jul 2006 20:56:09 -0000 1.28 --- Quotes.cs 30 Jul 2006 13:55:39 -0000 1.29 *************** *** 59,69 **** this.removeNonContainedDates( marketDays ); } ! private void removeNonContainedDates( SortedList marketDays ) { foreach( DataRow dataRow in this.Rows ) ! if ( marketDays.ContainsKey( (DateTime)dataRow[ Quotes.Date ] ) ) ! this.Rows.Remove( dataRow ); } public Quotes( string ticker ) { --- 59,87 ---- this.removeNonContainedDates( marketDays ); } ! #region removeNonContainedDates ! private ArrayList removeNonContainedDates_getDataRowsToBeRemoved( ! SortedList marketDays ) { + ArrayList dataRowsToBeRemoved = new ArrayList(); foreach( DataRow dataRow in this.Rows ) ! if ( !marketDays.ContainsKey( (DateTime)dataRow[ Quotes.Date ] ) ) ! dataRowsToBeRemoved.Add( dataRow ); ! return dataRowsToBeRemoved; ! } ! private void removeDataRows( ICollection dataRowsToBeRemoved ) ! { ! foreach ( DataRow dataRowToBeRemoved in dataRowsToBeRemoved ) ! this.Rows.Remove( dataRowToBeRemoved ); ! } ! private void removeNonContainedDates( SortedList marketDays ) ! { ! ArrayList dataRowsToBeRemoved = ! this.removeNonContainedDates_getDataRowsToBeRemoved( ! marketDays ); ! this.removeDataRows( dataRowsToBeRemoved ); } + #endregion + public Quotes( string ticker ) { |
|
From: Glauco S. <gla...@us...> - 2006-07-30 13:53:29
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv14660/b7_Scripts/WalkForwardTesting/WalkForwardLag Modified Files: WFLagCandidates.cs Log Message: - added a constructor's parameter checking procedure (at least two eligible tickers are required; lastQuoteDate is checked not to lead firstQuoteDate) - the public method GetTickersReturns has been added Index: WFLagCandidates.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagCandidates.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** WFLagCandidates.cs 14 May 2006 21:30:01 -0000 1.3 --- WFLagCandidates.cs 30 Jul 2006 13:53:26 -0000 1.4 *************** *** 44,51 **** --- 44,63 ---- DateTime firstQuoteDate , DateTime lastQuoteDate ) { + this.checkParameters( eligibleTickers , firstQuoteDate , + lastQuoteDate ); this.eligibleTickers = eligibleTickers; this.firstQuoteDate = firstQuoteDate; this.lastQuoteDate = lastQuoteDate; } + private void checkParameters( DataTable eligibleTickers , + DateTime firstQuoteDate , DateTime lastQuoteDate ) + { + if ( eligibleTickers.Rows.Count < 2 ) + throw new Exception( "eligibleTickers is expected to have at least " + + "two rows. It has less than two rows!" ); + if ( firstQuoteDate >= lastQuoteDate ) + throw new Exception( "firstQuoteDate has to be less than" + + "lastQuoteDate!" ); + } /// <summary> /// arrays of close to close returns, one for each ticker *************** *** 67,70 **** --- 79,98 ---- } + /// <summary> + /// arrays of close to close returns, one for each ticker + /// </summary> + /// <param name="tickers"></param> + /// <returns></returns> + public float[][] GetTickersReturns( string[] tickers ) + { + if ( this.closeToCloseReturns == null ) + this.set_closeToCloseReturns(); + float[][] tickersReturns = new float[ tickers.Length ][]; + int i = 0; + for ( i = 0 ; i < tickers.Length ; i++ ) + tickersReturns[ i ] = (float[])this.closeToCloseReturns[ tickers[ i ] ]; + return tickersReturns; + } + #region set_closeToCloseReturns private float[] getCloseToCloseTickerReturns( string ticker ) |
|
From: Glauco S. <gla...@us...> - 2006-07-30 13:50:29
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv13432/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger Modified Files: WFLagChosenPositions.cs Log Message: - WeightedPositions are used instead of SignedTickers - now the ISerializable interface is implemented, so that old logs can be examined yet - it may be worth looking at the deserializing code (not that simple...), as an example for future custom deserialization (if and when needed) Index: WFLagChosenPositions.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger/WFLagChosenPositions.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** WFLagChosenPositions.cs 8 Apr 2006 18:12:40 -0000 1.1 --- WFLagChosenPositions.cs 30 Jul 2006 13:50:26 -0000 1.2 *************** *** 22,27 **** --- 22,31 ---- using System; + using System.Collections; + using System.Reflection; + using System.Runtime.Serialization; using QuantProject.ADT.Collections; + using QuantProject.Business.Strategies; using QuantProject.Scripts.WalkForwardTesting.WalkForwardLag; *************** *** 32,53 **** /// </summary> [Serializable] ! public class WFLagChosenPositions { private QPHashtable drivingPositions; private QPHashtable portfolioPositions; private DateTime lastOptimizationDate; ! public QPHashtable DrivingPositions { get { ! return this.drivingPositions; } } ! public QPHashtable PortfolioPositions { get { ! return this.portfolioPositions; } } --- 36,67 ---- /// </summary> [Serializable] ! public class WFLagChosenPositions : ISerializable { + // these private members are used for old versions' deserialization, only private QPHashtable drivingPositions; private QPHashtable portfolioPositions; + + private WeightedPositions drivingWeightedPositions; + private WeightedPositions portfolioWeightedPositions; private DateTime lastOptimizationDate; ! public WeightedPositions DrivingWeightedPositions { get { ! if ( this.drivingWeightedPositions == null ) ! // an old version has been deserialized ! this.setWeightedPositionsFromQPHashtables(); ! return this.drivingWeightedPositions; } } ! public WeightedPositions PortfolioWeightedPositions { get { ! if ( this.portfolioWeightedPositions == null ) ! // an old version has been deserialized ! this.setWeightedPositionsFromQPHashtables(); ! return this.portfolioWeightedPositions; } } *************** *** 63,80 **** DateTime lastOptimizationDate ) { ! this.drivingPositions = ! this.copy( wFLagChosenTickers.DrivingPositions ); ! this.portfolioPositions = ! this.copy( wFLagChosenTickers.PortfolioPositions ); this.lastOptimizationDate = lastOptimizationDate; } ! private QPHashtable copy( QPHashtable qPHashTable ) { ! QPHashtable newCopy = new QPHashtable(); ! foreach ( string key in qPHashTable.Keys ) ! newCopy.Add( key , null ); ! return newCopy; } } } --- 77,232 ---- DateTime lastOptimizationDate ) { ! // this.drivingPositions = ! // this.copy( wFLagChosenTickers.DrivingWeightedPositions ); ! // this.portfolioPositions = ! // this.copy( wFLagChosenTickers.PortfolioWeightedPositions ); ! this.drivingWeightedPositions = wFLagChosenTickers.DrivingWeightedPositions; ! this.portfolioWeightedPositions = wFLagChosenTickers.PortfolioWeightedPositions; this.lastOptimizationDate = lastOptimizationDate; } ! #region deserialization related constructor and methods ! protected WFLagChosenPositions( SerializationInfo info , StreamingContext context ) { ! this.deserializeBaseClassMembers( info , context ); ! this.deserializeThisClassMembers( info , context ); ! } ! private void deserializeBaseClassMembers( SerializationInfo info , StreamingContext context ) ! { ! // get the set of serializable members for this class and its base classes ! Type thisType = this.GetType(); ! MemberInfo[] memberInfos = FormatterServices.GetSerializableMembers( ! thisType , context); ! ! // deserialize the fields from the info object, only if of the base clas ! for (Int32 i = 0 ; i < memberInfos.Length; i++) ! { ! // Don't deserialize fields for this class ! if (memberInfos[i].DeclaringType != thisType) ! { ! FieldInfo fieldInfo = (FieldInfo) memberInfos[i]; ! ! // set the field to the deserialized value ! fieldInfo.SetValue( this , ! info.GetValue( fieldInfo.Name, fieldInfo.FieldType ) ); ! } ! } ! } ! private void deserializeDrivingWeightedPositions( ! SerializationInfo info , StreamingContext context ) ! { ! try ! { ! // this.drivingWeightedPositions = new WeightedPositions() ! // System.Type type = System.Type.GetType( ! // "QuantProject.Scripts.WalkForwardTesting.WalkForwardLag.WeightedPositions" ); ! this.drivingWeightedPositions = (WeightedPositions)info.GetValue( ! "drivingWeightedPositions" , WeightedPositions.Type ); ! } ! catch( Exception ex1 ) ! { ! // the serialized WFLagChosenPositions is of old type ! // drivingPositions and portfolioPositions are QPHashtable ! try ! { ! string errorMessage1 = ex1.Message; ! this.drivingPositions = new QPHashtable(); ! this.drivingPositions = (QPHashtable)info.GetValue( ! "drivingPositions" , this.drivingPositions.GetType() ); ! // drivingWeightedPositions = this.getWeightedPositions( drivingPositions ); ! } ! catch( Exception ex2 ) ! { ! string errorMessage = ex2.Message; ! errorMessage = errorMessage; ! } ! } ! } ! private void deserializePortfolioWeightedPositions( ! SerializationInfo info , StreamingContext context ) ! { ! try ! { ! // this.portfolioWeightedPositions = new WeightedPositions(); ! // System.Type type = System.Type.GetType( ! // "QuantProject.Scripts.WalkForwardTesting.WalkForwardLag.WeightedPositions" ); ! this.portfolioWeightedPositions = (WeightedPositions)info.GetValue( ! "portfolioWeightedPositions" , WeightedPositions.Type ); ! } ! catch ! { ! // the serialized WFLagChosenPositions is of old type ! // drivingPositions and portfolioPositions are QPHashtable ! this.portfolioPositions = new QPHashtable(); ! this.portfolioPositions = (QPHashtable)info.GetValue( ! "portfolioPositions" , this.portfolioPositions.GetType() ); ! // portfolioWeightedPositions = this.getWeightedPositions( portfolioPositions ); ! } ! } ! private void deserializeThisClassMembers( SerializationInfo info , StreamingContext context ) ! { ! this.lastOptimizationDate = (DateTime)info.GetValue( "lastOptimizationDate" , ! this.lastOptimizationDate.GetType() ); ! this.deserializeDrivingWeightedPositions( info , context ); ! this.deserializePortfolioWeightedPositions( info , context ); ! } ! void ISerializable.GetObjectData( ! SerializationInfo info, StreamingContext context) ! { ! // get the set of serializable members for this class and base classes ! Type thisType = this.GetType(); ! MemberInfo[] mi = ! FormatterServices.GetSerializableMembers( thisType , context); ! ! // serialize the fields to the info object ! for (Int32 i = 0 ; i < mi.Length; i++) ! { ! string memberName = mi[i].Name; ! if ( ( memberName != "drivingPositions" ) && ( memberName != "portfolioPositions" ) ) ! // current member is not used for old versions' deserialization, only ! info.AddValue(mi[i].Name, ((FieldInfo) mi[i]).GetValue(this)); ! } } + // private Hashtable copy( Hashtable hashTable ) + // { + // Hashtable newCopy = new Hashtable(); + // foreach ( string key in hashTable.Keys ) + // newCopy.Add( key , null ); + // return newCopy; + // } + #region setWeightedPositionsFromQPHashtables + private double getWeightedPositions_getWeight( + double absoluteWeightForEachPosition , string signedTicker ) + { + double weight = absoluteWeightForEachPosition; + if ( SignedTicker.IsShort( signedTicker ) ) + weight = - absoluteWeightForEachPosition; + return weight; + } + private WeightedPositions getWeightedPositions( QPHashtable signedTickers ) + { + double absoluteWeightForEachPosition = + 1 / Convert.ToDouble( signedTickers.Count ); + double[] weights = new double[ signedTickers.Count ]; + string[] tickers = new string[ signedTickers.Count ]; + int i = 0; + foreach ( string signedTicker in signedTickers.Keys ) + { + weights[ i ] = this.getWeightedPositions_getWeight( + absoluteWeightForEachPosition , signedTicker ); + tickers[ i ] = SignedTicker.GetTicker( signedTicker ); + i++; + } + WeightedPositions weightedPositions = + new WeightedPositions( weights , tickers ); + return weightedPositions; + } + private void setWeightedPositionsFromQPHashtables() + { + this.drivingWeightedPositions = this.getWeightedPositions( this.drivingPositions ); + this.portfolioWeightedPositions = this.getWeightedPositions( this.portfolioPositions ); + } + #endregion + #endregion } } |
|
From: Glauco S. <gla...@us...> - 2006-07-30 13:45:58
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagGenomesDebugger In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv11204/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagGenomesDebugger Modified Files: WFLagChosenPositionsDebugInfo.cs Log Message: WeightedPositions are used instead of SignedTickers Index: WFLagChosenPositionsDebugInfo.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagGenomesDebugger/WFLagChosenPositionsDebugInfo.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** WFLagChosenPositionsDebugInfo.cs 22 Jul 2006 20:45:14 -0000 1.3 --- WFLagChosenPositionsDebugInfo.cs 30 Jul 2006 13:45:54 -0000 1.4 *************** *** 47,55 **** public string DrivingPositions { ! get { return this.wFLagChosenPositions.DrivingPositions.KeyConcat; } } public string PortfolioPositions { ! get { return this.wFLagChosenPositions.PortfolioPositions.KeyConcat; } } public DateTime LastOptimization --- 47,55 ---- public string DrivingPositions { ! get { return this.wFLagChosenPositions.DrivingWeightedPositions.ToString(); } } public string PortfolioPositions { ! get { return this.wFLagChosenPositions.PortfolioWeightedPositions.ToString(); } } public DateTime LastOptimization *************** *** 122,135 **** WFLagChosenPositions wFLagChosenPositions ) { ! int size = wFLagChosenPositions.DrivingPositions.Count + ! wFLagChosenPositions.PortfolioPositions.Count; string[] drivingAndPortfolioTickers = new string[ size ]; int i = 0; ! foreach ( string signedTicker in wFLagChosenPositions.DrivingPositions.Keys ) { drivingAndPortfolioTickers[ i ] = SignedTicker.GetTicker( signedTicker ); i++; } ! foreach ( string signedTicker in wFLagChosenPositions.PortfolioPositions.Keys ) { drivingAndPortfolioTickers[ i ] = SignedTicker.GetTicker( signedTicker ); --- 122,137 ---- WFLagChosenPositions wFLagChosenPositions ) { ! int size = wFLagChosenPositions.DrivingWeightedPositions.Count + ! wFLagChosenPositions.PortfolioWeightedPositions.Count; string[] drivingAndPortfolioTickers = new string[ size ]; int i = 0; ! foreach ( string signedTicker in ! wFLagChosenPositions.DrivingWeightedPositions.Keys ) { drivingAndPortfolioTickers[ i ] = SignedTicker.GetTicker( signedTicker ); i++; } ! foreach ( string signedTicker in ! wFLagChosenPositions.PortfolioWeightedPositions.Keys ) { drivingAndPortfolioTickers[ i ] = SignedTicker.GetTicker( signedTicker ); |
|
From: Glauco S. <gla...@us...> - 2006-07-30 13:44:51
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv10662/b7_Scripts/WalkForwardTesting/WalkForwardLag Modified Files: WFLagChosenTickers.cs Log Message: WeightedPositions are used instead of SignedTickers Index: WFLagChosenTickers.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagChosenTickers.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** WFLagChosenTickers.cs 8 Apr 2006 18:39:55 -0000 1.2 --- WFLagChosenTickers.cs 30 Jul 2006 13:44:48 -0000 1.3 *************** *** 27,30 **** --- 27,31 ---- using QuantProject.ADT.Collections; using QuantProject.ADT.Optimizing.Genetic; + using QuantProject.Business.Strategies; using QuantProject.Business.Timing; *************** *** 49,69 **** private int populationSizeForGeneticOptimizer; ! private QPHashtable drivingPositions; ! private QPHashtable portfolioPositions; private DateTime firstOptimizationDate; private DateTime lastOptimizationDate; ! public QPHashtable DrivingPositions { get { ! return this.drivingPositions; } } ! public QPHashtable PortfolioPositions { get { ! return this.portfolioPositions; } } --- 50,84 ---- private int populationSizeForGeneticOptimizer; ! private WeightedPositions drivingWeightedPositions; ! private WeightedPositions portfolioWeightedPositions; private DateTime firstOptimizationDate; private DateTime lastOptimizationDate; ! // public QPHashtable PortfolioPositions ! // { ! // get ! // { ! // return this.portfolioPositions; ! // } ! // } ! // public QPHashtable DrivingPositions ! // { ! // get ! // { ! // return this.drivingPositions; ! // } ! // } ! public WeightedPositions DrivingWeightedPositions { get { ! return this.drivingWeightedPositions; } } ! public WeightedPositions PortfolioWeightedPositions { get { ! return this.portfolioWeightedPositions; } } *************** *** 115,127 **** } private void setSignedTickers_setTickersFromGenome( ! WFLagGenomeManager genomeManager , Genome genome ) { ! WFLagSignedTickers wFLagSignedTickers = ! ( WFLagSignedTickers )genomeManager.Decode( genome ); ! this.drivingPositions = wFLagSignedTickers.DrivingPositions; ! this.portfolioPositions = wFLagSignedTickers.PortfolioPositions; } ! public void SetSignedTickers( WFLagEligibleTickers eligibleTickers ) { // this.setSignedTickers_clearPositions(); --- 130,144 ---- } private void setSignedTickers_setTickersFromGenome( ! IGenomeManager genomeManager , Genome genome ) { ! WFLagWeightedPositions wFLagWeightedPositions = ! ( WFLagWeightedPositions )genomeManager.Decode( genome ); ! this.drivingWeightedPositions = ! wFLagWeightedPositions.DrivingWeightedPositions; ! this.portfolioWeightedPositions = ! wFLagWeightedPositions.PortfolioWeightedPositions; } ! public void SetWeightedPositions( WFLagEligibleTickers eligibleTickers ) { // this.setSignedTickers_clearPositions(); *************** *** 133,140 **** this.endOfDayTimer.GetCurrentTime().DateTime; ! WFLagGenomeManager genomeManager = ! new WFLagGenomeManager( eligibleTickers.EligibleTickers , ! firstOptimizationDate , this.lastOptimizationDate , this.numberOfDrivingPositions , --- 150,158 ---- this.endOfDayTimer.GetCurrentTime().DateTime; ! WFLagGenomeManagerWithWeights genomeManager = ! new WFLagGenomeManagerWithWeights( eligibleTickers.EligibleTickers , ! eligibleTickers.EligibleTickers , ! this.firstOptimizationDate , this.lastOptimizationDate , this.numberOfDrivingPositions , |
|
From: Glauco S. <gla...@us...> - 2006-07-30 13:43:45
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv10200/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger Modified Files: WFLagDebugGenome.cs Log Message: Now two datagrid are used to display driving weighted positions and portfolio weighted positions. Previous version used two labels to display driving signed tickers and portfolio signed tickers. Index: WFLagDebugGenome.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger/WFLagDebugGenome.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** WFLagDebugGenome.cs 22 Jul 2006 20:32:42 -0000 1.3 --- WFLagDebugGenome.cs 30 Jul 2006 13:43:42 -0000 1.4 *************** *** 57,62 **** private System.Windows.Forms.Label labelDrivingPositions; private System.Windows.Forms.Label labelPortfolioPositions; ! private System.Windows.Forms.Label labelDrivingPositionsContent; ! private System.Windows.Forms.Label labelPortfolioPositionsContent; /// <summary> /// Required designer variable. --- 57,62 ---- private System.Windows.Forms.Label labelDrivingPositions; private System.Windows.Forms.Label labelPortfolioPositions; ! private System.Windows.Forms.DataGrid dataGridDrivingPositions; ! private System.Windows.Forms.DataGrid dataGridPortfolioPositions; /// <summary> /// Required designer variable. *************** *** 110,115 **** this.labelDrivingPositions = new System.Windows.Forms.Label(); this.labelPortfolioPositions = new System.Windows.Forms.Label(); ! this.labelDrivingPositionsContent = new System.Windows.Forms.Label(); ! this.labelPortfolioPositionsContent = new System.Windows.Forms.Label(); this.SuspendLayout(); // --- 110,117 ---- this.labelDrivingPositions = new System.Windows.Forms.Label(); this.labelPortfolioPositions = new System.Windows.Forms.Label(); ! this.dataGridDrivingPositions = new System.Windows.Forms.DataGrid(); ! this.dataGridPortfolioPositions = new System.Windows.Forms.DataGrid(); ! ((System.ComponentModel.ISupportInitialize)(this.dataGridDrivingPositions)).BeginInit(); ! ((System.ComponentModel.ISupportInitialize)(this.dataGridPortfolioPositions)).BeginInit(); this.SuspendLayout(); // *************** *** 134,138 **** // TestPostSample // ! this.TestPostSample.Location = new System.Drawing.Point(32, 144); this.TestPostSample.Name = "TestPostSample"; this.TestPostSample.Size = new System.Drawing.Size(160, 32); --- 136,140 ---- // TestPostSample // ! this.TestPostSample.Location = new System.Drawing.Point(32, 304); this.TestPostSample.Name = "TestPostSample"; this.TestPostSample.Size = new System.Drawing.Size(160, 32); *************** *** 143,147 **** // PostSampleDays // ! this.PostSampleDays.Location = new System.Drawing.Point(256, 152); this.PostSampleDays.Name = "PostSampleDays"; this.PostSampleDays.TabIndex = 3; --- 145,149 ---- // PostSampleDays // ! this.PostSampleDays.Location = new System.Drawing.Point(256, 312); this.PostSampleDays.Name = "PostSampleDays"; this.PostSampleDays.TabIndex = 3; *************** *** 150,154 **** // testPreSample // ! this.testPreSample.Location = new System.Drawing.Point(32, 216); this.testPreSample.Name = "testPreSample"; this.testPreSample.Size = new System.Drawing.Size(160, 32); --- 152,156 ---- // testPreSample // ! this.testPreSample.Location = new System.Drawing.Point(32, 376); this.testPreSample.Name = "testPreSample"; this.testPreSample.Size = new System.Drawing.Size(160, 32); *************** *** 159,163 **** // PreSampleDays // ! this.PreSampleDays.Location = new System.Drawing.Point(256, 224); this.PreSampleDays.Name = "PreSampleDays"; this.PreSampleDays.TabIndex = 5; --- 161,165 ---- // PreSampleDays // ! this.PreSampleDays.Location = new System.Drawing.Point(256, 384); this.PreSampleDays.Name = "PreSampleDays"; this.PreSampleDays.TabIndex = 5; *************** *** 166,171 **** // labelDrivingPositions // ! this.labelDrivingPositions.Location = new System.Drawing.Point(272, 16); this.labelDrivingPositions.Name = "labelDrivingPositions"; this.labelDrivingPositions.TabIndex = 6; this.labelDrivingPositions.Text = "Driving Pos."; --- 168,174 ---- // labelDrivingPositions // ! this.labelDrivingPositions.Location = new System.Drawing.Point(208, 16); this.labelDrivingPositions.Name = "labelDrivingPositions"; + this.labelDrivingPositions.Size = new System.Drawing.Size(72, 23); this.labelDrivingPositions.TabIndex = 6; this.labelDrivingPositions.Text = "Driving Pos."; *************** *** 174,204 **** // labelPortfolioPositions // ! this.labelPortfolioPositions.Location = new System.Drawing.Point(272, 64); this.labelPortfolioPositions.Name = "labelPortfolioPositions"; this.labelPortfolioPositions.TabIndex = 7; this.labelPortfolioPositions.Text = "Portfolio Pos."; this.labelPortfolioPositions.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // ! // labelDrivingPositionsContent // ! this.labelDrivingPositionsContent.Location = new System.Drawing.Point(384, 16); ! this.labelDrivingPositionsContent.Name = "labelDrivingPositionsContent"; ! this.labelDrivingPositionsContent.TabIndex = 8; ! this.labelDrivingPositionsContent.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // ! // labelPortfolioPositionsContent // ! this.labelPortfolioPositionsContent.Location = new System.Drawing.Point(384, 64); ! this.labelPortfolioPositionsContent.Name = "labelPortfolioPositionsContent"; ! this.labelPortfolioPositionsContent.TabIndex = 9; ! this.labelPortfolioPositionsContent.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // WFLagDebugGenome // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); ! this.ClientSize = new System.Drawing.Size(616, 365); this.Controls.AddRange(new System.Windows.Forms.Control[] { ! this.labelPortfolioPositionsContent, ! this.labelDrivingPositionsContent, this.labelPortfolioPositions, this.labelDrivingPositions, --- 177,212 ---- // labelPortfolioPositions // ! this.labelPortfolioPositions.Location = new System.Drawing.Point(208, 160); this.labelPortfolioPositions.Name = "labelPortfolioPositions"; + this.labelPortfolioPositions.Size = new System.Drawing.Size(72, 23); this.labelPortfolioPositions.TabIndex = 7; this.labelPortfolioPositions.Text = "Portfolio Pos."; this.labelPortfolioPositions.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // ! // dataGridDrivingPositions // ! this.dataGridDrivingPositions.DataMember = ""; ! this.dataGridDrivingPositions.HeaderForeColor = System.Drawing.SystemColors.ControlText; ! this.dataGridDrivingPositions.Location = new System.Drawing.Point(296, 16); ! this.dataGridDrivingPositions.Name = "dataGridDrivingPositions"; ! this.dataGridDrivingPositions.Size = new System.Drawing.Size(312, 128); ! this.dataGridDrivingPositions.TabIndex = 10; // ! // dataGridPortfolioPositions // ! this.dataGridPortfolioPositions.DataMember = ""; ! this.dataGridPortfolioPositions.HeaderForeColor = System.Drawing.SystemColors.ControlText; ! this.dataGridPortfolioPositions.Location = new System.Drawing.Point(296, 160); ! this.dataGridPortfolioPositions.Name = "dataGridPortfolioPositions"; ! this.dataGridPortfolioPositions.Size = new System.Drawing.Size(312, 128); ! this.dataGridPortfolioPositions.TabIndex = 11; // // WFLagDebugGenome // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); ! this.ClientSize = new System.Drawing.Size(616, 437); this.Controls.AddRange(new System.Windows.Forms.Control[] { ! this.dataGridPortfolioPositions, ! this.dataGridDrivingPositions, this.labelPortfolioPositions, this.labelDrivingPositions, *************** *** 212,215 **** --- 220,225 ---- this.Text = "WFLagDebugGenome"; this.Load += new System.EventHandler(this.WFLagDebugGenome_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridDrivingPositions)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridPortfolioPositions)).EndInit(); this.ResumeLayout(false); *************** *** 316,325 **** } private void WFLagDebugGenome_Load(object sender, System.EventArgs e) { ! this.labelDrivingPositionsContent.Text = ! this.wFLagChosenPositions.DrivingPositions.KeyConcat; ! this.labelPortfolioPositionsContent.Text = ! this.wFLagChosenPositions.PortfolioPositions.KeyConcat; } } --- 326,349 ---- } + private void setDataGridDrivingPositions() + { + ArrayList drivingWeightedPositions = + new ArrayList( this.wFLagChosenPositions.DrivingWeightedPositions.Values ); + this.dataGridDrivingPositions.DataSource = drivingWeightedPositions; + } + private void setDataGridPortfolioPositions() + { + ArrayList portfolioWeightedPositions = + new ArrayList( this.wFLagChosenPositions.PortfolioWeightedPositions.Values ); + this.dataGridPortfolioPositions.DataSource = portfolioWeightedPositions; + } private void WFLagDebugGenome_Load(object sender, System.EventArgs e) { ! // this.labelDrivingPositionsContent.Text = ! // this.wFLagChosenPositions.DrivingPositions.KeyConcat; ! // this.labelPortfolioPositionsContent.Text = ! // this.wFLagChosenPositions.PortfolioPositions.KeyConcat; ! this.setDataGridDrivingPositions(); ! this.setDataGridPortfolioPositions(); } } |
|
From: Glauco S. <gla...@us...> - 2006-07-30 13:41:54
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger/WFLagDebugPositions In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv9281/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger/WFLagDebugPositions Modified Files: WFLagDebugPositions.cs Log Message: WeightedPositions are used instead of SignedTickers Index: WFLagDebugPositions.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger/WFLagDebugPositions/WFLagDebugPositions.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** WFLagDebugPositions.cs 31 May 2006 14:19:43 -0000 1.3 --- WFLagDebugPositions.cs 30 Jul 2006 13:41:48 -0000 1.4 *************** *** 195,207 **** } #endregion ! private void addEquityLineForSignedTickers( ! ICollection signedTickers , Color color , Report report ) { ! EquityLine equityLineSignedTickers = ! this.getEquityLineForSignedTickers( ! signedTickers , report ); ! report.AddEquityLine( equityLineSignedTickers , color ); } public void oneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) --- 195,217 ---- } #endregion ! // private void addEquityLineForSignedTickers( ! // ICollection signedTickers , Color color , Report report ) ! // { ! // EquityLine equityLineSignedTickers = ! // this.getEquityLineForSignedTickers( ! // signedTickers , report ); ! // report.AddEquityLine( equityLineSignedTickers , ! // color ); ! // } ! private void addEquityLineForWeightedPositions( ! WeightedPositions weightedPositions , Color color , Report report ) { ! EquityLine equityLineForWeightedPositions = ! weightedPositions.GetVirtualEquityLine( ! 30000 , report.AccountReport.EquityLine ); ! report.AddEquityLine( equityLineForWeightedPositions , color ); } + public void oneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) *************** *** 219,228 **** // EquityLine equityLineForDrivingPositions = // this.getEquityLineForPositions( report ); ! this.addEquityLineForSignedTickers( ! this.wFLagChosenPositions.DrivingPositions.Keys , Color.YellowGreen , report ); ! this.addEquityLineForSignedTickers( ! this.wFLagChosenPositions.PortfolioPositions.Keys , Color.Brown , report ); report.Show(); } --- 229,244 ---- // EquityLine equityLineForDrivingPositions = // this.getEquityLineForPositions( report ); ! // this.addEquityLineForSignedTickers( ! // this.wFLagChosenPositions.DrivingWeightedPositions.Keys , ! // Color.YellowGreen , report ); ! this.addEquityLineForWeightedPositions( ! this.wFLagChosenPositions.DrivingWeightedPositions , Color.YellowGreen , report ); ! this.addEquityLineForWeightedPositions( ! this.wFLagChosenPositions.PortfolioWeightedPositions , Color.Brown , report ); + // this.addEquityLineForSignedTickers( + // this.wFLagChosenPositions.PortfolioWeightedPositions.Keys , + // Color.Brown , report ); report.Show(); } |
|
From: Glauco S. <gla...@us...> - 2006-07-30 13:40:39
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger/WFLagDebugPositions In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv8814/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger/WFLagDebugPositions Modified Files: WFLagDebugPositionsEndOfDayTimerHandler.cs Log Message: WeightedPositions are used instead of SignedTickers Index: WFLagDebugPositionsEndOfDayTimerHandler.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger/WFLagDebugPositions/WFLagDebugPositionsEndOfDayTimerHandler.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** WFLagDebugPositionsEndOfDayTimerHandler.cs 8 Apr 2006 18:16:08 -0000 1.1 --- WFLagDebugPositionsEndOfDayTimerHandler.cs 30 Jul 2006 13:40:35 -0000 1.2 *************** *** 52,59 **** double todayTotalGain = 0; DateTime today = this.account.EndOfDayTimer.GetCurrentTime().DateTime; ! foreach ( string signedTicker in ! this.wFLagChosenPositions.DrivingPositions.Keys ) todayTotalGain += ! SignedTicker.GetCloseToCloseDailyReturn( signedTicker , today ); // todayTotalGain += totalGainForSignedTicker( signedTicker ); return todayTotalGain; --- 52,59 ---- double todayTotalGain = 0; DateTime today = this.account.EndOfDayTimer.GetCurrentTime().DateTime; ! foreach ( WeightedPosition weightedPosition in ! this.wFLagChosenPositions.DrivingWeightedPositions.Values ) todayTotalGain += ! weightedPosition.GetCloseToCloseDailyReturn( today ); // todayTotalGain += totalGainForSignedTicker( signedTicker ); return todayTotalGain; *************** *** 64,68 **** return todayTotalGain > 0; } ! private string getFirstAccountPosition() { IEnumerator accountPositions = --- 64,68 ---- return todayTotalGain > 0; } ! private Position getFirstAccountPosition() { IEnumerator accountPositions = *************** *** 70,82 **** accountPositions.MoveNext(); Position firstPosition = (Position)accountPositions.Current; ! string firstAccountPosition = SignedTicker.GetSignedTicker( firstPosition ); ! return firstAccountPosition; } private bool isCurrentlyReversed() { ! string firstAccountPosition = this.getFirstAccountPosition(); bool isReversed = ! this.wFLagChosenPositions.PortfolioPositions.ContainsKey( ! SignedTicker.GetOppositeSignedTicker( firstAccountPosition ) ); return isReversed; } --- 70,87 ---- accountPositions.MoveNext(); Position firstPosition = (Position)accountPositions.Current; ! return firstPosition; } private bool isCurrentlyReversed() { ! Position firstAccountPosition = this.getFirstAccountPosition(); ! WeightedPosition weightedPosition = ! this.wFLagChosenPositions.PortfolioWeightedPositions.GetWeightedPosition( ! firstAccountPosition.Instrument.Key ); bool isReversed = ! ( ( weightedPosition.IsLong && firstAccountPosition.IsShort ) || ! ( weightedPosition.IsShort && firstAccountPosition.IsLong ) ); ! // bool isReversed = ! // this.wFLagChosenPositions.PortfolioWeightedPositions.ContainsKey( ! // SignedTicker.GetOppositeSignedTicker( firstAccountPosition ) ); return isReversed; } *************** *** 103,153 **** return returnValue; } ! private long getQuantity( string ticker ) { double accountValue = this.account.GetMarketValue(); double currentTickerAsk = ! this.account.DataStreamer.GetCurrentAsk( ticker ); double maxPositionValueForThisTicker = ! accountValue / this.wFLagChosenPositions.PortfolioPositions.Count; long quantity = Convert.ToInt64( Math.Floor( maxPositionValueForThisTicker / currentTickerAsk ) ); return quantity; } ! private void openPosition( string ticker , OrderType orderType ) { ! long quantity = this.getQuantity( ticker ); ! Order order = new Order( orderType , new Instrument( ticker ) , ! quantity ); this.account.AddOrder( order ); } private void fiveMinutesBeforeMarketCloseEventHandler_openThisPosition( ! string signedTicker ) { ! this.openPosition( SignedTicker.GetTicker( signedTicker ) , ! SignedTicker.GetMarketOrderType( signedTicker ) ); } private void fiveMinutesBeforeMarketCloseEventHandler_openOppositePosition( ! string signedTicker ) { this.fiveMinutesBeforeMarketCloseEventHandler_openThisPosition( ! SignedTicker.GetOppositeSignedTicker( signedTicker ) ); } private void fiveMinutesBeforeMarketCloseEventHandler_openPosition( ! string signedTicker ) { if ( this.isDrivingPositionsTodayValueHigherThanYesterday() ) fiveMinutesBeforeMarketCloseEventHandler_openThisPosition( ! signedTicker ); else fiveMinutesBeforeMarketCloseEventHandler_openOppositePosition( ! signedTicker ); } private void fiveMinutesBeforeMarketCloseEventHandler_openPositions() { // this.chosenTickers.SetTickers( this.bestPerformingTickers , this.account ); ! foreach ( string signedTicker in ! this.wFLagChosenPositions.PortfolioPositions.Keys ) this.fiveMinutesBeforeMarketCloseEventHandler_openPosition( ! signedTicker ); } public void FiveMinutesBeforeMarketCloseEventHandler( --- 108,158 ---- return returnValue; } ! private long getQuantity( WeightedPosition weightedPosition ) { double accountValue = this.account.GetMarketValue(); double currentTickerAsk = ! this.account.DataStreamer.GetCurrentAsk( weightedPosition.Ticker ); double maxPositionValueForThisTicker = ! accountValue * Math.Abs( weightedPosition.Weight ); long quantity = Convert.ToInt64( Math.Floor( maxPositionValueForThisTicker / currentTickerAsk ) ); return quantity; } ! private void openPosition( WeightedPosition weightedPosition ) { ! long quantity = this.getQuantity( weightedPosition ); ! OrderType orderType = weightedPosition.GetOrderType(); ! Order order = new Order( ! orderType , new Instrument( weightedPosition.Ticker ) , quantity ); this.account.AddOrder( order ); } private void fiveMinutesBeforeMarketCloseEventHandler_openThisPosition( ! WeightedPosition weightedPosition ) { ! this.openPosition( weightedPosition ); } private void fiveMinutesBeforeMarketCloseEventHandler_openOppositePosition( ! WeightedPosition weightedPosition ) { this.fiveMinutesBeforeMarketCloseEventHandler_openThisPosition( ! weightedPosition.GetOppositeWeightedPosition() ); } private void fiveMinutesBeforeMarketCloseEventHandler_openPosition( ! WeightedPosition weightedPosition ) { if ( this.isDrivingPositionsTodayValueHigherThanYesterday() ) fiveMinutesBeforeMarketCloseEventHandler_openThisPosition( ! weightedPosition ); else fiveMinutesBeforeMarketCloseEventHandler_openOppositePosition( ! weightedPosition ); } private void fiveMinutesBeforeMarketCloseEventHandler_openPositions() { // this.chosenTickers.SetTickers( this.bestPerformingTickers , this.account ); ! foreach ( WeightedPosition weightedPosition in ! this.wFLagChosenPositions.PortfolioWeightedPositions.Values ) this.fiveMinutesBeforeMarketCloseEventHandler_openPosition( ! weightedPosition ); } public void FiveMinutesBeforeMarketCloseEventHandler( |