quantproject-developers Mailing List for QuantProject (Page 75)
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...> - 2007-04-09 18:09:02
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes
In directory sc8-pr-cvs16:/tmp/cvs-serv6727/b7_Scripts/TickerSelectionTesting/TestingOTCTypes
Modified Files:
EndOfDayTimerHandlerOTCTypes.cs
Log Message:
Changed MutationRate and CrossoverRate for testing purposes
Index: EndOfDayTimerHandlerOTCTypes.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes/EndOfDayTimerHandlerOTCTypes.cs,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** EndOfDayTimerHandlerOTCTypes.cs 3 Jan 2007 23:01:52 -0000 1.6
--- EndOfDayTimerHandlerOTCTypes.cs 9 Apr 2007 18:08:59 -0000 1.7
***************
*** 262,267 ****
if(setGenomeCounter)
this.genomeCounter = new GenomeCounter(GO);
! GO.MutationRate = 0.4;
! GO.CrossoverRate = 0.0;
GO.Run(false);
this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod),
--- 262,267 ----
if(setGenomeCounter)
this.genomeCounter = new GenomeCounter(GO);
! GO.MutationRate = 0.25;
! GO.CrossoverRate = 0.90;
GO.Run(false);
this.addGenomeToBestGenomes(GO.BestGenome,currentDate.AddDays(-this.numDaysForOptimizationPeriod),
|
|
From: Marco M. <mi...@us...> - 2007-04-09 18:08:07
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator
In directory sc8-pr-cvs16:/tmp/cvs-serv6510/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator
Modified Files:
EndOfDayTimerHandlerPVO.cs
Log Message:
Added remarks for debugging purposes
Index: EndOfDayTimerHandlerPVO.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/EndOfDayTimerHandlerPVO.cs,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** EndOfDayTimerHandlerPVO.cs 27 Feb 2007 22:19:51 -0000 1.4
--- EndOfDayTimerHandlerPVO.cs 9 Apr 2007 18:08:04 -0000 1.5
***************
*** 288,292 ****
return quotedAtEachMarketDayFromLastSelection.GetTableOfSelectedTickers();
!
}
protected void addPVOGenomeToBestGenomes(Genome genome,
--- 288,297 ----
return quotedAtEachMarketDayFromLastSelection.GetTableOfSelectedTickers();
! //for debug
! // SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromLastSelection =
! // new SelectorByQuotationAtEachMarketDay(temporizedGroup.GetTableOfSelectedTickers(),
! // false, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate,
! // this.numberOfEligibleTickers, this.benchmark);
! // return quotedAtEachMarketDayFromLastSelection.GetTableOfSelectedTickers();
}
protected void addPVOGenomeToBestGenomes(Genome genome,
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/WeightedPVO/WeightedBalancedPVO
In directory sc8-pr-cvs16:/tmp/cvs-serv6229/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/WeightedPVO/WeightedBalancedPVO
Modified Files:
EndOfDayTimerHandlerWeightedBalancedPVO.cs
Log Message:
Changed mutation rate for testing purposes
Index: EndOfDayTimerHandlerWeightedBalancedPVO.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/WeightedPVO/WeightedBalancedPVO/EndOfDayTimerHandlerWeightedBalancedPVO.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** EndOfDayTimerHandlerWeightedBalancedPVO.cs 27 Feb 2007 22:52:40 -0000 1.1
--- EndOfDayTimerHandlerWeightedBalancedPVO.cs 9 Apr 2007 18:07:09 -0000 1.2
***************
*** 151,155 ****
if(setGenomeCounter)
this.genomeCounter = new GenomeCounter(GO);
! GO.MutationRate = 0.2;
GO.Run(false);
--- 151,155 ----
if(setGenomeCounter)
this.genomeCounter = new GenomeCounter(GO);
! GO.MutationRate = 0.1;
GO.Run(false);
|
|
From: Marco M. <mi...@us...> - 2007-04-09 18:06:28
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination
In directory sc8-pr-cvs16:/tmp/cvs-serv5777/b7_Scripts/WalkForwardTesting/LinearCombination
Modified Files:
FixedLevelOscillatorBiasedPVOStrategy.cs
Log Message:
The class (which is used for testing PVO Genomes out of sample) now supports multiple genomes having the same in sample optimization period
Index: FixedLevelOscillatorBiasedPVOStrategy.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/FixedLevelOscillatorBiasedPVOStrategy.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** FixedLevelOscillatorBiasedPVOStrategy.cs 27 Feb 2007 22:54:44 -0000 1.1
--- FixedLevelOscillatorBiasedPVOStrategy.cs 9 Apr 2007 18:06:25 -0000 1.2
***************
*** 62,67 ****
{
! this.chosenTickers = tickers;
! this.chosenTickersPortfolioWeights = tickersPortfolioWeights;
this.currentOversoldThreshold = oversoldThreshold;
this.currentOverboughtThreshold = overboughtThreshold;
--- 62,67 ----
{
! this.bestGenomesChosenTickers = tickers;
! this.bestGenomesChosenTickersPortfolioWeights = tickersPortfolioWeights;
this.currentOversoldThreshold = oversoldThreshold;
this.currentOverboughtThreshold = overboughtThreshold;
***************
*** 95,100 ****
for(int i = 0; i < this.numberOfTickersToBeChosen; i++)
{
! tickers[i] = this.chosenTickers[indexForChosenTickers,i];
! tickerWeights[i] = this.chosenTickersPortfolioWeights[indexForChosenTickers,i];
}
returnValue =
--- 95,100 ----
for(int i = 0; i < this.numberOfTickersToBeChosen; i++)
{
! tickers[i] = this.bestGenomesChosenTickers[indexForChosenTickers,i];
! tickerWeights[i] = this.bestGenomesChosenTickersPortfolioWeights[indexForChosenTickers,i];
}
returnValue =
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/BiasedPVO/BiasedOTC_PVONoThresholds
In directory sc8-pr-cvs16:/tmp/cvs-serv4536/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/BiasedPVO/BiasedOTC_PVONoThresholds
Modified Files:
GenomeManagerBiasedOTC_PVONoThresholds.cs
Log Message:
Different implementation for the overriden GetFitnessValue method
Index: GenomeManagerBiasedOTC_PVONoThresholds.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/BiasedPVO/BiasedOTC_PVONoThresholds/GenomeManagerBiasedOTC_PVONoThresholds.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** GenomeManagerBiasedOTC_PVONoThresholds.cs 27 Feb 2007 22:52:41 -0000 1.1
--- GenomeManagerBiasedOTC_PVONoThresholds.cs 9 Apr 2007 18:04:00 -0000 1.2
***************
*** 128,135 ****
// for( int i = 0; i<asbolutePortfolioRatesOfReturns.Length; i++ )
// asbolutePortfolioRatesOfReturns[i] = Math.Abs(this.portfolioRatesOfReturn[i]);
! returnValue = 1.0/
! //( BasicFunctions.SimpleAverage(asbolutePortfolioRatesOfReturns) *
! (
! Math.Abs( BasicFunctions.SimpleAverage(this.portfolioRatesOfReturn)));//) *
//BasicFunctions.StdDev(this.portfolioRatesOfReturn) ); //);
return returnValue;
--- 128,132 ----
// for( int i = 0; i<asbolutePortfolioRatesOfReturns.Length; i++ )
// asbolutePortfolioRatesOfReturns[i] = Math.Abs(this.portfolioRatesOfReturn[i]);
! returnValue = BasicFunctions.SimpleAverage(this.portfolioRatesOfReturn);
//BasicFunctions.StdDev(this.portfolioRatesOfReturn) ); //);
return returnValue;
|
|
From: Marco M. <mi...@us...> - 2007-04-09 18:03:51
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting
In directory sc8-pr-cvs16:/tmp/cvs-serv4086/b7_Scripts/TickerSelectionTesting
Modified Files:
GenomeManagerForEfficientOTCCTOPortfolio.cs
Log Message:
no message
Index: GenomeManagerForEfficientOTCCTOPortfolio.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForEfficientOTCCTOPortfolio.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** GenomeManagerForEfficientOTCCTOPortfolio.cs 3 Jan 2007 23:20:14 -0000 1.3
--- GenomeManagerForEfficientOTCCTOPortfolio.cs 9 Apr 2007 18:02:18 -0000 1.4
***************
*** 38,42 ****
/// </summary>
[Serializable]
! public class GenomeManagerForEfficientOTCCTOPortfolio : GenomeManagerForWeightedEfficientPortfolio
{
--- 38,42 ----
/// </summary>
[Serializable]
! public class GenomeManagerForEfficientOTCCTOPortfolio : GenomeManagerForEfficientPortfolio
{
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/WeightedPVO/WeightedBalancedPVO
In directory sc8-pr-cvs16:/tmp/cvs-serv3185/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/WeightedPVO/WeightedBalancedPVO
Modified Files:
GenomeManagerWeightedBalancedPVO.cs
Log Message:
Fixed bug in overriden method getTickerWeight
Index: GenomeManagerWeightedBalancedPVO.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/WeightedPVO/WeightedBalancedPVO/GenomeManagerWeightedBalancedPVO.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** GenomeManagerWeightedBalancedPVO.cs 27 Feb 2007 22:52:40 -0000 1.1
--- GenomeManagerWeightedBalancedPVO.cs 9 Apr 2007 18:00:52 -0000 1.2
***************
*** 115,118 ****
--- 115,119 ----
{
double totalOfWeightsForTickersOfTheSameSign = 0.0;
+ int numOfTickersOfTheSameSign = 0;
for(int j = this.numOfGenesDedicatedToThresholds; j < genes.Length; j++)
{
***************
*** 122,135 ****
//thresholds are asymmetrical and current Index Points To A Ticker Of The Same Sign
//0 has to be avoided !
! totalOfWeightsForTickersOfTheSameSign += Math.Abs(genes[j]) + 1.0;
! else if ( this.numOfGenesDedicatedToThresholds == 1 && j%2!=0 &&
this.getTickerWeight_currentIndexPointsToATickerOfTheSameSign(genes,j+1,tickerPositionInGenes) )
//ticker weight is contained in genes at odd position when
//thresholds are symmetrical and current Index Points To A Ticker Of The Same Sign
//0 has to be avoided !
! totalOfWeightsForTickersOfTheSameSign += Math.Abs(genes[j]) + 1.0;
}
! return ( Math.Abs(genes[tickerPositionInGenes-1]) + 1.0 ) /
! ( 2 * totalOfWeightsForTickersOfTheSameSign );
}
--- 123,148 ----
//thresholds are asymmetrical and current Index Points To A Ticker Of The Same Sign
//0 has to be avoided !
! {
! totalOfWeightsForTickersOfTheSameSign += Math.Abs(genes[j]) + 1.0;
! numOfTickersOfTheSameSign++;
! }
! else if ( this.numOfGenesDedicatedToThresholds == 1 && j%2!=0 &&
this.getTickerWeight_currentIndexPointsToATickerOfTheSameSign(genes,j+1,tickerPositionInGenes) )
//ticker weight is contained in genes at odd position when
//thresholds are symmetrical and current Index Points To A Ticker Of The Same Sign
//0 has to be avoided !
! {
! totalOfWeightsForTickersOfTheSameSign += Math.Abs(genes[j]) + 1.0;
! numOfTickersOfTheSameSign++;
! }
}
! double minimumWeight = 0.75*(0.5/numOfTickersOfTheSameSign);
! //with 0.75 the minimum weight for 4 ticker can be 0.1875 (2 long and 2 short)
! //or 0.125 (3 long and 1 short or viceversa)
! double normalizingWeight = ( ( Math.Abs(genes[tickerPositionInGenes-1]) + 1.0 ) /
! totalOfWeightsForTickersOfTheSameSign ) *
! (0.5 - numOfTickersOfTheSameSign*minimumWeight);
!
! return minimumWeight + normalizingWeight;
}
|
|
From: Marco M. <mi...@us...> - 2007-04-09 17:58:08
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting
In directory sc8-pr-cvs16:/tmp/cvs-serv2061/b7_Scripts/TickerSelectionTesting
Modified Files:
GenomeMeaning.cs
Log Message:
Added HashCodeForTickerComposition property, in order to create a unique identifier for genomes that are made of the same tickers
Index: GenomeMeaning.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeMeaning.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** GenomeMeaning.cs 17 Sep 2006 21:45:33 -0000 1.3
--- GenomeMeaning.cs 9 Apr 2007 17:58:04 -0000 1.4
***************
*** 22,25 ****
--- 22,26 ----
using System;
+ using System.Collections;
namespace QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios
***************
*** 37,40 ****
--- 38,42 ----
private double averageReturnInSample;
private double varianceReturnInSample;
+ private string hashCodeForTickerComposition;
public string[] Tickers
***************
*** 63,66 ****
--- 65,73 ----
}
+ public string HashCodeForTickerComposition
+ {
+ get{return this.hashCodeForTickerComposition;}
+ }
+
private void setDefaultTickersPortfolioWeights()
{
***************
*** 70,76 ****
}
public GenomeMeaning(string[] tickers)
{
! this.tickers = tickers;
this.setDefaultTickersPortfolioWeights();
}
--- 77,97 ----
}
+ private void genomeMeaning_setHashCodeForTickerComposition()
+ {
+ ArrayList listOfTickers = new ArrayList(this.tickers);
+ listOfTickers.Sort();
+ foreach(string tickerCode in listOfTickers)
+ this.hashCodeForTickerComposition += tickerCode;
+ }
+
+ private void genomeMeaning(string[] tickers)
+ {
+ this.tickers = tickers;
+ this.genomeMeaning_setHashCodeForTickerComposition();
+ }
+
public GenomeMeaning(string[] tickers)
{
! this.genomeMeaning(tickers);
this.setDefaultTickersPortfolioWeights();
}
***************
*** 78,82 ****
public GenomeMeaning(string[] tickers, double[] tickersPortfolioWeights)
{
! this.tickers = tickers;
this.tickersPortfolioWeights = tickersPortfolioWeights;
}
--- 99,103 ----
public GenomeMeaning(string[] tickers, double[] tickersPortfolioWeights)
{
! this.genomeMeaning(tickers);
this.tickersPortfolioWeights = tickersPortfolioWeights;
}
***************
*** 87,91 ****
double varianceReturnInSample)
{
! this.tickers = tickers;
this.returnAtLastDayInSample = returnAtLastDayInSample;
this.averageReturnInSample = averageReturnInSample;
--- 108,112 ----
double varianceReturnInSample)
{
! this.genomeMeaning(tickers);
this.returnAtLastDayInSample = returnAtLastDayInSample;
this.averageReturnInSample = averageReturnInSample;
***************
*** 100,104 ****
double varianceReturnInSample)
{
! this.tickers = tickers;
this.tickersPortfolioWeights = tickersPortfolioWeights;
this.returnAtLastDayInSample = returnAtLastDayInSample;
--- 121,125 ----
double varianceReturnInSample)
{
! this.genomeMeaning(tickers);
this.tickersPortfolioWeights = tickersPortfolioWeights;
this.returnAtLastDayInSample = returnAtLastDayInSample;
|
|
From: Marco M. <mi...@us...> - 2007-04-09 17:49:24
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataTables
In directory sc8-pr-cvs16:/tmp/cvs-serv30364/b3_Data/DataTables
Modified Files:
Quotes.cs
Log Message:
Added GetTickersByRawOpenPrice static method on overload, for returning tickers ordered only by average raw open price that is greater
than a given minimum, at a given time interval
Index: Quotes.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b3_Data/DataTables/Quotes.cs,v
retrieving revision 1.32
retrieving revision 1.33
diff -C2 -d -r1.32 -r1.33
*** Quotes.cs 7 Oct 2006 09:46:22 -0000 1.32
--- Quotes.cs 9 Apr 2007 17:48:47 -0000 1.33
***************
*** 444,448 ****
/// belonging to the specified range within the given set of tickers
/// </summary>
-
public static DataTable GetTickersByAverageRawOpenPrice( bool orderByASC,
DataTable setOfTickers,
--- 444,447 ----
***************
*** 476,480 ****
}
! private static void getTickersByAverageRawOpenPrice_deleteRows( DataTable setOfTickers,
double minPrice, double maxPrice,
double minStdDeviation,
--- 475,524 ----
}
! /// <summary>
! /// returns tickers with the average raw open price
! /// being greater than a given value
! /// </summary>
! public static DataTable GetTickersByAverageRawOpenPrice( bool orderByASC,
! DataTable setOfTickers,
! DateTime firstQuoteDate,
! DateTime lastQuoteDate,
! long maxNumOfReturnedTickers,
! double minimumAverageRawOpenPrice)
! {
! if(!setOfTickers.Columns.Contains("AverageRawOpenPrice"))
! setOfTickers.Columns.Add("AverageRawOpenPrice", System.Type.GetType("System.Double"));
! foreach(DataRow row in setOfTickers.Rows)
! row["AverageRawOpenPrice"] =
! QuantProject.DataAccess.Tables.Quotes.GetAverageRawOpenPrice( (string)row[0],
! firstQuoteDate,
! lastQuoteDate );
! getTickersByAverageRawOpenPrice_deleteRows(setOfTickers, minimumAverageRawOpenPrice);
! DataTable returnValue = ExtendedDataTable.CopyAndSort(setOfTickers,"AverageRawOpenPrice", orderByASC);
! ExtendedDataTable.DeleteRows(returnValue, maxNumOfReturnedTickers);
! return returnValue;
! }
!
! private static void getTickersByAverageRawOpenPrice_deleteRows( DataTable setOfTickers,
! double minimumAverageRawOpenPrice )
! {
! int currentNumRows = setOfTickers.Rows.Count;
! for(int i = 0;i<currentNumRows;i++)
! {
! if(setOfTickers.Rows[i].RowState != DataRowState.Deleted)
! {
! double averagePrice = (double)setOfTickers.Rows[i]["AverageRawOpenPrice"];
! if( averagePrice < minimumAverageRawOpenPrice )
! {
! setOfTickers.Rows[i].Delete();
! currentNumRows = setOfTickers.Rows.Count;
! i--;//deletion causes the new ID row
! //of the next row to be the ID row of the deleted Row
! //so, only in this way, all the rows are checked
! }
! }
! }
! }
!
! private static void getTickersByAverageRawOpenPrice_deleteRows( DataTable setOfTickers,
double minPrice, double maxPrice,
double minStdDeviation,
|
|
From: Marco M. <mi...@us...> - 2007-04-08 18:59:48
|
Update of /cvsroot/quantproject/QuantProject/b2_DataAccess/Tables
In directory sc8-pr-cvs16:/tmp/cvs-serv14966/b2_DataAccess/Tables
Modified Files:
Quotes.cs
Log Message:
Added GetTickersByRawOpenPrice on overload, for returning tickers ordered only by average raw open price that is greater
than a given minimum, at a given time interval
Index: Quotes.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b2_DataAccess/Tables/Quotes.cs,v
retrieving revision 1.31
retrieving revision 1.32
diff -C2 -d -r1.31 -r1.32
*** Quotes.cs 17 Sep 2006 21:36:09 -0000 1.31
--- Quotes.cs 8 Apr 2007 18:59:45 -0000 1.32
***************
*** 600,603 ****
--- 600,629 ----
/// <summary>
+ /// returns tickers ordered by the average raw open price that is over
+ /// a given minimum, at a given time interval
+ /// </summary>
+ public static DataTable GetTickersByRawOpenPrice( bool orderInASCMode, string groupID,
+ DateTime firstQuoteDate,
+ DateTime lastQuoteDate,
+ long maxNumOfReturnedTickers, double minPrice )
+ {
+ string sql = "SELECT TOP " + maxNumOfReturnedTickers + " quotes.quTicker, tickers.tiCompanyName, " +
+ "Avg(quotes.quOpen) AS AverageRawOpenPrice " +
+ "FROM (quotes INNER JOIN tickers ON quotes.quTicker=tickers.tiTicker) " +
+ "INNER JOIN tickers_tickerGroups ON tickers.tiTicker=tickers_tickerGroups.ttTiId " +
+ "WHERE quotes.quDate Between " + SQLBuilder.GetDateConstant(firstQuoteDate) + " " +
+ "AND " + SQLBuilder.GetDateConstant(lastQuoteDate) + " " +
+ "AND " + "tickers_tickerGroups.ttTgId='" + groupID + "' " +
+ "GROUP BY quotes.quTicker, tickers.tiCompanyName " +
+ "HAVING Avg(quotes.quOpen) >= " + minPrice + " " +
+ "ORDER BY Avg(quotes.quOpen)";
+ string sortDirection = " DESC";
+ if(orderInASCMode)
+ sortDirection = " ASC";
+ sql = sql + sortDirection;
+ return SqlExecutor.GetDataTable( sql );
+ }
+
+ /// <summary>
/// returns tickers ordered by average raw open price level,
/// with a given standard deviation, in a given time interval
|
|
From: Marco M. <mi...@us...> - 2007-04-08 18:56:04
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/BiasedPVO
In directory sc8-pr-cvs16:/tmp/cvs-serv13419/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/BiasedPVO
Modified Files:
RunBiasedPVO.cs
Log Message:
Better name for log file
Index: RunBiasedPVO.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/BiasedPVO/RunBiasedPVO.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** RunBiasedPVO.cs 27 Feb 2007 22:52:40 -0000 1.1
--- RunBiasedPVO.cs 8 Apr 2007 18:56:00 -0000 1.2
***************
*** 97,101 ****
this.numOfDifferentGenomesToEvaluateOutOfSample = numOfDifferentGenomesToEvaluateOutOfSample;
this.minimumAcceptableGain = minimumAcceptableGain;
! this.ScriptName = "PVO_Biased_NoWeightsPriceSel";
}
--- 97,101 ----
this.numOfDifferentGenomesToEvaluateOutOfSample = numOfDifferentGenomesToEvaluateOutOfSample;
this.minimumAcceptableGain = minimumAcceptableGain;
! this.ScriptName = "PVO_Biased_WithWeightsPriceSel";
}
|
|
From: Marco M. <mi...@us...> - 2007-04-08 18:55:25
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes
In directory sc8-pr-cvs16:/tmp/cvs-serv13391/b7_Scripts/TickerSelectionTesting/TestingOTCTypes
Modified Files:
RunEfficientOTCTypes.cs
Log Message:
Better name for log file
Index: RunEfficientOTCTypes.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/TestingOTCTypes/RunEfficientOTCTypes.cs,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** RunEfficientOTCTypes.cs 3 Jan 2007 23:11:34 -0000 1.7
--- RunEfficientOTCTypes.cs 8 Apr 2007 18:55:21 -0000 1.8
***************
*** 141,145 ****
public override void SaveScriptResults()
{
! string fileName = "From"+ this.tickerGroupID+ "_" +
this.numberOfEligibleTickers +
"_OptDays" + this.numDaysForOptimizationPeriod + "_Portf" +
--- 141,147 ----
public override void SaveScriptResults()
{
! string fileName = DateTime.Now.Hour.ToString().PadLeft(2,'0') + "_" +
! DateTime.Now.Minute.ToString().PadLeft(2,'0') + "_" +
! "From"+ this.tickerGroupID+ "_" +
this.numberOfEligibleTickers +
"_OptDays" + this.numDaysForOptimizationPeriod + "_Portf" +
|
|
From: Marco M. <mi...@us...> - 2007-04-08 18:54:05
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/Selectors
In directory sc8-pr-cvs16:/tmp/cvs-serv12601/b3_Data/Selectors
Modified Files:
SelectorByAverageRawOpenPrice.cs
Log Message:
Added new constructors, for retrieving data just by the raw open price (ignoring standard deviation)
Index: SelectorByAverageRawOpenPrice.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b3_Data/Selectors/SelectorByAverageRawOpenPrice.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** SelectorByAverageRawOpenPrice.cs 30 Mar 2005 16:02:58 -0000 1.2
--- SelectorByAverageRawOpenPrice.cs 8 Apr 2007 18:54:00 -0000 1.3
***************
*** 61,95 ****
this.maxStdDeviation = maxStdDeviation;
}
public SelectorByAverageRawOpenPrice(string groupID,
! bool orderInASCmode,
! DateTime firstQuoteDate,
! DateTime lastQuoteDate,
! long maxNumOfReturnedTickers, double minPrice,
! double maxPrice, double minStdDeviation,
! double maxStdDeviation):
! base(groupID,
! orderInASCmode,
! firstQuoteDate,
! lastQuoteDate,
! maxNumOfReturnedTickers)
{
this.minPrice = minPrice;
! this.maxPrice = maxPrice;
! this.minStdDeviation = minStdDeviation;
! this.maxStdDeviation = maxStdDeviation;
}
-
public DataTable GetTableOfSelectedTickers()
{
!
! if(this.setOfTickersToBeSelected == null)
! return QuantProject.DataAccess.Tables.Quotes.GetTickersByRawOpenPrice(this.isOrderedInASCMode,
! this.groupID, this.firstQuoteDate, this.lastQuoteDate, this.maxNumOfReturnedTickers,
! this.minPrice, this.maxPrice, this.minStdDeviation, this.maxStdDeviation);
! else
! return QuantProject.Data.DataTables.Quotes.GetTickersByAverageRawOpenPrice(this.isOrderedInASCMode,
! this.setOfTickersToBeSelected, this.firstQuoteDate, this.lastQuoteDate, this.maxNumOfReturnedTickers,
! this.minPrice, this.maxPrice, this.minStdDeviation, this.maxStdDeviation);
}
public void SelectAllTickers()
--- 61,145 ----
this.maxStdDeviation = maxStdDeviation;
}
+
+ public SelectorByAverageRawOpenPrice(DataTable setOfTickersToBeSelected,
+ bool orderInASCmode,
+ DateTime firstQuoteDate,
+ DateTime lastQuoteDate,
+ long maxNumOfReturnedTickers, double minPrice):
+ base(setOfTickersToBeSelected,
+ orderInASCmode,
+ firstQuoteDate,
+ lastQuoteDate,
+ maxNumOfReturnedTickers)
+ {
+ this.minPrice = minPrice;
+ this.maxPrice = 0.0;
+ this.minStdDeviation = 0.0;
+ this.maxStdDeviation = 0.0;
+ }
+
+ public SelectorByAverageRawOpenPrice(string groupID,
+ bool orderInASCmode,
+ DateTime firstQuoteDate,
+ DateTime lastQuoteDate,
+ long maxNumOfReturnedTickers, double minPrice,
+ double maxPrice, double minStdDeviation,
+ double maxStdDeviation):
+ base(groupID,
+ orderInASCmode,
+ firstQuoteDate,
+ lastQuoteDate,
+ maxNumOfReturnedTickers)
+ {
+ this.minPrice = minPrice;
+ this.maxPrice = maxPrice;
+ this.minStdDeviation = minStdDeviation;
+ this.maxStdDeviation = maxStdDeviation;
+ }
+
public SelectorByAverageRawOpenPrice(string groupID,
! bool orderInASCmode,
! DateTime firstQuoteDate,
! DateTime lastQuoteDate,
! long maxNumOfReturnedTickers, double minPrice):
! base(groupID,
! orderInASCmode,
! firstQuoteDate,
! lastQuoteDate,
! maxNumOfReturnedTickers)
{
this.minPrice = minPrice;
! this.maxPrice = 0.0;
! this.minStdDeviation = 0.0;
! this.maxStdDeviation = 0.0;
}
public DataTable GetTableOfSelectedTickers()
{
! DataTable returnValue;
! if(this.maxPrice == 0.0 && this.minStdDeviation == 0.0 && this.maxStdDeviation == 0.0)
! //selection only by average raw open price over a given minimum level
! {
! if(this.setOfTickersToBeSelected == null)
! returnValue = QuantProject.DataAccess.Tables.Quotes.GetTickersByRawOpenPrice(this.isOrderedInASCMode,
! this.groupID, this.firstQuoteDate, this.lastQuoteDate, this.maxNumOfReturnedTickers,
! this.minPrice);
! else
! returnValue = QuantProject.Data.DataTables.Quotes.GetTickersByAverageRawOpenPrice(this.isOrderedInASCMode,
! this.setOfTickersToBeSelected, this.firstQuoteDate, this.lastQuoteDate, this.maxNumOfReturnedTickers,
! this.minPrice);
! }
! else//selection is performed considering maxAveragePrice and min / max std Deviation
! {
! if(this.setOfTickersToBeSelected == null)
! returnValue = QuantProject.DataAccess.Tables.Quotes.GetTickersByRawOpenPrice(this.isOrderedInASCMode,
! this.groupID, this.firstQuoteDate, this.lastQuoteDate, this.maxNumOfReturnedTickers,
! this.minPrice, this.maxPrice, this.minStdDeviation, this.maxStdDeviation);
! else
! returnValue = QuantProject.Data.DataTables.Quotes.GetTickersByAverageRawOpenPrice(this.isOrderedInASCMode,
! this.setOfTickersToBeSelected, this.firstQuoteDate, this.lastQuoteDate, this.maxNumOfReturnedTickers,
! this.minPrice, this.maxPrice, this.minStdDeviation, this.maxStdDeviation);
! }
! return returnValue;
}
public void SelectAllTickers()
|
|
From: Marco M. <mi...@us...> - 2007-02-27 23:09:38
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv15383/b7_Scripts Modified Files: b7_Scripts.csproj Log Message: Removed reference to resx file Index: b7_Scripts.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/b7_Scripts.csproj,v retrieving revision 1.69 retrieving revision 1.70 diff -C2 -d -r1.69 -r1.70 *** b7_Scripts.csproj 27 Feb 2007 23:06:34 -0000 1.69 --- b7_Scripts.csproj 27 Feb 2007 23:09:35 -0000 1.70 *************** *** 704,712 **** /> <File - RelPath = "WalkForwardTesting\LinearCombination\TestDisplayer.resx" - DependentUpon = "TestDisplayer.cs" - BuildAction = "EmbeddedResource" - /> - <File RelPath = "WalkForwardTesting\LinearCombination\WalkForwardTest\RunWalkForwardLinearCombination.cs" SubType = "Code" --- 704,707 ---- |
|
From: Marco M. <mi...@us...> - 2007-02-27 23:07:49
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv14241/b7_Scripts/WalkForwardTesting/LinearCombination Modified Files: FixedLevelOscillatorPVOStrategy.cs Log Message: no message Index: FixedLevelOscillatorPVOStrategy.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/FixedLevelOscillatorPVOStrategy.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** FixedLevelOscillatorPVOStrategy.cs 3 Jan 2007 23:07:34 -0000 1.3 --- FixedLevelOscillatorPVOStrategy.cs 27 Feb 2007 23:07:44 -0000 1.4 *************** *** 76,79 **** --- 76,81 ---- double returnValue = 999.0; if(timer.CurrentDateArrayPosition + 2 >= this.numDaysForOscillatingPeriod) + //if there are sufficient data for computing currentChosenTickersValue + //that's why the method has been overriden { try |
|
From: Marco M. <mi...@us...> - 2007-02-27 23:06:45
|
Update of /cvsroot/quantproject/QuantProject/b4_Business In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv13737/b4_Business Modified Files: b4_Business.csproj Log Message: Updated vs net and sharpDevelop project's files Index: b4_Business.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/b4_Business.csproj,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** b4_Business.csproj 6 Dec 2006 16:07:17 -0000 1.38 --- b4_Business.csproj 27 Feb 2007 23:06:34 -0000 1.39 *************** *** 130,141 **** Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" /> - <Reference - Name = "Microsoft.Office.Core" - Guid = "{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}" - VersionMajor = "2" - VersionMinor = "3" - Lcid = "0" - WrapperTool = "primary" - /> </References> </Build> --- 130,133 ---- |
|
From: Marco M. <mi...@us...> - 2007-02-27 23:06:39
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv13737/b7_Scripts Modified Files: Scripts_SD.csproj b7_Scripts.csproj Log Message: Updated vs net and sharpDevelop project's files Index: Scripts_SD.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/Scripts_SD.csproj,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Scripts_SD.csproj 10 Dec 2006 20:11:41 -0000 1.4 --- Scripts_SD.csproj 27 Feb 2007 23:06:34 -0000 1.5 *************** *** 189,192 **** --- 189,207 ---- <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\EndOfDayTimerHandlerBiasedPVO.cs" /> <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\RunBiasedPVO.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\EndOfDayTimerHandlerWeightedPVO.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\GenomeManagerWeightedPVO.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\RunWeightedPVO.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\WeightedBalancedPVO\EndOfDayTimerHandlerWeightedBalancedPVO.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\WeightedBalancedPVO\GenomeManagerWeightedBalancedPVO.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\WeightedBalancedPVO\RunWeightedBalancedPVO.cs" /> + <Compile Include="WalkForwardTesting\LinearCombination\FixedLevelOscillatorBiasedPVOStrategy.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\BiasedPVONoThresholds\EndOfDayTimerHandlerBiasedPVONoThresholds.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\BiasedPVONoThresholds\GenomeManagerBiasedPVONoThresholds.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\BiasedPVONoThresholds\RunBiasedPVONoThresholds.cs" /> + <Compile Include="WalkForwardTesting\LinearCombination\FixedLevelOscillatorBiasedPVONoThresholdsStrategy.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\BiasedOTC_PVONoThresholds\EndOfDayTimerHandlerBiasedOTC_PVONoThresholds.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\BiasedOTC_PVONoThresholds\GenomeManagerBiasedOTC_PVONoThresholds.cs" /> + <Compile Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\BiasedOTC_PVONoThresholds\RunBiasedOTC_PVONoThresholds.cs" /> + <Compile Include="WalkForwardTesting\LinearCombination\FixedLevelOscBiasedOTC_PVONoThresholdsStrategy.cs" /> </ItemGroup> <ItemGroup> *************** *** 229,232 **** --- 244,251 ---- <Folder Include="WalkForwardTesting\WalkForwardLag\GeneticOptimizerTesting" /> <Folder Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO" /> + <Folder Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO" /> + <Folder Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\WeightedBalancedPVO" /> + <Folder Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\BiasedPVONoThresholds" /> + <Folder Include="TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\BiasedOTC_PVONoThresholds" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> Index: b7_Scripts.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/b7_Scripts.csproj,v retrieving revision 1.68 retrieving revision 1.69 diff -C2 -d -r1.68 -r1.69 *** b7_Scripts.csproj 18 Feb 2007 01:24:19 -0000 1.68 --- b7_Scripts.csproj 27 Feb 2007 23:06:34 -0000 1.69 *************** *** 284,287 **** --- 284,357 ---- /> <File + RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\EndOfDayTimerHandlerBiasedPVO.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\RunBiasedPVO.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\BiasedOTC_PVONoThresholds\EndOfDayTimerHandlerBiasedOTC_PVONoThresholds.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\BiasedOTC_PVONoThresholds\GenomeManagerBiasedOTC_PVONoThresholds.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\BiasedOTC_PVONoThresholds\RunBiasedOTC_PVONoThresholds.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\BiasedPVONoThresholds\EndOfDayTimerHandlerBiasedPVONoThresholds.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\BiasedPVONoThresholds\GenomeManagerBiasedPVONoThresholds.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\BiasedPVO\BiasedPVONoThresholds\RunBiasedPVONoThresholds.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\EndOfDayTimerHandlerWeightedPVO.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\GenomeManagerWeightedPVO.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\RunWeightedPVO.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\WeightedBalancedPVO\EndOfDayTimerHandlerWeightedBalancedPVO.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\WeightedBalancedPVO\GenomeManagerWeightedBalancedPVO.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TechnicalAnalysisTesting\Oscillators\FixedLevelOscillators\PortfolioValueOscillator\WeightedPVO\WeightedBalancedPVO\RunWeightedBalancedPVO.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "TechnicalAnalysisTesting\Oscillators\FixedPeriodOscillators\EndOfDayTimerHandlerFPOscillatorCTC.cs" SubType = "Code" *************** *** 554,557 **** --- 624,642 ---- /> <File + RelPath = "WalkForwardTesting\LinearCombination\FixedLevelOscBiasedOTC_PVONoThresholdsStrategy.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "WalkForwardTesting\LinearCombination\FixedLevelOscillatorBiasedPVONoThresholdsStrategy.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "WalkForwardTesting\LinearCombination\FixedLevelOscillatorBiasedPVOStrategy.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "WalkForwardTesting\LinearCombination\FixedLevelOscillatorPVOStrategy.cs" SubType = "Code" *************** *** 619,622 **** --- 704,712 ---- /> <File + RelPath = "WalkForwardTesting\LinearCombination\TestDisplayer.resx" + DependentUpon = "TestDisplayer.cs" + BuildAction = "EmbeddedResource" + /> + <File RelPath = "WalkForwardTesting\LinearCombination\WalkForwardTest\RunWalkForwardLinearCombination.cs" SubType = "Code" |
|
From: Marco M. <mi...@us...> - 2007-02-27 23:06:38
|
Update of /cvsroot/quantproject/QuantProject/b3_Data In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv13737/b3_Data Modified Files: b3_Data.csproj Log Message: Updated vs net and sharpDevelop project's files Index: b3_Data.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/b3_Data.csproj,v retrieving revision 1.44 retrieving revision 1.45 diff -C2 -d -r1.44 -r1.45 *** b3_Data.csproj 6 Dec 2006 16:07:18 -0000 1.44 --- b3_Data.csproj 27 Feb 2007 23:06:34 -0000 1.45 *************** *** 125,136 **** Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" /> - <Reference - Name = "Microsoft.Office.Core" - Guid = "{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}" - VersionMajor = "2" - VersionMinor = "3" - Lcid = "0" - WrapperTool = "primary" - /> </References> </Build> --- 125,128 ---- |
|
From: Marco M. <mi...@us...> - 2007-02-27 23:06:38
|
Update of /cvsroot/quantproject/QuantProject/b5_Presentation In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv13737/b5_Presentation Modified Files: b5_Presentation.csproj Log Message: Updated vs net and sharpDevelop project's files Index: b5_Presentation.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b5_Presentation/b5_Presentation.csproj,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** b5_Presentation.csproj 18 Feb 2007 00:53:13 -0000 1.34 --- b5_Presentation.csproj 27 Feb 2007 23:06:34 -0000 1.35 *************** *** 131,142 **** /> <Reference - Name = "Microsoft.Office.Core" - Guid = "{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}" - VersionMajor = "2" - VersionMinor = "3" - Lcid = "0" - WrapperTool = "primary" - /> - <Reference Name = "NPlot" AssemblyName = "NPlot" --- 131,134 ---- |
|
From: Marco M. <mi...@us...> - 2007-02-27 23:02:46
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv11917/b7_Scripts/WalkForwardTesting/LinearCombination Modified Files: TestDisplayer.cs StrategyType.cs LinearCombinationTest.cs Log Message: Added variations of PVO strategy for in sample testing. The form for in sample testing now supports multi genomes testing (for strategies that accept array of genomes with the same optimization dates) Index: LinearCombinationTest.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/LinearCombinationTest.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** LinearCombinationTest.cs 17 Sep 2006 21:24:53 -0000 1.10 --- LinearCombinationTest.cs 27 Feb 2007 23:02:41 -0000 1.11 *************** *** 46,53 **** private DateTime firstDate; private DateTime lastDate; ! private GenomeRepresentation genomeRepresentation; // private bool openToCloseDaily; private StrategyType strategyType; private int numDaysForOscillatorStrategy; private IHistoricalQuoteProvider historicalQuoteProvider; --- 46,55 ---- private DateTime firstDate; private DateTime lastDate; ! private GenomeRepresentation[] genomeRepresentations; // private bool openToCloseDaily; private StrategyType strategyType; private int numDaysForOscillatorStrategy; + private double stopLoss; + private double takeProfit; private IHistoricalQuoteProvider historicalQuoteProvider; *************** *** 58,67 **** public LinearCombinationTest( DateTime firstDate , DateTime lastDate , ! GenomeRepresentation genomeRepresentation , StrategyType strategyType, PortfolioType portfolioType) { this.firstDate = firstDate; this.lastDate = lastDate; ! this.genomeRepresentation = genomeRepresentation; // this.openToCloseDaily = openToCloseDaily; this.strategyType = strategyType; --- 60,69 ---- public LinearCombinationTest( DateTime firstDate , DateTime lastDate , ! GenomeRepresentation[] genomeRepresentations , StrategyType strategyType, PortfolioType portfolioType) { this.firstDate = firstDate; this.lastDate = lastDate; ! this.genomeRepresentations = genomeRepresentations; // this.openToCloseDaily = openToCloseDaily; this.strategyType = strategyType; *************** *** 70,74 **** public LinearCombinationTest( DateTime firstDate , DateTime lastDate , ! GenomeRepresentation genomeRepresentation , StrategyType strategyType, PortfolioType portfolioType, int numDaysForOscillatorStrategy) --- 72,76 ---- public LinearCombinationTest( DateTime firstDate , DateTime lastDate , ! GenomeRepresentation[] genomeRepresentations , StrategyType strategyType, PortfolioType portfolioType, int numDaysForOscillatorStrategy) *************** *** 76,80 **** this.firstDate = firstDate; this.lastDate = lastDate; ! this.genomeRepresentation = genomeRepresentation; // this.openToCloseDaily = openToCloseDaily; this.strategyType = strategyType; --- 78,82 ---- this.firstDate = firstDate; this.lastDate = lastDate; ! this.genomeRepresentations = genomeRepresentations; // this.openToCloseDaily = openToCloseDaily; this.strategyType = strategyType; *************** *** 82,86 **** this.numDaysForOscillatorStrategy = numDaysForOscillatorStrategy; } ! private void oneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) --- 84,102 ---- this.numDaysForOscillatorStrategy = numDaysForOscillatorStrategy; } ! public LinearCombinationTest( DateTime firstDate , DateTime lastDate , ! GenomeRepresentation[] genomeRepresentations , StrategyType strategyType, ! PortfolioType portfolioType, ! int numDaysForOscillatorStrategy, double stopLoss, double takeProfit) ! { ! this.firstDate = firstDate; ! this.lastDate = lastDate; ! this.genomeRepresentations = genomeRepresentations; ! // this.openToCloseDaily = openToCloseDaily; ! this.strategyType = strategyType; ! this.portfolioType = portfolioType; ! this.numDaysForOscillatorStrategy = numDaysForOscillatorStrategy; ! this.stopLoss = stopLoss; ! this.takeProfit = takeProfit; ! } private void oneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) *************** *** 98,106 **** this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); } private void run_setStrategy() { ! string[] signedTickers = genomeRepresentation.SignedTickers.Split(";".ToCharArray()); double[] weightsForSignedTickers = ! GenomeRepresentation.GetWeightsArray(this.genomeRepresentation.WeightsForSignedTickers); switch (this.strategyType) { --- 114,201 ---- this.historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); } + + private void run_setStrategy_setBiasedOTC_PVONoThresholdsStrategy() + { + int numberOfTickersToBeChosen = + GenomeRepresentation.GetSignedTickers(this.genomeRepresentations[0].SignedTickers).Length; + string[,] signedTickers = new string[this.genomeRepresentations.Length, numberOfTickersToBeChosen]; + double[,] tickersPortfolioWeights = new double[this.genomeRepresentations.Length, numberOfTickersToBeChosen]; + for(int i = 0; i < this.genomeRepresentations.Length; i++) + { + for(int j = 0; j < numberOfTickersToBeChosen; j++) + { + signedTickers[i,j] = + GenomeRepresentation.GetSignedTickers( + this.genomeRepresentations[i].SignedTickers)[j]; + tickersPortfolioWeights[i,j] = + GenomeRepresentation.GetWeightsArray( + this.genomeRepresentations[i].WeightsForSignedTickers)[j]; + } + } + this.endOfDayStrategy = new FixedLevelOscBiasedOTC_PVONoThresholdsStrategy( + this.account , signedTickers , tickersPortfolioWeights, + this.genomeRepresentations.Length); + } + + private void run_setStrategy_setBiasedPVONoThresholdsStrategy() + { + int numberOfTickersToBeChosen = + GenomeRepresentation.GetSignedTickers(this.genomeRepresentations[0].SignedTickers).Length; + string[,] signedTickers = new string[this.genomeRepresentations.Length, numberOfTickersToBeChosen]; + double[,] tickersPortfolioWeights = new double[this.genomeRepresentations.Length, numberOfTickersToBeChosen]; + for(int i = 0; i < this.genomeRepresentations.Length; i++) + { + for(int j = 0; j < numberOfTickersToBeChosen; j++) + { + signedTickers[i,j] = + GenomeRepresentation.GetSignedTickers( + this.genomeRepresentations[i].SignedTickers)[j]; + tickersPortfolioWeights[i,j] = + GenomeRepresentation.GetWeightsArray( + this.genomeRepresentations[i].WeightsForSignedTickers)[j]; + } + } + this.endOfDayStrategy = new FixedLevelOscillatorBiasedPVONoThresholdsStrategy( + this.account , signedTickers , tickersPortfolioWeights, + this.genomeRepresentations.Length, + this.stopLoss, + this.takeProfit); + } + + private void run_setStrategy_setBiasedPVOStrategy() + { + int numberOfTickersToBeChosen = + GenomeRepresentation.GetSignedTickers(this.genomeRepresentations[0].SignedTickers).Length; + string[,] signedTickers = new string[this.genomeRepresentations.Length, numberOfTickersToBeChosen]; + double[,] tickersPortfolioWeights = new double[this.genomeRepresentations.Length, numberOfTickersToBeChosen]; + double[] oversoldThresholds = new double[this.genomeRepresentations.Length]; + double[] overboughtThresholds = new double[this.genomeRepresentations.Length]; + for(int i = 0; i < this.genomeRepresentations.Length; i++) + { + for(int j = 0; j < numberOfTickersToBeChosen; j++) + { + signedTickers[i,j] = + GenomeRepresentation.GetSignedTickers( + this.genomeRepresentations[i].SignedTickers)[j]; + tickersPortfolioWeights[i,j] = + GenomeRepresentation.GetWeightsArray( + this.genomeRepresentations[i].WeightsForSignedTickers)[j]; + } + oversoldThresholds[i] = this.genomeRepresentations[i].OversoldThreshold; + overboughtThresholds[i] = this.genomeRepresentations[i].OverboughtThreshold; + } + this.endOfDayStrategy = new FixedLevelOscillatorBiasedPVOStrategy( + this.account , signedTickers , tickersPortfolioWeights, + oversoldThresholds, overboughtThresholds, + overboughtThresholds.Length, + this.numDaysForOscillatorStrategy,this.stopLoss, + this.takeProfit); + } + private void run_setStrategy() { ! string[] signedTickers = genomeRepresentations[0].SignedTickers.Split(";".ToCharArray()); double[] weightsForSignedTickers = ! GenomeRepresentation.GetWeightsArray(this.genomeRepresentations[0].WeightsForSignedTickers); switch (this.strategyType) { *************** *** 145,151 **** this.endOfDayStrategy = new FixedLevelOscillatorPVOStrategy( this.account , signedTickers , weightsForSignedTickers, ! this.genomeRepresentation.OversoldThreshold, this.genomeRepresentation.OverboughtThreshold, this.numDaysForOscillatorStrategy ); break; } } --- 240,258 ---- this.endOfDayStrategy = new FixedLevelOscillatorPVOStrategy( this.account , signedTickers , weightsForSignedTickers, ! this.genomeRepresentations[0].OversoldThreshold, this.genomeRepresentations[0].OverboughtThreshold, this.numDaysForOscillatorStrategy ); break; + + case StrategyType.PortfolioValueOscillatorBiased: + this.run_setStrategy_setBiasedPVOStrategy(); + break; + + case StrategyType.PortfolioValueOscillatorBiasedNoThresholds: + this.run_setStrategy_setBiasedPVONoThresholdsStrategy(); + break; + + case StrategyType.OTC_PVOBiasedNoThresholds: + this.run_setStrategy_setBiasedOTC_PVONoThresholdsStrategy(); + break; } } *************** *** 158,170 **** { string returnValue = "Fitness:" + ! this.genomeRepresentation.Fitness.ToString() + " | Tickers:" + ! this.genomeRepresentation.SignedTickers + " - " + "from " + this.getDateString( this.firstDate ) + " to " + this.getDateString( this.lastDate ) + " opt. in sample from " + this.getDateString( ! this.genomeRepresentation.FirstOptimizationDate ) + " to " + this.getDateString( ! this.genomeRepresentation.LastOptimizationDate ); return returnValue; } --- 265,277 ---- { string returnValue = "Fitness:" + ! this.genomeRepresentations[0].Fitness.ToString() + " | Tickers:" + ! this.genomeRepresentations[0].SignedTickers + " - " + "from " + this.getDateString( this.firstDate ) + " to " + this.getDateString( this.lastDate ) + " opt. in sample from " + this.getDateString( ! this.genomeRepresentations[0].FirstOptimizationDate ) + " to " + this.getDateString( ! this.genomeRepresentations[0].LastOptimizationDate ); return returnValue; } *************** *** 184,190 **** { double[] normalizedWeights = ! GenomeRepresentation.GetWeightsArray(this.genomeRepresentation.WeightsForSignedTickers); string[] tickers = ! GenomeRepresentation.GetSignedTickers(this.genomeRepresentation.SignedTickers); for(int i = 0; i<tickers.Length; i++) { --- 291,297 ---- { double[] normalizedWeights = ! GenomeRepresentation.GetWeightsArray(genomeRepresentation.WeightsForSignedTickers); string[] tickers = ! GenomeRepresentation.GetSignedTickers(genomeRepresentation.SignedTickers); for(int i = 0; i<tickers.Length; i++) { *************** *** 232,236 **** "^GSPC"); WeightedPositions weightedPositions = ! this.run_getWeightedPositions(this.genomeRepresentation); this.run_addEquityLineForWeightedPositions(weightedPositions, Color.Brown, report); --- 339,343 ---- "^GSPC"); WeightedPositions weightedPositions = ! this.run_getWeightedPositions(this.genomeRepresentations[0]); this.run_addEquityLineForWeightedPositions(weightedPositions, Color.Brown, report); Index: StrategyType.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/StrategyType.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** StrategyType.cs 17 Sep 2006 21:24:53 -0000 1.5 --- StrategyType.cs 27 Feb 2007 23:02:41 -0000 1.6 *************** *** 37,41 **** ExtremeCounterTrend, ImmediateTrendFollower, ! PortfolioValueOscillator } } --- 37,44 ---- ExtremeCounterTrend, ImmediateTrendFollower, ! PortfolioValueOscillator, ! PortfolioValueOscillatorBiased, ! PortfolioValueOscillatorBiasedNoThresholds, ! OTC_PVOBiasedNoThresholds } } Index: TestDisplayer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/TestDisplayer.cs,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** TestDisplayer.cs 17 Sep 2006 21:24:53 -0000 1.11 --- TestDisplayer.cs 27 Feb 2007 23:02:40 -0000 1.12 *************** *** 52,57 **** // Glauco code private ArrayList bestGenomes; ! private GenomeRepresentation lastSelectedGenomeRepresentation; private System.Windows.Forms.RadioButton radioButtonOTCCTODaily; private System.Windows.Forms.RadioButton radioButtonExtremeCounterTrend; --- 52,59 ---- // Glauco code + // Millo code: lastSelectedGenomeRepresentation has been + // changed into an array private ArrayList bestGenomes; ! private GenomeRepresentation[] lastSelectedGenomeRepresentations; private System.Windows.Forms.RadioButton radioButtonOTCCTODaily; private System.Windows.Forms.RadioButton radioButtonExtremeCounterTrend; *************** *** 60,63 **** --- 62,72 ---- private System.Windows.Forms.Label labelPortfolioType; private System.Windows.Forms.RadioButton radioButtonPVO; + private System.Windows.Forms.RadioButton radioButtonPVOBiased; + private System.Windows.Forms.Label labelStopLoss; + private System.Windows.Forms.TextBox textBoxStopLoss; + private System.Windows.Forms.Label labelTakeProfit; + private System.Windows.Forms.TextBox textBoxTakeProfit; + private System.Windows.Forms.RadioButton radioButtonPVOBiasedNoThresholds; + private System.Windows.Forms.RadioButton radioButtonOTCPVOBiasedNoThresholds; private System.Windows.Forms.ComboBox comboBoxPortfolioType; *************** *** 123,126 **** --- 132,151 ---- this.dgBestGenomes.AllowSorting = true; } + + private void testDisplayer_InitializeLastSelectedGenomeRepresentations(ArrayList bestGenomes) + { + //genomes with the same optimization's dates are grouped together + GenomeRepresentation firstGenomeRepresentation = + ((GenomeRepresentation)bestGenomes[0]); + DateTime firstDate = firstGenomeRepresentation.FirstOptimizationDate; + int counterOfGenomesWithSameOptimizationDates = 0; + foreach(Object item in bestGenomes) + if(firstDate == ((GenomeRepresentation)item).FirstOptimizationDate) + counterOfGenomesWithSameOptimizationDates++; + this.lastSelectedGenomeRepresentations = new GenomeRepresentation[counterOfGenomesWithSameOptimizationDates]; + this.lastSelectedGenomeRepresentations[0]= + ((GenomeRepresentation)bestGenomes[0]); + } + public TestDisplayer( DateTime firstDate , DateTime lastDate , ArrayList bestGenomes ) *************** *** 134,144 **** InitializeComponent(); ! // Glauco code ! this.lastSelectedGenomeRepresentation = ! ((GenomeRepresentation)bestGenomes[0]); this.dtpFirstDate.Value = ! this.lastSelectedGenomeRepresentation.FirstOptimizationDate; this.dtpLastDate.Value = ! this.lastSelectedGenomeRepresentation.LastOptimizationDate; this.bestGenomes = bestGenomes; this.comboBoxPortfolioType.Items.Add(PortfolioType.ShortAndLong); --- 159,168 ---- InitializeComponent(); ! // Glauco code + Millo code ! this.testDisplayer_InitializeLastSelectedGenomeRepresentations(bestGenomes); this.dtpFirstDate.Value = ! this.lastSelectedGenomeRepresentations[0].FirstOptimizationDate; this.dtpLastDate.Value = ! this.lastSelectedGenomeRepresentations[0].LastOptimizationDate; this.bestGenomes = bestGenomes; this.comboBoxPortfolioType.Items.Add(PortfolioType.ShortAndLong); *************** *** 189,192 **** --- 213,223 ---- this.labelPortfolioType = new System.Windows.Forms.Label(); this.radioButtonPVO = new System.Windows.Forms.RadioButton(); + this.radioButtonPVOBiased = new System.Windows.Forms.RadioButton(); + this.labelStopLoss = new System.Windows.Forms.Label(); + this.textBoxStopLoss = new System.Windows.Forms.TextBox(); + this.labelTakeProfit = new System.Windows.Forms.Label(); + this.textBoxTakeProfit = new System.Windows.Forms.TextBox(); + this.radioButtonPVOBiasedNoThresholds = new System.Windows.Forms.RadioButton(); + this.radioButtonOTCPVOBiasedNoThresholds = new System.Windows.Forms.RadioButton(); ((System.ComponentModel.ISupportInitialize)(this.dgBestGenomes)).BeginInit(); this.SuspendLayout(); *************** *** 197,203 **** this.dgBestGenomes.Dock = System.Windows.Forms.DockStyle.Bottom; this.dgBestGenomes.HeaderForeColor = System.Drawing.SystemColors.ControlText; ! this.dgBestGenomes.Location = new System.Drawing.Point(0, 205); this.dgBestGenomes.Name = "dgBestGenomes"; ! this.dgBestGenomes.Size = new System.Drawing.Size(704, 168); this.dgBestGenomes.TabIndex = 0; this.dgBestGenomes.MouseUp += new System.Windows.Forms.MouseEventHandler(this.dgBestGenomes_MouseUp); --- 228,234 ---- this.dgBestGenomes.Dock = System.Windows.Forms.DockStyle.Bottom; this.dgBestGenomes.HeaderForeColor = System.Drawing.SystemColors.ControlText; ! this.dgBestGenomes.Location = new System.Drawing.Point(0, 238); this.dgBestGenomes.Name = "dgBestGenomes"; ! this.dgBestGenomes.Size = new System.Drawing.Size(704, 176); this.dgBestGenomes.TabIndex = 0; this.dgBestGenomes.MouseUp += new System.Windows.Forms.MouseEventHandler(this.dgBestGenomes_MouseUp); *************** *** 205,209 **** // radioButtonCloseToOpenDaily // ! this.radioButtonCloseToOpenDaily.Location = new System.Drawing.Point(64, 120); this.radioButtonCloseToOpenDaily.Name = "radioButtonCloseToOpenDaily"; this.radioButtonCloseToOpenDaily.Size = new System.Drawing.Size(144, 24); --- 236,240 ---- // radioButtonCloseToOpenDaily // ! this.radioButtonCloseToOpenDaily.Location = new System.Drawing.Point(64, 104); this.radioButtonCloseToOpenDaily.Name = "radioButtonCloseToOpenDaily"; this.radioButtonCloseToOpenDaily.Size = new System.Drawing.Size(144, 24); *************** *** 214,218 **** // radioButtonOpenToCloseWeekly // ! this.radioButtonOpenToCloseWeekly.Location = new System.Drawing.Point(64, 144); this.radioButtonOpenToCloseWeekly.Name = "radioButtonOpenToCloseWeekly"; this.radioButtonOpenToCloseWeekly.Size = new System.Drawing.Size(144, 24); --- 245,249 ---- // radioButtonOpenToCloseWeekly // ! this.radioButtonOpenToCloseWeekly.Location = new System.Drawing.Point(64, 128); this.radioButtonOpenToCloseWeekly.Name = "radioButtonOpenToCloseWeekly"; this.radioButtonOpenToCloseWeekly.Size = new System.Drawing.Size(144, 24); *************** *** 223,227 **** // textBoxDaysFPOscillatorAndRevOneRank // ! this.textBoxDaysFPOscillatorAndRevOneRank.Location = new System.Drawing.Point(472, 128); this.textBoxDaysFPOscillatorAndRevOneRank.Name = "textBoxDaysFPOscillatorAndRevOneRank"; this.textBoxDaysFPOscillatorAndRevOneRank.Size = new System.Drawing.Size(56, 20); --- 254,258 ---- // textBoxDaysFPOscillatorAndRevOneRank // ! this.textBoxDaysFPOscillatorAndRevOneRank.Location = new System.Drawing.Point(480, 120); this.textBoxDaysFPOscillatorAndRevOneRank.Name = "textBoxDaysFPOscillatorAndRevOneRank"; this.textBoxDaysFPOscillatorAndRevOneRank.Size = new System.Drawing.Size(56, 20); *************** *** 231,235 **** // dtpFirstDate // ! this.dtpFirstDate.Location = new System.Drawing.Point(16, 24); this.dtpFirstDate.Name = "dtpFirstDate"; this.dtpFirstDate.TabIndex = 1; --- 262,266 ---- // dtpFirstDate // ! this.dtpFirstDate.Location = new System.Drawing.Point(48, 8); this.dtpFirstDate.Name = "dtpFirstDate"; this.dtpFirstDate.TabIndex = 1; *************** *** 237,241 **** // label1 // ! this.label1.Location = new System.Drawing.Point(32, 64); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(400, 40); --- 268,272 ---- // label1 // ! this.label1.Location = new System.Drawing.Point(32, 48); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(400, 40); *************** *** 246,250 **** // dtpLastDate // ! this.dtpLastDate.Location = new System.Drawing.Point(264, 24); this.dtpLastDate.Name = "dtpLastDate"; this.dtpLastDate.Size = new System.Drawing.Size(208, 20); --- 277,281 ---- // dtpLastDate // ! this.dtpLastDate.Location = new System.Drawing.Point(264, 8); this.dtpLastDate.Name = "dtpLastDate"; this.dtpLastDate.Size = new System.Drawing.Size(208, 20); *************** *** 253,259 **** // 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"; --- 284,290 ---- // radioButtonExtremeCounterTrend // ! this.radioButtonExtremeCounterTrend.Location = new System.Drawing.Point(64, 176); this.radioButtonExtremeCounterTrend.Name = "radioButtonExtremeCounterTrend"; ! this.radioButtonExtremeCounterTrend.Size = new System.Drawing.Size(144, 24); this.radioButtonExtremeCounterTrend.TabIndex = 10; this.radioButtonExtremeCounterTrend.Text = "Extreme counter trend"; *************** *** 262,266 **** // radioButtonOpenToCloseDaily // ! this.radioButtonOpenToCloseDaily.Location = new System.Drawing.Point(64, 96); this.radioButtonOpenToCloseDaily.Name = "radioButtonOpenToCloseDaily"; this.radioButtonOpenToCloseDaily.Size = new System.Drawing.Size(144, 24); --- 293,297 ---- // radioButtonOpenToCloseDaily // ! this.radioButtonOpenToCloseDaily.Location = new System.Drawing.Point(64, 80); this.radioButtonOpenToCloseDaily.Name = "radioButtonOpenToCloseDaily"; this.radioButtonOpenToCloseDaily.Size = new System.Drawing.Size(144, 24); *************** *** 271,277 **** // radioButtonFixedPeriodOscillator // ! this.radioButtonFixedPeriodOscillator.Location = new System.Drawing.Point(232, 96); this.radioButtonFixedPeriodOscillator.Name = "radioButtonFixedPeriodOscillator"; ! this.radioButtonFixedPeriodOscillator.Size = new System.Drawing.Size(192, 24); this.radioButtonFixedPeriodOscillator.TabIndex = 7; this.radioButtonFixedPeriodOscillator.Text = "Fixed Period n-days oscillator"; --- 302,308 ---- // radioButtonFixedPeriodOscillator // ! this.radioButtonFixedPeriodOscillator.Location = new System.Drawing.Point(232, 80); this.radioButtonFixedPeriodOscillator.Name = "radioButtonFixedPeriodOscillator"; ! this.radioButtonFixedPeriodOscillator.Size = new System.Drawing.Size(184, 24); this.radioButtonFixedPeriodOscillator.TabIndex = 7; this.radioButtonFixedPeriodOscillator.Text = "Fixed Period n-days oscillator"; *************** *** 280,284 **** // labelDays // ! this.labelDays.Location = new System.Drawing.Point(432, 136); this.labelDays.Name = "labelDays"; this.labelDays.Size = new System.Drawing.Size(32, 16); --- 311,315 ---- // labelDays // ! this.labelDays.Location = new System.Drawing.Point(424, 120); this.labelDays.Name = "labelDays"; this.labelDays.Size = new System.Drawing.Size(32, 16); *************** *** 288,292 **** // radioButtonOTCCTODaily // ! this.radioButtonOTCCTODaily.Location = new System.Drawing.Point(64, 168); this.radioButtonOTCCTODaily.Name = "radioButtonOTCCTODaily"; this.radioButtonOTCCTODaily.Size = new System.Drawing.Size(144, 24); --- 319,323 ---- // radioButtonOTCCTODaily // ! this.radioButtonOTCCTODaily.Location = new System.Drawing.Point(64, 152); this.radioButtonOTCCTODaily.Name = "radioButtonOTCCTODaily"; this.radioButtonOTCCTODaily.Size = new System.Drawing.Size(144, 24); *************** *** 296,300 **** // radioButtonImmediateTrendFollower // ! this.radioButtonImmediateTrendFollower.Location = new System.Drawing.Point(232, 144); this.radioButtonImmediateTrendFollower.Name = "radioButtonImmediateTrendFollower"; this.radioButtonImmediateTrendFollower.Size = new System.Drawing.Size(192, 24); --- 327,331 ---- // radioButtonImmediateTrendFollower // ! this.radioButtonImmediateTrendFollower.Location = new System.Drawing.Point(232, 104); this.radioButtonImmediateTrendFollower.Name = "radioButtonImmediateTrendFollower"; this.radioButtonImmediateTrendFollower.Size = new System.Drawing.Size(192, 24); *************** *** 305,309 **** // comboBoxPortfolioType // ! this.comboBoxPortfolioType.Location = new System.Drawing.Point(472, 80); this.comboBoxPortfolioType.Name = "comboBoxPortfolioType"; this.comboBoxPortfolioType.Size = new System.Drawing.Size(184, 21); --- 336,340 ---- // comboBoxPortfolioType // ! this.comboBoxPortfolioType.Location = new System.Drawing.Point(472, 64); this.comboBoxPortfolioType.Name = "comboBoxPortfolioType"; this.comboBoxPortfolioType.Size = new System.Drawing.Size(184, 21); *************** *** 313,317 **** // labelPortfolioType // ! this.labelPortfolioType.Location = new System.Drawing.Point(472, 64); this.labelPortfolioType.Name = "labelPortfolioType"; this.labelPortfolioType.Size = new System.Drawing.Size(100, 16); --- 344,348 ---- // labelPortfolioType // ! this.labelPortfolioType.Location = new System.Drawing.Point(472, 48); this.labelPortfolioType.Name = "labelPortfolioType"; this.labelPortfolioType.Size = new System.Drawing.Size(100, 16); *************** *** 321,325 **** // radioButtonPVO // ! this.radioButtonPVO.Location = new System.Drawing.Point(232, 168); this.radioButtonPVO.Name = "radioButtonPVO"; this.radioButtonPVO.Size = new System.Drawing.Size(192, 24); --- 352,356 ---- // radioButtonPVO // ! this.radioButtonPVO.Location = new System.Drawing.Point(232, 128); this.radioButtonPVO.Name = "radioButtonPVO"; this.radioButtonPVO.Size = new System.Drawing.Size(192, 24); *************** *** 328,336 **** this.radioButtonPVO.CheckedChanged += new System.EventHandler(this.radioButtonPVO_CheckedChanged); // // TestDisplayer // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); ! this.ClientSize = new System.Drawing.Size(704, 373); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.radioButtonPVO, this.labelPortfolioType, --- 359,433 ---- this.radioButtonPVO.CheckedChanged += new System.EventHandler(this.radioButtonPVO_CheckedChanged); // + // radioButtonPVOBiased + // + this.radioButtonPVOBiased.Location = new System.Drawing.Point(232, 152); + this.radioButtonPVOBiased.Name = "radioButtonPVOBiased"; + this.radioButtonPVOBiased.Size = new System.Drawing.Size(88, 24); + this.radioButtonPVOBiased.TabIndex = 16; + this.radioButtonPVOBiased.Text = "PVO Biased"; + this.radioButtonPVOBiased.CheckedChanged += new System.EventHandler(this.radioButtonPVOBiased_CheckedChanged); + // + // labelStopLoss + // + this.labelStopLoss.Location = new System.Drawing.Point(424, 160); + this.labelStopLoss.Name = "labelStopLoss"; + this.labelStopLoss.Size = new System.Drawing.Size(56, 16); + this.labelStopLoss.TabIndex = 18; + this.labelStopLoss.Text = "stop loss"; + // + // textBoxStopLoss + // + this.textBoxStopLoss.Location = new System.Drawing.Point(480, 160); + this.textBoxStopLoss.Name = "textBoxStopLoss"; + this.textBoxStopLoss.Size = new System.Drawing.Size(56, 20); + this.textBoxStopLoss.TabIndex = 17; + this.textBoxStopLoss.Text = "0.02"; + // + // labelTakeProfit + // + this.labelTakeProfit.Location = new System.Drawing.Point(544, 160); + this.labelTakeProfit.Name = "labelTakeProfit"; + this.labelTakeProfit.Size = new System.Drawing.Size(56, 16); + this.labelTakeProfit.TabIndex = 20; + this.labelTakeProfit.Text = "take profit"; + // + // textBoxTakeProfit + // + this.textBoxTakeProfit.Location = new System.Drawing.Point(608, 160); + this.textBoxTakeProfit.Name = "textBoxTakeProfit"; + this.textBoxTakeProfit.Size = new System.Drawing.Size(56, 20); + this.textBoxTakeProfit.TabIndex = 19; + this.textBoxTakeProfit.Text = "0.005"; + // + // radioButtonPVOBiasedNoThresholds + // + this.radioButtonPVOBiasedNoThresholds.Location = new System.Drawing.Point(232, 176); + this.radioButtonPVOBiasedNoThresholds.Name = "radioButtonPVOBiasedNoThresholds"; + this.radioButtonPVOBiasedNoThresholds.Size = new System.Drawing.Size(192, 24); + this.radioButtonPVOBiasedNoThresholds.TabIndex = 21; + this.radioButtonPVOBiasedNoThresholds.Text = "PVO Biased No Thresholds"; + this.radioButtonPVOBiasedNoThresholds.CheckedChanged += new System.EventHandler(this.radioButtonPVOBiasedNoThresholds_CheckedChanged); + // + // radioButtonOTCPVOBiasedNoThresholds + // + this.radioButtonOTCPVOBiasedNoThresholds.Location = new System.Drawing.Point(232, 200); + this.radioButtonOTCPVOBiasedNoThresholds.Name = "radioButtonOTCPVOBiasedNoThresholds"; + this.radioButtonOTCPVOBiasedNoThresholds.Size = new System.Drawing.Size(192, 24); + this.radioButtonOTCPVOBiasedNoThresholds.TabIndex = 22; + this.radioButtonOTCPVOBiasedNoThresholds.Text = "OTC_PVO Biased No Thresholds"; + this.radioButtonOTCPVOBiasedNoThresholds.CheckedChanged += new System.EventHandler(this.radioButtonOTCPVOBiasedNoThresholds_CheckedChanged); + // // TestDisplayer // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); ! this.ClientSize = new System.Drawing.Size(704, 414); this.Controls.AddRange(new System.Windows.Forms.Control[] { + this.radioButtonOTCPVOBiasedNoThresholds, + this.radioButtonPVOBiasedNoThresholds, + this.labelTakeProfit, + this.textBoxTakeProfit, + this.labelStopLoss, + this.textBoxStopLoss, + this.radioButtonPVOBiased, this.radioButtonPVO, this.labelPortfolioType, *************** *** 365,372 **** return hitTestInfo.Row>=0; } ! private GenomeRepresentation dgBestGenomes_MouseUp_getClickedGenomeRepresentation( object sender, System.Windows.Forms.MouseEventArgs e ) { ! GenomeRepresentation genomeRepresentation = null; DataGrid dataGrid = (DataGrid)sender; Point point = new Point( e.X , e.Y ); --- 462,470 ---- return hitTestInfo.Row>=0; } ! private GenomeRepresentation[] dgBestGenomes_MouseUp_getClickedGenomeRepresentation( object sender, System.Windows.Forms.MouseEventArgs e ) { ! GenomeRepresentation[] genomeRepresentations = ! new GenomeRepresentation[this.lastSelectedGenomeRepresentations.Length]; DataGrid dataGrid = (DataGrid)sender; Point point = new Point( e.X , e.Y ); *************** *** 376,382 **** if ( hitTestInfo.Row >= 0 ) // a grid row has been clicked, not the header ! genomeRepresentation = ! (GenomeRepresentation)bestGenomes[ hitTestInfo.Row ]; ! return genomeRepresentation; } private void dgBestGenomes_MouseUp_rightButton_updateDates( --- 474,491 ---- if ( hitTestInfo.Row >= 0 ) // a grid row has been clicked, not the header ! // all best genomes with the same optimization's dates ! // are saved in an array ! { ! genomeRepresentations[0] = ! (GenomeRepresentation)bestGenomes[ hitTestInfo.Row ]; ! for(int i = 1; i < bestGenomes.Count - hitTestInfo.Row; i++) ! if( genomeRepresentations[0].FirstOptimizationDate == ! ((GenomeRepresentation)bestGenomes[hitTestInfo.Row+i]).FirstOptimizationDate ) ! // the next row has the same optimization's date of the ! // original selected best genome by the user ! genomeRepresentations[i] = ! (GenomeRepresentation)bestGenomes[ hitTestInfo.Row + i]; ! } ! return genomeRepresentations; } private void dgBestGenomes_MouseUp_rightButton_updateDates( *************** *** 385,392 **** TimeSpan currentFirstDateDisplacement = ( this.dtpFirstDate.Value - ! this.lastSelectedGenomeRepresentation.FirstOptimizationDate ); TimeSpan currentLastDateDisplacement = ( this.dtpLastDate.Value - ! this.lastSelectedGenomeRepresentation.LastOptimizationDate ); this.dtpFirstDate.Value = newSelectedGenomeRepresentation.FirstOptimizationDate + currentFirstDateDisplacement; --- 494,501 ---- TimeSpan currentFirstDateDisplacement = ( this.dtpFirstDate.Value - ! this.lastSelectedGenomeRepresentations[0].FirstOptimizationDate ); TimeSpan currentLastDateDisplacement = ( this.dtpLastDate.Value - ! this.lastSelectedGenomeRepresentations[0].LastOptimizationDate ); this.dtpFirstDate.Value = newSelectedGenomeRepresentation.FirstOptimizationDate + currentFirstDateDisplacement; *************** *** 396,410 **** private void dgBestGenomes_MouseUp_rightButton(object sender, System.Windows.Forms.MouseEventArgs e) { ! GenomeRepresentation genomeRepresentation = this.dgBestGenomes_MouseUp_getClickedGenomeRepresentation( sender , e ); ! dgBestGenomes_MouseUp_rightButton_updateDates( genomeRepresentation ); ! string[] signedTickers = genomeRepresentation.SignedTickers.Split(";".ToCharArray()); LinearCombinationTest linearCombinationTest = new LinearCombinationTest( this.dtpFirstDate.Value , ! this.dtpLastDate.Value , genomeRepresentation , this.selectedStrategyType, ! (PortfolioType)this.comboBoxPortfolioType.SelectedItem, Convert.ToInt32(this.textBoxDaysFPOscillatorAndRevOneRank.Text)); linearCombinationTest.Run(); ! this.lastSelectedGenomeRepresentation = genomeRepresentation; } --- 505,520 ---- private void dgBestGenomes_MouseUp_rightButton(object sender, System.Windows.Forms.MouseEventArgs e) { ! GenomeRepresentation[] genomeRepresentations = this.dgBestGenomes_MouseUp_getClickedGenomeRepresentation( sender , e ); ! dgBestGenomes_MouseUp_rightButton_updateDates( genomeRepresentations[0] ); ! //string[] signedTickers = genomeRepresentation.SignedTickers.Split(";".ToCharArray()); LinearCombinationTest linearCombinationTest = new LinearCombinationTest( this.dtpFirstDate.Value , ! this.dtpLastDate.Value , genomeRepresentations , this.selectedStrategyType, ! (PortfolioType)this.comboBoxPortfolioType.SelectedItem, Convert.ToInt32(this.textBoxDaysFPOscillatorAndRevOneRank.Text), ! Convert.ToDouble(this.textBoxStopLoss.Text),Convert.ToDouble(this.textBoxTakeProfit.Text) ); linearCombinationTest.Run(); ! this.lastSelectedGenomeRepresentations = genomeRepresentations; } *************** *** 433,440 **** // a grid row has been clicked, not the header { ! GenomeRepresentation newSelectedGenomeRepresentation = this.dgBestGenomes_MouseUp_getClickedGenomeRepresentation( sender , e ); ! this.lastSelectedGenomeRepresentation = newSelectedGenomeRepresentation; ! dgBestGenomes_MouseUp_leftButton_updateForm( newSelectedGenomeRepresentation ); } } --- 543,550 ---- // a grid row has been clicked, not the header { ! GenomeRepresentation[] newSelectedGenomeRepresentations = this.dgBestGenomes_MouseUp_getClickedGenomeRepresentation( sender , e ); ! this.lastSelectedGenomeRepresentations = newSelectedGenomeRepresentations; ! dgBestGenomes_MouseUp_leftButton_updateForm( newSelectedGenomeRepresentations[0] ); } } *************** *** 465,468 **** --- 575,584 ---- else if(this.radioButtonPVO.Checked) this.selectedStrategyType = StrategyType.PortfolioValueOscillator; + else if(this.radioButtonPVOBiased.Checked) + this.selectedStrategyType = StrategyType.PortfolioValueOscillatorBiased; + else if(this.radioButtonPVOBiasedNoThresholds.Checked) + this.selectedStrategyType = StrategyType.PortfolioValueOscillatorBiasedNoThresholds; + else if(this.radioButtonOTCPVOBiasedNoThresholds.Checked) + this.selectedStrategyType = StrategyType.OTC_PVOBiasedNoThresholds; } *************** *** 503,506 **** --- 619,645 ---- this.update_selectedStrategyType(); } + + private void radioButtonPVOBiased_CheckedChanged(object sender, System.EventArgs e) + { + this.update_selectedStrategyType(); + this.labelStopLoss.Visible = this.radioButtonPVOBiased.Checked; + this.textBoxStopLoss.Visible = this.radioButtonPVOBiased.Checked; + this.labelTakeProfit.Visible = this.radioButtonPVOBiased.Checked; + this.textBoxTakeProfit.Visible = this.radioButtonPVOBiased.Checked; + } + + private void radioButtonPVOBiasedNoThresholds_CheckedChanged(object sender, System.EventArgs e) + { + this.update_selectedStrategyType(); + this.labelStopLoss.Visible = this.radioButtonPVOBiasedNoThresholds.Checked; + this.textBoxStopLoss.Visible = this.radioButtonPVOBiasedNoThresholds.Checked; + this.labelTakeProfit.Visible = this.radioButtonPVOBiasedNoThresholds.Checked; + this.textBoxTakeProfit.Visible = this.radioButtonPVOBiasedNoThresholds.Checked; + } + + private void radioButtonOTCPVOBiasedNoThresholds_CheckedChanged(object sender, System.EventArgs e) + { + this.update_selectedStrategyType(); + } } |
|
From: Marco M. <mi...@us...> - 2007-02-27 22:57:24
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv9357/b4_Business/a2_Strategies Modified Files: SignedTicker.cs Log Message: Added GetLastNightPortfolioReturn method Index: SignedTicker.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/SignedTicker.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** SignedTicker.cs 17 Sep 2006 21:33:27 -0000 1.6 --- SignedTicker.cs 27 Feb 2007 22:57:20 -0000 1.7 *************** *** 261,264 **** --- 261,307 ---- } + private static double getLastNightPortfolioReturn(float[] tickersLastNightReturns, + double[] tickersWeights) + { + double returnValue = 0.0; + for(int i = 0; i<tickersLastNightReturns.Length; i++) + returnValue += tickersLastNightReturns[i]*(float)tickersWeights[i]; + + return returnValue; + } + + private static float getLastNightPortfolioReturn_getLastNightReturnForTicker(string ticker, + DateTime lastMarketDay, DateTime today) + { + Quotes tickerQuotes = new Quotes(ticker, lastMarketDay, today); + return ( (float)tickerQuotes.Rows[1]["quOpen"] * + (float)tickerQuotes.Rows[1]["quAdjustedClose"]/ + (float)tickerQuotes.Rows[1]["quClose"] ) / + (float)tickerQuotes.Rows[0]["quAdjustedClose"] - 1; + } + + + /// <summary> + /// Gets portfolio's last night return for the given tickers + /// </summary> + /// <param name="signedTickers">Array of signed tickers that compose the portfolio</param> + /// <param name="tickersWeights">Array of weights for tickers - the same order has to be provided!</param> + /// <param name="lastMarketDay">The last market date before today</param> + /// <param name="today">today</param> + public static double GetLastNightPortfolioReturn(string[] signedTickers, + double[] tickersWeights, + DateTime lastMarketDay, + DateTime today) + { + float[] tickersLastNightReturns = new float[signedTickers.Length]; + for(int i = 0; i<signedTickers.Length; i++) + { + tickersLastNightReturns[i] = + getLastNightPortfolioReturn_getLastNightReturnForTicker( + SignedTicker.GetTicker(signedTickers[i]), lastMarketDay, today ); + } + return getLastNightPortfolioReturn(tickersLastNightReturns, tickersWeights); + } + private static string[] getSignedTickersArray( ICollection signedTickers ) { |
|
From: Marco M. <mi...@us...> - 2007-02-27 22:54:48
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv7856/b7_Scripts/WalkForwardTesting/LinearCombination Added Files: FixedLevelOscillatorBiasedPVOStrategy.cs FixedLevelOscillatorBiasedPVONoThresholdsStrategy.cs FixedLevelOscBiasedOTC_PVONoThresholdsStrategy.cs Log Message: Added inherited classes for in sample testing --- NEW FILE: FixedLevelOscillatorBiasedPVOStrategy.cs --- /* QuantProject - Quantitative Finance Library FixedLevelOscillatorBiasedPVOStrategy.cs Copyright (C) 2007 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.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; using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.BiasedPVO; namespace QuantProject.Scripts.WalkForwardTesting.LinearCombination { /// <summary> /// Fixed Level Oscillators /// Biased Portfolio Value Oscillator strategy: /// from a group of optimized PVO portfolios, the strategy indicates /// to buy the portfolio that presents the highest degree /// of moving from a threshold /// </summary> [Serializable] public class FixedLevelOscillatorBiasedPVOStrategy : EndOfDayTimerHandlerBiasedPVO, IEndOfDayStrategy { public FixedLevelOscillatorBiasedPVOStrategy( Account accountPVO , string[,] tickers, double[,] tickersPortfolioWeights, double[] oversoldThreshold, double[] overboughtThreshold, int numOfDifferentGenomesToEvaluateOutOfSample, int numDaysForOscillatingPeriod, double maxAcceptableCloseToCloseDrawdown, double minimumAcceptableGain): base("", 0, tickers.GetUpperBound(1)+1, 0, accountPVO, 0, 0, "", numOfDifferentGenomesToEvaluateOutOfSample, numDaysForOscillatingPeriod,1,1,1,1,1,false,false,0, PortfolioType.ShortAndLong,maxAcceptableCloseToCloseDrawdown, minimumAcceptableGain) { this.chosenTickers = tickers; this.chosenTickersPortfolioWeights = tickersPortfolioWeights; this.currentOversoldThreshold = oversoldThreshold; this.currentOverboughtThreshold = overboughtThreshold; this.numDaysForOscillatingPeriod = numDaysForOscillatingPeriod; this.numOfDifferentGenomesToEvaluateOutOfSample = numOfDifferentGenomesToEvaluateOutOfSample; } public void FiveMinutesBeforeMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs) { } protected override double getCurrentChosenTickersGainOrLoss(IndexBasedEndOfDayTimer timer, int indexForChosenTickers) { double returnValue = 999.0; if(timer.CurrentDateArrayPosition + 2 >= this.numDaysForOscillatingPeriod) //if there are sufficient data for computing currentChosenTickersValue //that's why the method has been overriden { try { DateTime initialDate = (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition - this.numDaysForOscillatingPeriod + 2]["quDate"]; //so to replicate exactly in sample scheme, where only numOscillatingDay - 1 returns //are computed DateTime finalDate = (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition]["quDate"]; string[] tickers = new string[this.numberOfTickersToBeChosen]; double[] tickerWeights = new double[this.numberOfTickersToBeChosen]; for(int i = 0; i < this.numberOfTickersToBeChosen; i++) { tickers[i] = this.chosenTickers[indexForChosenTickers,i]; tickerWeights[i] = this.chosenTickersPortfolioWeights[indexForChosenTickers,i]; } returnValue = SignedTicker.GetCloseToClosePortfolioReturn( tickers, tickerWeights, initialDate,finalDate) + 1.0; } catch(MissingQuotesException ex) { ex = ex; } } return returnValue; } public override void OneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs) { } } } --- NEW FILE: FixedLevelOscBiasedOTC_PVONoThresholdsStrategy.cs --- /* QuantProject - Quantitative Finance Library FixedLevelOscBiasedOTC_PVONoThresholdsStrategy.cs Copyright (C) 2007 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.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; using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.BiasedPVO; using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.BiasedPVO.BiasedPVONoThresholds; using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.BiasedPVO.BiasedOTC_PVONoThresholds; namespace QuantProject.Scripts.WalkForwardTesting.LinearCombination { /// <summary> /// Fixed Level Oscillators /// Open To Close Portfolio Value Oscillator Biased strategy: /// from a group of non-moving OTC - CTO genomes, the strategy indicates /// to buy the portfolio that presents at open the highest gain or loss /// closing all positions at close /// </summary> [Serializable] public class FixedLevelOscBiasedOTC_PVONoThresholdsStrategy : EndOfDayTimerHandlerBiasedOTC_PVONoThresholds, IEndOfDayStrategy { public FixedLevelOscBiasedOTC_PVONoThresholdsStrategy( Account accountPVO , string[,] tickers, double[,] tickersPortfolioWeights, int numOfDifferentGenomesToEvaluateOutOfSample): base("", 0, tickers.GetUpperBound(1)+1, 0, accountPVO, 0, 0, "", numOfDifferentGenomesToEvaluateOutOfSample,0, PortfolioType.ShortAndLong) { this.chosenTickers = tickers; this.chosenTickersPortfolioWeights = tickersPortfolioWeights; } public override void MarketOpenEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if(this.account.Portfolio.Count == 0) this.marketOpenEventHandler_openPositions((IndexBasedEndOfDayTimer)sender); } public void FiveMinutesBeforeMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs) { } protected override double getCurrentChosenTickersGainOrLoss(IndexBasedEndOfDayTimer timer, int indexForChosenTickers) { double returnValue = 999.0; if(timer.CurrentDateArrayPosition >= 1) //if there are sufficient data for computing currentChosenTickersValue //that's why the method has been overriden { try { DateTime today = (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition]["quDate"]; DateTime lastMarketDay = (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition - 1]["quDate"]; string[] tickers = new string[this.numberOfTickersToBeChosen]; double[] tickerWeights = new double[this.numberOfTickersToBeChosen]; for(int i = 0; i < this.numberOfTickersToBeChosen; i++) { tickers[i] = this.chosenTickers[indexForChosenTickers,i]; tickerWeights[i] = this.chosenTickersPortfolioWeights[indexForChosenTickers,i]; } returnValue = SignedTicker.GetLastNightPortfolioReturn( tickers, tickerWeights, lastMarketDay, today); } catch(MissingQuotesException ex) { ex = ex; } } return returnValue; } public override void OneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs) { } } } --- NEW FILE: FixedLevelOscillatorBiasedPVONoThresholdsStrategy.cs --- /* QuantProject - Quantitative Finance Library FixedLevelOscillatorBiasedPVONoThresholdsStrategy.cs Copyright (C) 2007 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.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; using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.BiasedPVO; using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.BiasedPVO.BiasedPVONoThresholds; namespace QuantProject.Scripts.WalkForwardTesting.LinearCombination { /// <summary> /// Fixed Level Oscillators /// Biased Portfolio Value Oscillator strategy: /// from a group of optimized PVO portfolios, the strategy indicates /// to buy the portfolio that presents the highest degree /// of moving from a threshold /// </summary> [Serializable] public class FixedLevelOscillatorBiasedPVONoThresholdsStrategy : EndOfDayTimerHandlerBiasedPVONoThresholds, IEndOfDayStrategy { public FixedLevelOscillatorBiasedPVONoThresholdsStrategy( Account accountPVO , string[,] tickers, double[,] tickersPortfolioWeights, int numOfDifferentGenomesToEvaluateOutOfSample, double maxAcceptableCloseToCloseDrawdown, double minimumAcceptableGain): base("", 0, tickers.GetUpperBound(1)+1, 0, accountPVO, 0, 0, "", numOfDifferentGenomesToEvaluateOutOfSample,0, PortfolioType.ShortAndLong,maxAcceptableCloseToCloseDrawdown, minimumAcceptableGain) { this.chosenTickers = tickers; this.chosenTickersPortfolioWeights = tickersPortfolioWeights; } public void FiveMinutesBeforeMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs) { } protected override double getCurrentChosenTickersGainOrLoss(IndexBasedEndOfDayTimer timer, int indexForChosenTickers) { double returnValue = 999.0; if(timer.CurrentDateArrayPosition + 2 >= this.numDaysForOscillatingPeriod) //if there are sufficient data for computing currentChosenTickersValue //that's why the method has been overriden { try { DateTime date = (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition]["quDate"]; string[] tickers = new string[this.numberOfTickersToBeChosen]; double[] tickerWeights = new double[this.numberOfTickersToBeChosen]; for(int i = 0; i < this.numberOfTickersToBeChosen; i++) { tickers[i] = this.chosenTickers[indexForChosenTickers,i]; tickerWeights[i] = this.chosenTickersPortfolioWeights[indexForChosenTickers,i]; } returnValue = SignedTicker.GetCloseToClosePortfolioReturn( tickers, tickerWeights, date,date); } catch(MissingQuotesException ex) { ex = ex; } } return returnValue; } public override void OneHourAfterMarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs) { } } } |
|
From: Marco M. <mi...@us...> - 2007-02-27 22:52:47
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/BiasedPVO/BiasedOTC_PVONoThresholds In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv6633/BiasedPVO/BiasedOTC_PVONoThresholds Added Files: RunBiasedOTC_PVONoThresholds.cs GenomeManagerBiasedOTC_PVONoThresholds.cs EndOfDayTimerHandlerBiasedOTC_PVONoThresholds.cs Log Message: Added variations of Portfolio Value Oscillator strategy (some of these files have to be tested yet and will be re-written as soon as possible ...): - WeightedPVO: basic PVO (with thresholds); - weigthedBalancedPVO: the weighted PVO with 50% of portfolio invested in short positions and the remaining half in long ones; - biasedPVO: it is not simply chosen the genome with the highest fitness (as in the PVO base), but it is chosen the genome (from a given set of genomes with a good fitness) that has the highest degree of deviation from a threshold; - biasedPVO No Thresholds: as the biased, but the signal is just the highest gain or loss; - biasedOTC_PVONoThresholds: as the previous one, but with these differences: new positions are opened at market open, choosing the genome that opens with the highest gain or loss with respect to the last close All positions are closed at market close (at the moment ...tests are in progress ...) --- NEW FILE: RunBiasedOTC_PVONoThresholds.cs --- /* QuantProject - Quantitative Finance Library RunBiasedOTC_PVONoThresholds.cs Copyright (C) 2007 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; using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator; namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.BiasedPVO.BiasedOTC_PVONoThresholds { /// <summary> /// Script that implements the PVO strategy, /// with these differences: /// when it is time to open new positions (only at open), /// it is not simply chosen the genome with the highest fitness /// (as in the PVO base), but it is chosen the genome (from a /// given set of genomes with a good fitness) that /// has the highest gain or loss. All positions are closed /// at close /// </summary> [Serializable] public class RunBiasedOTC_PVONoThresholds : RunPVO { private int numOfDifferentGenomesToEvaluateOutOfSample; public RunBiasedOTC_PVONoThresholds(string tickerGroupID, int maxNumOfEligibleTickersForOptimization, int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, int generationNumberForGeneticOptimizer, int populationSizeForGeneticOptimizer, string benchmark, DateTime startDate, DateTime endDate, int numOfDifferentGenomesToEvaluateOutOfSample, int numDaysBetweenEachOptimization, PortfolioType inSamplePortfolioType, double maxRunningHours): base(tickerGroupID, maxNumOfEligibleTickersForOptimization, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, generationNumberForGeneticOptimizer, populationSizeForGeneticOptimizer, benchmark, startDate, endDate, 2, 0, 0, 0, 0, 1, true, false, numDaysBetweenEachOptimization, inSamplePortfolioType, 0.0, maxRunningHours) { this.numOfDifferentGenomesToEvaluateOutOfSample = numOfDifferentGenomesToEvaluateOutOfSample; this.scriptName = "OTC_PVO_PriceSel_NoWeightsAndThresholds"; } #region auxiliary overriden methods for Run protected override void run_initializeEndOfDayTimerHandler() { this.endOfDayTimerHandler = new EndOfDayTimerHandlerBiasedOTC_PVONoThresholds(this.tickerGroupID, this.numberOfEligibleTickers, this.numberOfTickersToBeChosen, this.numDaysForOptimizationPeriod, this.account, this.generationNumberForGeneticOptimizer, this.populationSizeForGeneticOptimizer, this.benchmark, this.numOfDifferentGenomesToEvaluateOutOfSample, this.numDaysBetweenEachOptimization, this.portfolioType); } public override void SaveScriptResults() { string fileName = DateTime.Now.Hour.ToString().PadLeft(2,'0') + "_" + DateTime.Now.Minute.ToString().PadLeft(2,'0') + "_" + this.scriptName + "GenOS_" + this.numOfDifferentGenomesToEvaluateOutOfSample + "_OsDays_" + numDaysForOscillatingPeriod + "_From_" + this.tickerGroupID + "_" + this.numberOfEligibleTickers + "_DaysForOpt" + this.numDaysForOptimizationPeriod + "Tick" + this.numberOfTickersToBeChosen + "GenN°" + this.generationNumberForGeneticOptimizer + "PopSize" + this.populationSizeForGeneticOptimizer + Convert.ToString(this.portfolioType); string dirNameWhereToSaveReports = System.Configuration.ConfigurationSettings.AppSettings["ReportsArchive"] + "\\" + this.ScriptName + "\\"; string dirNameWhereToSaveTransactions = System.Configuration.ConfigurationSettings.AppSettings["TransactionsArchive"] + "\\" + this.ScriptName + "\\"; string dirNameWhereToSaveBestGenomes = System.Configuration.ConfigurationSettings.AppSettings["GenomesArchive"] + "\\" + this.ScriptName + "\\"; this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveBestGenomes); OptimizationOutput optimizationOutput = new OptimizationOutput(); foreach(GenomeRepresentation genomeRepresentation in this.endOfDayTimerHandler.BestGenomes) optimizationOutput.Add(genomeRepresentation); ObjectArchiver.Archive(optimizationOutput, dirNameWhereToSaveBestGenomes + fileName + ".bgn"); //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.endOfDayTimer.Stop(); } #endregion } } --- NEW FILE: EndOfDayTimerHandlerBiasedOTC_PVONoThresholds.cs --- /* QuantProject - Quantitative Finance Library EndOfDayTimerHandlerBiasedOTC_PVONoThresholds.cs Copyright (C) 2007 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; using QuantProject.Scripts.WalkForwardTesting.LinearCombination; using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator; namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.BiasedPVO.BiasedOTC_PVONoThresholds { /// <summary> /// Implements MarketOpenEventHandler and MarketCloseEventHandler /// These handlers contain the core strategy for the Biased Portfolio Value /// Oscillator, with no thresholds and including quotes at open /// </summary> [Serializable] public class EndOfDayTimerHandlerBiasedOTC_PVONoThresholds : EndOfDayTimerHandlerPVO { protected int numOfDifferentGenomesToEvaluateOutOfSample; protected int currentGenomeIndex = 0; protected double currentTickersGainOrLoss = 0.0; protected Hashtable genomesCollector; new protected string[,] chosenTickers; new protected double[,] chosenTickersPortfolioWeights; public EndOfDayTimerHandlerBiasedOTC_PVONoThresholds(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, Account account, int generationNumberForGeneticOptimizer, int populationSizeForGeneticOptimizer, string benchmark, int numOfDifferentGenomesToEvaluateOutOfSample, int numDaysBetweenEachOptimization, PortfolioType portfolioType): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, account, generationNumberForGeneticOptimizer, populationSizeForGeneticOptimizer, benchmark, 2, 0, 0, 0, 0, 1, true, false, numDaysBetweenEachOptimization, portfolioType, 0.0) { this.numOfDifferentGenomesToEvaluateOutOfSample = numOfDifferentGenomesToEvaluateOutOfSample; this.chosenTickers = new string[numOfDifferentGenomesToEvaluateOutOfSample, numberOfTickersToBeChosen]; this.chosenTickersPortfolioWeights = new double[numOfDifferentGenomesToEvaluateOutOfSample, numberOfTickersToBeChosen]; this.genomesCollector = new Hashtable(); } protected virtual double getCurrentChosenTickersGainOrLoss(IndexBasedEndOfDayTimer timer, int indexForChosenTickers) { double returnValue = 999.0; try { DateTime today = (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition]["quDate"]; DateTime lastMarketDay = (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition - 1]["quDate"]; string[] tickers = new string[this.numberOfTickersToBeChosen]; double[] tickerWeights = new double[this.numberOfTickersToBeChosen]; for(int i = 0; i < this.numberOfTickersToBeChosen; i++) { tickers[i] = this.chosenTickers[indexForChosenTickers,i]; tickerWeights[i] = this.chosenTickersPortfolioWeights[indexForChosenTickers,i]; } returnValue = SignedTicker.GetLastNightPortfolioReturn( tickers, tickerWeights, lastMarketDay, today); } catch(MissingQuotesException ex) { ex = ex; } return returnValue; } //sets currentGenomeIndex with the genome's index that crosses an overbought/oversold threshold with the //highest degree and sets currentTickersGainOrLoss accordingly private void marketOpenEventHandler_openPositions_chooseBestGenome(IndexBasedEndOfDayTimer timer) { //default genome index is the first //genome (with the highest plain fitness), if no other genome //presents a gain or a loss greater than the first genome double currentTickersGainOrLoss = 0.0; double currentMaxAbsoluteMove = 0.0; double currentAbsoluteMove = 0.0; for(int i = 0; i < this.numOfDifferentGenomesToEvaluateOutOfSample; i++) { currentTickersGainOrLoss = this.getCurrentChosenTickersGainOrLoss(timer, i); currentAbsoluteMove = Math.Abs( currentTickersGainOrLoss ); if(currentAbsoluteMove != 999.0 && currentAbsoluteMove > currentMaxAbsoluteMove) //currentAbsoluteMove has been properly computed and it is //greater than the current greatest move up to date { currentMaxAbsoluteMove = currentAbsoluteMove; this.currentGenomeIndex = i; this.currentTickersGainOrLoss = currentTickersGainOrLoss; } } } protected void marketOpenEventHandler_openPositions(IndexBasedEndOfDayTimer timer) { this.currentTickersGainOrLoss = 999.0; this.marketOpenEventHandler_openPositions_chooseBestGenome(timer); if(this.currentTickersGainOrLoss != 999.0) //currentChosenTickersValue has been properly computed { string[] tickers = new string[this.numberOfTickersToBeChosen]; for(int i = 0; i < this.numberOfTickersToBeChosen; i++) tickers[i] = this.chosenTickers[this.currentGenomeIndex,i]; if(this.currentTickersGainOrLoss > 0.0) { SignedTicker.ChangeSignOfEachTicker(tickers); base.openPositions(tickers); } else //(currentChosenTickersGainOrLoss < 0.0) { base.openPositions(tickers); } } } public override void MarketOpenEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if(this.account.Portfolio.Count == 0 && this.genomesCollector.Count > 0) this.marketOpenEventHandler_openPositions((IndexBasedEndOfDayTimer)sender); } public override void MarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { base.closePositions(); this.orders.Clear(); } #region OneHourAfterMarketCloseEventHandler private void setTickers_updateTickersListAndAddGenomesForLog(GeneticOptimizer GO, int eligibleTickersForGO) { int addedGenomes = 0; int counter = 0; Genome currentGenome = null; this.genomesCollector.Clear(); while(addedGenomes < this.numOfDifferentGenomesToEvaluateOutOfSample && counter < GO.PopulationSize) { currentGenome = (Genome)GO.CurrentGeneration[GO.PopulationSize - 1 - counter]; if(counter == 0 || !this.genomesCollector.ContainsKey(currentGenome.Fitness) ) //it is the first genome to be added or no genome with the current // fitness has been added to the hashtable yet { for(int i = 0; i<this.numberOfTickersToBeChosen; i++) { this.chosenTickers[addedGenomes,i] = ((GenomeMeaningPVO)currentGenome.Meaning).Tickers[i]; this.chosenTickersPortfolioWeights[addedGenomes,i] = ((GenomeMeaningPVO)currentGenome.Meaning).TickersPortfolioWeights[i]; } this.genomesCollector.Add(currentGenome.Fitness, null); this.addPVOGenomeToBestGenomes(currentGenome,((GenomeManagerForEfficientPortfolio)this.iGenomeManager).FirstQuoteDate, ((GenomeManagerForEfficientPortfolio)this.iGenomeManager).LastQuoteDate, eligibleTickersForGO, 2, this.portfolioType, GO.GenerationCounter, 0.0, 0.0); addedGenomes ++ ; } counter ++ ; } } protected override void setTickers(DateTime currentDate, bool setGenomeCounter) { DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); this.iGenomeManager = new GenomeManagerBiasedOTC_PVONoThresholds(setOfTickersToBeOptimized, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, this.numberOfTickersToBeChosen, this.portfolioType); GeneticOptimizer GO = new GeneticOptimizer(this.iGenomeManager, this.populationSizeForGeneticOptimizer, this.generationNumberForGeneticOptimizer, this.seedForRandomGenerator); if(setGenomeCounter) this.genomeCounter = new GenomeCounter(GO); GO.MutationRate = 0.1; GO.Run(false); this.setTickers_updateTickersListAndAddGenomesForLog(GO, setOfTickersToBeOptimized.Rows.Count); } #endregion } } --- NEW FILE: GenomeManagerBiasedOTC_PVONoThresholds.cs --- /* QuantProject - Quantitative Finance Library GenomeManagerBiasedOTC_PVONoThresholds.cs Copyright (C) 2007 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Data; using System.Collections; using QuantProject.ADT; using QuantProject.ADT.Statistics; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Data; using QuantProject.Data.DataTables; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.BiasedPVO.BiasedOTC_PVONoThresholds { /// <summary> /// Implements what needed to use the Genetic Optimizer /// for finding the portfolio that best suites /// the Biased Portfolio Value Oscillator strategy, with no thresholds /// </summary> [Serializable] public class GenomeManagerBiasedOTC_PVONoThresholds : GenomeManagerForEfficientPortfolio { public GenomeManagerBiasedOTC_PVONoThresholds(DataTable setOfInitialTickers, DateTime firstQuoteDate, DateTime lastQuoteDate, int numberOfTickersInPortfolio, PortfolioType inSamplePortfolioType) : base(setOfInitialTickers, firstQuoteDate, lastQuoteDate, numberOfTickersInPortfolio, 0.0, inSamplePortfolioType) { this.retrieveData(); } #region Get Min and Max Value public override int GetMinValueForGenes(int genePosition) { int returnValue; switch (this.portfolioType) { case PortfolioType.OnlyLong : returnValue = 0; break; default://For ShortAndLong or OnlyShort portfolios returnValue = - this.originalNumOfTickers; break; } return returnValue; } public override int GetMaxValueForGenes(int genePosition) { int returnValue; switch (this.portfolioType) { case PortfolioType.OnlyShort : returnValue = - 1; break; default ://For ShortAndLong or OnlyLong portfolios returnValue = this.originalNumOfTickers - 1; break; } return returnValue; } #endregion protected override float[] getArrayOfRatesOfReturn(string ticker) { Quotes tickerQuotes = new Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); float[] returnValue = new float[2*tickerQuotes.Rows.Count - 1]; int j = 0; for(int i = 0;i<tickerQuotes.Rows.Count; i++) { //open to close returnValue[j] = (float)tickerQuotes.Rows[i]["quClose"]/ (float)tickerQuotes.Rows[i]["quOpen"] - 1; //close to open if(i<tickerQuotes.Rows.Count-1) { returnValue[j+1] = ( (float)tickerQuotes.Rows[i+1]["quOpen"]* (float)tickerQuotes.Rows[i+1]["quAdjustedClose"]/ (float)tickerQuotes.Rows[i+1]["quClose"] ) /(float)tickerQuotes.Rows[i]["quAdjustedClose"] - 1; } j += 2 ; } this.numberOfExaminedReturns = returnValue.Length; return returnValue; } //fitness is a number that indicates how much the portfolio //tends to preserve equity (no gain and no loss), with a low std dev public override double GetFitnessValue(Genome genome) { double returnValue = -1.0; this.portfolioRatesOfReturn = this.getPortfolioRatesOfReturn( genome.Genes() ); //double[] asbolutePortfolioRatesOfReturns = new double[this.portfolioRatesOfReturn.Length]; // for( int i = 0; i<asbolutePortfolioRatesOfReturns.Length; i++ ) // asbolutePortfolioRatesOfReturns[i] = Math.Abs(this.portfolioRatesOfReturn[i]); returnValue = 1.0/ //( BasicFunctions.SimpleAverage(asbolutePortfolioRatesOfReturns) * ( Math.Abs( BasicFunctions.SimpleAverage(this.portfolioRatesOfReturn)));//) * //BasicFunctions.StdDev(this.portfolioRatesOfReturn) ); //); return returnValue; } public override object Decode(Genome genome) { string[] arrayOfTickers = new string[genome.Genes().Length]; int indexOfTicker; for(int index = 0; index < genome.Genes().Length; index++) { indexOfTicker = (int)genome.Genes().GetValue(index); arrayOfTickers[index] = this.decode_getTickerCodeForLongOrShortTrade(indexOfTicker); } GenomeMeaningPVO meaning = new GenomeMeaningPVO(arrayOfTickers, 0.0, 0.0, 2); return meaning; } } } |
|
From: Marco M. <mi...@us...> - 2007-02-27 22:52:47
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/WeightedPVO/WeightedBalancedPVO In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv6633/WeightedPVO/WeightedBalancedPVO Added Files: RunWeightedBalancedPVO.cs GenomeManagerWeightedBalancedPVO.cs EndOfDayTimerHandlerWeightedBalancedPVO.cs Log Message: Added variations of Portfolio Value Oscillator strategy (some of these files have to be tested yet and will be re-written as soon as possible ...): - WeightedPVO: basic PVO (with thresholds); - weigthedBalancedPVO: the weighted PVO with 50% of portfolio invested in short positions and the remaining half in long ones; - biasedPVO: it is not simply chosen the genome with the highest fitness (as in the PVO base), but it is chosen the genome (from a given set of genomes with a good fitness) that has the highest degree of deviation from a threshold; - biasedPVO No Thresholds: as the biased, but the signal is just the highest gain or loss; - biasedOTC_PVONoThresholds: as the previous one, but with these differences: new positions are opened at market open, choosing the genome that opens with the highest gain or loss with respect to the last close All positions are closed at market close (at the moment ...tests are in progress ...) --- NEW FILE: EndOfDayTimerHandlerWeightedBalancedPVO.cs --- /* QuantProject - Quantitative Finance Library EndOfDayTimerHandlerWeightedBalancedPVO.cs Copyright (C) 2006 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; using QuantProject.Scripts.WalkForwardTesting.LinearCombination; using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator; namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.WeightedPVO.WeightedBalancedPVO { /// <summary> /// Implements MarketOpenEventHandler and MarketCloseEventHandler /// These handlers contain the core strategy for the Portfolio Value /// Oscillator using different weights for tickers, in such a way that /// portfolio is invested for the 50% in long positions, /// and the other 50% in short positions (also with an odd number /// of tickers in portfolio) /// </summary> [Serializable] public class EndOfDayTimerHandlerWeightedBalancedPVO : EndOfDayTimerHandlerPVO { public EndOfDayTimerHandlerWeightedBalancedPVO(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, Account account, int generationNumberForGeneticOptimizer, int populationSizeForGeneticOptimizer, string benchmark, int numDaysForOscillatingPeriod, int minLevelForOversoldThreshold, int maxLevelForOversoldThreshold, int minLevelForOverboughtThreshold, int maxLevelForOverboughtThreshold, int divisorForThresholdComputation, bool symmetricalThresholds, bool overboughtMoreThanOversoldForFixedPortfolio, int numDaysBetweenEachOptimization, PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, account, generationNumberForGeneticOptimizer, populationSizeForGeneticOptimizer, benchmark, numDaysForOscillatingPeriod, minLevelForOversoldThreshold, maxLevelForOversoldThreshold, minLevelForOverboughtThreshold, maxLevelForOverboughtThreshold, divisorForThresholdComputation, symmetricalThresholds, overboughtMoreThanOversoldForFixedPortfolio, numDaysBetweenEachOptimization, portfolioType, maxAcceptableCloseToCloseDrawdown) { } protected override 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.AddDays(-30), currentDate, numOfTickersInGroupAtCurrentDate, 20,500, 0.0001,100); SelectorByLiquidity mostLiquidSelector = new SelectorByLiquidity(byPrice.GetTableOfSelectedTickers(), false,currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, this.numberOfEligibleTickers); // SelectorByCloseToCloseCorrelationToBenchmark byCorrelationToBenchmark = // new SelectorByCloseToCloseCorrelationToBenchmark(mostLiquidSelector.GetTableOfSelectedTickers(), // "^GSPC",false, // currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, // this.numberOfEligibleTickers/2,false); // SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromLastSelection = new SelectorByQuotationAtEachMarketDay(mostLiquidSelector.GetTableOfSelectedTickers(), false, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, this.numberOfEligibleTickers, this.benchmark); return quotedAtEachMarketDayFromLastSelection.GetTableOfSelectedTickers(); } protected override 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 GenomeManagerWeightedBalancedPVO(setOfTickersToBeOptimized, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, this.numberOfTickersToBeChosen, this.numDaysForOscillatingPeriod, this.minLevelForOversoldThreshold, this.maxLevelForOversoldThreshold, this.minLevelForOverboughtThreshold, this.maxLevelForOverboughtThreshold, this.divisorForThresholdComputation, this.symmetricalThresholds, this.overboughtMoreThanOversoldForFixedPortfolio, this.portfolioType); GeneticOptimizer GO = new GeneticOptimizer(this.iGenomeManager, this.populationSizeForGeneticOptimizer, this.generationNumberForGeneticOptimizer, this.seedForRandomGenerator); if(setGenomeCounter) this.genomeCounter = new GenomeCounter(GO); GO.MutationRate = 0.2; GO.Run(false); this.chosenTickers = ((GenomeMeaningPVO)GO.BestGenome.Meaning).Tickers; this.chosenTickersPortfolioWeights = ((GenomeMeaningPVO)GO.BestGenome.Meaning).TickersPortfolioWeights; this.currentOversoldThreshold = ((GenomeMeaningPVO)GO.BestGenome.Meaning).OversoldThreshold; this.currentOverboughtThreshold = ((GenomeMeaningPVO)GO.BestGenome.Meaning).OverboughtThreshold; this.addPVOGenomeToBestGenomes(GO.BestGenome,((GenomeManagerForEfficientPortfolio)this.iGenomeManager).FirstQuoteDate, ((GenomeManagerForEfficientPortfolio)this.iGenomeManager).LastQuoteDate, setOfTickersToBeOptimized.Rows.Count, this.numDaysForOscillatingPeriod, this.portfolioType, GO.GenerationCounter, this.currentOversoldThreshold, this.currentOverboughtThreshold); } //else it will be buyed again the previous optimized portfolio //that's it the actual chosenTickers member } } } --- NEW FILE: RunWeightedBalancedPVO.cs --- /* QuantProject - Quantitative Finance Library RunWeightedBalancedPVO.cs Copyright (C) 2006 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.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.WeightedPVO.WeightedBalancedPVO { /// <summary> /// Script that implements an oscillating strategy using weights for tickers, /// based on the classical technical indicator /// RelativeStrengthIndex - RSI /// </summary> [Serializable] public class RunWeightedBalancedPVO : RunEfficientPortfolio { protected int minLevelForOversoldThreshold; protected int maxLevelForOversoldThreshold; protected int minLevelForOverboughtThreshold; protected int maxLevelForOverboughtThreshold; protected int divisorForThresholdComputation; //to be used by the optimizer protected int numDaysBetweenEachOptimization; protected double maxAcceptableCloseToCloseDrawdown; protected int numDaysForOscillatingPeriod; protected bool symmetricalThresholds = false; protected bool overboughtMoreThanOversoldForFixedPortfolio = false; public RunWeightedBalancedPVO(string tickerGroupID, int maxNumOfEligibleTickersForOptimization, int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, int generationNumberForGeneticOptimizer, int populationSizeForGeneticOptimizer, string benchmark, DateTime startDate, DateTime endDate, int numDaysForOscillatingPeriod, int minLevelForOversoldThreshold, int maxLevelForOversoldThreshold, int minLevelForOverboughtThreshold, int maxLevelForOverboughtThreshold, int divisorForThresholdComputation, bool symmetricalThresholds, bool overboughtMoreThanOversoldForFixedPortfolio, int numDaysBetweenEachOptimization, PortfolioType inSamplePortfolioType, double maxAcceptableCloseToCloseDrawdown, double maxRunningHours): base(tickerGroupID, maxNumOfEligibleTickersForOptimization, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, generationNumberForGeneticOptimizer, populationSizeForGeneticOptimizer, benchmark, startDate, endDate, 0.0, inSamplePortfolioType, maxRunningHours) { this.ScriptName = "PVO_SR_BalancedWeights_PriceSel"; this.minLevelForOversoldThreshold = minLevelForOversoldThreshold; this.maxLevelForOversoldThreshold = maxLevelForOversoldThreshold; this.minLevelForOverboughtThreshold = minLevelForOverboughtThreshold; this.maxLevelForOverboughtThreshold = maxLevelForOverboughtThreshold; this.divisorForThresholdComputation = divisorForThresholdComputation; this.symmetricalThresholds = symmetricalThresholds; this.overboughtMoreThanOversoldForFixedPortfolio = overboughtMoreThanOversoldForFixedPortfolio; this.maxAcceptableCloseToCloseDrawdown = maxAcceptableCloseToCloseDrawdown; this.numDaysForOscillatingPeriod = numDaysForOscillatingPeriod; this.numDaysBetweenEachOptimization = numDaysBetweenEachOptimization; } #region auxiliary overriden methods for Run protected override void run_initializeEndOfDayTimerHandler() { this.endOfDayTimerHandler = new EndOfDayTimerHandlerWeightedBalancedPVO(this.tickerGroupID, this.numberOfEligibleTickers, this.numberOfTickersToBeChosen, this.numDaysForOptimizationPeriod, this.account, this.generationNumberForGeneticOptimizer, this.populationSizeForGeneticOptimizer, this.benchmark, this.numDaysForOscillatingPeriod, this.minLevelForOversoldThreshold, this.maxLevelForOversoldThreshold, this.minLevelForOverboughtThreshold, this.maxLevelForOverboughtThreshold, this.divisorForThresholdComputation, this.symmetricalThresholds, this.overboughtMoreThanOversoldForFixedPortfolio, 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 = DateTime.Now.Hour.ToString().PadLeft(2,'0') + "_" + DateTime.Now.Minute.ToString().PadLeft(2,'0') + "_" + this.scriptName + "OsDays_" + numDaysForOscillatingPeriod + "_From_" + this.tickerGroupID + "_" + this.numberOfEligibleTickers + "_DaysForOpt" + this.numDaysForOptimizationPeriod + "Tick" + this.numberOfTickersToBeChosen + "GenN°" + this.generationNumberForGeneticOptimizer + "PopSize" + this.populationSizeForGeneticOptimizer + Convert.ToString(this.portfolioType); string dirNameWhereToSaveReports = System.Configuration.ConfigurationSettings.AppSettings["ReportsArchive"] + "\\" + this.ScriptName + "\\"; string dirNameWhereToSaveTransactions = System.Configuration.ConfigurationSettings.AppSettings["TransactionsArchive"] + "\\" + this.ScriptName + "\\"; string dirNameWhereToSaveBestGenomes = System.Configuration.ConfigurationSettings.AppSettings["GenomesArchive"] + "\\" + this.ScriptName + "\\"; this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveBestGenomes); OptimizationOutput optimizationOutput = new OptimizationOutput(); foreach(GenomeRepresentation genomeRepresentation in this.endOfDayTimerHandler.BestGenomes) optimizationOutput.Add(genomeRepresentation); ObjectArchiver.Archive(optimizationOutput, dirNameWhereToSaveBestGenomes + fileName + ".bgn"); //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.endOfDayTimer.Stop(); } #endregion } } --- NEW FILE: GenomeManagerWeightedBalancedPVO.cs --- /* QuantProject - Quantitative Finance Library GenomeManagerWeightedBalancedPVO.cs Copyright (C) 2006 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Data; using System.Collections; using QuantProject.ADT; using QuantProject.ADT.Statistics; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Data; using QuantProject.Data.DataTables; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.WeightedPVO; namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.WeightedPVO.WeightedBalancedPVO { /// <summary> /// Implements what needed to use the Genetic Optimizer /// for finding the portfolio that best suites /// the Portfolio Value Oscillator strategy (with weights /// that balance the portfolio between long and short positions) /// </summary> [Serializable] public class GenomeManagerWeightedBalancedPVO : GenomeManagerWeightedPVO { private bool arePrecedingTickersOnlyLong(Genome genome, int genePositionOfCurrentTicker) { bool returnValue = true; for(int i = 0; i<genePositionOfCurrentTicker ; i++) { if(this.genePositionPointsToATicker(i) && genome.GetGeneValue(i) < 0 ) // current i points to a short ticker returnValue = false; } return returnValue; } private bool arePrecedingTickersOnlyShort(Genome genome, int genePositionOfCurrentTicker) { bool returnValue = true; for(int i = 0; i<genePositionOfCurrentTicker ; i++) { if(this.genePositionPointsToATicker(i) && genome.GetGeneValue(i) >= 0 ) // current i points to a long ticker returnValue = false; } return returnValue; } public GenomeManagerWeightedBalancedPVO(DataTable setOfInitialTickers, DateTime firstQuoteDate, DateTime lastQuoteDate, int numberOfTickersInPortfolio, int numDaysForOscillatingPeriod, int minLevelForOversoldThreshold, int maxLevelForOversoldThreshold, int minLevelForOverboughtThreshold, int maxLevelForOverboughtThreshold, int divisorForThresholdComputation, bool symmetricalThresholds, bool overboughtMoreThanOversoldForFixedPortfolio, PortfolioType inSamplePortfolioType) : base(setOfInitialTickers, firstQuoteDate, lastQuoteDate, numberOfTickersInPortfolio, numDaysForOscillatingPeriod, minLevelForOversoldThreshold, maxLevelForOversoldThreshold, minLevelForOverboughtThreshold, maxLevelForOverboughtThreshold, divisorForThresholdComputation, symmetricalThresholds, overboughtMoreThanOversoldForFixedPortfolio, inSamplePortfolioType) { } private bool getTickerWeight_currentIndexPointsToATickerOfTheSameSign( int[]genes, int currentIndexOfTicker, int tickerPositionForComparison ) { //return true iif both point to long tickers or both point to short tickers return (genes[currentIndexOfTicker] >= 0 && genes[tickerPositionForComparison] >= 0) || (genes[currentIndexOfTicker] < 0 && genes[tickerPositionForComparison] < 0); } protected override double getTickerWeight(int[] genes, int tickerPositionInGenes) { double totalOfWeightsForTickersOfTheSameSign = 0.0; for(int j = this.numOfGenesDedicatedToThresholds; j < genes.Length; j++) { if( this.numOfGenesDedicatedToThresholds == 2 && j%2==0 && this.getTickerWeight_currentIndexPointsToATickerOfTheSameSign(genes,j+1,tickerPositionInGenes) ) //ticker weight is contained in genes at even position when //thresholds are asymmetrical and current Index Points To A Ticker Of The Same Sign //0 has to be avoided ! totalOfWeightsForTickersOfTheSameSign += Math.Abs(genes[j]) + 1.0; else if ( this.numOfGenesDedicatedToThresholds == 1 && j%2!=0 && this.getTickerWeight_currentIndexPointsToATickerOfTheSameSign(genes,j+1,tickerPositionInGenes) ) //ticker weight is contained in genes at odd position when //thresholds are symmetrical and current Index Points To A Ticker Of The Same Sign //0 has to be avoided ! totalOfWeightsForTickersOfTheSameSign += Math.Abs(genes[j]) + 1.0; } return ( Math.Abs(genes[tickerPositionInGenes-1]) + 1.0 ) / ( 2 * totalOfWeightsForTickersOfTheSameSign ); } private int getNewGeneValue_getGeneValue(Genome genome, int genePosition) { int returnValue; int minValueForGene = genome.GetMinValueForGenes(genePosition); int maxValueForGene = genome.GetMaxValueForGenes(genePosition); if ( this.numOfGenesDedicatedToThresholds == 2 && this.overboughtMoreThanOversoldForFixedPortfolio && genePosition == 1 ) //genePosition points to overbought threshold, //dipendent from the oversold one such that the portfolio tends to be fix returnValue = Convert.ToInt32(Convert.ToDouble(genome.GetGeneValue(0)) * Convert.ToDouble(this.divisorForThresholdComputation) / (Convert.ToDouble(this.divisorForThresholdComputation) - Convert.ToDouble(genome.GetGeneValue(0)))); else if( genePosition == genome.Size - 1 && this.arePrecedingTickersOnlyLong(genome, genePosition) ) //genePosition points to the last ticker and the preceding ones //point only to long tickers. In this case it has to be produced //a value pointing to a short ticker returnValue = GenomeManagement.RandomGenerator.Next(minValueForGene,0); else if( genePosition == genome.Size - 1 && this.arePrecedingTickersOnlyShort(genome, genePosition) ) //genePosition points to the last ticker and the preceding ones //point only to short tickers. In this case it has to be produced //a value pointing to a long ticker returnValue = GenomeManagement.RandomGenerator.Next(0,maxValueForGene + 1); else // genePosition doesn't point to the last ticker // or it points to the last ticker but the preceding tickers // are not of the same sign returnValue = GenomeManagement.RandomGenerator.Next(minValueForGene, maxValueForGene + 1); return returnValue; } public override int GetNewGeneValue(Genome genome, int genePosition) { // in this implementation only new gene values pointing to tickers // must be different from the others already stored int returnValue = this.getNewGeneValue_getGeneValue(genome,genePosition); while( this.genePositionPointsToATicker(genePosition) && GenomeManipulator.IsTickerContainedInGenome( returnValue, genome, this.GetGenePositionsPointingToTickers(genome) ) ) //while in the given position has to be stored //a new gene pointing to a ticker and //the proposed returnValue points to a ticker //already stored in the given genome, at the given genePositionsPointingToTickers returnValue = this.getNewGeneValue_getGeneValue(genome,genePosition); return returnValue; } } } |
|
From: Marco M. <mi...@us...> - 2007-02-27 22:52:47
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TechnicalAnalysisTesting/Oscillators/FixedLevelOscillators/PortfolioValueOscillator/BiasedPVO/BiasedPVONoThresholds In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv6633/BiasedPVO/BiasedPVONoThresholds Added Files: RunBiasedPVONoThresholds.cs GenomeManagerBiasedPVONoThresholds.cs EndOfDayTimerHandlerBiasedPVONoThresholds.cs Log Message: Added variations of Portfolio Value Oscillator strategy (some of these files have to be tested yet and will be re-written as soon as possible ...): - WeightedPVO: basic PVO (with thresholds); - weigthedBalancedPVO: the weighted PVO with 50% of portfolio invested in short positions and the remaining half in long ones; - biasedPVO: it is not simply chosen the genome with the highest fitness (as in the PVO base), but it is chosen the genome (from a given set of genomes with a good fitness) that has the highest degree of deviation from a threshold; - biasedPVO No Thresholds: as the biased, but the signal is just the highest gain or loss; - biasedOTC_PVONoThresholds: as the previous one, but with these differences: new positions are opened at market open, choosing the genome that opens with the highest gain or loss with respect to the last close All positions are closed at market close (at the moment ...tests are in progress ...) --- NEW FILE: RunBiasedPVONoThresholds.cs --- /* QuantProject - Quantitative Finance Library RunBiasedPVONoThresholds.cs Copyright (C) 2007 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; using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator; namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.BiasedPVO.BiasedPVONoThresholds { /// <summary> /// Script that implements the PVO strategy, /// with these differences: /// when it is time to open new positions, /// it is not simply chosen the genome with the highest fitness /// (as in the PVO base), but it is chosen the genome (from a /// given set of genomes with a good fitness) that /// has the highest gain or loss /// </summary> [Serializable] public class RunBiasedPVONoThresholds : RunPVO { private int numOfDifferentGenomesToEvaluateOutOfSample; private double minimumAcceptableGain; public RunBiasedPVONoThresholds(string tickerGroupID, int maxNumOfEligibleTickersForOptimization, int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, int generationNumberForGeneticOptimizer, int populationSizeForGeneticOptimizer, string benchmark, DateTime startDate, DateTime endDate, int numOfDifferentGenomesToEvaluateOutOfSample, int numDaysBetweenEachOptimization, PortfolioType inSamplePortfolioType, double maxAcceptableCloseToCloseDrawdown, double minimumAcceptableGain, double maxRunningHours): base(tickerGroupID, maxNumOfEligibleTickersForOptimization, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, generationNumberForGeneticOptimizer, populationSizeForGeneticOptimizer, benchmark, startDate, endDate, 2, 0, 0, 0, 0, 1, true, false, numDaysBetweenEachOptimization, inSamplePortfolioType, maxAcceptableCloseToCloseDrawdown, maxRunningHours) { this.numOfDifferentGenomesToEvaluateOutOfSample = numOfDifferentGenomesToEvaluateOutOfSample; this.minimumAcceptableGain = minimumAcceptableGain; this.scriptName = "PVO_PriceSel_NoWeightsAndThresholds"; } #region auxiliary overriden methods for Run protected override void run_initializeEndOfDayTimerHandler() { this.endOfDayTimerHandler = new EndOfDayTimerHandlerBiasedPVONoThresholds(this.tickerGroupID, this.numberOfEligibleTickers, this.numberOfTickersToBeChosen, this.numDaysForOptimizationPeriod, this.account, this.generationNumberForGeneticOptimizer, this.populationSizeForGeneticOptimizer, this.benchmark, this.numOfDifferentGenomesToEvaluateOutOfSample, this.numDaysBetweenEachOptimization, this.portfolioType, this.maxAcceptableCloseToCloseDrawdown, this.minimumAcceptableGain); } public override void SaveScriptResults() { string fileName = DateTime.Now.Hour.ToString().PadLeft(2,'0') + "_" + DateTime.Now.Minute.ToString().PadLeft(2,'0') + "_" + this.scriptName + "GenOS_" + this.numOfDifferentGenomesToEvaluateOutOfSample + "_OsDays_" + numDaysForOscillatingPeriod + "_From_" + this.tickerGroupID + "_" + this.numberOfEligibleTickers + "_DaysForOpt" + this.numDaysForOptimizationPeriod + "Tick" + this.numberOfTickersToBeChosen + "GenN°" + this.generationNumberForGeneticOptimizer + "PopSize" + this.populationSizeForGeneticOptimizer + Convert.ToString(this.portfolioType); string dirNameWhereToSaveReports = System.Configuration.ConfigurationSettings.AppSettings["ReportsArchive"] + "\\" + this.ScriptName + "\\"; string dirNameWhereToSaveTransactions = System.Configuration.ConfigurationSettings.AppSettings["TransactionsArchive"] + "\\" + this.ScriptName + "\\"; string dirNameWhereToSaveBestGenomes = System.Configuration.ConfigurationSettings.AppSettings["GenomesArchive"] + "\\" + this.ScriptName + "\\"; this.checkDateForReport_createDirIfNotPresent(dirNameWhereToSaveBestGenomes); OptimizationOutput optimizationOutput = new OptimizationOutput(); foreach(GenomeRepresentation genomeRepresentation in this.endOfDayTimerHandler.BestGenomes) optimizationOutput.Add(genomeRepresentation); ObjectArchiver.Archive(optimizationOutput, dirNameWhereToSaveBestGenomes + fileName + ".bgn"); //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.endOfDayTimer.Stop(); } #endregion } } --- NEW FILE: GenomeManagerBiasedPVONoThresholds.cs --- /* QuantProject - Quantitative Finance Library GenomeManagerBiasedPVONoThresholds.cs Copyright (C) 2007 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Data; using System.Collections; using QuantProject.ADT; using QuantProject.ADT.Statistics; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.Data; using QuantProject.Data.DataTables; using QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios; namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.BiasedPVO.BiasedPVONoThresholds { /// <summary> /// Implements what needed to use the Genetic Optimizer /// for finding the portfolio that best suites /// the Biased Portfolio Value Oscillator strategy, with no thresholds /// </summary> [Serializable] public class GenomeManagerBiasedPVONoThresholds : GenomeManagerForEfficientPortfolio { public GenomeManagerBiasedPVONoThresholds(DataTable setOfInitialTickers, DateTime firstQuoteDate, DateTime lastQuoteDate, int numberOfTickersInPortfolio, PortfolioType inSamplePortfolioType) : base(setOfInitialTickers, firstQuoteDate, lastQuoteDate, numberOfTickersInPortfolio, 0.0, inSamplePortfolioType) { this.retrieveData(); } #region Get Min and Max Value public override int GetMinValueForGenes(int genePosition) { int returnValue; switch (this.portfolioType) { case PortfolioType.OnlyLong : returnValue = 0; break; default://For ShortAndLong or OnlyShort portfolios returnValue = - this.originalNumOfTickers; break; } return returnValue; } public override int GetMaxValueForGenes(int genePosition) { int returnValue; switch (this.portfolioType) { case PortfolioType.OnlyShort : returnValue = - 1; break; default ://For ShortAndLong or OnlyLong portfolios returnValue = this.originalNumOfTickers - 1; break; } return returnValue; } #endregion protected override float[] getArrayOfRatesOfReturn(string ticker) { float[] returnValue = null; Quotes tickerQuotes = new Quotes(ticker, this.firstQuoteDate, this.lastQuoteDate); tickerQuotes.RecalculateCloseToCloseRatios(); returnValue = QuantProject.ADT.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 number that indicates how much the portfolio //tends to preserve equity (no gain and no loss), with a low std dev public override double GetFitnessValue(Genome genome) { double returnValue = -1.0; this.portfolioRatesOfReturn = this.getPortfolioRatesOfReturn( genome.Genes() ); //double[] asbolutePortfolioRatesOfReturns = new double[this.portfolioRatesOfReturn.Length]; // for( int i = 0; i<asbolutePortfolioRatesOfReturns.Length; i++ ) // asbolutePortfolioRatesOfReturns[i] = Math.Abs(this.portfolioRatesOfReturn[i]); returnValue = 1.0/ //( BasicFunctions.SimpleAverage(asbolutePortfolioRatesOfReturns) * ( Math.Abs( BasicFunctions.SimpleAverage(this.portfolioRatesOfReturn) ) * BasicFunctions.StdDev(this.portfolioRatesOfReturn) ); //); return returnValue; } public override object Decode(Genome genome) { string[] arrayOfTickers = new string[genome.Genes().Length]; int indexOfTicker; for(int index = 0; index < genome.Genes().Length; index++) { indexOfTicker = (int)genome.Genes().GetValue(index); arrayOfTickers[index] = this.decode_getTickerCodeForLongOrShortTrade(indexOfTicker); } GenomeMeaningPVO meaning = new GenomeMeaningPVO(arrayOfTickers, 0.0, 0.0, 2); return meaning; } } } --- NEW FILE: EndOfDayTimerHandlerBiasedPVONoThresholds.cs --- /* QuantProject - Quantitative Finance Library EndOfDayTimerHandlerBiasedPVONoThresholds.cs Copyright (C) 2007 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; using QuantProject.Scripts.WalkForwardTesting.LinearCombination; using QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator; namespace QuantProject.Scripts.TechnicalAnalysisTesting.Oscillators.FixedLevelOscillators.PortfolioValueOscillator.BiasedPVO.BiasedPVONoThresholds { /// <summary> /// Implements MarketOpenEventHandler and MarketCloseEventHandler /// These handlers contain the core strategy for the Biased Portfolio Value /// Oscillator, with no thresholds /// </summary> [Serializable] public class EndOfDayTimerHandlerBiasedPVONoThresholds : EndOfDayTimerHandlerPVO { protected int numOfDifferentGenomesToEvaluateOutOfSample; protected double minimumAcceptableGain; protected int currentGenomeIndex = 0; protected double currentTickersGainOrLoss = 0.0; protected Hashtable genomesCollector; protected bool takeProfitConditionReached; new protected string[,] chosenTickers; new protected double[,] chosenTickersPortfolioWeights; public EndOfDayTimerHandlerBiasedPVONoThresholds(string tickerGroupID, int numberOfEligibleTickers, int numberOfTickersToBeChosen, int numDaysForOptimizationPeriod, Account account, int generationNumberForGeneticOptimizer, int populationSizeForGeneticOptimizer, string benchmark, int numOfDifferentGenomesToEvaluateOutOfSample, int numDaysBetweenEachOptimization, PortfolioType portfolioType, double maxAcceptableCloseToCloseDrawdown, double minimumAcceptableGain): base(tickerGroupID, numberOfEligibleTickers, numberOfTickersToBeChosen, numDaysForOptimizationPeriod, account, generationNumberForGeneticOptimizer, populationSizeForGeneticOptimizer, benchmark, 2, 0, 0, 0, 0, 1, true, false, numDaysBetweenEachOptimization, portfolioType, maxAcceptableCloseToCloseDrawdown) { this.numOfDifferentGenomesToEvaluateOutOfSample = numOfDifferentGenomesToEvaluateOutOfSample; this.minimumAcceptableGain = minimumAcceptableGain; this.chosenTickers = new string[numOfDifferentGenomesToEvaluateOutOfSample, numberOfTickersToBeChosen]; this.chosenTickersPortfolioWeights = new double[numOfDifferentGenomesToEvaluateOutOfSample, numberOfTickersToBeChosen]; this.genomesCollector = new Hashtable(); } #region MarketCloseEventHandler protected virtual double getCurrentChosenTickersGainOrLoss(IndexBasedEndOfDayTimer timer, int indexForChosenTickers) { double returnValue = 999.0; try { DateTime date = (DateTime)timer.IndexQuotes.Rows[timer.CurrentDateArrayPosition]["quDate"]; string[] tickers = new string[this.numberOfTickersToBeChosen]; double[] tickerWeights = new double[this.numberOfTickersToBeChosen]; for(int i = 0; i < this.numberOfTickersToBeChosen; i++) { tickers[i] = this.chosenTickers[indexForChosenTickers,i]; tickerWeights[i] = this.chosenTickersPortfolioWeights[indexForChosenTickers,i]; } returnValue = SignedTicker.GetCloseToClosePortfolioReturn( tickers, tickerWeights, date,date); } catch(MissingQuotesException ex) { ex = ex; } return returnValue; } //sets currentGenomeIndex with the genome's index that crosses an overbought/oversold threshold with the //highest degree and sets currentTickersGainOrLoss accordingly private void marketCloseEventHandler_openPositions_chooseBestGenome(IndexBasedEndOfDayTimer timer) { //default genome index is the first //genome (with the highest plain fitness), if no other genome //presents a gain or a loss greater than the first genome double currentTickersGainOrLoss = 0.0; double currentMaxAbsoluteMove = 0.0; double currentAbsoluteMove = 0.0; for(int i = 0; i < this.numOfDifferentGenomesToEvaluateOutOfSample; i++) { currentTickersGainOrLoss = this.getCurrentChosenTickersGainOrLoss(timer, i); currentAbsoluteMove = Math.Abs( currentTickersGainOrLoss ); if(currentAbsoluteMove != 999.0 && currentAbsoluteMove > currentMaxAbsoluteMove) //currentAbsoluteMove has been properly computed and it is //greater than the current greatest move up to date { currentMaxAbsoluteMove = currentAbsoluteMove; this.currentGenomeIndex = i; this.currentTickersGainOrLoss = currentTickersGainOrLoss; } } } private void marketCloseEventHandler_openPositions(IndexBasedEndOfDayTimer timer) { this.currentTickersGainOrLoss = 999.0; this.marketCloseEventHandler_openPositions_chooseBestGenome(timer); if(this.currentTickersGainOrLoss != 999.0) //currentChosenTickersValue has been properly computed { string[] tickers = new string[this.numberOfTickersToBeChosen]; for(int i = 0; i < this.numberOfTickersToBeChosen; i++) tickers[i] = this.chosenTickers[this.currentGenomeIndex,i]; if(this.currentTickersGainOrLoss > 0.0) { SignedTicker.ChangeSignOfEachTicker(tickers); base.openPositions(tickers); } else //(currentChosenTickersGainOrLoss < 0.0) { base.openPositions(tickers); } this.currentAccountValue = this.account.GetMarketValue(); } } private void marketCloseEventHandler_closeIfItIsTimeToClose_updateStopLossAndTakeProfitConditions() { this.previousAccountValue = this.currentAccountValue; this.currentAccountValue = this.account.GetMarketValue(); double portfolioGainOrLoss = (this.currentAccountValue - this.previousAccountValue) /this.previousAccountValue; if( portfolioGainOrLoss < -this.maxAcceptableCloseToCloseDrawdown ) { this.stopLossConditionReached = true; this.takeProfitConditionReached = false; } else if (portfolioGainOrLoss >= this.minimumAcceptableGain) { this.stopLossConditionReached = false; this.takeProfitConditionReached = true; } else { this.stopLossConditionReached = false; this.takeProfitConditionReached = false; } } private void marketCloseEventHandler_closeIfItIsTimeToClose() { this.marketCloseEventHandler_closeIfItIsTimeToClose_updateStopLossAndTakeProfitConditions(); if(this.stopLossConditionReached || this.takeProfitConditionReached || this.numDaysElapsedSinceLastOptimization + 1 == this.numDaysBetweenEachOptimization ) //reversal conditions have not been reached but //stop loss or take profit conditions yes //or after the close it is necessary to run //another optimization { base.closePositions(); this.orders.Clear(); } } public override void MarketCloseEventHandler( Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { if(this.account.Portfolio.Count > 0) //this.marketCloseEventHandler_reverseOrClose((IndexBasedEndOfDayTimer)sender); this.marketCloseEventHandler_closeIfItIsTimeToClose(); else if ( this.account.Portfolio.Count == 0 && this.chosenTickers[0,0] != null ) //portfolio is empty and optimization has been already launched this.marketCloseEventHandler_openPositions((IndexBasedEndOfDayTimer)sender); } #endregion #region OneHourAfterMarketCloseEventHandler private void setTickers_updateTickersListAndAddGenomesForLog(GeneticOptimizer GO, int eligibleTickersForGO) { int addedGenomes = 0; int counter = 0; Genome currentGenome = null; this.genomesCollector.Clear(); while(addedGenomes < this.numOfDifferentGenomesToEvaluateOutOfSample && counter < GO.PopulationSize) { currentGenome = (Genome)GO.CurrentGeneration[GO.PopulationSize - 1 - counter]; if(counter == 0 || !this.genomesCollector.ContainsKey(currentGenome.Fitness) ) //it is the first genome to be added or no genome with the current // fitness has been added to the hashtable yet { for(int i = 0; i<this.numberOfTickersToBeChosen; i++) { this.chosenTickers[addedGenomes,i] = ((GenomeMeaningPVO)currentGenome.Meaning).Tickers[i]; this.chosenTickersPortfolioWeights[addedGenomes,i] = ((GenomeMeaningPVO)currentGenome.Meaning).TickersPortfolioWeights[i]; } this.genomesCollector.Add(currentGenome.Fitness, null); this.addPVOGenomeToBestGenomes(currentGenome,((GenomeManagerForEfficientPortfolio)this.iGenomeManager).FirstQuoteDate, ((GenomeManagerForEfficientPortfolio)this.iGenomeManager).LastQuoteDate, eligibleTickersForGO, 2, this.portfolioType, GO.GenerationCounter, 0.0, 0.0); addedGenomes ++ ; } counter ++ ; } } protected override void setTickers(DateTime currentDate, bool setGenomeCounter) { DataTable setOfTickersToBeOptimized = this.getSetOfTickersToBeOptimized(currentDate); this.iGenomeManager = new GenomeManagerBiasedPVONoThresholds(setOfTickersToBeOptimized, currentDate.AddDays(-this.numDaysForOptimizationPeriod), currentDate, this.numberOfTickersToBeChosen, this.portfolioType); GeneticOptimizer GO = new GeneticOptimizer(this.iGenomeManager, this.populationSizeForGeneticOptimizer, this.generationNumberForGeneticOptimizer, this.seedForRandomGenerator); if(setGenomeCounter) this.genomeCounter = new GenomeCounter(GO); GO.MutationRate = 0.1; GO.Run(false); this.setTickers_updateTickersListAndAddGenomesForLog(GO, setOfTickersToBeOptimized.Rows.Count); } #endregion } } |