quantproject-developers Mailing List for QuantProject (Page 84)
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: Glauco S. <gla...@us...> - 2006-07-30 13:40:00
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv8338/b7_Scripts/WalkForwardTesting/WalkForwardLag Modified Files: WFLagEndOfDayTimerHandler.cs Log Message: WeightedPositions are used instead of SignedTickers Index: WFLagEndOfDayTimerHandler.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagEndOfDayTimerHandler.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** WFLagEndOfDayTimerHandler.cs 18 Jun 2006 14:13:30 -0000 1.4 --- WFLagEndOfDayTimerHandler.cs 30 Jul 2006 13:39:56 -0000 1.5 *************** *** 29,32 **** --- 29,33 ---- using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Financial.Instruments; + using QuantProject.Business.Strategies; using QuantProject.Business.Timing; using QuantProject.Scripts.SimpleTesting; *************** *** 61,64 **** --- 62,66 ---- private DateTime lastOptimizationDate; + private bool arePositionsUpToDateWithChosenTickers; public event InSampleNewProgressEventHandler InSampleNewProgress; *************** *** 120,141 **** } #region fiveMinutesBeforeMarketCloseEventHandler_openPositions ! private string getTicker( string signedTicker ) ! { ! string returnValue; ! if ( signedTicker.IndexOf( "-" ) == 0 ) ! returnValue = signedTicker.Substring( 1 , signedTicker.Length - 1 ); ! else ! returnValue = signedTicker; ! return returnValue; ! } ! private int getReturnMultiplier( string signedTicker ) ! { ! int returnValue; ! if ( signedTicker.IndexOf( "-" ) == 0 ) ! returnValue = -1; ! else ! returnValue = 1; ! return returnValue; ! } private double getTodayReturnForTicker( string ticker ) { --- 122,143 ---- } #region fiveMinutesBeforeMarketCloseEventHandler_openPositions ! // private string getTicker( string signedTicker ) ! // { ! // string returnValue; ! // if ( signedTicker.IndexOf( "-" ) == 0 ) ! // returnValue = signedTicker.Substring( 1 , signedTicker.Length - 1 ); ! // else ! // returnValue = signedTicker; ! // return returnValue; ! // } ! // private int getReturnMultiplier( string signedTicker ) ! // { ! // int returnValue; ! // if ( signedTicker.IndexOf( "-" ) == 0 ) ! // returnValue = -1; ! // else ! // returnValue = 1; ! // return returnValue; ! // } private double getTodayReturnForTicker( string ticker ) { *************** *** 154,162 **** return returnValue; } ! private double getTodayReturnForSignedTicker( string signedTicker ) { double todayReturnForTicker = this.getTodayReturnForTicker( ! WFLagGenomeManager.GetTicker( signedTicker ) ); ! int returnMultiplier = this.getReturnMultiplier( signedTicker ); return todayReturnForTicker * returnMultiplier; } --- 156,165 ---- return returnValue; } ! private double getTodayReturn( ! WeightedPosition weightedPosition ) { double todayReturnForTicker = this.getTodayReturnForTicker( ! weightedPosition.Ticker ); ! double returnMultiplier = weightedPosition.Weight; return todayReturnForTicker * returnMultiplier; } *************** *** 168,196 **** { double totalReturn = 0; ! foreach ( string signedTicker in this.chosenTickers.DrivingPositions.Keys ) ! totalReturn += this.getTodayReturnForSignedTicker( signedTicker ); return totalReturn < 0; } private OrderType fiveMinutesBeforeMarketCloseEventHandler_openPosition_getOrderType( ! string signedTicker , bool isToReverse ) { OrderType orderType = OrderType.MarketBuy; ! if ( ( signedTicker.StartsWith( "-" ) && !isToReverse ) || ! ( !signedTicker.StartsWith( "-" ) && isToReverse ) ) orderType = OrderType.MarketSellShort; return orderType; } private void fiveMinutesBeforeMarketCloseEventHandler_openPosition( ! string signedTicker , bool isToReverse ) { ! string ticker = this.getTicker( signedTicker ); OrderType orderType = this.fiveMinutesBeforeMarketCloseEventHandler_openPosition_getOrderType( ! signedTicker , isToReverse ); double maxPositionValue = this.account.GetMarketValue() / this.numberOfPositionsToBeChosen; ! long sharesToBeTraded = OneRank.MaxBuyableShares( ticker , ! maxPositionValue , this.account.DataStreamer ); this.account.AddOrder( new Order( orderType , new Instrument( ticker ) , sharesToBeTraded ) ); --- 171,207 ---- { double totalReturn = 0; ! foreach ( WeightedPosition weightedPosition in ! this.chosenTickers.DrivingWeightedPositions.Values ) ! totalReturn += this.getTodayReturn( weightedPosition ); return totalReturn < 0; } private OrderType fiveMinutesBeforeMarketCloseEventHandler_openPosition_getOrderType( ! WeightedPosition weightedPosition , bool isToReverse ) { OrderType orderType = OrderType.MarketBuy; ! if ( ( weightedPosition.IsShort && !isToReverse ) || ! ( weightedPosition.IsLong && isToReverse ) ) orderType = OrderType.MarketSellShort; return orderType; } + private long getMaxBuyableShares( WeightedPosition weightedPosition ) + { + double maxPositionValue = this.account.GetMarketValue() * + Math.Abs( weightedPosition.Weight ); + double currentAsk = + this.account.DataStreamer.GetCurrentAsk( weightedPosition.Ticker ); + return Convert.ToInt64( Math.Floor( maxPositionValue / currentAsk ) ); + } private void fiveMinutesBeforeMarketCloseEventHandler_openPosition( ! WeightedPosition weightedPosition , bool isToReverse ) { ! string ticker = weightedPosition.Ticker; OrderType orderType = this.fiveMinutesBeforeMarketCloseEventHandler_openPosition_getOrderType( ! weightedPosition , isToReverse ); double maxPositionValue = this.account.GetMarketValue() / this.numberOfPositionsToBeChosen; ! long sharesToBeTraded = this.getMaxBuyableShares( weightedPosition ); this.account.AddOrder( new Order( orderType , new Instrument( ticker ) , sharesToBeTraded ) ); *************** *** 199,210 **** { bool isToReverse = this.isToReverse(); ! foreach ( string signedTicker ! in this.chosenTickers.PortfolioPositions.Keys ) this.fiveMinutesBeforeMarketCloseEventHandler_openPosition( ! signedTicker , isToReverse ); } private void fiveMinutesBeforeMarketCloseEventHandler_openPositions() { ! if ( this.chosenTickers.DrivingPositions != null ) this.fiveMinutesBeforeMarketCloseEventHandler_openPositions_actually(); } --- 210,222 ---- { bool isToReverse = this.isToReverse(); ! foreach ( WeightedPosition weightedPosition ! in this.chosenTickers.PortfolioWeightedPositions.Values ) this.fiveMinutesBeforeMarketCloseEventHandler_openPosition( ! weightedPosition , isToReverse ); ! this.arePositionsUpToDateWithChosenTickers = true; } private void fiveMinutesBeforeMarketCloseEventHandler_openPositions() { ! if ( this.chosenTickers.DrivingWeightedPositions != null ) this.fiveMinutesBeforeMarketCloseEventHandler_openPositions_actually(); } *************** *** 212,218 **** { double totalReturn = 0; ! foreach ( string signedTicker in ! this.chosenTickers.DrivingPositions.Keys ) ! totalReturn += this.getTodayReturnForSignedTicker( signedTicker ); return totalReturn; } --- 224,230 ---- { double totalReturn = 0; ! foreach ( WeightedPosition weightedPosition in ! this.chosenTickers.DrivingWeightedPositions.Values ) ! totalReturn += this.getTodayReturn( weightedPosition ); return totalReturn; } *************** *** 225,293 **** return position; } ! private string getSignedTicker( string ticker ) ! { ! string signedTicker = ""; ! if ( this.chosenTickers.PortfolioPositions.ContainsKey( ticker ) ) ! signedTicker = ticker; ! if ( this.chosenTickers.PortfolioPositions.ContainsKey( "-" + ticker ) ) ! signedTicker = "-" + ticker; ! if ( signedTicker == "" ) ! throw new Exception( "Nor ticker, nor '-'+ticker are contained in " + ! "chosenTickers.PortfolioPositions ; this is an unexpected " + ! "situation, when this method is invoked." ); ! return signedTicker; ! } ! private bool isShort( string signedTicker ) ! { ! return ( signedTicker.StartsWith( "-" ) ); ! } ! private bool isLong( string signedTicker ) ! { ! return ( !this.isShort( signedTicker ) ); ! } ! private bool isContainedInPortfolio( string signedTicker ) ! { ! string ticker = this.getTicker( signedTicker ); ! bool isContained = ! ( this.account.Portfolio.ContainsKey( ticker ) ) ! && ! ( ( this.isLong( signedTicker ) && ! this.account.Portfolio.IsLong( ticker ) ) || ! ( !this.isLong( signedTicker ) && ! this.account.Portfolio.IsShort( ticker ) ) ); ! return isContained; ! } ! private bool doPositionsCorrespondTo( ICollection signedTickers ) ! { ! bool areUpTodate = true; ! foreach ( string signedTicker in signedTickers ) ! areUpTodate = areUpTodate && this.isContainedInPortfolio( signedTicker ); ! return areUpTodate; ! } ! private string reverse( string signedTicker ) ! { ! string reversedSignedTicker = ""; ! if ( this.isLong( signedTicker ) ) ! reversedSignedTicker = "-" + signedTicker; ! if ( !this.isLong( signedTicker ) ) ! // signedTicker starts with a "-" character ! reversedSignedTicker = signedTicker.Substring( 1 ); ! return reversedSignedTicker; ! } ! private ICollection reverse( ICollection signedTickers ) ! { ! Hashtable reversedCollection = new Hashtable(); ! foreach ( string signedTicker in signedTickers ) ! reversedCollection.Add( this.reverse( signedTicker ) , null ); ! return reversedCollection.Keys; ! } ! private bool arePositionsUpToDateWithChosenTickers() { ! bool areUpTodate = ! this.doPositionsCorrespondTo( ! this.chosenTickers.PortfolioPositions.Keys ) || ! this.doPositionsCorrespondTo( ! this.reverse( this.chosenTickers.PortfolioPositions.Keys ) ); ! return areUpTodate; } private bool isReversed() --- 237,317 ---- return position; } ! // private string getSignedTicker( string ticker ) ! // { ! // string signedTicker = ""; ! // if ( this.chosenTickers.PortfolioWeightedPositions.ContainsKey( ticker ) ) ! // signedTicker = ticker; ! // if ( this.chosenTickers.PortfolioWeightedPositions.ContainsKey( "-" + ticker ) ) ! // signedTicker = "-" + ticker; ! // if ( signedTicker == "" ) ! // throw new Exception( "Nor ticker, nor '-'+ticker are contained in " + ! // "chosenTickers.PortfolioPositions ; this is an unexpected " + ! // "situation, when this method is invoked." ); ! // return signedTicker; ! // } ! // private bool isShort( string signedTicker ) ! // { ! // return ( signedTicker.StartsWith( "-" ) ); ! // } ! // private bool isLong( string signedTicker ) ! // { ! // return ( !this.isShort( signedTicker ) ); ! // } ! // private bool isContainedInPortfolio( WeightedPosition weightedPosition ) ! // { ! // bool isContained = false; ! // if ( this.account.Portfolio.ContainsKey( weightedPosition.Ticker ) ) ! // { ! // Position position = ! // this.account.Portfolio.GetPosition( weightedPosition.Ticker ); ! // isContained = ( position.q ! // } ! // bool isContained = ! // ( this.account.Portfolio.ContainsKey( weightedPosition.Ticker ) ) ! // && ! // ( ( weightedPosition.IsLong && ! // this.account.Portfolio.IsLong( weightedPosition.Ticker ) ) || ! // ( weightedPosition.IsShort && ! // this.account.Portfolio.IsShort( weightedPosition.Ticker ) ) ); ! // return isContained; ! // } ! // private bool doPositionsCorrespondTo( ICollection signedTickers ) ! // { ! // bool areUpTodate = true; ! // foreach ( string signedTicker in signedTickers ) ! // areUpTodate = areUpTodate && ! // this.isContainedInPortfolio( signedTicker ); ! // return areUpTodate; ! // } ! // private string reverse( string signedTicker ) ! // { ! // string reversedSignedTicker = ""; ! // if ( this.isLong( signedTicker ) ) ! // reversedSignedTicker = "-" + signedTicker; ! // if ( !this.isLong( signedTicker ) ) ! // // signedTicker starts with a "-" character ! // reversedSignedTicker = signedTicker.Substring( 1 ); ! // return reversedSignedTicker; ! // } ! // private ICollection reverse( ICollection signedTickers ) ! // { ! // Hashtable reversedCollection = new Hashtable(); ! // foreach ( string signedTicker in signedTickers ) ! // reversedCollection.Add( this.reverse( signedTicker ) , null ); ! // return reversedCollection.Keys; ! // } ! // private bool arePositionsUpToDateWithChosenTickers() ! // { ! // bool areUpTodate = ! // this.doPositionsCorrespondTo( ! // this.chosenTickers.PortfolioWeightedPositions ) || ! // this.doPositionsCorrespondTo( ! // this.reverse( this.chosenTickers.PortfolioWeightedPositions ) ); ! // return areUpTodate; ! // } ! private WeightedPosition getWeightedPosition( string ticker ) { ! return this.chosenTickers.PortfolioWeightedPositions.GetWeightedPosition( ! ticker ); } private bool isReversed() *************** *** 295,304 **** Position position = this.getFirstPosition(); PositionType positionType = position.Type; ! string positionTicker = position.Instrument.Key; ! String signedTicker = this.getSignedTicker( positionTicker ); bool isReversedPosition = ! ( ( this.isLong( signedTicker )&& ( position.Type == PositionType.Short ) ) || ! ( !this.isLong( signedTicker ) && ( position.Type == PositionType.Long ) ) ); return isReversedPosition; --- 319,329 ---- Position position = this.getFirstPosition(); PositionType positionType = position.Type; ! string firstPositionTicker = position.Instrument.Key; ! WeightedPosition weightedPosition = ! this.getWeightedPosition( firstPositionTicker ); bool isReversedPosition = ! ( ( weightedPosition.IsLong && ( position.Type == PositionType.Short ) ) || ! ( weightedPosition.IsShort && ( position.Type == PositionType.Long ) ) ); return isReversedPosition; *************** *** 318,322 **** { bool areToBeClosed = ! (!this.arePositionsUpToDateWithChosenTickers()) || this.isReversingNeeded(); return areToBeClosed; --- 343,347 ---- { bool areToBeClosed = ! ( !this.arePositionsUpToDateWithChosenTickers ) || this.isReversingNeeded(); return areToBeClosed; *************** *** 368,372 **** // Console.WriteLine( "Number of Eligible tickers: " + // this.eligibleTickers.EligibleTickers.Rows.Count ); ! this.chosenTickers.SetSignedTickers( this.eligibleTickers ); this.NewChosenTickers( this , new WFLagNewChosenTickersEventArgs( this.chosenTickers ) ); --- 393,398 ---- // Console.WriteLine( "Number of Eligible tickers: " + // this.eligibleTickers.EligibleTickers.Rows.Count ); ! this.chosenTickers.SetWeightedPositions( this.eligibleTickers ); ! this.arePositionsUpToDateWithChosenTickers = false; this.NewChosenTickers( this , new WFLagNewChosenTickersEventArgs( this.chosenTickers ) ); |
|
From: Glauco S. <gla...@us...> - 2006-07-30 13:37:09
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagGenomesDebugger In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv6957/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagGenomesDebugger Modified Files: WFLagSharpeRatioComputer.cs Log Message: WeightedPositions are used instead of SignedTickers Index: WFLagSharpeRatioComputer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagGenomesDebugger/WFLagSharpeRatioComputer.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** WFLagSharpeRatioComputer.cs 22 Jul 2006 20:25:06 -0000 1.2 --- WFLagSharpeRatioComputer.cs 30 Jul 2006 13:37:05 -0000 1.3 *************** *** 114,123 **** getCommonMarketDays( wFLagChosenPositions , firstDate , lastDate ); double[] drivingPositionsReturns = ! SignedTicker.GetCloseToClosePortfolioReturns( ! wFLagChosenPositions.DrivingPositions.Keys , commonMarketDays ); double[] portfolioPositionsReturns = ! SignedTicker.GetCloseToClosePortfolioReturns( ! wFLagChosenPositions.PortfolioPositions.Keys , commonMarketDays ); double[] strategyReturns = getStrategyReturns( --- 114,121 ---- getCommonMarketDays( wFLagChosenPositions , firstDate , lastDate ); double[] drivingPositionsReturns = ! wFLagChosenPositions.DrivingWeightedPositions.GetCloseToClosePortfolioReturns( commonMarketDays ); double[] portfolioPositionsReturns = ! wFLagChosenPositions.PortfolioWeightedPositions.GetCloseToClosePortfolioReturns( commonMarketDays ); double[] strategyReturns = getStrategyReturns( |
|
From: Glauco S. <gla...@us...> - 2006-07-30 13:36:09
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv6509/b7_Scripts/WalkForwardTesting/WalkForwardLag Modified Files: WFLagSignedTickers.cs Log Message: Minor code formatting change Index: WFLagSignedTickers.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagSignedTickers.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** WFLagSignedTickers.cs 14 Mar 2006 15:05:46 -0000 1.1 --- WFLagSignedTickers.cs 30 Jul 2006 13:36:06 -0000 1.2 *************** *** 30,34 **** /// <summary> /// This class identifies all the signed tickers to apply ! /// the lag strategy our of sample: it contains both the /// driving positions and the portfolio positions. Each genome /// can be decoded to an instance of this class --- 30,34 ---- /// <summary> /// This class identifies all the signed tickers to apply ! /// the lag strategy out of sample: it contains both the /// driving positions and the portfolio positions. Each genome /// can be decoded to an instance of this class |
|
From: Glauco S. <gla...@us...> - 2006-07-30 13:06:19
|
Update of /cvsroot/quantproject/QuantProject/b3_Data In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv27153/b3_Data Modified Files: b3_Data.csproj Log Message: a couple of useless .resx file have been removed Index: b3_Data.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/b3_Data.csproj,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** b3_Data.csproj 2 Jul 2006 20:10:43 -0000 1.40 --- b3_Data.csproj 30 Jul 2006 13:06:15 -0000 1.41 *************** *** 136,140 **** <File RelPath = "ExtendedDataTable.cs" ! SubType = "Code" BuildAction = "Compile" /> --- 136,140 ---- <File RelPath = "ExtendedDataTable.cs" ! SubType = "Component" BuildAction = "Compile" /> *************** *** 215,223 **** /> <File - RelPath = "DataTables\Quotes.resx" - DependentUpon = "Quotes.cs" - BuildAction = "EmbeddedResource" - /> - <File RelPath = "DataTables\TickerDataTable.cs" SubType = "Component" --- 215,218 ---- *************** *** 225,233 **** /> <File - RelPath = "DataTables\TickerDataTable.resx" - DependentUpon = "TickerDataTable.cs" - BuildAction = "EmbeddedResource" - /> - <File RelPath = "DataTables\Tickers_tickerGroups.cs" SubType = "Component" --- 220,223 ---- |
|
From: Glauco S. <gla...@us...> - 2006-07-30 13:05:22
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv26723/b7_Scripts Modified Files: b7_Scripts.csproj Log Message: - WalkForwardTesting\WalkForwardLag\WFLagGenomeManagerWithWeights.cs has been added Index: b7_Scripts.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/b7_Scripts.csproj,v retrieving revision 1.57 retrieving revision 1.58 diff -C2 -d -r1.57 -r1.58 *** b7_Scripts.csproj 2 Jul 2006 20:12:59 -0000 1.57 --- b7_Scripts.csproj 30 Jul 2006 13:05:18 -0000 1.58 *************** *** 614,617 **** --- 614,622 ---- /> <File + RelPath = "WalkForwardTesting\WalkForwardLag\WFLagGenomeManagerWithWeights.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "WalkForwardTesting\WalkForwardLag\WFLagMain.cs" SubType = "Form" *************** *** 629,632 **** --- 634,642 ---- /> <File + RelPath = "WalkForwardTesting\WalkForwardLag\WFLagWeightedPositions.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "WalkForwardTesting\WalkForwardLag\WFLagDebugger\WFLagChosenPositions.cs" SubType = "Code" *************** *** 689,697 **** /> <File - RelPath = "WalkForwardTesting\WalkForwardLag\WFLagLogDebugger\WFLagLogDebugger.resx" - DependentUpon = "WFLagLogDebugger.cs" - BuildAction = "EmbeddedResource" - /> - <File RelPath = "WalkForwardTesting\WalkForwardMultiOneRank\RunWalkForwardMultiOneRank.cs" SubType = "Code" --- 699,702 ---- |
|
From: Glauco S. <gla...@us...> - 2006-07-30 13:00:28
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv24683/b7_Scripts/WalkForwardTesting/WalkForwardLag Added Files: WFLagWeightedPositions.cs Log Message: This class identifies all the weighted positions to apply the lag strategy out of sample: it contains both the driving positions and the portfolio positions. Each genome can be decoded to an instance of this class --- NEW FILE: WFLagWeightedPositions.cs --- /* QuantProject - Quantitative Finance Library WFLagWeightedPositions.cs Copyright (C) 2003 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using QuantProject.Business.Strategies; namespace QuantProject.Scripts.WalkForwardTesting.WalkForwardLag { [Serializable] /// <summary> /// This class identifies all the weighted positions to apply /// the lag strategy out of sample: it contains both the /// driving positions and the portfolio positions. Each genome /// can be decoded to an instance of this class /// </summary> public class WFLagWeightedPositions { private WeightedPositions drivingWeightedPositions; private WeightedPositions portfolioWeightedPositions; public WeightedPositions DrivingWeightedPositions { get { return this.drivingWeightedPositions; } } public WeightedPositions PortfolioWeightedPositions { get { return this.portfolioWeightedPositions; } } public WFLagWeightedPositions( WeightedPositions drivingWeightedPositions , WeightedPositions portfolioWeightedPositions ) { this.drivingWeightedPositions = drivingWeightedPositions; this.portfolioWeightedPositions = portfolioWeightedPositions; } } } |
|
From: Glauco S. <gla...@us...> - 2006-07-30 12:59:11
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv24258/b7_Scripts/WalkForwardTesting/WalkForwardLag Added Files: WFLagGenomeManagerWithWeights.cs Log Message: This class implements IGenomeManager, in order to find the best driving position group and the best portfolio position group with respect to the lag strategy. Weighted positions are used for both the driving positions and the portfolio positions --- NEW FILE: WFLagGenomeManagerWithWeights.cs --- using System; using System.Collections; using System.Data; using QuantProject.ADT.Optimizing.Genetic; using QuantProject.ADT.Statistics; using QuantProject.Business.Strategies; namespace QuantProject.Scripts.WalkForwardTesting.WalkForwardLag { /// <summary> /// This class implements IGenomeManager, in order to find the /// best driving position group and the best /// portfolio position group with respect to the lag strategy. /// Weighted positions are used for both the driving positions /// and the portfolio positions /// </summary> public class WFLagGenomeManagerWithWeights : IGenomeManager { private int numberOfDrivingPositions; private int numberOfTickersInPortfolio; private int numberOfEligibleTickersForDrivingWeightedPositions; private DataTable eligibleTickersForDrivingWeightedPositions; private DataTable eligibleTickersForPortfolioWeightedPositions; private DateTime firstOptimizationDate; private DateTime lastOptimizationDate; private double minimumPositionWeight; private WFLagCandidates wFLagCandidates; private GeneticOptimizer currentGeneticOptimizer; public int GenomeSize { get { return ( this.numberOfDrivingPositions + this.numberOfTickersInPortfolio ) * 2; } } public int MinValueForGenes { get { return -this.numberOfEligibleTickersForDrivingWeightedPositions; } } public int MaxValueForGenes { get { return this.numberOfEligibleTickersForDrivingWeightedPositions - 1; } } public GeneticOptimizer CurrentGeneticOptimizer { get{ return this.currentGeneticOptimizer; } set{ this.currentGeneticOptimizer = value; } } /// <summary> /// This class implements IGenomeManager, in order to find the /// best driving position group and the best /// portfolio position group with respect to the lag strategy. /// Weighted positions are used for both the driving positions /// and the portfolio positions /// </summary> /// <param name="eligibleTickersForDrivingWeightedPositions">weighted positions /// for driving positions will be chosen among these tickers</param> /// <param name="eligibleTickersForPortfolioWeightedPositions">weighted positions /// for portfolio positions will be chosen among these tickers</param> /// <param name="firstOptimizationDate"></param> /// <param name="lastQuoteDate"></param> /// <param name="numberOfDrivingPositions"></param> /// <param name="numberOfTickersInPortfolio"></param> public WFLagGenomeManagerWithWeights( DataTable eligibleTickersForDrivingWeightedPositions , DataTable eligibleTickersForPortfolioWeightedPositions , DateTime firstOptimizationDate , DateTime lastOptimizationDate , int numberOfDrivingPositions , int numberOfTickersInPortfolio ) { this.numberOfDrivingPositions = numberOfDrivingPositions; this.numberOfTickersInPortfolio = numberOfTickersInPortfolio; this.numberOfEligibleTickersForDrivingWeightedPositions = eligibleTickersForDrivingWeightedPositions.Rows.Count; this.eligibleTickersForDrivingWeightedPositions = eligibleTickersForDrivingWeightedPositions; this.eligibleTickersForPortfolioWeightedPositions = eligibleTickersForPortfolioWeightedPositions; this.firstOptimizationDate = firstOptimizationDate; this.lastOptimizationDate = lastOptimizationDate; this.minimumPositionWeight = 0.2; // TO DO this value should become a constructor parameter this.wFLagCandidates = new WFLagCandidates( this.eligibleTickersForDrivingWeightedPositions , this.firstOptimizationDate , this.lastOptimizationDate ); } #region GetFitnessValue private string[] getTickers( WeightedPositions weightedPositions ) { string[] tickers = new string[ weightedPositions.Count ]; for ( int i = 0 ; i < weightedPositions.Count ; i++ ) { WeightedPosition weightedPosition = weightedPositions.GetWeightedPosition( i ); tickers[ i ] = weightedPosition.Ticker; } return tickers; } private float[] getMultipliers( WeightedPositions weightedPositions ) { float[] multipliers = new float[ weightedPositions.Count ]; for ( int i = 0 ; i < weightedPositions.Count ; i++ ) { WeightedPosition weightedPosition = weightedPositions.GetWeightedPosition( i ); multipliers[ i ] = Convert.ToSingle( weightedPosition.Weight ); } return multipliers; } private double[] getFitnessValue_getLinearCombinationReturns( WeightedPositions weightedPositions ) { // ArrayList enumeratedweightedPositions = // this.getEnumeratedWeightedPositions( weightedPositions ); int numberOfWeightedPositions = weightedPositions.Count; string[] tickers = this.getTickers( weightedPositions ); float[] multipliers = this.getMultipliers( weightedPositions ); // arrays of close to close returns, one for each signed ticker float[][] tickersReturns = this.wFLagCandidates.GetTickersReturns( tickers ); double[] linearCombinationReturns = new double[ tickersReturns[ 0 ].Length ]; for( int i = 0; i < linearCombinationReturns.Length ; i++ ) // computes linearCombinationReturns[ i ] { linearCombinationReturns[ i ] = 0; for ( int j=0 ; j < weightedPositions.Count ; j++ ) { double weightedPositionReturn = tickersReturns[ j ][ i ] * multipliers[ j ]; linearCombinationReturns[ i ] += weightedPositionReturn; } } return linearCombinationReturns; } private double[] getFitnessValue_getStrategyReturn( double[] drivingPositionsReturns , double[] portfolioPositionsReturns ) { // strategyReturns contains one element less than drivingPositionsReturns, // because there is no strategy for the very first period (at least // one day signal is needed) double[] strategyReturns = new double[ portfolioPositionsReturns.Length - 1 ]; for ( int i = 0 ; i < portfolioPositionsReturns.Length - 1 ; i++ ) if ( drivingPositionsReturns[ i ] < 0 ) // the current linear combination of tickers, at period i // has a negative return // go short tomorrow strategyReturns[ i ] = -portfolioPositionsReturns[ i + 1 ]; else // the current linear combination of tickers, at period i // has a positive return // go long tomorrow strategyReturns[ i ] = portfolioPositionsReturns[ i + 1 ]; return strategyReturns; } private double getFitnessValue( double[] strategyReturns ) { // double fitnessValue = // AdvancedFunctions.GetSharpeRatio( // strategyReturns ); double fitnessValue = AdvancedFunctions.GetExpectancyScore( strategyReturns ); // double fitnessValue = // this.getFitnessValue_withGoodFinal( strategyReturns ); // double fitnessValue = // BasicFunctions.GetSimpleAverage( strategyReturns ) / // ( Math.Pow( BasicFunctions.GetStdDev( strategyReturns ) , 1.3 ) ); return fitnessValue; } private double getFitnessValue( WFLagWeightedPositions wFLagWeightedPositions ) { double[] drivingPositionsReturns = this.getFitnessValue_getLinearCombinationReturns( wFLagWeightedPositions.DrivingWeightedPositions ); double[] portfolioPositionsReturns = this.getFitnessValue_getLinearCombinationReturns( wFLagWeightedPositions.PortfolioWeightedPositions ); double[] strategyReturns = this.getFitnessValue_getStrategyReturn( drivingPositionsReturns , portfolioPositionsReturns ); double fitnessValue = this.getFitnessValue( strategyReturns ); return fitnessValue; } public double GetFitnessValue( Genome genome ) { double fitnessValue; WFLagWeightedPositions wFLagWeightedPositions = ( WFLagWeightedPositions )this.Decode( genome ); int genomeLength = genome.Genes().Length; int decodedWeightedPositions = wFLagWeightedPositions.DrivingWeightedPositions.Count + wFLagWeightedPositions.PortfolioWeightedPositions.Count; if ( ( decodedWeightedPositions * 2 ) < genomeLength ) // genome contains a duplicate gene either for // driving positions or for portfolio positions fitnessValue = double.MinValue; else // all driving positions genes are distinct and // all portfolio positions genes are distinct fitnessValue = this.getFitnessValue( wFLagWeightedPositions ); return fitnessValue; } #endregion public Genome[] GetChilds( Genome parent1 , Genome parent2 ) { return GenomeManagement.AlternateFixedCrossover(parent1, parent2); } public void Mutate( Genome genome , double mutationRate ) { // int newValueForGene = GenomeManagement.RandomGenerator.Next( // genome.MinValueForGenes , // genome.MaxValueForGenes + 1 ); int genePositionToBeMutated = GenomeManagement.RandomGenerator.Next( genome.Size ); int newValueForGene = this.GetNewGeneValue( genome , genePositionToBeMutated ); GenomeManagement.MutateOneGene( genome , mutationRate , genePositionToBeMutated , newValueForGene ); } #region Decode private int[] getWeightRelatedGeneValuesForDrivingPositions( Genome genome ) { int[] weightRelatedGeneValuesForDrivingPositions = new int[ this.numberOfDrivingPositions ]; for ( int i = 0 ; i < this.numberOfDrivingPositions ; i++ ) { int genePosition = 2 * i; weightRelatedGeneValuesForDrivingPositions[ i ] = genome.GetGeneValue( genePosition ); } return weightRelatedGeneValuesForDrivingPositions; } private int[] getTickerRelatedGeneValuesForDrivingPositions( Genome genome ) { int[] tickerRelatedGeneValuesForDrivingPositions = new int[ this.numberOfDrivingPositions ]; for ( int i = 0 ; i < this.numberOfDrivingPositions ; i++ ) { int genePosition = 2 * i + 1; tickerRelatedGeneValuesForDrivingPositions[ i ] = genome.GetGeneValue( genePosition ); } return tickerRelatedGeneValuesForDrivingPositions; } private int[] getWeightRelatedGeneValuesForPortfolioPositions( Genome genome ) { int[] weightRelatedGeneValuesForPortfolioPositions = new int[ this.numberOfTickersInPortfolio ]; int firstPositionForPortfolioRelatedGenomes = this.numberOfDrivingPositions * 2; for ( int i = 0 ; i < this.numberOfTickersInPortfolio ; i++ ) { int genePosition = firstPositionForPortfolioRelatedGenomes + 2 * i; weightRelatedGeneValuesForPortfolioPositions[ i ] = genome.GetGeneValue( genePosition ); } return weightRelatedGeneValuesForPortfolioPositions; } private int[] getTickerRelatedGeneValuesForPortfolioPositions( Genome genome ) { int[] tickerRelatedGeneValuesForPortfolioPositions = new int[ this.numberOfTickersInPortfolio ]; int firstPositionForPortfolioRelatedGenomes = this.numberOfDrivingPositions * 2; for ( int i = 0 ; i < this.numberOfTickersInPortfolio ; i++ ) { int genePosition = firstPositionForPortfolioRelatedGenomes + 2 * i + 1; tickerRelatedGeneValuesForPortfolioPositions[ i ] = genome.GetGeneValue( genePosition ); } return tickerRelatedGeneValuesForPortfolioPositions; } #region decodeWeightedPositions #region getNormalizedWeightValues private double getAdditionalWeight( int weightRelatedGeneValue ) { double midrangeValue = ( this.MinValueForGenes + this.MaxValueForGenes ) / 2; double singleWeightFreeRange = 1 - this.minimumPositionWeight; double scaleRange = Convert.ToDouble( this.MaxValueForGenes - this.MinValueForGenes ); double nonScaledAdditionalWeight = Convert.ToDouble( weightRelatedGeneValue ) - midrangeValue; double scaledAdditionalWeight = nonScaledAdditionalWeight * singleWeightFreeRange / scaleRange; return scaledAdditionalWeight; } private double getNonNormalizedWeightValue( int weightRelatedGeneValue ) { double additionalWeight = this.getAdditionalWeight( weightRelatedGeneValue ); double nonNormalizedWeightValue = 0; if ( additionalWeight >= 0 ) // the gene value represents a long position nonNormalizedWeightValue = this.minimumPositionWeight + additionalWeight; else // additionalWeight < 0 , i.e. the gene value represents a short position nonNormalizedWeightValue = -this.minimumPositionWeight + additionalWeight; return nonNormalizedWeightValue; } private double[] getNonNormalizedWeightValues( int[] weightRelatedGeneValues ) { double[] nonNormalizedWeightValues = new double[ weightRelatedGeneValues.Length ]; for ( int i = 0 ; i < weightRelatedGeneValues.Length ; i++ ) nonNormalizedWeightValues[ i ] = this.getNonNormalizedWeightValue( weightRelatedGeneValues[ i ] ); return nonNormalizedWeightValues; } private double getNormalizingFactor( double[] nonNormalizedWeightValues ) { // the absolute value for each nonNormalizedWeightValue is between // this.minimumPositionWeight and 1 double totalForNonNormalizedWeightValues = BasicFunctions.SumOfAbs( nonNormalizedWeightValues ); double normalizingFactor = 1 / totalForNonNormalizedWeightValues; return normalizingFactor; } private double[] getNormalizedWeightValues( double[] nonNormalizedWeightValues , double normalizingFactor ) { return BasicFunctions.MultiplyBy( nonNormalizedWeightValues , normalizingFactor ); } private double[] getNormalizedWeightValues( double[] nonNormalizedWeightValues ) { double normalizingFactor = this.getNormalizingFactor( nonNormalizedWeightValues ); return getNormalizedWeightValues( nonNormalizedWeightValues , normalizingFactor ); } private double[] getNormalizedWeightValues( int[] weightRelatedGeneValues ) { double[] nonNormalizedWeightValues = this.getNonNormalizedWeightValues( weightRelatedGeneValues ); return this.getNormalizedWeightValues( nonNormalizedWeightValues ); } #endregion private string[] decodeTickers( int[] tickerRelatedGeneValues , DataTable eligibleTickers ) { string[] tickers = new string[ tickerRelatedGeneValues.Length ]; for( int i = 0 ; i < tickerRelatedGeneValues.Length ; i++ ) { int currentGeneValue = tickerRelatedGeneValues[ i ]; tickers[ i ] = ( string )eligibleTickers.Rows[ currentGeneValue ][ 0 ]; } return tickers; } private WeightedPositions decodeWeightedPositions( int[] weightRelatedGeneValues , int[] tickerRelatedGeneValues , DataTable eligibleTickers ) { double[] normalizedWeightValues = this.getNormalizedWeightValues( weightRelatedGeneValues ); string[] tickers = this.decodeTickers( tickerRelatedGeneValues , eligibleTickers ); WeightedPositions weightedPositions = new WeightedPositions( normalizedWeightValues , tickers ); return weightedPositions; } #endregion private WeightedPositions decodeDrivingWeightedPositions( Genome genome ) { int[] weightRelatedGeneValuesForDrivingPositions = this.getWeightRelatedGeneValuesForDrivingPositions( genome ); int[] tickerRelatedGeneValuesForDrivingPositions = this.getTickerRelatedGeneValuesForDrivingPositions( genome ); return decodeWeightedPositions( weightRelatedGeneValuesForDrivingPositions , tickerRelatedGeneValuesForDrivingPositions , this.eligibleTickersForDrivingWeightedPositions ); // // double weight = this.decodeDrivingWeight( genome , geneIndex ); // string ticker = this.decodeDrivingTicker( genome , geneIndex ); // WeightedPosition weightedPosition = new WeightedPosition( // weight , ticker ); // wFLagWeightedPositions.DrivingWeightedPositions.AddWeightedPosition( // weightedPosition ); } private WeightedPositions decodePortfolioWeightedPositions( Genome genome ) { int[] weightRelatedGeneValuesForPortfolioPositions = this.getWeightRelatedGeneValuesForPortfolioPositions( genome ); int[] tickerRelatedGeneValuesForPortfolioPositions = this.getTickerRelatedGeneValuesForPortfolioPositions( genome ); return decodeWeightedPositions( weightRelatedGeneValuesForPortfolioPositions , tickerRelatedGeneValuesForPortfolioPositions , this.eligibleTickersForPortfolioWeightedPositions ); // // double weight = this.decodeDrivingWeight( genome , geneIndex ); // string ticker = this.decodeDrivingTicker( genome , geneIndex ); // WeightedPosition weightedPosition = new WeightedPosition( // weight , ticker ); // wFLagWeightedPositions.DrivingWeightedPositions.AddWeightedPosition( // weightedPosition ); } public virtual object Decode(Genome genome) { WeightedPositions drivingWeightedPositions = this.decodeDrivingWeightedPositions( genome ); WeightedPositions portfolioWeightedPositions = this.decodePortfolioWeightedPositions( genome ); WFLagWeightedPositions wFLagWeightedPositions = new WFLagWeightedPositions( drivingWeightedPositions , portfolioWeightedPositions ); // int[] drivingGeneValues = this.getDrivingGeneValues( genome ); // for ( int geneIndex = 0 ; geneIndex < this.numberOfDrivingPositions * 2 ; // geneIndex += 2 ) // this.decode_addDrivingPosition( genome , geneIndex , wFLagWeightedPositions ); // for ( int geneIndex = this.numberOfDrivingPositions * 2 ; // geneIndex < // ( this.numberOfDrivingPositions + this.numberOfTickersInPortfolio ) * 2 ; // geneIndex += 2 ) // this.decode_addPortfolioPosition( genome , geneIndex , wFLagSignedTickers ); // 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_getSignedTickerForGeneValue(indexOfTicker); // } return wFLagWeightedPositions; } #endregion #region GetNewGeneValue private int getMinGeneValue( int i ) { int minGeneValue = 0; if ( i % 2 == 0 ) minGeneValue = this.MinValueForGenes; return minGeneValue; } private int getMaxGeneValue( int i ) { return this.MaxValueForGenes; } public int GetNewGeneValue( Genome genome , int i ) { int minGeneValue = this.getMinGeneValue( i ); int maxGeneValue = this.getMaxGeneValue( i ); int returnValue = GenomeManagement.RandomGenerator.Next( minGeneValue , maxGeneValue + 1); return returnValue; } #endregion } } |
|
From: Glauco S. <gla...@us...> - 2006-07-30 12:57:37
|
Update of /cvsroot/quantproject/QuantProject/b4_Business In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv23834/b4_Business Modified Files: b4_Business.csproj Log Message: a2_Strategies\WeightedPositions.cs has been added Index: b4_Business.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/b4_Business.csproj,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** b4_Business.csproj 30 Jul 2006 10:46:17 -0000 1.34 --- b4_Business.csproj 30 Jul 2006 12:57:34 -0000 1.35 *************** *** 620,623 **** --- 620,628 ---- /> <File + RelPath = "a2_Strategies\WeightedPositions.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "a3_Testing\BackTester.cs" SubType = "Code" |
|
From: Glauco S. <gla...@us...> - 2006-07-30 12:56:43
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv23790/b4_Business/a2_Strategies Added Files: WeightedPositions.cs Log Message: Consistent group of weighted positions: weights are checked to sum up to 1. --- NEW FILE: WeightedPositions.cs --- /* QuantProject - Quantitative Finance Library WeightedPositions.cs Copyright (C) 2003 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections; using QuantProject.Business.DataProviders; using QuantProject.Business.Financial.Accounting; using QuantProject.Business.Strategies; using QuantProject.Business.Timing; namespace QuantProject.Business.Strategies { [Serializable] /// <summary> /// Consistent group of weighted positions: weights are /// checked to sum up to 1. /// </summary> public class WeightedPositions : SortedList { /// <summary> /// returns the type for this class /// </summary> public static System.Type Type { get { return getType(); } } public WeightedPositions( double[] normalizedWeightValues , string[] tickers ) { this.checkParameters( normalizedWeightValues , tickers ); for ( int i=0 ; i < tickers.Length ; i++ ) { string ticker = tickers[ i ]; double weight = normalizedWeightValues[ i ]; if ( !this.ContainsKey( ticker ) ) this.Add( ticker , new WeightedPosition( weight , ticker ) ); else ((WeightedPosition)this[ ticker ]).Weight += weight; } } private void checkParameters( double[] normalizedWeightValues , string[] tickers ) { if ( normalizedWeightValues.Length != tickers.Length ) throw new Exception( "The number of normalized weights is " + "different from the number of tickers. They should be the same " + "number!" ); double totalWeight = ADT.Statistics.BasicFunctions.SumOfAbs( normalizedWeightValues ); if ( ( totalWeight < 0.999 ) || ( totalWeight > 1.001 ) ) throw new Exception( "The total of (absolute) weights " + "should sum up to 1, " + "but it sums up to " + totalWeight.ToString() ); } public WeightedPosition GetWeightedPosition( string ticker ) { return (WeightedPosition)this[ ticker ]; } public WeightedPosition GetWeightedPosition( int i ) { return (WeightedPosition)this.GetByIndex( i ); } #region GetEquityLine /// <summary> /// Returns a virtual amount of quantities for each virtual ticker. /// Non integer values can be returned also, that's why we call /// them virtual quantities /// </summary> /// <returns></returns> private Hashtable getVirtualQuantities( double beginningCash , DateTime dateTime ) { Hashtable virtualQuantities = new Hashtable(); HistoricalAdjustedQuoteProvider historicalAdjustedQuoteProvider = new HistoricalAdjustedQuoteProvider(); EndOfDayDateTime endOfDayDateTime = new EndOfDayDateTime( dateTime , EndOfDaySpecificTime.MarketClose ); foreach( WeightedPosition weightedPosition in this.Values ) { string ticker = weightedPosition.Ticker; double valueForThisPosition = beginningCash * Math.Abs( weightedPosition.Weight ); double tickerQuote = historicalAdjustedQuoteProvider.GetMarketValue( ticker , endOfDayDateTime ); double virtualQuantityForThisPosition = valueForThisPosition / tickerQuote; if ( weightedPosition.IsShort ) virtualQuantityForThisPosition = -virtualQuantityForThisPosition; virtualQuantities.Add( ticker , virtualQuantityForThisPosition ); } return virtualQuantities; } private double getCash( double beginningCash , Hashtable virtualQuantities ) { double cash = beginningCash; foreach ( WeightedPosition weightedPosition in this.Values ) { double thisVirtualQuantity = (double)virtualQuantities[ weightedPosition.Ticker ]; double thisPositionValue = beginningCash * Math.Abs( weightedPosition.Weight ); if ( thisVirtualQuantity > 0 ) // long position cash -= thisPositionValue; else // virtualQuantity < 0 i.e. short position cash += thisPositionValue; } return cash; } private double getVirtualPortfolioValue( DateTime dateTime , Hashtable tickerVirtualQuantities ) { HistoricalAdjustedQuoteProvider historicalAdjustedQuoteProvider = new HistoricalAdjustedQuoteProvider(); double virtualPortfolioValue = 0; foreach( string ticker in tickerVirtualQuantities.Keys ) { EndOfDayDateTime endOfDayDateTime = new EndOfDayDateTime( dateTime , EndOfDaySpecificTime.MarketClose ); double tickerQuote = historicalAdjustedQuoteProvider.GetMarketValue( ticker , endOfDayDateTime ); double virtualQuantity = (double)tickerVirtualQuantities[ ticker ]; virtualPortfolioValue += virtualQuantity * tickerQuote; } return virtualPortfolioValue; } /// <summary> /// computes the equity line for this weighted positions. The equity line is virtual because /// quantities for each ticker can be non integer also (it is simulated an account where /// every single penny is always invested, so fractional quantities are simulated) /// </summary> /// <param name="beginningCash">cash amount when the simulated strategy begins</param> /// <param name="equityDates">an ordered list of DateTime(s) where the equity line has to be computed</param> /// <returns></returns> public EquityLine GetVirtualEquityLine( double beginningCash , SortedList equityDates ) { DateTime firstDate = (DateTime)equityDates.GetKey( 0 ); EquityLine equityLine = new EquityLine(); Hashtable virtualQuantities = this.getVirtualQuantities( beginningCash , firstDate ); double cash = this.getCash( beginningCash , virtualQuantities ); for( int i = 0 ; i < equityDates.Count ; i++ ) { DateTime dateTime = (DateTime)equityDates.GetKey( i ); equityLine.Add( dateTime , cash + this.getVirtualPortfolioValue( dateTime , virtualQuantities ) ); } return equityLine; } #endregion #region getType private static WeightedPositions getSimpleDummyInstance() { double[] weights = {1.0}; string[] tickers = {"DUMMY"}; WeightedPositions dummyInstance = new WeightedPositions( weights , tickers ); return dummyInstance; } private static System.Type getType() { WeightedPositions weightedPositions = WeightedPositions.getSimpleDummyInstance(); return weightedPositions.GetType(); } #endregion #region GetCloseToClosePortfolioReturns // private static double getCloseToCloseReturn( string ticker , // SortedList datesForReturnComputation , int i ) // { // DateTime previousDate = (DateTime)datesForReturnComputation.GetByIndex( i ); // DateTime currentDate = // (DateTime)datesForReturnComputation.GetByIndex( i + 1 ); // HistoricalAdjustedQuoteProvider historicalQuoteProvider = // new HistoricalAdjustedQuoteProvider(); // double previousQuote = historicalQuoteProvider.GetMarketValue( ticker , // new EndOfDayDateTime( previousDate , EndOfDaySpecificTime.MarketClose ) ); // double currentQuote = historicalQuoteProvider.GetMarketValue( ticker , // new EndOfDayDateTime( currentDate , EndOfDaySpecificTime.MarketClose ) ); // double closeToCloseReturn = currentQuote / previousQuote - 1.0; // return closeToCloseReturn; // } // private static double getMultiplier( string signedTicker ) // { // double multiplier = 1.0; // if ( IsShort( signedTicker ) ) // multiplier = -multiplier; // return multiplier; // } private double getCloseToClosePortfolioReturn( SortedList datesForReturnComputation , int i ) { DateTime dateTime = (DateTime)datesForReturnComputation.GetByIndex( i + 1 ); double dailyReturn = 0.0; foreach ( WeightedPosition weightedPosition in this.Values ) dailyReturn += weightedPosition.GetCloseToCloseDailyReturn( dateTime ); return dailyReturn; } private double[] getCloseToClosePortfolioReturns( SortedList datesForReturnComputation ) { // the return for first DateTime cannot be computed so the returned // array will have one element less the datesForReturnComputation double[] closeToClosePortfolioReturns = new double[ datesForReturnComputation.Count - 1 ]; for ( int i=0 ; i < closeToClosePortfolioReturns.Length ; i++ ) closeToClosePortfolioReturns[ i ] = this.getCloseToClosePortfolioReturn( datesForReturnComputation , i ); return closeToClosePortfolioReturns; } /// <summary> /// Gets portfolio's return (for this weighted positions) computed on the /// market days contained in commonMarketDays /// </summary> /// <param name="commonMarketDays">SortedList of DateTime objects: positions /// are assumed to be exchanged in all such market days, otherwise /// an exception should be thrown</param> /// <returns></returns> public double[] GetCloseToClosePortfolioReturns( SortedList commonMarketDays ) { // TO DO check parameter: check if each position is exchanged in each common market day return getCloseToClosePortfolioReturns( commonMarketDays ); } #endregion } } |
|
From: Glauco S. <gla...@us...> - 2006-07-30 10:46:25
|
Update of /cvsroot/quantproject/QuantProject/b4_Business In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv14873/b4_Business Modified Files: b4_Business.csproj Log Message: a2_Strategies\WeightedPosition.cs has been added Index: b4_Business.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/b4_Business.csproj,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** b4_Business.csproj 2 Jul 2006 20:16:16 -0000 1.33 --- b4_Business.csproj 30 Jul 2006 10:46:17 -0000 1.34 *************** *** 615,618 **** --- 615,623 ---- /> <File + RelPath = "a2_Strategies\WeightedPosition.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "a3_Testing\BackTester.cs" SubType = "Code" |
|
From: Glauco S. <gla...@us...> - 2006-07-30 10:44:52
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv14116/b4_Business/a2_Strategies Added Files: WeightedPosition.cs Log Message: Weighted representation for possible position --- NEW FILE: WeightedPosition.cs --- /* QuantProject - Quantitative Finance Library SignedTicker.cs Copyright (C) 2003 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using QuantProject.Business.DataProviders; using QuantProject.Business.Financial.Ordering; using QuantProject.Business.Timing; namespace QuantProject.Business.Strategies { [Serializable] /// <summary> /// Weighted representation for a possible position /// </summary> public class WeightedPosition { private string ticker; private double weight; public string Ticker { get { return this.ticker; } } public double Weight { get { return this.weight; } set { this.weight = value; } } public bool IsShort { get { return ( this.weight < 0 ); } } public bool IsLong { get { return ( !this.IsShort ); } } public WeightedPosition( double weight , string ticker ) { if ( ( weight > 1 ) || ( weight < -1 ) ) throw new Exception( "Unacceptable weight value. The weight must be " + "in the [-1,+1] interval, but the given weight parameter value is " + weight.ToString() ); else { this.weight = weight; this.ticker = ticker; } } /// <summary> /// returns a MarketBuy if the position is long, a /// MarketSellShort otherwise /// </summary> /// <returns></returns> public OrderType GetOrderType() { OrderType orderType = OrderType.MarketBuy; if ( this.IsShort ) orderType = OrderType.MarketSellShort; return orderType; } /// <summary> /// returns the WeightedPosition with an opposite weight /// </summary> /// <returns></returns> public WeightedPosition GetOppositeWeightedPosition() { return new WeightedPosition( -this.weight , this.ticker ); } /// <summary> /// returns the close to close daily return, for this weighted /// position, at the dateTime date /// </summary> /// <param name="dateTime">date when to compute the daily return</param> /// <returns></returns> public double GetCloseToCloseDailyReturn( DateTime dateTime ) { string ticker = this.Ticker; HistoricalAdjustedQuoteProvider historicalAdjustedQuoteProvider = new HistoricalAdjustedQuoteProvider(); double todayMarketValueAtClose = historicalAdjustedQuoteProvider.GetMarketValue( ticker , new EndOfDayDateTime( dateTime , EndOfDaySpecificTime.MarketClose ) ); DateTime yesterday = dateTime.AddDays( -1 ); EndOfDayDateTime yesterdayAtClose = new EndOfDayDateTime( yesterday , EndOfDaySpecificTime.MarketClose ); double yesterdayMarketValueAtClose = historicalAdjustedQuoteProvider.GetMarketValue( ticker , yesterdayAtClose ); double dailyReturnForLongPosition = ( todayMarketValueAtClose / yesterdayMarketValueAtClose ) - 1; double dailyReturn = dailyReturnForLongPosition * this.Weight; // if ( this.IsShort ) // // this weighted position represents a short position // dailyReturn = - dalyReturnForLongPosition; // else // // this weighted position represents a long position // dailyReturn = dalyReturnForLongPosition; return dailyReturn; } } } |
|
From: Marco M. <mi...@us...> - 2006-07-25 15:23:00
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv13868/b1_ADT Modified Files: ConstantsProvider.cs Log Message: Minimum weight now depends on the new constant AmountOfVariableWeightToBeAssignedToTickers, which substitutes the old constant MinimumPortfolioWeightForTicker. In this way, the method getTickerWeight shouldn't fail with any number of tickers in portfolio Index: ConstantsProvider.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/ConstantsProvider.cs,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** ConstantsProvider.cs 8 Jun 2006 18:46:53 -0000 1.17 --- ConstantsProvider.cs 25 Jul 2006 15:22:50 -0000 1.18 *************** *** 40,45 **** public static DateTime DefaultDateForTickersAddedToGroups = new DateTime(1980,1,1); //conventional date for new tickers added to groups ! public static double MinimumPortfolioWeightForTicker = 0.2; ! //default minimum weight for ticker, used by GenomeManagerForWeightedEfficientPortfolio public static string SeparatorForTickers = ";"; //separator for tickers in GenomeRepresentation class --- 40,46 ---- public static DateTime DefaultDateForTickersAddedToGroups = new DateTime(1980,1,1); //conventional date for new tickers added to groups ! public static double AmountOfVariableWeightToBeAssignedToTickers = 0.5; ! //total weight to be assigned to portfolio's tickers through genetic optimizer, ! //this constant is used at the moment only by GenomeManagerForWeightedEfficientPortfolio public static string SeparatorForTickers = ";"; //separator for tickers in GenomeRepresentation class |
|
From: Marco M. <mi...@us...> - 2006-07-25 15:22:59
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv13868/b7_Scripts/TickerSelectionTesting Modified Files: GenomeManagerForWeightedEfficientPortfolio.cs Log Message: Minimum weight now depends on the new constant AmountOfVariableWeightToBeAssignedToTickers, which substitutes the old constant MinimumPortfolioWeightForTicker. In this way, the method getTickerWeight shouldn't fail with any number of tickers in portfolio Index: GenomeManagerForWeightedEfficientPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManagerForWeightedEfficientPortfolio.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** GenomeManagerForWeightedEfficientPortfolio.cs 2 Jun 2006 18:58:09 -0000 1.3 --- GenomeManagerForWeightedEfficientPortfolio.cs 25 Jul 2006 15:22:50 -0000 1.4 *************** *** 62,66 **** protected override double getTickerWeight(int[] genes, int tickerPositionInGenes) { ! double minimumWeight = ConstantsProvider.MinimumPortfolioWeightForTicker; double totalOfValuesForWeightsInGenes = 0.0; for(int j = 0; j<genes.Length; j++) --- 62,67 ---- protected override double getTickerWeight(int[] genes, int tickerPositionInGenes) { ! double minimumWeight = (1.0 - ConstantsProvider.AmountOfVariableWeightToBeAssignedToTickers)/ ! (genes.Length / 2); double totalOfValuesForWeightsInGenes = 0.0; for(int j = 0; j<genes.Length; j++) |
|
From: Glauco S. <gl...@my...> - 2006-07-23 18:18:53
|
... mmm ... la triste verita' e' che, evidentemente, di li' non ci passo=
mai...
Grazie della segnalazione.
At 01:12 PM 7/23/2006 +0200, you wrote:
> > + private void removeNonContainedDates( SortedList marketDays )
> > + {
> > + foreach( DataRow dataRow in this.Rows )
> > + if ( marketDays.ContainsKey(
> > + (DateTime)dataRow[ Quotes.Date ] ) )
> > + this.Rows.Remove( dataRow );
> > + }
>
>Ma guarda un po' quante belle cosine che ha portato il caldo afoso (di cui,
>fortunatamente, sento solo parlare in tv)
>di questi giorni ... :-).
>
>Ho per=F2 un paio di dubbi riguardo al metodo di cui sopra:
>1) nell'if non manca "!" ? (leggendo il nome del metodo sarei portato a
>concludere che il remove si applica se la data non =E8 contenuta, appunto=
...)
>2) il foreach non funzionava solo in lettura? Cio=E8: mi sembrava d'aver
>capito che all'interno di un foreach non si potevano fare operazioni di add
>o delete sugli items della collections. Ma se tu mi confermi che in runTime
>il metodo non d=E0 problemi, allora devo proprio aprire la guida ...
>
>
>-------------------------------------------------------------------------
>Take Surveys. Earn Cash. Influence the Future of IT
>Join SourceForge.net's Techsay panel and you'll get the chance to share=
your
>opinions on IT & business topics through brief surveys -- and earn cash
>http://www.techsay.com/default.php?page=3Djoin.php&p=3Dsourceforge&CID=3DDE=
VDEV
>_______________________________________________
>Quantproject-developers mailing list
>Qua...@li...
>https://lists.sourceforge.net/lists/listinfo/quantproject-developers
|
|
From: Marco M. <mar...@po...> - 2006-07-23 15:08:29
|
> + private void removeNonContainedDates( SortedList marketDays )
> + {
> + foreach( DataRow dataRow in this.Rows )
> + if ( marketDays.ContainsKey(
> + (DateTime)dataRow[ Quotes.Date ] ) )
> + this.Rows.Remove( dataRow );
> + }
Ma guarda un po' quante belle cosine che ha portato il caldo afoso (di cu=
i,=20
fortunatamente, sento solo parlare in tv)
di questi giorni ... :-).
Ho per=F2 un paio di dubbi riguardo al metodo di cui sopra:
1) nell'if non manca "!" ? (leggendo il nome del metodo sarei portato a=20
concludere che il remove si applica se la data non =E8 contenuta, appunto=
...)
2) il foreach non funzionava solo in lettura? Cio=E8: mi sembrava d'aver=20
capito che all'interno di un foreach non si potevano fare operazioni di a=
dd=20
o delete sugli items della collections. Ma se tu mi confermi che in runTi=
me=20
il metodo non d=E0 problemi, allora devo proprio aprire la guida ...
|
|
From: Glauco S. <gla...@us...> - 2006-07-22 20:57:41
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv10302/b1_ADT Modified Files: ExtendedDateTime.cs Log Message: - the GetArray method has been commented out (useless) Index: ExtendedDateTime.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/ExtendedDateTime.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ExtendedDateTime.cs 28 Aug 2004 17:09:43 -0000 1.2 --- ExtendedDateTime.cs 22 Jul 2006 20:57:38 -0000 1.3 *************** *** 22,25 **** --- 22,26 ---- using System; + using System.Collections; namespace QuantProject.ADT *************** *** 102,105 **** --- 103,122 ---- return this.DateTime.ToString() + " - " + this.BarComponent.ToString(); } + // public static SortedList GetArray( SortedList sortedDateTimes ) + // { + // SortedList dateTimes = new DateTime[ sortedDateTimes.Count ]; + // for ( int i = 0; i<sortedDateTimes.Count ; i++ ) + // { + // if ( !(sortedDateTimes.GetByIndex( i ) is DateTime ) ) + // throw( new Exception( "sortedDateTimes is expected to contain only DateTime elements. " + + // "The element number " + i + " is not a DateTime, instead." ) ); + // else + // { + // DateTime dateTime = (DateTime)sortedDateTimes.GetByIndex( i ); + // dateTimes[ i ] = dateTime; + // } + // } + // return dateTimes; + // } } } |
|
From: Glauco S. <gla...@us...> - 2006-07-22 20:56:13
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataTables In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv9859/b3_Data/DataTables Modified Files: Quotes.cs Log Message: - a new constructor public Quotes( string ticker , SortedList marketDays ) has been added. It builds a Quotes data table containing the ticker's quotes for the market days contained in the marketDays SortedList - the new public static method GetCommonMarketDays has been added (it returns the common market days for a given set of ticker, in a given date's interval) - the public static method GetFirstQuoteDate( string ticker ) has been added Index: Quotes.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/DataTables/Quotes.cs,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** Quotes.cs 2 Jul 2006 19:07:26 -0000 1.27 --- Quotes.cs 22 Jul 2006 20:56:09 -0000 1.28 *************** *** 44,53 **** this.fillDataTable( ticker , startDate , endDate ); } public Quotes( string ticker ) { this.fillDataTable( ticker , ! QuantProject.DataAccess.Tables.Quotes.GetStartDate( ticker ) , ! QuantProject.DataAccess.Tables.Quotes.GetEndDate( ticker ) ); } public Quotes(SerializationInfo info, StreamingContext context) --- 44,75 ---- this.fillDataTable( ticker , startDate , endDate ); } + + /// <summary> + /// builds a Quotes data table containing the ticker's quotes for the + /// market days contained in the marketDays SortedList + /// </summary> + /// <param name="ticker"></param> + /// <param name="marketDays"></param> + public Quotes( string ticker , SortedList marketDays ) + { + DateTime firstDate = (DateTime)marketDays.GetByIndex( 0 ); + DateTime lastDate = (DateTime)marketDays.GetByIndex( + marketDays.Count - 1 ); + this.fillDataTable( ticker , firstDate , lastDate ); + this.removeNonContainedDates( marketDays ); + } + private void removeNonContainedDates( SortedList marketDays ) + { + foreach( DataRow dataRow in this.Rows ) + if ( marketDays.ContainsKey( + (DateTime)dataRow[ Quotes.Date ] ) ) + this.Rows.Remove( dataRow ); + } public Quotes( string ticker ) { this.fillDataTable( ticker , ! QuantProject.DataAccess.Tables.Quotes.GetFirstQuoteDate( ticker ) , ! QuantProject.DataAccess.Tables.Quotes.GetLastQuoteDate( ticker ) ); } public Quotes(SerializationInfo info, StreamingContext context) *************** *** 626,638 **** /// <param name="lastDate">end interval</param> /// <returns></returns> ! public static DateTime[] GetMarketDays( string ticker , DateTime firstDate , DateTime lastDate ) { Quotes quotes = new Quotes( ticker , firstDate , lastDate ); ! DateTime[] marketDays = new DateTime[ quotes.Rows.Count ]; int i = 0; foreach ( DataRow dataRow in quotes.Rows ) { ! marketDays[ i ] = (DateTime)dataRow[ Quotes.Date ]; i++; } --- 648,662 ---- /// <param name="lastDate">end interval</param> /// <returns></returns> ! public static SortedList GetMarketDays( string ticker , DateTime firstDate , DateTime lastDate ) { Quotes quotes = new Quotes( ticker , firstDate , lastDate ); ! // DateTime[] marketDays = new DateTime[ quotes.Rows.Count ]; ! SortedList marketDays = new SortedList(); int i = 0; foreach ( DataRow dataRow in quotes.Rows ) { ! // marketDays[ i ] = (DateTime)dataRow[ Quotes.Date ]; ! marketDays.Add( (DateTime)dataRow[ Quotes.Date ] , (DateTime)dataRow[ Quotes.Date ] ); i++; } *************** *** 641,645 **** ! private History history; /// <summary> --- 665,720 ---- ! #region GetCommonMarketDays ! private static Hashtable getMarketDays( ICollection tickers , DateTime firstDate , ! DateTime lastDate ) ! { ! Hashtable marketDays = new Hashtable(); ! foreach ( string ticker in tickers ) ! if ( !marketDays.ContainsKey( ticker ) ) ! { ! SortedList marketDaysForSingleTicker = ! GetMarketDays( ticker , firstDate , lastDate ); ! marketDays.Add( ticker , marketDaysForSingleTicker ); ! } ! return marketDays; ! } ! private static bool isCommonDate( ICollection tickers , DateTime dateTime , ! Hashtable marketDays ) ! { ! bool itIsCommon = true; ! foreach ( string ticker in tickers ) ! itIsCommon = itIsCommon && ! ((SortedList)marketDays[ ticker ]).ContainsKey( dateTime ); ! return itIsCommon; ! } ! private static void getCommonMarketDays_ifTheCaseAdd( ICollection tickers , DateTime dateTime , ! Hashtable marketDays , AdvancedSortedList commonMarketDays ) ! { ! if ( isCommonDate( tickers , dateTime , marketDays ) ) ! commonMarketDays.Add( dateTime , dateTime ); ! } ! private static SortedList getCommonMarketDays( ICollection tickers , ! DateTime firstDate , DateTime lastDate , Hashtable marketDays ) ! { ! AdvancedSortedList commonMarketDays = new AdvancedSortedList(); ! DateTime currentDateTime = firstDate; ! while ( currentDateTime <= lastDate ) ! { ! getCommonMarketDays_ifTheCaseAdd( tickers , ! currentDateTime , marketDays , commonMarketDays ); ! currentDateTime = currentDateTime.AddDays( 1 ); ! } ! return commonMarketDays; ! } ! ! public static SortedList GetCommonMarketDays( ICollection tickers , ! DateTime firstDate , DateTime lastDate ) ! { ! Hashtable marketDays = getMarketDays( tickers , firstDate , lastDate ); ! return getCommonMarketDays( tickers , firstDate , lastDate , marketDays ); ! } ! ! #endregion ! private History history; /// <summary> *************** *** 861,864 **** --- 936,949 ---- } } + /// <summary> + /// returns the first quote date for the ticker + /// </summary> + /// <param name="ticker"></param> + /// <returns></returns> + public static DateTime GetFirstQuoteDate( string ticker ) + { + return QuantProject.DataAccess.Tables.Quotes.GetFirstQuoteDate( ticker ); + } + /// <summary> |
|
From: Glauco S. <gla...@us...> - 2006-07-22 20:52:47
|
Update of /cvsroot/quantproject/QuantProject/b2_DataAccess/Tables In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv8281/b2_DataAccess/Tables Modified Files: Quotes.cs Log Message: - the public static method GetFirstQuoteDate replaces the previous GetStartDate method (the implementation is more efficient now) - the public static method GetLastQuoteDate replaces the previous GetEndDate method Index: Quotes.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b2_DataAccess/Tables/Quotes.cs,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** Quotes.cs 18 Jun 2006 14:19:44 -0000 1.29 --- Quotes.cs 22 Jul 2006 20:52:44 -0000 1.30 *************** *** 61,70 **** /// <param name="ticker">ticker for which the starting date has to be returned</param> /// <returns></returns> ! public static DateTime GetStartDate( string ticker ) { DataTable dataTable = SqlExecutor.GetDataTable( ! "select * from quotes where quTicker='" + ticker + "' " + ! "order by quDate"); ! return (DateTime)(dataTable.Rows[ 0 ][ "quDate" ]); } /// <summary> --- 61,70 ---- /// <param name="ticker">ticker for which the starting date has to be returned</param> /// <returns></returns> ! public static DateTime GetFirstQuoteDate( string ticker ) { DataTable dataTable = SqlExecutor.GetDataTable( ! "select min(quDate) as minDate from quotes where quTicker='" + ticker + "' " + ! "group by quTicker"); ! return (DateTime)(dataTable.Rows[ 0 ][ "minDate" ]); } /// <summary> *************** *** 73,77 **** /// <param name="ticker">ticker for which the lasat date has to be returned</param> /// <returns></returns> ! public static DateTime GetEndDate( string ticker ) { DataTable dataTable = SqlExecutor.GetDataTable( --- 73,77 ---- /// <param name="ticker">ticker for which the lasat date has to be returned</param> /// <returns></returns> ! public static DateTime GetLastQuoteDate( string ticker ) { DataTable dataTable = SqlExecutor.GetDataTable( |
|
From: Glauco S. <gla...@us...> - 2006-07-22 20:50:19
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv7429/b4_Business/a2_Strategies Modified Files: SignedTicker.cs Log Message: - the GetCloseToClosePortfolioReturn method has been added, to compute the close to close portfolio return using a given a SortedList commonMarketDays to select the dates to be used for the calculation - the same method above has been overloaded to use weights also Index: SignedTicker.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/SignedTicker.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SignedTicker.cs 2 Jul 2006 19:04:49 -0000 1.4 --- SignedTicker.cs 22 Jul 2006 20:50:16 -0000 1.5 *************** *** 197,213 **** /// <param name="startDate">Start date for the period for which return has to be computed</param> /// <param name="endDate">End date for the period for which return has to be computed</param> ! public static double GetCloseToClosePortfolioReturn(string[] signedTickers, ! DateTime startDate, ! DateTime endDate ) ! { ! double[] tickersWeights = new double[signedTickers.Length]; ! for(int i = 0; i<signedTickers.Length; i++) ! tickersWeights[i] = 1.0/signedTickers.Length; ! return GetCloseToClosePortfolioReturn( signedTickers,tickersWeights, startDate, endDate); } private static string[] getSignedTickersArray( ICollection signedTickers ) { --- 197,260 ---- /// <param name="startDate">Start date for the period for which return has to be computed</param> /// <param name="endDate">End date for the period for which return has to be computed</param> ! public static double GetCloseToClosePortfolioReturn(string[] signedTickers, ! DateTime startDate, ! DateTime endDate ) ! { ! double[] tickersWeights = new double[signedTickers.Length]; ! for(int i = 0; i<signedTickers.Length; i++) ! tickersWeights[i] = 1.0/signedTickers.Length; ! return GetCloseToClosePortfolioReturn( signedTickers,tickersWeights, startDate, endDate); } + /// <summary> + /// Gets portfolio's return for a given period, for 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="startDate">Start date for the period for which return has to be computed</param> + /// <param name="endDate">End date for the period for which return has to be computed</param> + public static double GetCloseToClosePortfolioReturn( string[] signedTickers , + double[] tickersWeights , + SortedList commonMarketDays ) + { + double returnValue = 0.0; + Quotes[] tickersQuotes = new Quotes[ signedTickers.Length ]; + for( int i = 0 ; i < signedTickers.Length ; i++ ) + { + tickersQuotes[ i ] = + new Quotes( SignedTicker.GetTicker( (string)signedTickers[ i ] ) , + commonMarketDays ); + } + double[] returns = new double[ tickersQuotes[0].Rows.Count ]; + getCloseToClosePortfolioReturn_setReturns( returns , signedTickers , + tickersWeights , tickersQuotes); + for( int i = 0 ; i < returns.Length ; i++ ) + returnValue = (1.0+returnValue) * returns[i]; + + return returnValue; + } + + /// <summary> + /// Gets portfolio's return, for the given tickers, considering only + /// the market days contained in commonMarketDays + /// </summary> + /// <param name="signedTickers"></param> + /// <param name="commonMarketDays"></param> + /// <returns></returns> + public static double GetCloseToClosePortfolioReturn( + string[] signedTickers, + SortedList commonMarketDays ) + { + double[] tickersWeights = new double[signedTickers.Length]; + for(int i = 0; i<signedTickers.Length; i++) + tickersWeights[i] = 1.0/signedTickers.Length; + + return GetCloseToClosePortfolioReturn( + signedTickers , tickersWeights , commonMarketDays ); + } + private static string[] getSignedTickersArray( ICollection signedTickers ) { *************** *** 234,241 **** #region GetCloseToClosePortfolioReturns private static double getCloseToCloseReturn( string ticker , ! DateTime[] datesForReturnComputation , int i ) { ! DateTime previousDate = datesForReturnComputation[ i ]; ! DateTime currentDate = datesForReturnComputation[ i + 1 ]; HistoricalAdjustedQuoteProvider historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); --- 281,289 ---- #region GetCloseToClosePortfolioReturns private static double getCloseToCloseReturn( string ticker , ! SortedList datesForReturnComputation , int i ) { ! DateTime previousDate = (DateTime)datesForReturnComputation.GetByIndex( i ); ! DateTime currentDate = ! (DateTime)datesForReturnComputation.GetByIndex( i + 1 ); HistoricalAdjustedQuoteProvider historicalQuoteProvider = new HistoricalAdjustedQuoteProvider(); *************** *** 255,259 **** } private static double getCloseToClosePortfolioReturn( ! string[] signedTickers , DateTime[] datesForReturnComputation , int i ) { double dailyReturn = 0.0; --- 303,307 ---- } private static double getCloseToClosePortfolioReturn( ! string[] signedTickers , SortedList datesForReturnComputation , int i ) { double dailyReturn = 0.0; *************** *** 266,275 **** } private static double[] getCloseToClosePortfolioReturns( ! string[] signedTickers , DateTime[] datesForReturnComputation ) { // the return for first DateTime cannot be computed so the returned // array will have one element less the datesForReturnComputation double[] closeToClosePortfolioReturns = ! new double[ datesForReturnComputation.Length - 1 ]; for ( int i=0 ; i < closeToClosePortfolioReturns.Length ; i++ ) closeToClosePortfolioReturns[ i ] = getCloseToClosePortfolioReturn( --- 314,323 ---- } private static double[] getCloseToClosePortfolioReturns( ! string[] signedTickers , SortedList datesForReturnComputation ) { // the return for first DateTime cannot be computed so the returned // array will have one element less the datesForReturnComputation double[] closeToClosePortfolioReturns = ! new double[ datesForReturnComputation.Count - 1 ]; for ( int i=0 ; i < closeToClosePortfolioReturns.Length ; i++ ) closeToClosePortfolioReturns[ i ] = getCloseToClosePortfolioReturn( *************** *** 277,280 **** --- 325,336 ---- return closeToClosePortfolioReturns; } + private static double[] getCloseToClosePortfolioReturns( + ICollection signedTickers, SortedList datesForReturnComputation ) + { + string[] signedTickerArray = + getSignedTickerArray( signedTickers ); + return getCloseToClosePortfolioReturns( signedTickerArray , + datesForReturnComputation ); + } /// <summary> /// Gets portfolio's return for a given period, for given tickers *************** *** 286,295 **** ICollection signedTickers, DateTime firstDate, DateTime lastDate ) { ! string[] signedTickerArray = ! getSignedTickerArray( signedTickers ); ! DateTime[] datesForReturnComputation = Quotes.GetMarketDays( ! GetTicker( signedTickerArray[ 0 ] ), firstDate , lastDate ); ! return getCloseToClosePortfolioReturns( signedTickerArray , ! datesForReturnComputation ); } #endregion --- 342,362 ---- ICollection signedTickers, DateTime firstDate, DateTime lastDate ) { ! SortedList datesForReturnComputation = Quotes.GetCommonMarketDays( ! signedTickers , firstDate , lastDate ); ! return GetCloseToClosePortfolioReturns( ! signedTickers , datesForReturnComputation ); ! } ! /// <summary> ! /// Gets portfolio's return (for given signed tickers) computed on the ! /// market days contained in commonMarketDays ! /// </summary> ! /// <param name="signedTickers"></param> ! /// <param name="commonMarketDays">SortedList of DateTime objects</param> ! /// <returns></returns> ! public static double[] GetCloseToClosePortfolioReturns( ! ICollection signedTickers, SortedList commonMarketDays ) ! { ! return ! getCloseToClosePortfolioReturns( signedTickers , commonMarketDays ); } #endregion |
|
From: Glauco S. <gla...@us...> - 2006-07-22 20:45:17
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagGenomesDebugger In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv5450/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagGenomesDebugger Modified Files: WFLagChosenPositionsDebugInfo.cs Log Message: The following additional information are available now (as public properties, displayed into the debug DataGrid): - InSampleExpectancyScore (self explaining) - MaxPreSampleDays (the max number of days for which the genome can be tested pre sample) - PreSampleMaxSharpeRatio (the sharpe ratio for the MaxPreSampleDays pre sample) - PreSample30SharpeRatio (the sharpe ratio for 150 days pre sample) - PreSample150SharpeRatio (the sharpe ratio for 150 days pre sample) - PostSample30SharpeRatio (the sharpe ratio for 30 days post sample) - PostSample150SharpeRatio (the sharpe ratio for 150 post sample) Furthermore, some methods have been added: - the new static method GetDrivingAndPortfolioTickers( WFLagChosenPositions wFLagChosenPositions ) - the new method GetChosenPositions Index: WFLagChosenPositionsDebugInfo.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagGenomesDebugger/WFLagChosenPositionsDebugInfo.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** WFLagChosenPositionsDebugInfo.cs 29 Jun 2006 17:46:49 -0000 1.2 --- WFLagChosenPositionsDebugInfo.cs 22 Jul 2006 20:45:14 -0000 1.3 *************** *** 22,25 **** --- 22,28 ---- using System; + using System.Collections; + + using QuantProject.Business.Strategies; namespace QuantProject.Scripts.WalkForwardTesting.WalkForwardLag.WFLagDebugger *************** *** 30,38 **** --- 33,47 ---- public class WFLagChosenPositionsDebugInfo { + private double dummyValue; + private int maxPreSampleDays; private WFLagChosenPositions wFLagChosenPositions; private WFLagLog wFLagLog; private double inSampleSharpeRatio; private double preSampleSharpeRatio30; + private double preSampleSharpeRatio150; + private double preSampleMaxSharpeRatio; private double postSampleSharpeRatio30; + private double postSampleSharpeRatio150; + private double inSampleExpectancyScore; public string DrivingPositions *************** *** 56,67 **** get { return this.inSampleSharpeRatio; } } ! public double PreSampleSharpeRatio30 { get { return this.preSampleSharpeRatio30; } } ! public double PostSampleSharpeRatio30 { get { return this.postSampleSharpeRatio30; } } public WFLagChosenPositionsDebugInfo( WFLagChosenPositions wFLagChosenPositions , --- 65,101 ---- get { return this.inSampleSharpeRatio; } } ! public double InSampleExpectancyScore ! { ! get { return this.inSampleExpectancyScore; } ! } ! public int MaxPreSampleDays ! { ! get ! { ! if ( this.maxPreSampleDays == int.MinValue ) ! this.setMaxPreSampleDays(); ! return this.maxPreSampleDays; ! } ! } ! public double PreSample30SharpeRatio { get { return this.preSampleSharpeRatio30; } } ! public double PreSampleMaxSharpeRatio ! { ! get { return this.preSampleMaxSharpeRatio; } ! } ! public double PreSample150SharpeRatio ! { ! get { return this.preSampleSharpeRatio150; } ! } ! public double PostSample30SharpeRatio { get { return this.postSampleSharpeRatio30; } } + public double PostSample150SharpeRatio + { + get { return this.postSampleSharpeRatio150; } + } public WFLagChosenPositionsDebugInfo( WFLagChosenPositions wFLagChosenPositions , *************** *** 71,79 **** --- 105,172 ---- // TODO: Add constructor logic here // + this.dummyValue = -999; + this.wFLagChosenPositions = wFLagChosenPositions; this.wFLagLog = wFLagLog; this.inSampleSharpeRatio = this.getInSampleSharpeRatio(); + this.inSampleExpectancyScore = this.getInSampleExpectancyScore(); + this.setMaxPreSampleDays(); this.preSampleSharpeRatio30 = this.getPreSampleSharpeRatio( 30 ); + this.preSampleSharpeRatio150 = this.getPreSampleSharpeRatio( 150 ); + this.preSampleMaxSharpeRatio = this.getPreSampleSharpeRatio( + this.MaxPreSampleDays ); this.postSampleSharpeRatio30 = this.getPostSampleSharpeRatio( 30 ); + this.postSampleSharpeRatio150 = this.getPostSampleSharpeRatio( 150 ); + } + public static string[] GetDrivingAndPortfolioTickers( + WFLagChosenPositions wFLagChosenPositions ) + { + int size = wFLagChosenPositions.DrivingPositions.Count + + wFLagChosenPositions.PortfolioPositions.Count; + string[] drivingAndPortfolioTickers = new string[ size ]; + int i = 0; + foreach ( string signedTicker in wFLagChosenPositions.DrivingPositions.Keys ) + { + drivingAndPortfolioTickers[ i ] = SignedTicker.GetTicker( signedTicker ); + i++; + } + foreach ( string signedTicker in wFLagChosenPositions.PortfolioPositions.Keys ) + { + drivingAndPortfolioTickers[ i ] = SignedTicker.GetTicker( signedTicker ); + i++; + } + return drivingAndPortfolioTickers; + } + /// <summary> + /// returns the chosen positions. A method is used instead of a property, because + /// we don't want this as a column displayed in the grid + /// </summary> + public WFLagChosenPositions GetChosenPositions() + { + return this.wFLagChosenPositions; + } + private ArrayList getMinDatesForTickers() + { + string[] tickers = GetDrivingAndPortfolioTickers( this.wFLagChosenPositions ); + ArrayList minDatesForTickers = new ArrayList(); + foreach ( string ticker in tickers ) + minDatesForTickers.Add( + QuantProject.Data.DataTables.Quotes.GetFirstQuoteDate( ticker ) ); + return minDatesForTickers; + } + private DateTime getFirstCommonDateForTickers() + { + ArrayList minDatesForTickers = + this.getMinDatesForTickers(); + minDatesForTickers.Sort(); + return (DateTime)minDatesForTickers[ minDatesForTickers.Count - 1 ]; + } + private void setMaxPreSampleDays() + { + DateTime firstCommonDateForTickers = + this.getFirstCommonDateForTickers(); + TimeSpan timeSpan = this.getInSampleFirstDate() - + firstCommonDateForTickers; + this.maxPreSampleDays = timeSpan.Days - 1; // I subtract one, so I have the number of daily returns } private DateTime getInSampleFirstDate() *************** *** 90,100 **** this.LastOptimization ); } ! private double getPreSampleSharpeRatio( int days ) { ! DateTime lastDateTime = this.getInSampleFirstDate(); ! DateTime firstDateTime = lastDateTime.AddDays( -days - 1 ); // I subtract one more day, so I have days daily returns ! return WFLagSharpeRatioComputer.GetSharpeRatio( this.wFLagChosenPositions , firstDateTime , ! lastDateTime ); } private double getPostSampleSharpeRatio( int days ) --- 183,205 ---- this.LastOptimization ); } ! private double getInSampleExpectancyScore() { ! DateTime firstDateTime = this.getInSampleFirstDate(); ! return WFLagSharpeRatioComputer.GetExpectancyScore( this.wFLagChosenPositions , firstDateTime , ! this.LastOptimization ); ! } ! private double getPreSampleSharpeRatio( int days ) ! { ! double preSampleSharpeRatio = this.dummyValue; ! if ( this.MaxPreSampleDays >= days ) ! { ! DateTime lastDateTime = this.getInSampleFirstDate(); ! DateTime firstDateTime = lastDateTime.AddDays( -days - 1 ); // I subtract one more day, so I have days daily returns ! preSampleSharpeRatio = WFLagSharpeRatioComputer.GetSharpeRatio( ! this.wFLagChosenPositions , firstDateTime , ! lastDateTime ); ! } ! return preSampleSharpeRatio; } private double getPostSampleSharpeRatio( int days ) |
|
From: Glauco S. <gla...@us...> - 2006-07-22 20:37:24
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagGenomesDebugger In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv2229/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagGenomesDebugger Modified Files: WFLagDebugChosenPositionsCollection.cs Log Message: - the WFLagDebugChosenPositionsCollection constructor now requires also the number of in sample days, the benchmark and a list of chosen positions debug info - the right click on a single chosen positions debug info data grid row is handled now (the DebugGenome form is invoked, for that exact genome) Index: WFLagDebugChosenPositionsCollection.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagGenomesDebugger/WFLagDebugChosenPositionsCollection.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** WFLagDebugChosenPositionsCollection.cs 22 Jun 2006 20:53:06 -0000 1.1 --- WFLagDebugChosenPositionsCollection.cs 22 Jul 2006 20:37:20 -0000 1.2 *************** *** 40,46 **** private System.ComponentModel.Container components = null; ! private ICollection chosenPositionsCollection; ! public WFLagDebugChosenPositionsCollection( ICollection chosenPositionsCollection ) { // --- 40,49 ---- private System.ComponentModel.Container components = null; ! private ArrayList chosenPositionsDebugInfoList; ! private int inSampleDays; ! string benchmark; ! public WFLagDebugChosenPositionsCollection( int inSampleDays , string benchmark , ! ArrayList chosenPositionsDebugInfoList ) { // *************** *** 52,56 **** // TODO: Add any constructor code after InitializeComponent call // ! this.chosenPositionsCollection = chosenPositionsCollection; this.updateGrid(); } --- 55,62 ---- // TODO: Add any constructor code after InitializeComponent call // ! this.inSampleDays = inSampleDays; ! this.benchmark = benchmark; ! this.chosenPositionsDebugInfoList = chosenPositionsDebugInfoList; ! this.setDataGridTableStyle(); this.updateGrid(); } *************** *** 90,93 **** --- 96,100 ---- this.dataGridChosenPositionsWithAttributes.Size = new System.Drawing.Size(576, 240); this.dataGridChosenPositionsWithAttributes.TabIndex = 0; + this.dataGridChosenPositionsWithAttributes.MouseUp += new System.Windows.Forms.MouseEventHandler(this.dataGridChosenPositionsWithAttributes_MouseUp); // // WFLagDebugChosenPositionsCollection *************** *** 106,115 **** private void updateGrid() { this.dataGridChosenPositionsWithAttributes.DataSource = ! this.chosenPositionsCollection; this.dataGridChosenPositionsWithAttributes.Refresh(); } } } --- 113,172 ---- + private void setDataGridTableStyle() + { + DataGridTableStyle dataGridTableStyle = new DataGridTableStyle( true ); + // DataGridColumnStyle dataGridColumnStyle = new DataGridColumnStyle(); + } private void updateGrid() { this.dataGridChosenPositionsWithAttributes.DataSource = ! this.chosenPositionsDebugInfoList; this.dataGridChosenPositionsWithAttributes.Refresh(); } + + #region DataGridMouseClickEventHandler + private int rightClickEventHandler_getRowNumber( object sender , + MouseEventArgs eventArgs ) + { + DataGrid dataGrid = (DataGrid)sender; + Point point = new Point( eventArgs.X , eventArgs.Y ); + DataGrid.HitTestInfo hitTestInfo = dataGrid.HitTest( point ); + // DataTable dataTable = (DataTable)dataGrid.DataSource; + return hitTestInfo.Row; + } + private WFLagChosenPositions rightClickEventHandler_getWFLagChosenPositions( + DataGrid dataGrid , int rowNumber ) + { + // DataTable dataTable = (DataTable)dataGrid.DataSource; + WFLagChosenPositionsDebugInfo wFLagChosenPositionsDebugInfo = + (WFLagChosenPositionsDebugInfo)(this.chosenPositionsDebugInfoList[ rowNumber ]); + WFLagChosenPositions wFLagChosenPositions = + wFLagChosenPositionsDebugInfo.GetChosenPositions(); + return wFLagChosenPositions; + } + + private WFLagChosenPositions rightClickEventHandler_getWFLagChosenPositions( + object sender, System.Windows.Forms.MouseEventArgs e ) + { + int rowNumber = rightClickEventHandler_getRowNumber( + sender , e ); + WFLagChosenPositions wFLagChosenPositions = + this.rightClickEventHandler_getWFLagChosenPositions( (DataGrid)sender , rowNumber ); + return wFLagChosenPositions; + } + private void rightClickEventHandler(object sender, System.Windows.Forms.MouseEventArgs e) + { + WFLagChosenPositions wFLagChosenPositions = + this.rightClickEventHandler_getWFLagChosenPositions( sender , e ); + WFLagDebugGenome wFLagDebugGenome = new WFLagDebugGenome( wFLagChosenPositions , + this.inSampleDays , this.benchmark ); + wFLagDebugGenome.Show(); + } + private void dataGridChosenPositionsWithAttributes_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) + { + if ( e.Button == MouseButtons.Right ) + this.rightClickEventHandler( sender , e ); + } + #endregion } } |
|
From: Glauco S. <gla...@us...> - 2006-07-22 20:33:07
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv473/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger Modified Files: WFLagReportDebugger.cs Log Message: - the WFLagDebugGenome constructor now requires also the number of in sample days and the benchmark; furthermore, the WFLagChosenPositions are passed instead of a WFLagLog Index: WFLagReportDebugger.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger/WFLagReportDebugger.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** WFLagReportDebugger.cs 14 May 2006 21:14:50 -0000 1.2 --- WFLagReportDebugger.cs 22 Jul 2006 20:33:04 -0000 1.3 *************** *** 91,96 **** this.getRowDateTime( (DataGrid)sender , rowNumber ); WFLagDebugGenome wFLagDebugGenome = ! new WFLagDebugGenome( transactionDateTime , ! this.wFLagLog ); wFLagDebugGenome.Show(); } --- 91,96 ---- this.getRowDateTime( (DataGrid)sender , rowNumber ); WFLagDebugGenome wFLagDebugGenome = ! new WFLagDebugGenome( this.wFLagLog.GetChosenPositions( transactionDateTime ) , ! this.wFLagLog.InSampleDays , this.wFLagLog.Benchmark ); wFLagDebugGenome.Show(); } |
|
From: Glauco S. <gla...@us...> - 2006-07-22 20:32:45
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv32679/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger Modified Files: WFLagDebugGenome.cs Log Message: - the WFLagDebugGenome constructor now requires also the number of in sample days and the benchmark; furthermore, the WFLagChosenPositions are passed instead of a WFLagLog Index: WFLagDebugGenome.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger/WFLagDebugGenome.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** WFLagDebugGenome.cs 22 Jun 2006 21:33:47 -0000 1.2 --- WFLagDebugGenome.cs 22 Jul 2006 20:32:42 -0000 1.3 *************** *** 37,43 **** public class WFLagDebugGenome : System.Windows.Forms.Form { ! DateTime transactionDateTime; ! WFLagLog wFLagLog; WFLagChosenPositions wFLagChosenPositions; private System.Windows.Forms.Button TestPreInSampleAndPost; --- 37,51 ---- public class WFLagDebugGenome : System.Windows.Forms.Form { ! int inSampleDays; ! string benchmark; WFLagChosenPositions wFLagChosenPositions; + + private WFLagChosenPositionsDebugInfo wFLagChosenPositionsDebugInfo; + + public WFLagChosenPositionsDebugInfo WFLagChosenPositionsDebugInfo + { + set { this.wFLagChosenPositionsDebugInfo = value; } + get { return this.wFLagChosenPositionsDebugInfo; } + } private System.Windows.Forms.Button TestPreInSampleAndPost; *************** *** 56,61 **** private System.ComponentModel.Container components = null; ! public WFLagDebugGenome( DateTime transactionDateTime , ! WFLagLog wFLagLog ) { // --- 64,69 ---- private System.ComponentModel.Container components = null; ! public WFLagDebugGenome( WFLagChosenPositions wFLagChosenPositions , ! int inSampleDays , string benchmark ) { // *************** *** 67,72 **** // TODO: Add any constructor code after InitializeComponent call // ! this.transactionDateTime = transactionDateTime; ! this.wFLagLog = wFLagLog; } --- 75,81 ---- // TODO: Add any constructor code after InitializeComponent call // ! this.inSampleDays = inSampleDays; ! this.benchmark = benchmark; ! this.wFLagChosenPositions = wFLagChosenPositions; } *************** *** 208,221 **** #endregion ! private DateTime getInSampleLastDateTime() ! { ! DateTime inSampleLastDateTime = ! this.transactionDateTime.AddDays( - 1 ); ! return inSampleLastDateTime; ! } private DateTime getPreSampleLastDateTime() { DateTime preSampleLastDateTime = ! this.getInSampleLastDateTime().AddDays( -this.wFLagLog.InSampleDays ); return preSampleLastDateTime; } --- 217,230 ---- #endregion ! // private DateTime getInSampleLastDateTime() ! // { ! // DateTime inSampleLastDateTime = ! // this.transactionDateTime.AddDays( - 1 ); ! // return inSampleLastDateTime; ! // } private DateTime getPreSampleLastDateTime() { DateTime preSampleLastDateTime = ! this.wFLagChosenPositions.LastOptimizationDate.AddDays( -this.inSampleDays ); return preSampleLastDateTime; } *************** *** 232,235 **** --- 241,265 ---- return preSampleDays; } + + // private void setChosenPositions_actually() + // { + // if ( this.wFLagChosenPositionsDebugInfo != null ) + // { + // // the form was given a valid WFLagChosenPositionsDebugInfo object + // this.wFLagChosenPositions = this.wFLagChosenPositionsDebugInfo.GetChosenPositions(); + // } + // else + // { + // // the form was given a valid WFLagLog object + // this.wFLagChosenPositions = this.wflagl + // } + // } + // private void setChosenPositions() + // { + // if ( this.wFLagChosenPositions == null ) + // { + // this.setChosenPositions_actually(); + // } + // } private void run( DateTime inSampleLastDateTime , int preSampleDays , int inSampleDays , int postSampleDays ) *************** *** 242,259 **** inSampleLastDateTime , preSampleDays , inSampleDays , postSampleDays , ! this.wFLagLog.Benchmark ); wFLagDebugPositions.Run(); } private void TestPreInSampleAndPost_Click(object sender, System.EventArgs e) { - WFLagChosenPositions wFLagChosenPositions = - this.wFLagLog.GetChosenPositions( - this.transactionDateTime ); WFLagDebugPositions wFLagDebugPositions = ! new WFLagDebugPositions( wFLagChosenPositions , ! this.transactionDateTime.AddDays( - 1 ) , 30 , ! this.wFLagLog.InSampleDays , Convert.ToInt32( this.PostSampleDays.Text ) , ! this.wFLagLog.Benchmark ); wFLagDebugPositions.Run(); } --- 272,286 ---- inSampleLastDateTime , preSampleDays , inSampleDays , postSampleDays , ! this.benchmark ); wFLagDebugPositions.Run(); } private void TestPreInSampleAndPost_Click(object sender, System.EventArgs e) { WFLagDebugPositions wFLagDebugPositions = ! new WFLagDebugPositions( this.wFLagChosenPositions , ! this.wFLagChosenPositions.LastOptimizationDate , 30 , ! this.inSampleDays , Convert.ToInt32( this.PostSampleDays.Text ) , ! this.benchmark ); wFLagDebugPositions.Run(); } *************** *** 261,277 **** private void TestInSample_Click(object sender, System.EventArgs e) { - WFLagChosenPositions wFLagChosenPositions = - this.wFLagLog.GetChosenPositions( - this.transactionDateTime ); WFLagDebugPositions wFLagDebugPositions = ! new WFLagDebugPositions( wFLagChosenPositions , ! this.transactionDateTime.AddDays( - 1 ) , 0 , ! this.wFLagLog.InSampleDays , 0 , ! this.wFLagLog.Benchmark ); wFLagDebugPositions.Run(); } private void TestPostSample_Click(object sender, System.EventArgs e) { ! this.run( this.getInSampleLastDateTime() , 0 , 0 , this.getPostSampleDays() ); } --- 288,301 ---- private void TestInSample_Click(object sender, System.EventArgs e) { WFLagDebugPositions wFLagDebugPositions = ! new WFLagDebugPositions( this.wFLagChosenPositions , ! this.wFLagChosenPositions.LastOptimizationDate , 0 , ! this.inSampleDays , 0 , ! this.benchmark ); wFLagDebugPositions.Run(); } private void TestPostSample_Click(object sender, System.EventArgs e) { ! this.run( this.wFLagChosenPositions.LastOptimizationDate , 0 , 0 , this.getPostSampleDays() ); } *************** *** 294,300 **** private void WFLagDebugGenome_Load(object sender, System.EventArgs e) { - this.wFLagChosenPositions = - this.wFLagLog.GetChosenPositions( - this.transactionDateTime ); this.labelDrivingPositionsContent.Text = this.wFLagChosenPositions.DrivingPositions.KeyConcat; --- 318,321 ---- |
|
From: Glauco S. <gla...@us...> - 2006-07-22 20:29:06
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagGenomesDebugger In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv31045/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagGenomesDebugger Modified Files: WFLagRunGenomesDebugger.cs Log Message: - the WFLagDebugChosenPositionsCollection constructor now requires also the number of in sample days and the benchmark Index: WFLagRunGenomesDebugger.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagGenomesDebugger/WFLagRunGenomesDebugger.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** WFLagRunGenomesDebugger.cs 29 Jun 2006 17:42:32 -0000 1.3 --- WFLagRunGenomesDebugger.cs 22 Jul 2006 20:29:01 -0000 1.4 *************** *** 83,88 **** { WFLagDebugChosenPositionsCollection wFLagDebugChosenPositionsCollection = ! new WFLagDebugChosenPositionsCollection( this.chosenPositionsDebugInfoList ); ! wFLagDebugChosenPositionsCollection.ShowDialog(); } public void Run( WFLagLog wFLagLog ) --- 83,89 ---- { WFLagDebugChosenPositionsCollection wFLagDebugChosenPositionsCollection = ! new WFLagDebugChosenPositionsCollection( this.wFLagLog.InSampleDays , ! this.wFLagLog.Benchmark , this.chosenPositionsDebugInfoList ); ! wFLagDebugChosenPositionsCollection.Show(); } public void Run( WFLagLog wFLagLog ) |
|
From: Glauco S. <gla...@us...> - 2006-07-22 20:25:12
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagGenomesDebugger In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv29615/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagGenomesDebugger Modified Files: WFLagSharpeRatioComputer.cs Log Message: - the private static method getCommonMarketDays returns the exact set of common market days, for a set of given tickers - the public static method GetExpectancyScore has been added (I understand the class' name is not appropriate anymore; to be changed in the future) Index: WFLagSharpeRatioComputer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagGenomesDebugger/WFLagSharpeRatioComputer.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** WFLagSharpeRatioComputer.cs 29 Jun 2006 17:00:51 -0000 1.1 --- WFLagSharpeRatioComputer.cs 22 Jul 2006 20:25:06 -0000 1.2 *************** *** 95,110 **** return strategyReturns; } private static double[] getStrategyReturns( WFLagChosenPositions wFLagChosenPositions , DateTime firstDate , DateTime lastDate ) { double[] drivingPositionsReturns = SignedTicker.GetCloseToClosePortfolioReturns( wFLagChosenPositions.DrivingPositions.Keys , ! firstDate , lastDate ); double[] portfolioPositionsReturns = SignedTicker.GetCloseToClosePortfolioReturns( wFLagChosenPositions.PortfolioPositions.Keys , ! firstDate , lastDate ); double[] strategyReturns = getStrategyReturns( drivingPositionsReturns , portfolioPositionsReturns ); --- 95,124 ---- return strategyReturns; } + private static SortedList getCommonMarketDays( + WFLagChosenPositions wFLagChosenPositions , + DateTime firstDate , DateTime lastDate ) + { + string[] tickers = + WFLagChosenPositionsDebugInfo.GetDrivingAndPortfolioTickers( + wFLagChosenPositions ); + SortedList commonMarketDays = + QuantProject.Data.DataTables.Quotes.GetCommonMarketDays( + tickers , firstDate , lastDate ); + return commonMarketDays; + } private static double[] getStrategyReturns( WFLagChosenPositions wFLagChosenPositions , DateTime firstDate , DateTime lastDate ) { + SortedList commonMarketDays = + getCommonMarketDays( wFLagChosenPositions , firstDate , lastDate ); double[] drivingPositionsReturns = SignedTicker.GetCloseToClosePortfolioReturns( wFLagChosenPositions.DrivingPositions.Keys , ! commonMarketDays ); double[] portfolioPositionsReturns = SignedTicker.GetCloseToClosePortfolioReturns( wFLagChosenPositions.PortfolioPositions.Keys , ! commonMarketDays ); double[] strategyReturns = getStrategyReturns( drivingPositionsReturns , portfolioPositionsReturns ); *************** *** 131,134 **** --- 145,167 ---- return sharpeRatio; } + public static double GetExpectancyScore( + WFLagChosenPositions wFLagChosenPositions , + DateTime firstDate , DateTime lastDate ) + { + double expectancyScore = double.MinValue; + try + { + double[] strategyReturns = getStrategyReturns( + wFLagChosenPositions , firstDate , lastDate ); + expectancyScore = + AdvancedFunctions.GetExpectancyScore( strategyReturns ); + } + catch( MissingQuoteException ex ) + { + expectancyScore = double.MinValue; + string dummy = ex.Message; + } + return expectancyScore; + } } } |