quantproject-developers Mailing List for QuantProject (Page 71)
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...> - 2007-08-15 19:26:16
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagBruteForceOptimizableItemManager In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv3876/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagBruteForceOptimizableItemManager Modified Files: WFLagFixedPortfolioBruteForceOptParamManagerWithNormalizedVolatility.cs Log Message: The WeigthedPositions class has been moved from the QuantProject.Scripts.WalkForwardTesting.WalkForwardLag namespace to the QuantProject.Business.Strategies namespace. The WalkForwardTesting\WalkForwardLag\WeightedPositions.cs file has been moved from the b7_scripts project, to a2_Strategies\WeightedPositions.cs, in the b4_business project. Index: WFLagFixedPortfolioBruteForceOptParamManagerWithNormalizedVolatility.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagBruteForceOptimizableItemManager/WFLagFixedPortfolioBruteForceOptParamManagerWithNormalizedVolatility.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** WFLagFixedPortfolioBruteForceOptParamManagerWithNormalizedVolatility.cs 3 Nov 2006 16:37:17 -0000 1.2 --- WFLagFixedPortfolioBruteForceOptParamManagerWithNormalizedVolatility.cs 15 Aug 2007 19:26:12 -0000 1.3 *************** *** 25,28 **** --- 25,29 ---- using QuantProject.ADT.Statistics; + using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.EquityEvaluation; |
|
From: Glauco S. <gla...@us...> - 2007-08-15 19:25:49
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagBruteForceOptimizableItemManager In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv3434/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagBruteForceOptimizableItemManager Modified Files: WFLagFixedPortfolioBruteForceOptimizableParametersManager.cs Log Message: The WeigthedPositions class has been moved from the QuantProject.Scripts.WalkForwardTesting.WalkForwardLag namespace to the QuantProject.Business.Strategies namespace. The WalkForwardTesting\WalkForwardLag\WeightedPositions.cs file has been moved from the b7_scripts project, to a2_Strategies\WeightedPositions.cs, in the b4_business project. Index: WFLagFixedPortfolioBruteForceOptimizableParametersManager.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagBruteForceOptimizableItemManager/WFLagFixedPortfolioBruteForceOptimizableParametersManager.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** WFLagFixedPortfolioBruteForceOptimizableParametersManager.cs 3 Nov 2006 16:36:44 -0000 1.4 --- WFLagFixedPortfolioBruteForceOptimizableParametersManager.cs 15 Aug 2007 19:25:46 -0000 1.5 *************** *** 26,29 **** --- 26,30 ---- using QuantProject.ADT.Optimizing.BruteForce; using QuantProject.ADT.Statistics.Combinatorial; + using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.EquityEvaluation; |
|
From: Glauco S. <gla...@us...> - 2007-08-15 19:25:30
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagBruteForceOptimizableItemManager In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv3376/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagBruteForceOptimizableItemManager Modified Files: WFLagBruteForceOptimizableParametersManager.cs Log Message: The WeigthedPositions class has been moved from the QuantProject.Scripts.WalkForwardTesting.WalkForwardLag namespace to the QuantProject.Business.Strategies namespace. The WalkForwardTesting\WalkForwardLag\WeightedPositions.cs file has been moved from the b7_scripts project, to a2_Strategies\WeightedPositions.cs, in the b4_business project. Index: WFLagBruteForceOptimizableParametersManager.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagBruteForceOptimizableItemManager/WFLagBruteForceOptimizableParametersManager.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** WFLagBruteForceOptimizableParametersManager.cs 3 Nov 2006 16:40:20 -0000 1.3 --- WFLagBruteForceOptimizableParametersManager.cs 15 Aug 2007 19:25:24 -0000 1.4 *************** *** 26,29 **** --- 26,30 ---- using QuantProject.ADT.Optimizing.BruteForce; using QuantProject.ADT.Statistics.Combinatorial; + using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.EquityEvaluation; |
|
From: Glauco S. <gla...@us...> - 2007-08-15 19:25:18
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WeightedPositionsChoosers In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv3325/b7_Scripts/WalkForwardTesting/WalkForwardLag/WeightedPositionsChoosers Modified Files: WFLagBruteForceFixedPortfolioWeightedPositionsChooser.cs Log Message: The WeigthedPositions class has been moved from the QuantProject.Scripts.WalkForwardTesting.WalkForwardLag namespace to the QuantProject.Business.Strategies namespace. The WalkForwardTesting\WalkForwardLag\WeightedPositions.cs file has been moved from the b7_scripts project, to a2_Strategies\WeightedPositions.cs, in the b4_business project. Index: WFLagBruteForceFixedPortfolioWeightedPositionsChooser.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WeightedPositionsChoosers/WFLagBruteForceFixedPortfolioWeightedPositionsChooser.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** WFLagBruteForceFixedPortfolioWeightedPositionsChooser.cs 11 Jun 2007 17:50:01 -0000 1.2 --- WFLagBruteForceFixedPortfolioWeightedPositionsChooser.cs 15 Aug 2007 19:25:11 -0000 1.3 *************** *** 28,32 **** using QuantProject.ADT.Optimizing.BruteForce; //using QuantProject.ADT.Optimizing.Genetic; ! //using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.EquityEvaluation; using QuantProject.Business.Timing; --- 28,32 ---- using QuantProject.ADT.Optimizing.BruteForce; //using QuantProject.ADT.Optimizing.Genetic; ! using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.EquityEvaluation; using QuantProject.Business.Timing; |
|
From: Glauco S. <gla...@us...> - 2007-08-15 19:24:55
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv2918/b7_Scripts/WalkForwardTesting/WalkForwardLag Removed Files: WeightedPositions.cs Log Message: The WeigthedPositions class has been moved from the QuantProject.Scripts.WalkForwardTesting.WalkForwardLag namespace to the QuantProject.Business.Strategies namespace. The WalkForwardTesting\WalkForwardLag\WeightedPositions.cs file has been moved from the b7_scripts project, to a2_Strategies\WeightedPositions.cs, in the b4_business project. --- WeightedPositions.cs DELETED --- |
|
From: Glauco S. <gla...@us...> - 2007-08-15 19:24:29
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv2824/b4_Business/a2_Strategies Added Files: WeightedPositions.cs Log Message: The WeigthedPositions class has been moved from the QuantProject.Scripts.WalkForwardTesting.WalkForwardLag namespace to the QuantProject.Business.Strategies namespace. The WalkForwardTesting\WalkForwardLag\WeightedPositions.cs file has been moved from the b7_scripts project, to a2_Strategies\WeightedPositions.cs, in the b4_business project. --- 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.ADT.Statistics; using QuantProject.Business.DataProviders; using QuantProject.Business.Financial.Accounting; using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.ReturnsManagement; using QuantProject.Business.Timing; using QuantProject.Data.DataTables; 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(); } } private int numberOfLongPositions = int.MaxValue; private int numberOfShortPositions = int.MaxValue; public int NumberOfLongPositions { get { if(this.numberOfLongPositions == int.MaxValue) //that is private field has not been assigned yet { this.numberOfLongPositions = 0; foreach(WeightedPosition weightedPosition in this) if(weightedPosition.IsLong) this.numberOfLongPositions++; } return this.numberOfLongPositions; } } public int NumberOfShortPositions { get { if(this.numberOfShortPositions == int.MaxValue) //that is private field has not been assigned yet { this.numberOfShortPositions = 0; foreach(WeightedPosition weightedPosition in this) if(weightedPosition.IsShort) this.numberOfShortPositions++; } return this.numberOfShortPositions; } } private void weightedPositions_default( 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 ) ); } } public WeightedPositions( double[] normalizedWeightValues , string[] tickers ) { this.weightedPositions_default( normalizedWeightValues, tickers ); } public WeightedPositions( double[] normalizedUnsignedWeightValues, SignedTickers signedTickers ) { string[] unsignedTickers = new string [ signedTickers.Count ]; double[] normalizedSignedWeightValues = new double[ normalizedUnsignedWeightValues.Length ]; for(int i = 0; i < signedTickers.Count; i++) { unsignedTickers[i] = signedTickers[i].Ticker; normalizedSignedWeightValues[i] = signedTickers[i].Multiplier * normalizedUnsignedWeightValues[i]; } this.weightedPositions_default(normalizedSignedWeightValues, unsignedTickers); } #region checkParameters private void checkParameters_checkDoubleTickers( string[] tickers ) { SortedList sortedTicker = new SortedList(); foreach ( string ticker in tickers ) if ( !sortedTicker.ContainsKey( ticker ) ) sortedTicker.Add( ticker , ticker ); else throw new Exception( "The WeightedPositions constructur " + "has received a tickers parameter with the ticker '" + ticker + "' that is contained twice! This is not allowed." ); } 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() ); this.checkParameters_checkDoubleTickers( tickers ); } #endregion public WeightedPosition GetWeightedPosition( string ticker ) { return (WeightedPosition)this[ ticker ]; } public WeightedPosition GetWeightedPosition( int i ) { return (WeightedPosition)this.GetByIndex( i ); } public WeightedPosition this[ int index ] { get { return (WeightedPosition)this.GetByIndex( index ); } set { this.SetByIndex( index, value ); } } #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 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 /// <summary> /// It controls if a WeightedPositions class may be build on the /// given tickers /// </summary> /// <param name="tickers"></param> /// <returns></returns> public static bool AreValidTickers( string[] tickers ) { return !QuantProject.ADT.Collections.CollectionManager.ContainsDuplicates( tickers ); } #region GetNormalizedWeights private static double getAbsoluteWeightSum( double[] nonNormalizedWeights ) { double absoluteWeightSum = 0; foreach ( double nonNormalizedWeight in nonNormalizedWeights ) absoluteWeightSum += Math.Abs( nonNormalizedWeight ); return absoluteWeightSum; } private static double getNormalizingFactor( double[] nonNormalizedWeights ) { double absoluteWeightSum = getAbsoluteWeightSum( nonNormalizedWeights ); double normalizingFactor = 1 / absoluteWeightSum; return normalizingFactor; } private static double[] getNormalizedWeights( double[] nonNormalizedWeights , double normalizingFactor ) { double[] normalizedWeights = new double[ nonNormalizedWeights.Length ]; for ( int i = 0 ; i < nonNormalizedWeights.Length ; i ++ ) normalizedWeights[ i ] = nonNormalizedWeights[ i ] * normalizingFactor; return normalizedWeights; } /// <summary> /// Returns weights whose absolute values sum up to 1 /// </summary> /// <param name="nonNormalizedWeights"></param> /// <returns></returns> /// public static double[] GetNormalizedWeights( double[] nonNormalizedWeights ) { double normalizingFactor = getNormalizingFactor( nonNormalizedWeights ); return getNormalizedWeights( nonNormalizedWeights , normalizingFactor ); } #endregion #region GetBalancedWeights private static float[][] getTickerCloseToCloseReturnsForSignedTickers( string[] signedTickers , DateTime firstDate , DateTime lastDate ) { float[][] tickerReturns = new float[ signedTickers.Length ][]; for ( int i = 0 ; i < signedTickers.Length ; i++ ) { string ticker = SignedTicker.GetTicker( signedTickers[ i ] ); tickerReturns[ i ] = Quotes.GetArrayOfCloseToCloseRatios( ticker , firstDate , lastDate ); } return tickerReturns; } private static float getTickerReturnsStandardDeviations( int tickerIndex , SignedTickers signedTickers , ReturnsManager returnsManager ) { string ticker = signedTickers[ tickerIndex ].Ticker; return returnsManager.GetReturnsStandardDeviation( ticker ); } private static float[] getTickersReturnsStandardDeviations( SignedTickers signedTickers , ReturnsManager returnsManager ) { float[] tickersReturnsStandardDeviations = new float[ signedTickers.Count ]; for ( int i = 0 ; i < signedTickers.Count ; i++ ) tickersReturnsStandardDeviations[ i ] = getTickerReturnsStandardDeviations( i , signedTickers , returnsManager ); return tickersReturnsStandardDeviations; } private static double getNonNormalizedWeightsButBalancedForVolatility( float[] standardDeviations , float maxStandardDeviation , int i ) { return maxStandardDeviation / standardDeviations[ i ]; } private static double[] getNonNormalizedWeightsButBalancedForVolatility( float[] standardDeviations , float maxStandardDeviation ) { double[] nonNormalizedWeightsButBalancedForVolatility = new double[ standardDeviations.Length ]; for ( int i = 0 ; i < standardDeviations.Length ; i++ ) nonNormalizedWeightsButBalancedForVolatility[ i ] = getNonNormalizedWeightsButBalancedForVolatility( standardDeviations , maxStandardDeviation , i ); return nonNormalizedWeightsButBalancedForVolatility; } private static double[] getNonNormalizedWeightsButBalancedForVolatility( float[] standardDeviations ) { float maxStandardDeviation = (float)BasicFunctions.GetMax( standardDeviations ); return getNonNormalizedWeightsButBalancedForVolatility( standardDeviations , maxStandardDeviation ); } private static double[] getUnsignedNormalizedBalancedWeights( SignedTickers signedTickers , ReturnsManager returnManager ) { float[] standardDeviations = getTickersReturnsStandardDeviations( signedTickers , returnManager ); double[] nonNormalizedButBalancedWeights = getNonNormalizedWeightsButBalancedForVolatility( standardDeviations ); double[] normalizedBalancedWeights = GetNormalizedWeights( nonNormalizedButBalancedWeights ); return normalizedBalancedWeights; } private static double[] getSignedNormalizedBalancedWeights( double[] multipliers , double[] unsignedNormalizedBalancedWeights ) { double[] signedNormalizedBalancedWeights = new double[ unsignedNormalizedBalancedWeights.Length ]; for( int i = 0 ; i < unsignedNormalizedBalancedWeights.Length ; i++ ) signedNormalizedBalancedWeights[ i ] = multipliers[ i ] * unsignedNormalizedBalancedWeights[ i ]; return signedNormalizedBalancedWeights; } private static double[] getSignedNormalizedBalancedWeights( SignedTickers signedTickers , double[] unsignedNormalizedBalancedWeights ) { double[] multipliers = signedTickers.Multipliers; double[] signedNormalizedBalancedWeights = getSignedNormalizedBalancedWeights( multipliers , unsignedNormalizedBalancedWeights ); return signedNormalizedBalancedWeights; } /// <summary> /// Returns weights balanced with respect to the close to close volatility, /// in the given period /// (the most volatile ticker is given the lighter weight) /// </summary> /// <param name="signedTickers"></param> /// <returns></returns> public static double[] GetBalancedWeights( SignedTickers signedTickers , ReturnsManager returnManager ) { double[] unsignedNormalizedBalancedWeights = getUnsignedNormalizedBalancedWeights( signedTickers , returnManager ); double[] balancedWeights = getSignedNormalizedBalancedWeights( signedTickers , unsignedNormalizedBalancedWeights ); return balancedWeights; } #endregion //GetBalancedWeights #region GetReturn private void getReturnCheckParameters( int i , ReturnsManager returnsManager ) { if ( ( i < 0 ) || ( i > returnsManager.TimeLine.Count - 2 ) ) throw new Exception( "i is larger than the number of returns" ); } private float getTickerReturn( string ticker , int i , ReturnsManager returnsManager ) { return returnsManager.GetReturn( ticker , i ); } private float getReturnActually( WeightedPosition weightedPosition , int i , ReturnsManager returnsManager ) { float tickerReturn = this.getTickerReturn( weightedPosition.Ticker , i , returnsManager ); return tickerReturn * Convert.ToSingle( weightedPosition.Weight ); // 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 ); // Aggiungi!!! weightedPositions.GetReturns( this.closeToCloseReturnsManager ) // 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 float getReturnActually( int i , ReturnsManager returnsManager ) { float linearCombinationReturn = 0; foreach ( WeightedPosition weightedPosition in this.Values ) linearCombinationReturn += this.getReturnActually( weightedPosition , i , returnsManager ); return linearCombinationReturn; } /// <summary> /// returns the i_th return of the sum of the weighted positions /// </summary> /// <param name="i"></param> /// <param name="returnsManager">used to efficiently store /// ticker returns</param> /// <returns></returns> public float GetReturn( int i , ReturnsManager returnsManager ) { this.getReturnCheckParameters( i , returnsManager ); return getReturnActually( i , returnsManager ); } #endregion GetReturn /// <summary> /// Computes an array of floats representing the returns /// of all weighted position /// </summary> /// <param name="returnsManager"></param> /// <returns></returns> public float[] GetReturns( ReturnsManager returnsManager ) { float[] returns = new float[ returnsManager.TimeLine.Count - 1 ]; for ( int i = 0 ; i < returnsManager.NumberOfReturns ; i++ ) returns[ i ] = this.GetReturn( i , returnsManager ); return returns; } /// <summary> /// Gets the Open To Close return for the current instance of WeightedPositions /// </summary> /// <param name="marketDate">Market date for which return has to be computed</param> public double GetOpenToCloseReturn(DateTime marketDate) { Quotes[] tickersQuotes = new Quotes[this.Count]; for(int i = 0; i<this.Count; i++) tickersQuotes[i] = new Quotes( this[i].Ticker,marketDate,marketDate ); double openToCloseReturn = 0.0; for(int i = 0; i < this.Count ; i++) openToCloseReturn += ( (float)tickersQuotes[i].Rows[0]["quClose"] / (float)tickersQuotes[i].Rows[0]["quOpen"] - 1.0f ) * (float)this[i].Weight; return openToCloseReturn; } /// <summary> /// Reverse the sign of each weight for each position in the current instance: /// long positions become then short positions and viceversa /// </summary> public void Reverse() { foreach(WeightedPosition weightedPosition in this) weightedPosition.Weight = - weightedPosition.Weight; } } } |
|
From: Glauco S. <gla...@us...> - 2007-08-15 19:23:57
|
Update of /cvsroot/quantproject/QuantProject/b4_Business In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv2315/b4_Business Modified Files: b4_Business.csproj Log Message: The WeigthedPositions class has been moved from the QuantProject.Scripts.WalkForwardTesting.WalkForwardLag namespace to the QuantProject.Business.Strategies namespace. The WalkForwardTesting\WalkForwardLag\WeightedPositions.cs file has been moved from the b7_scripts project, to a2_Strategies\WeightedPositions.cs, in the b4_business project. Index: b4_Business.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/b4_Business.csproj,v retrieving revision 1.44 retrieving revision 1.45 diff -C2 -d -r1.44 -r1.45 *** b4_Business.csproj 14 Aug 2007 14:49:03 -0000 1.44 --- b4_Business.csproj 15 Aug 2007 19:23:52 -0000 1.45 *************** *** 633,636 **** --- 633,641 ---- /> <File + RelPath = "a2_Strategies\WeightedPositions.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "a2_Strategies\EquityEvaluation\ExpectancyScore.cs" SubType = "Code" |
|
From: Glauco S. <gla...@us...> - 2007-08-15 19:23:39
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv2250/b7_Scripts Modified Files: b7_Scripts.csproj Log Message: The WeigthedPositions class has been moved from the QuantProject.Scripts.WalkForwardTesting.WalkForwardLag namespace to the QuantProject.Business.Strategies namespace. The WalkForwardTesting\WalkForwardLag\WeightedPositions.cs file has been moved from the b7_scripts project, to a2_Strategies\WeightedPositions.cs, in the b4_business project. Index: b7_Scripts.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/b7_Scripts.csproj,v retrieving revision 1.74 retrieving revision 1.75 diff -C2 -d -r1.74 -r1.75 *** b7_Scripts.csproj 24 Jun 2007 21:21:33 -0000 1.74 --- b7_Scripts.csproj 15 Aug 2007 19:23:31 -0000 1.75 *************** *** 734,742 **** /> <File - RelPath = "WalkForwardTesting\WalkForwardLag\WeightedPositions.cs" - SubType = "Code" - BuildAction = "Compile" - /> - <File RelPath = "WalkForwardTesting\WalkForwardLag\WFLagCandidates.cs" SubType = "Code" --- 734,737 ---- |
|
From: Marco M. <mi...@us...> - 2007-08-15 14:25:32
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv32004/WalkForwardTesting/WalkForwardLag Modified Files: WeightedPositions.cs Log Message: Added Reverse method, for reversing sign of weights in the weighted position collection. Now the file must be moved to the Business project (I will not modify the file until then). Index: WeightedPositions.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WeightedPositions.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** WeightedPositions.cs 12 Aug 2007 19:09:41 -0000 1.9 --- WeightedPositions.cs 15 Aug 2007 14:25:24 -0000 1.10 *************** *** 561,564 **** --- 561,573 ---- return openToCloseReturn; } + /// <summary> + /// Reverse the sign of each weight for each position in the current instance: + /// long positions become then short positions and viceversa + /// </summary> + public void Reverse() + { + foreach(WeightedPosition weightedPosition in this) + weightedPosition.Weight = - weightedPosition.Weight; + } } } |
|
From: Glauco S. <gla...@us...> - 2007-08-14 14:52:53
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv12871/b7_Scripts/WalkForwardTesting/WalkForwardLag Modified Files: WFLagMain.cs Log Message: The ExpectancyScore equity evaluator is invoked, in this revision Index: WFLagMain.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagMain.cs,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** WFLagMain.cs 11 Aug 2007 20:00:46 -0000 1.11 --- WFLagMain.cs 14 Aug 2007 14:52:49 -0000 1.12 *************** *** 152,155 **** --- 152,160 ---- new QuantProject.Business.Strategies.EquityEvaluation.SharpeRatio() , 10000 , 30 ); + wFLagWeightedPositionsChooser = + new WFLagGeneticFixedPortfolioWithNormalDrivingAndPortfolio( + 4 , new SignedTickers( "IWM;-SPY" ) , 100 , "EWQ" , + new QuantProject.Business.Strategies.EquityEvaluation.ExpectancyScore() , + 10000 , 30 ); new RunWalkForwardLag( "DrvPstns" , 200 , wFLagWeightedPositionsChooser , 7 , |
|
From: Glauco S. <gla...@us...> - 2007-08-14 14:51:08
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/EquityEvaluation In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv12045/b4_Business/a2_Strategies/EquityEvaluation Modified Files: SharpeRatio.cs Log Message: Minor change: the file name in the copyright claim has been fixed Index: SharpeRatio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/EquityEvaluation/SharpeRatio.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SharpeRatio.cs 11 Aug 2007 19:58:43 -0000 1.1 --- SharpeRatio.cs 14 Aug 2007 14:51:01 -0000 1.2 *************** *** 3,7 **** QuantProject - Quantitative Finance Library ! WinningPeriods.cs Copyright (C) 2006 Glauco Siliprandi --- 3,7 ---- QuantProject - Quantitative Finance Library ! SharpeRatio.cs Copyright (C) 2006 Glauco Siliprandi |
|
From: Glauco S. <gla...@us...> - 2007-08-14 14:49:07
|
Update of /cvsroot/quantproject/QuantProject/b4_Business In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv11193/b4_Business Modified Files: b4_Business.csproj Log Message: a2_Strategies\EquityEvaluation\ExpectancyScore.cs has been added Index: b4_Business.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/b4_Business.csproj,v retrieving revision 1.43 retrieving revision 1.44 diff -C2 -d -r1.43 -r1.44 *** b4_Business.csproj 11 Aug 2007 19:59:19 -0000 1.43 --- b4_Business.csproj 14 Aug 2007 14:49:03 -0000 1.44 *************** *** 633,636 **** --- 633,641 ---- /> <File + RelPath = "a2_Strategies\EquityEvaluation\ExpectancyScore.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "a2_Strategies\EquityEvaluation\IEquityEvaluator.cs" SubType = "Code" |
|
From: Glauco S. <gla...@us...> - 2007-08-14 14:48:24
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Statistics In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv11034/b1_ADT/Statistics Modified Files: AdvancedFunctions.cs Log Message: Fixed bug for non double collections Index: AdvancedFunctions.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Statistics/AdvancedFunctions.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** AdvancedFunctions.cs 1 Jun 2006 23:33:23 -0000 1.3 --- AdvancedFunctions.cs 14 Aug 2007 14:48:19 -0000 1.4 *************** *** 136,141 **** double probabilityOfWinning; double probabilityOfLosing; ! foreach ( double singleReturn in returns ) { if ( singleReturn > 0 ) { --- 136,142 ---- double probabilityOfWinning; double probabilityOfLosing; ! foreach ( object numericSingleReturn in returns ) { + double singleReturn = Convert.ToDouble( numericSingleReturn ); if ( singleReturn > 0 ) { |
|
From: Glauco S. <gla...@us...> - 2007-08-14 14:47:13
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/EquityEvaluation In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv10131/b4_Business/a2_Strategies/EquityEvaluation Added Files: ExpectancyScore.cs Log Message: Equity line evaluator, measuring the risk to reward Expectancy Score --- NEW FILE: ExpectancyScore.cs --- /* QuantProject - Quantitative Finance Library ExpectancyScore.cs Copyright (C) 2006 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.ADT.Statistics; namespace QuantProject.Business.Strategies.EquityEvaluation { /// <summary> /// Equity line evaluator, measuring the /// risk to reward Expectancy Score /// </summary> public class ExpectancyScore : IEquityEvaluator { public ExpectancyScore() { // // TODO: Add constructor logic here // } public float GetReturnsEvaluation( float[] returns ) { return Convert.ToSingle( AdvancedFunctions.GetExpectancyScore( returns ) ); } } } |
|
From: Marco M. <mi...@us...> - 2007-08-12 19:09:47
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv19348/b7_Scripts/WalkForwardTesting/WalkForwardLag Modified Files: WeightedPositions.cs Log Message: Added the Indexer construct, for an array-like access to the WeightedPositions' items. Added GetOpenToCloseReturn method. Index: WeightedPositions.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WeightedPositions.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** WeightedPositions.cs 8 Aug 2007 18:31:35 -0000 1.8 --- WeightedPositions.cs 12 Aug 2007 19:09:41 -0000 1.9 *************** *** 153,156 **** --- 153,168 ---- return (WeightedPosition)this.GetByIndex( i ); } + public WeightedPosition this[ int index ] + { + get + { + return (WeightedPosition)this.GetByIndex( index ); + } + set + { + this.SetByIndex( index, value ); + } + } + #region GetEquityLine /// <summary> *************** *** 532,535 **** --- 544,564 ---- return returns; } + /// <summary> + /// Gets the Open To Close return for the current instance of WeightedPositions + /// </summary> + /// <param name="marketDate">Market date for which return has to be computed</param> + public double GetOpenToCloseReturn(DateTime marketDate) + { + Quotes[] tickersQuotes = new Quotes[this.Count]; + for(int i = 0; i<this.Count; i++) + tickersQuotes[i] = new Quotes( this[i].Ticker,marketDate,marketDate ); + double openToCloseReturn = 0.0; + for(int i = 0; i < this.Count ; i++) + openToCloseReturn += + ( (float)tickersQuotes[i].Rows[0]["quClose"] / + (float)tickersQuotes[i].Rows[0]["quOpen"] - 1.0f ) * + (float)this[i].Weight; + return openToCloseReturn; + } } } |
|
From: Glauco S. <gla...@us...> - 2007-08-11 20:00:54
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv31554/b7_Scripts/WalkForwardTesting/WalkForwardLag Modified Files: WFLagMain.cs Log Message: The SharpeRatio equity evaluator is invoked, in this revision Index: WFLagMain.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagMain.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** WFLagMain.cs 7 Aug 2007 16:56:01 -0000 1.10 --- WFLagMain.cs 11 Aug 2007 20:00:46 -0000 1.11 *************** *** 147,150 **** --- 147,155 ---- new QuantProject.Business.Strategies.EquityEvaluation.WinningPeriods() , 10000 , 30 ); + wFLagWeightedPositionsChooser = + new WFLagGeneticFixedPortfolioWithNormalDrivingAndPortfolio( + 4 , new SignedTickers( "IWM;-SPY" ) , 100 , "EWQ" , + new QuantProject.Business.Strategies.EquityEvaluation.SharpeRatio() , + 10000 , 30 ); new RunWalkForwardLag( "DrvPstns" , 200 , wFLagWeightedPositionsChooser , 7 , |
|
From: Glauco S. <gla...@us...> - 2007-08-11 19:59:24
|
Update of /cvsroot/quantproject/QuantProject/b4_Business In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv31063/b4_Business Modified Files: b4_Business.csproj Log Message: a2_Strategies\EquityEvaluation\SharpeRatio.cs has been added Index: b4_Business.csproj =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b4_Business/b4_Business.csproj,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** b4_Business.csproj 7 Aug 2007 16:39:56 -0000 1.42 --- b4_Business.csproj 11 Aug 2007 19:59:19 -0000 1.43 *************** *** 638,641 **** --- 638,646 ---- /> <File + RelPath = "a2_Strategies\EquityEvaluation\SharpeRatio.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "a2_Strategies\EquityEvaluation\WinningPeriods.cs" SubType = "Code" |
|
From: Glauco S. <gla...@us...> - 2007-08-11 19:58:50
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/EquityEvaluation In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv31025/b4_Business/a2_Strategies/EquityEvaluation Added Files: SharpeRatio.cs Log Message: Equity line evaluator, measuring the well known risk to reward Sharpe Ratio --- NEW FILE: SharpeRatio.cs --- /* QuantProject - Quantitative Finance Library WinningPeriods.cs Copyright (C) 2006 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.ADT.Statistics; namespace QuantProject.Business.Strategies.EquityEvaluation { /// <summary> /// Equity line evaluator, measuring the well known /// risk to reward Sharpe Ratio /// </summary> public class SharpeRatio : IEquityEvaluator { public SharpeRatio() { // // TODO: Add constructor logic here // } public float GetReturnsEvaluation( float[] returns ) { return Convert.ToSingle( AdvancedFunctions.GetSharpeRatio( returns ) ); } } } |
|
From: Marco M. <mi...@us...> - 2007-08-08 18:31:44
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv23216/b7_Scripts/WalkForwardTesting/WalkForwardLag Modified Files: WeightedPositions.cs Log Message: A new constructor has been added. Added new properties (NumberOfLongPositions and NumberOfShortPositions). Other minor changes. Index: WeightedPositions.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WeightedPositions.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** WeightedPositions.cs 7 Aug 2007 16:51:44 -0000 1.7 --- WeightedPositions.cs 8 Aug 2007 18:31:35 -0000 1.8 *************** *** 48,52 **** get { return getType(); } } ! public WeightedPositions( double[] normalizedWeightValues , string[] tickers ) { --- 48,85 ---- get { return getType(); } } ! ! private int numberOfLongPositions = int.MaxValue; ! private int numberOfShortPositions = int.MaxValue; ! ! public int NumberOfLongPositions { ! get { ! if(this.numberOfLongPositions == int.MaxValue) ! //that is private field has not been assigned yet ! { ! this.numberOfLongPositions = 0; ! foreach(WeightedPosition weightedPosition in this) ! if(weightedPosition.IsLong) ! this.numberOfLongPositions++; ! } ! return this.numberOfLongPositions; ! } ! } ! ! public int NumberOfShortPositions { ! get { ! if(this.numberOfShortPositions == int.MaxValue) ! //that is private field has not been assigned yet ! { ! this.numberOfShortPositions = 0; ! foreach(WeightedPosition weightedPosition in this) ! if(weightedPosition.IsShort) ! this.numberOfShortPositions++; ! } ! return this.numberOfShortPositions; ! } ! } ! ! ! private void weightedPositions_default( double[] normalizedWeightValues , string[] tickers ) { *************** *** 58,65 **** if ( !this.ContainsKey( ticker ) ) this.Add( ticker , new WeightedPosition( weight , ticker ) ); - else - ((WeightedPosition)this[ ticker ]).Weight += weight; } } #region checkParameters private void checkParameters_checkDoubleTickers( string[] tickers ) --- 91,120 ---- if ( !this.ContainsKey( ticker ) ) this.Add( ticker , new WeightedPosition( weight , ticker ) ); } } + + public WeightedPositions( double[] normalizedWeightValues , + string[] tickers ) + { + this.weightedPositions_default( normalizedWeightValues, + tickers ); + } + + public WeightedPositions( double[] normalizedUnsignedWeightValues, + SignedTickers signedTickers ) + { + string[] unsignedTickers = new string [ signedTickers.Count ]; + double[] normalizedSignedWeightValues = + new double[ normalizedUnsignedWeightValues.Length ]; + for(int i = 0; i < signedTickers.Count; i++) + { + unsignedTickers[i] = signedTickers[i].Ticker; + normalizedSignedWeightValues[i] = + signedTickers[i].Multiplier * normalizedUnsignedWeightValues[i]; + } + this.weightedPositions_default(normalizedSignedWeightValues, + unsignedTickers); + } + #region checkParameters private void checkParameters_checkDoubleTickers( string[] tickers ) |
|
From: Glauco S. <gla...@us...> - 2007-08-07 16:56:09
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv24466/b7_Scripts/WalkForwardTesting/WalkForwardLag Modified Files: WFLagMain.cs Log Message: SignedTickers class is now used, instead of string arrays Index: WFLagMain.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagMain.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** WFLagMain.cs 24 Jun 2007 21:36:59 -0000 1.9 --- WFLagMain.cs 7 Aug 2007 16:56:01 -0000 1.10 *************** *** 27,30 **** --- 27,31 ---- using System.Windows.Forms; + using QuantProject.Business.Strategies; using QuantProject.Presentation; using QuantProject.Scripts.WalkForwardTesting.WalkForwardLag.WeightedPositionsChoosers; *************** *** 143,153 **** wFLagWeightedPositionsChooser = new WFLagGeneticFixedPortfolioWithNormalDrivingAndPortfolio( ! 4 , new string[]{ "IWM" , "-SPY" } , 100 , "EWQ" , new QuantProject.Business.Strategies.EquityEvaluation.WinningPeriods() , ! 1000 , 15 ); new RunWalkForwardLag( "DrvPstns" , 200 , ! wFLagWeightedPositionsChooser , 13 , new DateTime( 2001 , 1 , 1 ) , ! new DateTime( 2001 , 1 , 8 ) , 0.5 ).Run(); --- 144,154 ---- wFLagWeightedPositionsChooser = new WFLagGeneticFixedPortfolioWithNormalDrivingAndPortfolio( ! 4 , new SignedTickers( "IWM;-SPY" ) , 100 , "EWQ" , new QuantProject.Business.Strategies.EquityEvaluation.WinningPeriods() , ! 10000 , 30 ); new RunWalkForwardLag( "DrvPstns" , 200 , ! wFLagWeightedPositionsChooser , 7 , new DateTime( 2001 , 1 , 1 ) , ! new DateTime( 2001 , 1 , 19 ) , 0.5 ).Run(); |
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WeightedPositionsChoosers/WFLagGeneticFixedPortfolioWithNormalDrivingAndPortfolio In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv24417/b7_Scripts/WalkForwardTesting/WalkForwardLag/WeightedPositionsChoosers/WFLagGeneticFixedPortfolioWithNormalDrivingAndPortfolio Modified Files: WFLagGenomeManagerForFixedPortfolioWithNormalDrivingAndPortfolio.cs Log Message: SignedTickers and SignedTicker classes are now used, instead of plain text strings Index: WFLagGenomeManagerForFixedPortfolioWithNormalDrivingAndPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WeightedPositionsChoosers/WFLagGeneticFixedPortfolioWithNormalDrivingAndPortfolio/WFLagGenomeManagerForFixedPortfolioWithNormalDrivingAndPortfolio.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** WFLagGenomeManagerForFixedPortfolioWithNormalDrivingAndPortfolio.cs 13 Jul 2007 10:16:59 -0000 1.3 --- WFLagGenomeManagerForFixedPortfolioWithNormalDrivingAndPortfolio.cs 7 Aug 2007 16:55:22 -0000 1.4 *************** *** 46,50 **** { private int numberOfDrivingPositions; ! private string[] portfolioSignedTickers; private History timeLineForOptimization; // this time line goes from // the first optimization date for driving positions to the --- 46,50 ---- { private int numberOfDrivingPositions; ! private SignedTickers portfolioSignedTickers; private History timeLineForOptimization; // this time line goes from // the first optimization date for driving positions to the *************** *** 98,102 **** int numberOfDrivingPositions , DataTable eligibleTickersForDrivingWeightedPositions , ! string[] portfolioSignedTickers , History timeLineForOptimization , IEquityEvaluator equityEvaluator , --- 98,102 ---- int numberOfDrivingPositions , DataTable eligibleTickersForDrivingWeightedPositions , ! SignedTickers portfolioSignedTickers , History timeLineForOptimization , IEquityEvaluator equityEvaluator , *************** *** 346,356 **** private void setTickerForPortfolioPositions( int i ) { ! string signedTicker = this.portfolioSignedTickers[ i ]; ! this.tickersForPortfolioPositions[ i ] = SignedTicker.GetTicker( signedTicker ); } private void setTickersForPortfolioPositions() { ! this.tickersForPortfolioPositions = new string[ this.portfolioSignedTickers.Length ]; ! for( int i=0 ; i < portfolioSignedTickers.Length ; i++ ) this.setTickerForPortfolioPositions( i ); } --- 346,356 ---- private void setTickerForPortfolioPositions( int i ) { ! SignedTicker signedTicker = this.portfolioSignedTickers[ i ]; ! this.tickersForPortfolioPositions[ i ] = signedTicker.Ticker; } private void setTickersForPortfolioPositions() { ! this.tickersForPortfolioPositions = new string[ this.portfolioSignedTickers.Count ]; ! for( int i=0 ; i < portfolioSignedTickers.Count ; i++ ) this.setTickerForPortfolioPositions( i ); } |
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WeightedPositionsChoosers/WFLagGeneticFixedPortfolioWithNormalDrivingAndPortfolio In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv23979/b7_Scripts/WalkForwardTesting/WalkForwardLag/WeightedPositionsChoosers/WFLagGeneticFixedPortfolioWithNormalDrivingAndPortfolio Modified Files: WFLagGeneticFixedPortfolioWithNormalDrivingAndPortfolio.cs Log Message: - SignedTickers class is now used, instead of string arrays Index: WFLagGeneticFixedPortfolioWithNormalDrivingAndPortfolio.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WeightedPositionsChoosers/WFLagGeneticFixedPortfolioWithNormalDrivingAndPortfolio/WFLagGeneticFixedPortfolioWithNormalDrivingAndPortfolio.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** WFLagGeneticFixedPortfolioWithNormalDrivingAndPortfolio.cs 1 Aug 2007 23:15:39 -0000 1.5 --- WFLagGeneticFixedPortfolioWithNormalDrivingAndPortfolio.cs 7 Aug 2007 16:54:17 -0000 1.6 *************** *** 26,29 **** --- 26,30 ---- using QuantProject.ADT.Histories; using QuantProject.ADT.Optimizing.Genetic; + using QuantProject.Business.Strategies; using QuantProject.Business.Strategies.EquityEvaluation; using QuantProject.Business.Timing; *************** *** 44,48 **** protected int numberOfDrivingPositions; ! private string[] portfolioSignedTickers; protected int inSampleDays; protected string benchmark; --- 45,49 ---- protected int numberOfDrivingPositions; ! private SignedTickers portfolioSignedTickers; protected int inSampleDays; protected string benchmark; *************** *** 70,74 **** get { ! return this.portfolioSignedTickers.Length; } } --- 71,75 ---- get { ! return this.portfolioSignedTickers.Count; } } *************** *** 108,112 **** public WFLagGeneticFixedPortfolioWithNormalDrivingAndPortfolio( int numberOfDrivingPositions , ! string[] portfolioSignedTickers , int inSampleDays , string benchmark , --- 109,113 ---- public WFLagGeneticFixedPortfolioWithNormalDrivingAndPortfolio( int numberOfDrivingPositions , ! SignedTickers portfolioSignedTickers , int inSampleDays , string benchmark , |
|
From: Glauco S. <gla...@us...> - 2007-08-07 16:53:26
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger/WFLagDebugPositions In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv23524/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger/WFLagDebugPositions Modified Files: WFLagDebugPositions.cs Log Message: - SignedTicker class is now used, instead of plain text strings Index: WFLagDebugPositions.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger/WFLagDebugPositions/WFLagDebugPositions.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** WFLagDebugPositions.cs 30 Jul 2006 13:41:48 -0000 1.4 --- WFLagDebugPositions.cs 7 Aug 2007 16:53:21 -0000 1.5 *************** *** 129,135 **** double valueForEachPosition = 30000 / positions.Count; ! foreach( string signedTicker in positions ) { ! string ticker = SignedTicker.GetTicker( signedTicker ); EndOfDayDateTime endOfDayDateTime = new EndOfDayDateTime( dateTime , EndOfDaySpecificTime.MarketClose ); --- 129,136 ---- double valueForEachPosition = 30000 / positions.Count; ! foreach( string stringForSignedTicker in positions ) { ! SignedTicker signedTicker = new SignedTicker( stringForSignedTicker ); ! string ticker = signedTicker.Ticker; EndOfDayDateTime endOfDayDateTime = new EndOfDayDateTime( dateTime , EndOfDaySpecificTime.MarketClose ); *************** *** 138,142 **** ticker , endOfDayDateTime ); double virtualQuantity = valueForEachPosition / tickerQuote; ! if ( SignedTicker.IsShort( signedTicker ) ) virtualQuantity = -virtualQuantity; virtualQuantities.Add( ticker , virtualQuantity ); --- 139,143 ---- ticker , endOfDayDateTime ); double virtualQuantity = valueForEachPosition / tickerQuote; ! if ( signedTicker.IsShort ) virtualQuantity = -virtualQuantity; virtualQuantities.Add( ticker , virtualQuantity ); |
|
From: Glauco S. <gla...@us...> - 2007-08-07 16:52:55
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv23121/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger Modified Files: WFLagChosenPositions.cs Log Message: - SignedTicker class is now used, instead of plain text strings Index: WFLagChosenPositions.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WFLagDebugger/WFLagChosenPositions.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** WFLagChosenPositions.cs 1 Aug 2007 23:13:54 -0000 1.5 --- WFLagChosenPositions.cs 7 Aug 2007 16:52:48 -0000 1.6 *************** *** 242,249 **** #region setWeightedPositionsFromQPHashtables private double getWeightedPositions_getWeight( ! double absoluteWeightForEachPosition , string signedTicker ) { double weight = absoluteWeightForEachPosition; ! if ( SignedTicker.IsShort( signedTicker ) ) weight = - absoluteWeightForEachPosition; return weight; --- 242,249 ---- #region setWeightedPositionsFromQPHashtables private double getWeightedPositions_getWeight( ! double absoluteWeightForEachPosition , SignedTicker signedTicker ) { double weight = absoluteWeightForEachPosition; ! if ( signedTicker.IsShort ) weight = - absoluteWeightForEachPosition; return weight; *************** *** 259,263 **** { weights[ i ] = this.getWeightedPositions_getWeight( ! absoluteWeightForEachPosition , signedTicker ); tickers[ i ] = SignedTicker.GetTicker( signedTicker ); i++; --- 259,263 ---- { weights[ i ] = this.getWeightedPositions_getWeight( ! absoluteWeightForEachPosition , new SignedTicker( signedTicker ) ); tickers[ i ] = SignedTicker.GetTicker( signedTicker ); i++; |
|
From: Glauco S. <gla...@us...> - 2007-08-07 16:51:48
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv22704/b7_Scripts/WalkForwardTesting/WalkForwardLag Modified Files: WeightedPositions.cs Log Message: - fixed bug in the GetBalancedWeights public method - SignedTickers and SignedTicker classes are now used, instead of plain text strings Index: WeightedPositions.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/WalkForwardTesting/WalkForwardLag/WeightedPositions.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** WeightedPositions.cs 1 Aug 2007 23:12:46 -0000 1.6 --- WeightedPositions.cs 7 Aug 2007 16:51:44 -0000 1.7 *************** *** 307,321 **** } private static float getTickerReturnsStandardDeviations( int tickerIndex , ! string[] signedTickers , ReturnsManager returnsManager ) { ! string ticker = SignedTicker.GetTicker( signedTickers[ tickerIndex ] ); return returnsManager.GetReturnsStandardDeviation( ticker ); } private static float[] getTickersReturnsStandardDeviations( ! string[] signedTickers , ReturnsManager returnsManager ) { float[] tickersReturnsStandardDeviations = ! new float[ signedTickers.Length ]; ! for ( int i = 0 ; i < signedTickers.Length ; i++ ) tickersReturnsStandardDeviations[ i ] = getTickerReturnsStandardDeviations( i , --- 307,321 ---- } private static float getTickerReturnsStandardDeviations( int tickerIndex , ! SignedTickers signedTickers , ReturnsManager returnsManager ) { ! string ticker = signedTickers[ tickerIndex ].Ticker; return returnsManager.GetReturnsStandardDeviation( ticker ); } private static float[] getTickersReturnsStandardDeviations( ! SignedTickers signedTickers , ReturnsManager returnsManager ) { float[] tickersReturnsStandardDeviations = ! new float[ signedTickers.Count ]; ! for ( int i = 0 ; i < signedTickers.Count ; i++ ) tickersReturnsStandardDeviations[ i ] = getTickerReturnsStandardDeviations( i , *************** *** 347,359 **** standardDeviations , maxStandardDeviation ); } ! /// <summary> ! /// Returns weights balanced with respect to the close to close volatility, ! /// in the given period ! /// (the most volatile ticker is given the lighter weight) ! /// </summary> ! /// <param name="signedTickers"></param> ! /// <returns></returns> ! public static double[] GetBalancedWeights( ! string[] signedTickers , ReturnsManager returnManager ) { float[] standardDeviations = --- 347,352 ---- standardDeviations , maxStandardDeviation ); } ! private static double[] getUnsignedNormalizedBalancedWeights( ! SignedTickers signedTickers , ReturnsManager returnManager ) { float[] standardDeviations = *************** *** 366,369 **** --- 359,402 ---- return normalizedBalancedWeights; } + private static double[] getSignedNormalizedBalancedWeights( + double[] multipliers , + double[] unsignedNormalizedBalancedWeights ) + { + double[] signedNormalizedBalancedWeights = + new double[ unsignedNormalizedBalancedWeights.Length ]; + for( int i = 0 ; i < unsignedNormalizedBalancedWeights.Length ; i++ ) + signedNormalizedBalancedWeights[ i ] = + multipliers[ i ] * unsignedNormalizedBalancedWeights[ i ]; + return signedNormalizedBalancedWeights; + } + private static double[] getSignedNormalizedBalancedWeights( + SignedTickers signedTickers , + double[] unsignedNormalizedBalancedWeights ) + { + double[] multipliers = + signedTickers.Multipliers; + double[] signedNormalizedBalancedWeights = + getSignedNormalizedBalancedWeights( multipliers , + unsignedNormalizedBalancedWeights ); + return signedNormalizedBalancedWeights; + } + /// <summary> + /// Returns weights balanced with respect to the close to close volatility, + /// in the given period + /// (the most volatile ticker is given the lighter weight) + /// </summary> + /// <param name="signedTickers"></param> + /// <returns></returns> + public static double[] GetBalancedWeights( + SignedTickers signedTickers , ReturnsManager returnManager ) + { + double[] unsignedNormalizedBalancedWeights = + getUnsignedNormalizedBalancedWeights( + signedTickers , returnManager ); + double[] balancedWeights = + getSignedNormalizedBalancedWeights( + signedTickers , unsignedNormalizedBalancedWeights ); + return balancedWeights; + } #endregion //GetBalancedWeights #region GetReturn |