[Quantproject-developers] QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination FixedLevelO
Brought to you by:
glauco_1
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv17302/LinearCombination Modified Files: FixedLevelOscillatorBiasedPVOStrategy.cs FixedLevelOscillatorPVOStrategy.cs FixedPeriodOscillatorStrategy.cs Log Message: The new revision moves toward an intraday enabled framework. EndOfDayDate time has been removed, DateTime is used now. The code has been changed accordingly. Index: FixedPeriodOscillatorStrategy.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/FixedPeriodOscillatorStrategy.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** FixedPeriodOscillatorStrategy.cs 29 Aug 2007 09:43:36 -0000 1.3 --- FixedPeriodOscillatorStrategy.cs 29 Sep 2008 21:19:09 -0000 1.4 *************** *** 3,7 **** FixedPeriodOscillatorStrategy.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- FixedPeriodOscillatorStrategy.cs ! Copyright (C) 2003 Marco Milletti *************** *** 19,23 **** 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; --- 19,23 ---- 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; *************** *** 37,134 **** /// </summary> [Serializable] ! public class FixedPeriodOscillatorStrategy : EndOfDayTimerHandler, IEndOfDayStrategy { private int daysForRightPeriod; ! private int daysForReversalPeriod; ! //length for movement upwards or downwards of the given tickers ! private int daysCounterWithRightPositions; ! private int daysCounterWithReversalPositions; ! private bool isReversalPeriodOn = false; ! private int numOfClosesElapsed = 0; ! public FixedPeriodOscillatorStrategy( Account account , ! WeightedPositions weightedPositions, ! int daysForRightPeriod, ! int daysForReversalPeriod): ! base("", 0, ! weightedPositions.Count, 0, account, ! 0, ! 0, ! "^GSPC", 0.0, ! PortfolioType.ShortAndLong) { this.account = account; this.chosenWeightedPositions = weightedPositions; ! this.daysForRightPeriod = daysForRightPeriod; ! this.daysForReversalPeriod = daysForReversalPeriod; } ! ! public override void MarketOpenEventHandler( ! Object sender , EndOfDayTimingEventArgs endOfDayTimingEventArgs ) { ! } - - private void marketCloseEventHandler_updateCounters(bool isTheFirstClose) - { - if(this.account.Portfolio.Count > 0 && isTheFirstClose == false) - { - if(this.isReversalPeriodOn) - this.daysCounterWithReversalPositions++ ; - else - this.daysCounterWithRightPositions++ ; - } - } ! public override void MarketCloseEventHandler( Object sender , ! EndOfDayTimingEventArgs endOfDayTimingEventArgs) { ! bool firstClose = false; ! if( (this.numOfClosesElapsed + 1) >= ! (this.daysForRightPeriod + this.daysForReversalPeriod) ) ! //strategy can now be applied because it is tuned with the optimization's results ! { ! if (this.account.Transactions.Count == 0) ! // it is the first close ! { ! firstClose = true; ! this.openPositions(); ! } ! this.marketCloseEventHandler_updateCounters(firstClose); ! if(firstClose == false && this.isReversalPeriodOn == false && ! this.daysCounterWithRightPositions == this.daysForRightPeriod) ! ! { ! AccountManager.ReversePositions(this.account); ! this.isReversalPeriodOn = true; ! } ! ! if(this.isReversalPeriodOn == true && ! this.daysCounterWithReversalPositions == this.daysForReversalPeriod) ! ! { ! AccountManager.ReversePositions(this.account); ! this.isReversalPeriodOn = false; ! } ! } ! ! this.numOfClosesElapsed++; } ! public override void OneHourAfterMarketCloseEventHandler( Object sender , ! EndOfDayTimingEventArgs endOfDayTimingEventArgs) { ! } ! ! public void FiveMinutesBeforeMarketCloseEventHandler( Object sender , ! EndOfDayTimingEventArgs endOfDayTimingEventArgs) { ! } } } --- 37,148 ---- /// </summary> [Serializable] ! public class FixedPeriodOscillatorStrategy : ! QuantProject.Scripts.TickerSelectionTesting.EfficientPortfolios.EndOfDayTimerHandler , ! IStrategy { private int daysForRightPeriod; ! private int daysForReversalPeriod; ! //length for movement upwards or downwards of the given tickers ! private int daysCounterWithRightPositions; ! private int daysCounterWithReversalPositions; ! private bool isReversalPeriodOn = false; ! private int numOfClosesElapsed = 0; ! public FixedPeriodOscillatorStrategy( Account account , ! WeightedPositions weightedPositions, ! int daysForRightPeriod, ! int daysForReversalPeriod): ! base("", 0, ! weightedPositions.Count, 0, account, ! 0, ! 0, ! "^GSPC", 0.0, ! PortfolioType.ShortAndLong) { this.account = account; this.chosenWeightedPositions = weightedPositions; ! this.daysForRightPeriod = daysForRightPeriod; ! this.daysForReversalPeriod = daysForReversalPeriod; } ! ! protected override void marketOpenEventHandler( ! Object sender , DateTime dateTime ) { ! ! } ! ! private void marketCloseEventHandler_updateCounters(bool isTheFirstClose) ! { ! if(this.account.Portfolio.Count > 0 && isTheFirstClose == false) ! { ! if(this.isReversalPeriodOn) ! this.daysCounterWithReversalPositions++ ; ! else ! this.daysCounterWithRightPositions++ ; ! } } ! protected override void marketCloseEventHandler( ! Object sender , DateTime dateTime) { ! bool firstClose = false; ! if( (this.numOfClosesElapsed + 1) >= ! (this.daysForRightPeriod + this.daysForReversalPeriod) ) ! //strategy can now be applied because it is tuned with the optimization's results ! { ! if (this.account.Transactions.Count == 0) ! // it is the first close ! { ! firstClose = true; ! this.openPositions(); ! } ! this.marketCloseEventHandler_updateCounters(firstClose); ! if(firstClose == false && this.isReversalPeriodOn == false && ! this.daysCounterWithRightPositions == this.daysForRightPeriod) ! ! { ! AccountManager.ReversePositions(this.account); ! this.isReversalPeriodOn = true; ! } ! ! if(this.isReversalPeriodOn == true && ! this.daysCounterWithReversalPositions == this.daysForReversalPeriod) ! ! { ! AccountManager.ReversePositions(this.account); ! this.isReversalPeriodOn = false; ! } ! } ! ! this.numOfClosesElapsed++; } ! protected override void oneHourAfterMarketCloseEventHandler( Object sender , ! DateTime dateTime) { ! } ! ! public void FiveMinutesBeforeMarketCloseEventHandler( Object sender , ! DateTime dateTime) { ! ! } ! ! public virtual void NewTimeEventHandler( ! Object sender , DateTime dateTime ) ! { ! if ( HistoricalEndOfDayTimer.IsMarketOpen( dateTime ) ) ! this.marketOpenEventHandler( sender , dateTime ); ! if ( HistoricalEndOfDayTimer.IsMarketClose( dateTime ) ) ! this.marketCloseEventHandler( sender , dateTime ); ! if ( HistoricalEndOfDayTimer.IsOneHourAfterMarketClose( dateTime ) ) ! this.oneHourAfterMarketCloseEventHandler( sender , dateTime ); } + } } Index: FixedLevelOscillatorBiasedPVOStrategy.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/FixedLevelOscillatorBiasedPVOStrategy.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** FixedLevelOscillatorBiasedPVOStrategy.cs 19 Aug 2008 17:11:29 -0000 1.6 --- FixedLevelOscillatorBiasedPVOStrategy.cs 29 Sep 2008 21:19:08 -0000 1.7 *************** *** 43,47 **** /// </summary> [Serializable] ! public class FixedLevelOscillatorBiasedPVOStrategy : EndOfDayTimerHandlerBiasedPVO, IEndOfDayStrategy { --- 43,48 ---- /// </summary> [Serializable] ! public class FixedLevelOscillatorBiasedPVOStrategy : ! EndOfDayTimerHandlerBiasedPVO, IStrategy { *************** *** 74,79 **** } ! public void FiveMinutesBeforeMarketCloseEventHandler( Object sender , ! EndOfDayTimingEventArgs endOfDayTimingEventArgs) { } --- 75,80 ---- } ! protected void fiveMinutesBeforeMarketCloseEventHandler( ! Object sender , DateTime dateTime) { } *************** *** 107,112 **** } ! public override void OneHourAfterMarketCloseEventHandler( Object sender , ! EndOfDayTimingEventArgs endOfDayTimingEventArgs) { --- 108,113 ---- } ! protected override void oneHourAfterMarketCloseEventHandler( ! Object sender , DateTime dateTime) { Index: FixedLevelOscillatorPVOStrategy.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/LinearCombination/FixedLevelOscillatorPVOStrategy.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** FixedLevelOscillatorPVOStrategy.cs 12 Mar 2008 22:09:04 -0000 1.8 --- FixedLevelOscillatorPVOStrategy.cs 29 Sep 2008 21:19:08 -0000 1.9 *************** *** 3,7 **** FixedLevelOscillatorPVOStrategy.cs ! Copyright (C) 2003 Marco Milletti --- 3,7 ---- FixedLevelOscillatorPVOStrategy.cs ! Copyright (C) 2003 Marco Milletti *************** *** 19,23 **** 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; --- 19,23 ---- 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; *************** *** 35,84 **** { /// <summary> ! /// Fixed Level Oscillators /// Portfolio Value Oscillator strategy /// </summary> [Serializable] ! public class FixedLevelOscillatorPVOStrategy : EndOfDayTimerHandlerPVO, IEndOfDayStrategy { ! public FixedLevelOscillatorPVOStrategy( Account accountPVO , ! WeightedPositions chosenWeightedPositions, ! double oversoldThreshold, ! double overboughtThreshold, ! int numDaysForOscillatingPeriod): ! base("", 0, chosenWeightedPositions.Count, 0, ! accountPVO, ! 0,0, ! "^GSPC", ! 0, 0, 0, 0, 0, 0, false, false, 0, ! PortfolioType.ShortAndLong, 0.5, 0.5) { this.chosenWeightedPositions = chosenWeightedPositions; ! this.currentOversoldThreshold = oversoldThreshold; ! this.currentOverboughtThreshold = overboughtThreshold; ! this.numDaysForOscillatingPeriod = numDaysForOscillatingPeriod; } ! public void FiveMinutesBeforeMarketCloseEventHandler( Object sender , ! EndOfDayTimingEventArgs endOfDayTimingEventArgs) ! { ! } ! protected override double getCurrentChosenWeightedPositionsReturn(IndexBasedEndOfDayTimer timer) ! { ! double returnValue = 999.0; ! if(timer.CurrentDateArrayPosition - this.numDaysForOscillatingPeriod >= 0) ! //if there are sufficient data for computing currentChosenWeightedPositionsReturn ! //that's why the method has been overriden ! returnValue = ! base.getCurrentChosenWeightedPositionsReturn(timer); ! ! return returnValue; ! } ! public override void OneHourAfterMarketCloseEventHandler( Object sender , ! EndOfDayTimingEventArgs endOfDayTimingEventArgs) { ! } } --- 35,84 ---- { /// <summary> ! /// Fixed Level Oscillators /// Portfolio Value Oscillator strategy /// </summary> [Serializable] ! public class FixedLevelOscillatorPVOStrategy : EndOfDayTimerHandlerPVO, IStrategy { ! public FixedLevelOscillatorPVOStrategy( Account accountPVO , ! WeightedPositions chosenWeightedPositions, ! double oversoldThreshold, ! double overboughtThreshold, ! int numDaysForOscillatingPeriod): ! base("", 0, chosenWeightedPositions.Count, 0, ! accountPVO, ! 0,0, ! "^GSPC", ! 0, 0, 0, 0, 0, 0, false, false, 0, ! PortfolioType.ShortAndLong, 0.5, 0.5) { this.chosenWeightedPositions = chosenWeightedPositions; ! this.currentOversoldThreshold = oversoldThreshold; ! this.currentOverboughtThreshold = overboughtThreshold; ! this.numDaysForOscillatingPeriod = numDaysForOscillatingPeriod; } ! public void FiveMinutesBeforeMarketCloseEventHandler( Object sender , ! DateTime dateTime) ! { ! } ! protected override double getCurrentChosenWeightedPositionsReturn(IndexBasedEndOfDayTimer timer) ! { ! double returnValue = 999.0; ! if(timer.CurrentDateArrayPosition - this.numDaysForOscillatingPeriod >= 0) ! //if there are sufficient data for computing currentChosenWeightedPositionsReturn ! //that's why the method has been overriden ! returnValue = ! base.getCurrentChosenWeightedPositionsReturn(timer); ! ! return returnValue; ! } ! protected override void oneHourAfterMarketCloseEventHandler( Object sender , ! DateTime dateTime) { ! } } |