quantproject-developers Mailing List for QuantProject (Page 3)
Brought to you by:
glauco_1
You can subscribe to this list here.
| 2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(7) |
Nov
(103) |
Dec
(67) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2004 |
Jan
(52) |
Feb
(9) |
Mar
(69) |
Apr
(53) |
May
(80) |
Jun
(23) |
Jul
(24) |
Aug
(112) |
Sep
(9) |
Oct
|
Nov
(58) |
Dec
(93) |
| 2005 |
Jan
(90) |
Feb
(93) |
Mar
(61) |
Apr
(56) |
May
(37) |
Jun
(61) |
Jul
(55) |
Aug
(68) |
Sep
(25) |
Oct
(46) |
Nov
(41) |
Dec
(37) |
| 2006 |
Jan
(33) |
Feb
(7) |
Mar
(19) |
Apr
(27) |
May
(73) |
Jun
(49) |
Jul
(83) |
Aug
(66) |
Sep
(45) |
Oct
(16) |
Nov
(15) |
Dec
(7) |
| 2007 |
Jan
(14) |
Feb
(33) |
Mar
|
Apr
(21) |
May
|
Jun
(34) |
Jul
(18) |
Aug
(100) |
Sep
(39) |
Oct
(55) |
Nov
(12) |
Dec
(2) |
| 2008 |
Jan
(120) |
Feb
(133) |
Mar
(129) |
Apr
(104) |
May
(42) |
Jun
(2) |
Jul
(52) |
Aug
(99) |
Sep
(134) |
Oct
|
Nov
(137) |
Dec
(48) |
| 2009 |
Jan
(48) |
Feb
(55) |
Mar
(61) |
Apr
(3) |
May
(2) |
Jun
(1) |
Jul
|
Aug
(51) |
Sep
|
Oct
(7) |
Nov
|
Dec
|
| 2010 |
Jan
(7) |
Feb
(1) |
Mar
(145) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(8) |
Dec
|
| 2011 |
Jan
(78) |
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(88) |
Sep
(6) |
Oct
(1) |
Nov
|
Dec
|
| 2012 |
Jan
|
Feb
(1) |
Mar
|
Apr
(6) |
May
(5) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
| 2013 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(2) |
| 2014 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: Marco M. <mi...@us...> - 2011-08-21 13:59:30
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/EndOfDayStrategies
In directory vz-cvs-3.sog:/tmp/cvs-serv18177/EndOfDayStrategies
Added Files:
BuyAndHoldStrategy.cs
Log Message:
BuyAndHoldStrategy has been added
--- NEW FILE: BuyAndHoldStrategy.cs ---
/*
QuantProject - Quantitative Finance Library
BuyAndHoldStrategy.cs
Copyright (C) 2011
Marco Milletti
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using QuantProject.ADT;
using QuantProject.ADT.Histories;
using QuantProject.ADT.Messaging;
using QuantProject.ADT.Timing;
using QuantProject.Business.Financial.Accounting;
using QuantProject.Business.Financial.Instruments;
using QuantProject.Business.Financial.Ordering;
using QuantProject.Business.Timing;
using QuantProject.Business.Strategies;
using QuantProject.Business.Strategies.InSample;
using QuantProject.Business.Strategies.InSample.InSampleFitnessDistributionEstimation;
using QuantProject.Business.Strategies.OutOfSample;
using QuantProject.Business.Strategies.Logging;
using QuantProject.Business.DataProviders;
using QuantProject.Data;
using QuantProject.Data.DataProviders;
namespace QuantProject.Business.Strategies
{
/// <summary>
/// Implements a simple buy and hold strategy:
/// given testing positions are bought on the first day
/// fired by the timer (at 16 or after)
/// and held through all the period of testing
/// </summary>
[Serializable]
public class BuyAndHoldStrategy : IStrategyForBacktester
{
public event NewLogItemEventHandler NewLogItem;
public event NewMessageEventHandler NewMessage;
private TestingPositions testingPositions;
// private Benchmark benchmark;
// private HistoricalMarketValueProvider historicalMarketValueProvider;
private Account account;
public Account Account
{
get { return this.account; }
set { this.account = value; }
}
public string Description
{
get
{
string description =
"BuyAndHoldStrategy";
return description;
}
}
public bool StopBacktestIfMaxRunningHoursHasBeenReached
{
get
{
return true;
}
}
// public BuyAndHoldStrategy(TestingPositions testingPositions,
// Benchmark benchmark,
// HistoricalMarketValueProvider historicalMarketValueProvider)
// {
// this.testingPositions = testingPositions;
// this.benchmark = benchmark;
// this.historicalMarketValueProvider = historicalMarketValueProvider;
// }
public BuyAndHoldStrategy(TestingPositions testingPositions)
{
this.testingPositions = testingPositions;
}
#region newDateTimeEventHandler_closePositions
private void newDateTimeEventHandler_closePositions()
{
DateTime currentDateTime = this.now();
AccountManager.ClosePositions( this.account );
}
#endregion newDateTimeEventHandler_closePositions
#region newDateTimeEventHandler_openPositions
private void newDateTimeEventHandler_openPositions()
{
try
{
AccountManager.OpenPositions( this.testingPositions.WeightedPositions,
this.account );
}
catch(Exception ex)
{
string forBreakpoint = ex.Message; forBreakpoint = forBreakpoint + "";
}
}
#endregion newDateTimeEventHandler_openPositions
public virtual void NewDateTimeEventHandler(
Object sender , DateTime dateTime )
{
if( this.account.Portfolio.Count == 0 &&
dateTime.Hour >= 16)
this.newDateTimeEventHandler_openPositions();
}
private DateTime now()
{
return this.account.Timer.GetCurrentDateTime();
}
private void raiseNewLogItem( )
{
DummyLogItem logItem = new DummyLogItem( this.now() );
NewLogItemEventArgs newLogItemEventArgs =
new NewLogItemEventArgs( logItem );
this.NewLogItem( this , newLogItemEventArgs );
}
private void notifyMessage( )
{
string message = "BuyAndHold";
NewMessageEventArgs newMessageEventArgs =
new NewMessageEventArgs( message );
if ( this.NewMessage != null )
this.NewMessage( this , newMessageEventArgs );
}
private void logOptimizationInfo( )
{
this.raiseNewLogItem( );
this.notifyMessage( );
}
}
}
|
|
From: Marco M. <mi...@us...> - 2011-08-21 13:58:43
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Optimizing/Decoding
In directory vz-cvs-3.sog:/tmp/cvs-serv18153/Optimizing/Decoding
Added Files:
BasicDecoderForTestingPositionsWithWeights.cs
Log Message:
BasicDecoderForTestingPositionsWithWeights has been added
--- NEW FILE: BasicDecoderForTestingPositionsWithWeights.cs ---
/*
QuantProject - Quantitative Finance Library
BasicDecoderForTestingPositionsWithWeights.cs
Copyright (C) 2011
Marco Milletti
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
using System;
using QuantProject.ADT.Collections;
using QuantProject.ADT.Optimizing.Decoding;
using QuantProject.Business.Strategies;
using QuantProject.Business.Strategies.OutOfSample;
using QuantProject.Business.Strategies.Optimizing.Decoding;
namespace QuantProject.Business.Strategies.Optimizing.Decoding
{
/// <summary>
/// Decodes optimization candidates to a
/// TestingPositions with weights
/// </summary>
[Serializable]
public class BasicDecoderForTestingPositionsWithWeights : DecoderForTestingPositionsWithWeights
{
public BasicDecoderForTestingPositionsWithWeights() : base()
{
}
protected override TestingPositions getMeaningForUndecodable()
{
return new TestingPositionsForUndecodableEncoded();
}
protected override string getDescription()
{
return "Basic_Dcdr_WithWghts";
}
}
}
|
|
From: Marco M. <mi...@us...> - 2011-08-21 13:57:55
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Optimizing/Decoding
In directory vz-cvs-3.sog:/tmp/cvs-serv18132/Optimizing/Decoding
Modified Files:
BasicDecoderForTestingPositions.cs
Log Message:
decodeSignedTickers method has been modified to virtual
Index: BasicDecoderForTestingPositions.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Optimizing/Decoding/BasicDecoderForTestingPositions.cs,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** BasicDecoderForTestingPositions.cs 28 Mar 2010 13:50:39 -0000 1.10
--- BasicDecoderForTestingPositions.cs 21 Aug 2011 13:57:53 -0000 1.11
***************
*** 87,91 ****
}
! private SignedTicker decodeSignedTickers( int i )
{
int signedTickerCode = this.tickerRelatedGeneValues[ i ];
--- 87,91 ----
}
! protected virtual SignedTicker decodeSignedTickers( int i )
{
int signedTickerCode = this.tickerRelatedGeneValues[ i ];
|
|
From: Marco M. <mi...@us...> - 2011-08-21 13:56:56
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Optimizing/Decoding
In directory vz-cvs-3.sog:/tmp/cvs-serv18104/Optimizing/Decoding
Modified Files:
DecoderForTestingPositionsWithWeights.cs
Log Message:
BasicDecoderForGeneticallyOptimizableTestingPositions are used now
Index: DecoderForTestingPositionsWithWeights.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Optimizing/Decoding/DecoderForTestingPositionsWithWeights.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** DecoderForTestingPositionsWithWeights.cs 30 Oct 2009 23:09:23 -0000 1.1
--- DecoderForTestingPositionsWithWeights.cs 21 Aug 2011 13:56:54 -0000 1.2
***************
*** 36,40 ****
[Serializable]
public abstract class DecoderForTestingPositionsWithWeights :
! BasicDecoderForTestingPositions
{
protected int[] weightsRelatedGeneValues;
--- 36,40 ----
[Serializable]
public abstract class DecoderForTestingPositionsWithWeights :
! BasicDecoderForGeneticallyOptimizableTestingPositions
{
protected int[] weightsRelatedGeneValues;
|
|
From: Marco M. <mi...@us...> - 2011-08-21 13:55:57
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/OutOfSample
In directory vz-cvs-3.sog:/tmp/cvs-serv18082/OutOfSample
Modified Files:
GeneticallyOptimizableTestingPositions.cs
Log Message:
Copy method in TestingPositions in not virtual; so the Copy method in this class hide the Copy method in the base class
Index: GeneticallyOptimizableTestingPositions.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/OutOfSample/GeneticallyOptimizableTestingPositions.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** GeneticallyOptimizableTestingPositions.cs 16 Jan 2011 19:03:57 -0000 1.1
--- GeneticallyOptimizableTestingPositions.cs 21 Aug 2011 13:55:55 -0000 1.2
***************
*** 47,51 ****
}
! public GeneticallyOptimizableTestingPositions Copy()
{
return new GeneticallyOptimizableTestingPositions( this.WeightedPositions,
--- 47,51 ----
}
! public new GeneticallyOptimizableTestingPositions Copy()
{
return new GeneticallyOptimizableTestingPositions( this.WeightedPositions,
|
|
From: Marco M. <mi...@us...> - 2011-08-21 13:53:50
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/InSample
In directory vz-cvs-3.sog:/tmp/cvs-serv18029/InSample
Modified Files:
SelectTopEligiblesInSampleChooser.cs
Log Message:
Fixed bug
Index: SelectTopEligiblesInSampleChooser.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/InSample/SelectTopEligiblesInSampleChooser.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** SelectTopEligiblesInSampleChooser.cs 16 Jan 2011 19:09:22 -0000 1.1
--- SelectTopEligiblesInSampleChooser.cs 21 Aug 2011 13:53:48 -0000 1.2
***************
*** 40,45 ****
public event NewMessageEventHandler NewMessage;
public event NewProgressEventHandler NewProgress;
! private int maxNumOfTestingPositionsToBeReturned;
! private int numOfTickersInEachTestingPosition;
public string Description
--- 40,45 ----
public event NewMessageEventHandler NewMessage;
public event NewProgressEventHandler NewProgress;
! protected int maxNumOfTestingPositionsToBeReturned;
! protected int numOfTickersInEachTestingPosition;
public string Description
***************
*** 57,61 ****
}
! private GeneticallyOptimizableTestingPositions[] analyzeInSample_getTestingPositionsArray(EligibleTickers eligibleTickers)
{
if( eligibleTickers.Count <
--- 57,71 ----
}
! protected virtual string analyzeInSample_getTestingPositionsArray_getTicker(EligibleTickers eligibleTickers,
! int idxOfTicker)
! {
! string returnValue =
! eligibleTickers.Tickers[idxOfTicker];
!
! return returnValue;
! }
!
!
! protected GeneticallyOptimizableTestingPositions[] analyzeInSample_getTestingPositionsArray(EligibleTickers eligibleTickers)
{
if( eligibleTickers.Count <
***************
*** 73,77 ****
idxEligible < eligibleTickers.Count && j < numOfTickersInEachTestingPosition;
j++ )
! signedTickers[j] = eligibleTickers.Tickers[idxEligible + j];
returnValue[i] =
--- 83,89 ----
idxEligible < eligibleTickers.Count && j < numOfTickersInEachTestingPosition;
j++ )
! signedTickers[j] =
! this.analyzeInSample_getTestingPositionsArray_getTicker(
! eligibleTickers, idxEligible + j);
returnValue[i] =
|
|
From: Marco M. <mi...@us...> - 2011-08-21 13:52:22
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Eligibles
In directory vz-cvs-3.sog:/tmp/cvs-serv17978/Eligibles
Modified Files:
ByPriceMostLiquidAlwaysQuoted.cs
Log Message:
Minor improvements to the class have been added
Index: ByPriceMostLiquidAlwaysQuoted.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Eligibles/ByPriceMostLiquidAlwaysQuoted.cs,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** ByPriceMostLiquidAlwaysQuoted.cs 29 Sep 2008 21:14:49 -0000 1.6
--- ByPriceMostLiquidAlwaysQuoted.cs 21 Aug 2011 13:52:20 -0000 1.7
***************
*** 118,130 ****
// dataSet.WriteXml( "c:\\qpReports\\pairsTrading\\eligiblesCon_ByPriceMostLiquidAlwaysQuoted.xml" );
! SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromLastSelection =
! new SelectorByQuotationAtEachMarketDay( dataTableMostLiquid ,
! false, history,
! this.maxNumberOfEligibleTickersToBeChosen);
DataTable dataTableToBeReturned =
quotedAtEachMarketDayFromLastSelection.GetTableOfSelectedTickers();
return
! new EligibleTickers( dataTableToBeReturned );
}
--- 118,136 ----
// dataSet.WriteXml( "c:\\qpReports\\pairsTrading\\eligiblesCon_ByPriceMostLiquidAlwaysQuoted.xml" );
! // SelectorByQuotationAtEachMarketDay quotedAtEachMarketDayFromLastSelection =
! // new SelectorByQuotationAtEachMarketDay( dataTableMostLiquid ,
! // false, history,
! // this.maxNumberOfEligibleTickersToBeChosen);
!
! SelectorByQuotationAtAGivenPercentageOfDateTimes quotedAtEachMarketDayFromLastSelection =
! new SelectorByQuotationAtAGivenPercentageOfDateTimes( dataTableMostLiquid ,
! false, history, 0,
! this.maxNumberOfEligibleTickersToBeChosen, 0.9);
!
DataTable dataTableToBeReturned =
quotedAtEachMarketDayFromLastSelection.GetTableOfSelectedTickers();
return
! new EligibleTickers( dataTableToBeReturned, currentDate );
}
|
|
From: Marco M. <mi...@us...> - 2011-08-21 13:51:23
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Eligibles
In directory vz-cvs-3.sog:/tmp/cvs-serv17954/Eligibles
Modified Files:
ByMostDiscountedPrices.cs
Log Message:
Minor improvements to the class have been added
Index: ByMostDiscountedPrices.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Eligibles/ByMostDiscountedPrices.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** ByMostDiscountedPrices.cs 16 Jan 2011 18:34:18 -0000 1.2
--- ByMostDiscountedPrices.cs 21 Aug 2011 13:51:21 -0000 1.3
***************
*** 112,120 ****
if(!initialTableFromWhichToChooseTheMostDiscountedTickers.Columns.Contains("RelativeDifferenceBetweenFairAndMarketPrice"))
initialTableFromWhichToChooseTheMostDiscountedTickers.Columns.Add("RelativeDifferenceBetweenFairAndMarketPrice", System.Type.GetType("System.Double"));
! foreach(DataRow row in initialTableFromWhichToChooseTheMostDiscountedTickers.Rows)
{
try{
currentFairPrice = this.fairValueProvider.GetFairValue( (string)row[0],
! date.AddDays(-this.numOfDaysForFundamentalAnalysis),
date );
row["FairPrice"] = currentFairPrice;
--- 112,121 ----
if(!initialTableFromWhichToChooseTheMostDiscountedTickers.Columns.Contains("RelativeDifferenceBetweenFairAndMarketPrice"))
initialTableFromWhichToChooseTheMostDiscountedTickers.Columns.Add("RelativeDifferenceBetweenFairAndMarketPrice", System.Type.GetType("System.Double"));
! this.fairValueProvider.Run(date);
! foreach(DataRow row in initialTableFromWhichToChooseTheMostDiscountedTickers.Rows)
{
try{
currentFairPrice = this.fairValueProvider.GetFairValue( (string)row[0],
! //date.AddDays(-this.numOfDaysForFundamentalAnalysis),
date );
row["FairPrice"] = currentFairPrice;
***************
*** 150,153 ****
--- 151,157 ----
tableOfEligibleTickers.PrimaryKey = columnPrimaryKeys;
+ string[] tableOfEligibleTickersForDebugging =
+ ExtendedDataTable.GetArrayOfStringFromRows(tableOfEligibleTickers);
+
return new EligibleTickers(tableOfEligibleTickers);
}
***************
*** 167,170 ****
--- 171,176 ----
group = new SelectorByGroup(this.tickersGroupID);
DataTable tickersFromGroup = group.GetTableOfSelectedTickers();
+ string[] tickersFromGroupForDebugging =
+ ExtendedDataTable.GetArrayOfStringFromRows(tickersFromGroup);
SelectorByNumOfMinGrowingIncomesInARow selectorByMinimumGrowingIncomes =
new SelectorByNumOfMinGrowingIncomesInARow(tickersFromGroup, history.FirstDateTime,
***************
*** 175,178 ****
--- 181,187 ----
selectorByMinimumGrowingIncomes.GetTableOfSelectedTickers();
+ string[] tickersWithPositiveGrowingIncomesForDebugging =
+ ExtendedDataTable.GetArrayOfStringFromRows(tickersWithPositiveGrowingIncomes);
+
return this.getEligibleTickers_actually_getTableOfMostDiscountedTickers(tickersWithPositiveGrowingIncomes, currentDate);
|
|
From: Marco M. <mi...@us...> - 2011-08-21 13:50:05
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Eligibles
In directory vz-cvs-3.sog:/tmp/cvs-serv17892/Eligibles
Modified Files:
EligibleTickers.cs
Log Message:
Minor improvements to the class have been added
Index: EligibleTickers.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/Eligibles/EligibleTickers.cs,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** EligibleTickers.cs 13 Feb 2011 19:25:30 -0000 1.6
--- EligibleTickers.cs 21 Aug 2011 13:50:03 -0000 1.7
***************
*** 59,66 ****
--- 59,81 ----
}
}
+ private DateTime dateAtWhichTickersAreEligible;
+ /// <summary>
+ /// Returns the dateTime at which tickers
+ /// are eligible
+ /// </summary>
+ public DateTime DateAtWhichTickersAreEligible
+ {
+ get
+ {
+ return this.dateAtWhichTickersAreEligible;
+ }
+ }
+
public EligibleTickers( ICollection<string> tickers )
{
foreach( string ticker in tickers )
this.List.Add( ticker );
+ this.dateAtWhichTickersAreEligible =
+ new DateTime(1900,1,1);
}
***************
*** 74,77 ****
--- 89,106 ----
this.sourceDataTable = dtTickers;
this.addTickers( dtTickers );
+ this.dateAtWhichTickersAreEligible =
+ new DateTime(1900,1,1);
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="dtTickers">DataTable in the form returned by
+ /// a ticker selector</param>
+ public EligibleTickers( DataTable dtTickers,
+ DateTime dateAtWhichTickersAreEligible )
+ {
+ this.sourceDataTable = dtTickers;
+ this.addTickers( dtTickers );
+ this.dateAtWhichTickersAreEligible = dateAtWhichTickersAreEligible;
}
#region addTickers
***************
*** 119,122 ****
--- 148,155 ----
this.addTicker_actually( ticker );
}
+ public void AddAdditionalTicker( string ticker )
+ {
+ this.List.Add( ticker );
+ }
}
}
|
|
From: Marco M. <mi...@us...> - 2011-08-21 13:46:35
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/OutOfSample
In directory vz-cvs-3.sog:/tmp/cvs-serv17808/OutOfSample
Modified Files:
TestingPositions.cs
Log Message:
Added methods: Copy() and AddWeightedPosition
Index: TestingPositions.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/OutOfSample/TestingPositions.cs,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** TestingPositions.cs 28 Mar 2010 14:39:20 -0000 1.6
--- TestingPositions.cs 21 Aug 2011 13:46:33 -0000 1.7
***************
*** 166,169 ****
--- 166,197 ----
this.fitnessInSample = double.MinValue;
}
+
+ public TestingPositions Copy()
+ {
+ return new TestingPositions(this.weightedPositions, this.fitnessInSample);
+ }
+
+ private void AddWeightedPosition_adjustPreviousWeights(double weightOfNewPositionToAdd )
+ {
+ double weightToBeRedistributedToThePrevious = 1.0 - weightOfNewPositionToAdd;
+ double previousWeight;
+ for(int i = 0; i < this.WeightedPositions.Count; i ++)
+ {
+ previousWeight = this.WeightedPositions[i].Weight;
+ this.WeightedPositions[i].Weight =
+ previousWeight * weightToBeRedistributedToThePrevious;
+ }
+ }
+
+ /// <summary>
+ /// Adds a WeightedPosition to the current instance of testing positions
+ /// the previous weights are adjusted according to the amount
+ /// of weight of the added WeightedPosition
+ /// </summary>
+ public void AddWeightedPosition(WeightedPosition positionToAdd )
+ {
+ this.AddWeightedPosition_adjustPreviousWeights(positionToAdd.Weight);
+ this.weightedPositions.Add(positionToAdd);
+ }
}
}
|
|
From: Marco M. <mi...@us...> - 2011-08-21 13:44:45
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies
In directory vz-cvs-3.sog:/tmp/cvs-serv17774
Modified Files:
EndOfDayStrategyBackTester.cs
Log Message:
The progress message in the log file has been improved (more info are logged: such as account value and positions in portfolio)
Index: EndOfDayStrategyBackTester.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/EndOfDayStrategyBackTester.cs,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** EndOfDayStrategyBackTester.cs 13 Feb 2011 15:27:16 -0000 1.18
--- EndOfDayStrategyBackTester.cs 21 Aug 2011 13:44:43 -0000 1.19
***************
*** 416,427 ****
#endregion stopTheScriptIfTheCase
private void notifyProgress(
Timer timer )
{
! string progressMessage = "Current out of sample date:" +
! this.timer.GetCurrentDateTime().ToString() + " - " +
! "First date:" + this.firstDateTime.ToString() + " - " +
! "Last date:" + this.lastDateTime.ToString() + " - " +
! "Real time:" + DateTime.Now;
NewMessageEventArgs newMessageEventArgs =
new NewMessageEventArgs( progressMessage );
--- 416,446 ----
#endregion stopTheScriptIfTheCase
+ private string notifyProgress_getPositions()
+ {
+ string returnValue = null;
+ foreach(Position pos in this.strategyForBacktester.Account.Portfolio.Positions)
+ returnValue += pos.Instrument.Key + "; ";
+ return returnValue;
+ }
+
private void notifyProgress(
Timer timer )
{
! string progressMessage;
! try
! {
! progressMessage = "Curr. out of s. date:" +
! this.timer.GetCurrentDateTime().ToString() + " - " +
! "Acc.Value: " + this.strategyForBacktester.Account.GetMarketValue().ToString() + " - " +
! "positions: " + this.notifyProgress_getPositions() + " - " +
! "First date:" + this.firstDateTime.ToString() + " - " +
! "Last date:" + this.lastDateTime.ToString() + " - " +
! "Real time:" + DateTime.Now;
! }
! catch(Exception ex)
! {
! progressMessage = "Error occured during building progressMessage: " +
! ex.Message;
! }
NewMessageEventArgs newMessageEventArgs =
new NewMessageEventArgs( progressMessage );
|
|
From: Marco M. <mi...@us...> - 2011-08-21 13:15:58
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/InSample
In directory vz-cvs-3.sog:/tmp/cvs-serv16022/InSample
Modified Files:
GeneticChooser.cs
Log Message:
Resolved conflict
Index: GeneticChooser.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/InSample/GeneticChooser.cs,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** GeneticChooser.cs 13 Feb 2011 19:30:10 -0000 1.13
--- GeneticChooser.cs 21 Aug 2011 13:15:56 -0000 1.14
***************
*** 186,189 ****
--- 186,197 ----
{
if ( eligibleTickers.Count < this.numberOfPortfolioPositions )
+ throw new Exception( "Eligible tickers at date " +
+ eligibleTickers.DateAtWhichTickersAreEligible.ToString() + " " +
+ "for driving positions contains only " +
+ eligibleTickers.Count + " " +
+ "elements, while number of portfolio positions is " +
+ this.numberOfPortfolioPositions );
+ if ( this.numberOfBestTestingPositionsToBeReturned >
+ this.populationSizeForGeneticOptimizer )
throw new Exception( "Eligible tickers for driving positions contains " +
"only " + eligibleTickers.Count +
***************
*** 206,223 ****
}
#region sendNewMessage
! private string getProgressMessage(
! int generationCounter , int generationNumber )
{
string progressMessage =
! generationCounter.ToString() + " / " +
! generationNumber.ToString() +
! " - " +
! DateTime.Now.ToString();
return progressMessage;
}
private void sendNewMessage( NewGenerationEventArgs e )
{
! string message = this.getProgressMessage(
! e.GenerationCounter , e.GenerationNumber );
NewMessageEventArgs newMessageEventArgs =
new NewMessageEventArgs( message );
--- 214,248 ----
}
#region sendNewMessage
! private double getProgressMessage_getAverageFitness(NewGenerationEventArgs e)
{
+ double totalFitness = 0.0;
+ int populationSize = e.CurrentGeneticOptimizer.PopulationSize;
+ for(int i = 0; i < populationSize; i++)
+ totalFitness += ((Genome)e.Generation[i]).Fitness;
+
+ return totalFitness / populationSize;
+ }
+ private string getProgressMessage(NewGenerationEventArgs e)
+ {
+ Genome bestGenome = (Genome)e.Generation[e.Generation.Count - 1];
+ if( e.CurrentGeneticOptimizer.BestGenome != null )
+ bestGenome = e.CurrentGeneticOptimizer.BestGenome;
+ double worstFitness = ((Genome)e.Generation[0]).Fitness;
+ if( e.CurrentGeneticOptimizer.WorstGenome != null)
+ worstFitness = e.CurrentGeneticOptimizer.WorstGenome.Fitness;
+ double averageFitness = this.getProgressMessage_getAverageFitness(e);
string progressMessage =
! e.GenerationCounter.ToString() + " / " +
! e.GenerationNumber.ToString() +
! " ; Abs Best: " + bestGenome.Fitness.ToString("0.00000000") +
! " (gen: " + bestGenome.Generation.ToString() + ")" +
! " ; Abs Worst: " + worstFitness.ToString("0.000000") +
! " ; Avg of gen : " + averageFitness.ToString("0.0000") +
! " - " + DateTime.Now.ToString();
return progressMessage;
}
private void sendNewMessage( NewGenerationEventArgs e )
{
! string message = this.getProgressMessage( e );
NewMessageEventArgs newMessageEventArgs =
new NewMessageEventArgs( message );
|
|
From: Marco M. <mi...@us...> - 2011-08-21 13:14:58
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a4_Fundamentals
In directory vz-cvs-3.sog:/tmp/cvs-serv16007/a4_Fundamentals
Added Files:
ReturnOnAssetsProvider.cs
Log Message:
Added ReturnOnAssetsProvider
--- NEW FILE: ReturnOnAssetsProvider.cs ---
/*
QuantProject - Quantitative Finance Library
ReturnOnAssetsProvider.cs
Copyright (C) 2011
Marco Milletti
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.*/
using System;
using QuantProject.DataAccess.Tables;
using QuantProject.Business.DataProviders;
using QuantProject.Business.Financial.Fundamentals;
namespace QuantProject.Business.Financial.Fundamentals
{
/// <summary>
/// Class implementing FundamentalDataProvider.
/// It provides the last available ROA
/// </summary>
[Serializable]
public class ReturnOnAssetsProvider : FundamentalDataProvider
{
public ReturnOnAssetsProvider(int daysForAvailabilityOfData) :
base(daysForAvailabilityOfData)
{
}
public override double GetValue( string ticker , DateTime atDate )
{
double returnValue;
DateTime limitDateForEndingPeriodDate =
atDate.AddDays(- this.daysForAvailabilityOfData);
returnValue =
FinancialValues.GetLastFinancialValueForTicker(ticker, FinancialValueType.ROA, 12,
limitDateForEndingPeriodDate);
return returnValue;
}
}
}
|
|
From: Marco M. <mi...@us...> - 2011-08-21 13:14:33
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a4_Fundamentals
In directory vz-cvs-3.sog:/tmp/cvs-serv15992/a4_Fundamentals
Added Files:
BookValueProvider.cs
Log Message:
Added BookValueProvider
--- NEW FILE: BookValueProvider.cs ---
/*
QuantProject - Quantitative Finance Library
BookValueProvider.cs
Copyright (C) 2011
Marco Milletti
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.*/
using System;
using QuantProject.DataAccess.Tables;
using QuantProject.Business.DataProviders;
using QuantProject.Business.Financial.Fundamentals;
namespace QuantProject.Business.Financial.Fundamentals
{
/// <summary>
/// Class implementing FundamentalDataProvider.
/// It provides the last available BookValue
/// </summary>
[Serializable]
public class BookValueProvider : FundamentalDataProvider
{
public BookValueProvider(int daysForAvailabilityOfData) :
base(daysForAvailabilityOfData)
{
}
public override double GetValue( string ticker , DateTime atDate )
{
double returnValue;
DateTime limitDateForEndingPeriodDate =
atDate.AddDays(- this.daysForAvailabilityOfData);
returnValue =
FinancialValues.GetLastFinancialValueForTicker(ticker, FinancialValueType.BookValuePerShare, 12,
limitDateForEndingPeriodDate);
// FinancialValues.GetFinancialValue(ticker, FinancialValueType.BookValuePerShare, 12,
// limitDateForEndingPeriodDate);
return returnValue;
}
}
}
|
|
From: Marco M. <mi...@us...> - 2011-08-21 13:13:49
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a4_Fundamentals/FairValueProviders
In directory vz-cvs-3.sog:/tmp/cvs-serv15972/a4_Fundamentals/FairValueProviders
Modified Files:
PEGRatioFairValueProvider.cs
Log Message:
Updated the implementation of the interface
Index: PEGRatioFairValueProvider.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a4_Fundamentals/FairValueProviders/PEGRatioFairValueProvider.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** PEGRatioFairValueProvider.cs 16 Jan 2011 18:42:37 -0000 1.1
--- PEGRatioFairValueProvider.cs 21 Aug 2011 13:13:47 -0000 1.2
***************
*** 52,56 ****
}
! private double getPEGRatio(string ticker , DateTime firstDateForFundamentals,
DateTime dateOfFairValueComputation)
{
--- 52,56 ----
}
! private double getPEGRatio(string ticker ,
DateTime dateOfFairValueComputation)
{
***************
*** 68,72 ****
}
! public double GetFairValue( string ticker , DateTime firstDateForFundamentals,
DateTime dateOfFairValueComputation )
{
--- 68,85 ----
}
! public void Run(DateTime dateTime)
! {
! ;
! }
!
! public string Description
! {
! get
! {
! return "PEGRatioFairValueProvider";
! }
! }
!
! public double GetFairValue( string ticker ,
DateTime dateOfFairValueComputation )
{
***************
*** 76,81 ****
dateOfFairValueComputation);
returnValue = priceAtDateOfFairValueComputation * this.fairPEGRatioLevel /
! this.getPEGRatio(ticker,
! firstDateForFundamentals,
dateOfFairValueComputation);
--- 89,93 ----
dateOfFairValueComputation);
returnValue = priceAtDateOfFairValueComputation * this.fairPEGRatioLevel /
! this.getPEGRatio(ticker,
dateOfFairValueComputation);
|
|
From: Marco M. <mi...@us...> - 2011-08-21 13:12:40
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a4_Fundamentals/FairValueProviders
In directory vz-cvs-3.sog:/tmp/cvs-serv15943/a4_Fundamentals/FairValueProviders
Modified Files:
IFairValueProvider.cs
Log Message:
Objects implementing this interface have to implement also ILogDescriptor.
Added Run method to the interface
Index: IFairValueProvider.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a4_Fundamentals/FairValueProviders/IFairValueProvider.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** IFairValueProvider.cs 16 Jan 2011 18:42:37 -0000 1.1
--- IFairValueProvider.cs 21 Aug 2011 13:12:38 -0000 1.2
***************
*** 21,24 ****
--- 21,25 ----
using System;
+ using QuantProject.Business.Strategies.Logging;
namespace QuantProject.Business.Financial.Fundamentals.FairValueProviders
***************
*** 29,35 ****
/// available fundamental data since another previous date
/// </summary>
! public interface IFairValueProvider
{
! double GetFairValue( string ticker , DateTime firstDateForFundamentals,
DateTime dateOfFairValueComputation );
}
--- 30,41 ----
/// available fundamental data since another previous date
/// </summary>
! public interface IFairValueProvider : ILogDescriptor
{
! void Run(DateTime dateOfFairValueComputation);
! //for IFairValueProvider objects of some complexity,
! //a run method may be required before
! //calling GetFairValue, for providing
! //the actual computation of the fair value
! double GetFairValue( string ticker ,
DateTime dateOfFairValueComputation );
}
|
|
From: Marco M. <mi...@us...> - 2011-08-21 13:09:54
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a4_Fundamentals
In directory vz-cvs-3.sog:/tmp/cvs-serv15872/a4_Fundamentals
Modified Files:
FundamentalDataProvider.cs
Log Message:
The class has become abstract
Index: FundamentalDataProvider.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a4_Fundamentals/FundamentalDataProvider.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** FundamentalDataProvider.cs 16 Jan 2011 19:49:34 -0000 1.1
--- FundamentalDataProvider.cs 21 Aug 2011 13:09:52 -0000 1.2
***************
*** 25,34 ****
{
/// <summary>
! /// Base class for fundamental data providers
/// </summary>
[Serializable]
! public class FundamentalDataProvider
{
protected int daysForAvailabilityOfData;
/// <summary>
/// FundamentalDataProvider's constructor
--- 25,41 ----
{
/// <summary>
! /// Base abstract class for fundamental data providers
/// </summary>
[Serializable]
! public abstract class FundamentalDataProvider
{
protected int daysForAvailabilityOfData;
+ public int DaysForAvailabilityOfData
+ {
+ get
+ {
+ return daysForAvailabilityOfData;
+ }
+ }
/// <summary>
/// FundamentalDataProvider's constructor
***************
*** 46,49 ****
--- 53,60 ----
this.daysForAvailabilityOfData = daysForAvailabilityOfData;
}
+ public abstract double GetValue(string ticker , DateTime atDate);
+ // {
+ // return 0.0;
+ // }
}
}
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a4_Fundamentals/RatioProviders
In directory vz-cvs-3.sog:/tmp/cvs-serv15717
Modified Files:
AverageAndDebtAdjustedGrowthRateProvider.cs
LastAvailableGrowthRateProvider.cs LastAvailablePEProvider.cs
Log Message:
FinancialValueType enum has been used
Index: AverageAndDebtAdjustedGrowthRateProvider.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a4_Fundamentals/RatioProviders/AverageAndDebtAdjustedGrowthRateProvider.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** AverageAndDebtAdjustedGrowthRateProvider.cs 16 Jan 2011 19:01:10 -0000 1.1
--- AverageAndDebtAdjustedGrowthRateProvider.cs 21 Aug 2011 13:05:31 -0000 1.2
***************
*** 64,68 ****
DataTable tableOfDebtEquityRatios =
FinancialValues.GetLastFinancialValuesForTicker(
! ticker, 64, 12, limitDateForEndingPeriodDate);//64 CODE FOR DEBT EQUITY RATIO
int numOfRows = tableOfDebtEquityRatios.Rows.Count;
if( numOfRows > 0)
--- 64,68 ----
DataTable tableOfDebtEquityRatios =
FinancialValues.GetLastFinancialValuesForTicker(
! ticker, FinancialValueType.DebtEquityRatio, 12, limitDateForEndingPeriodDate);
int numOfRows = tableOfDebtEquityRatios.Rows.Count;
if( numOfRows > 0)
***************
*** 112,119 ****
DateTime limitDateForEndingPeriodDate =
atDate.AddDays(- this.daysForAvailabilityOfData);
- //40 financial code for "net income"
DataTable tableOfEarnings =
FinancialValues.GetLastFinancialValuesForTicker(
! ticker, 40, 12, limitDateForEndingPeriodDate);
double averageGrowthRate =
this.getGrowthRate_getAverageGrowthRate(tableOfEarnings);
--- 112,118 ----
DateTime limitDateForEndingPeriodDate =
atDate.AddDays(- this.daysForAvailabilityOfData);
DataTable tableOfEarnings =
FinancialValues.GetLastFinancialValuesForTicker(
! ticker, FinancialValueType.NetIncome, 12, limitDateForEndingPeriodDate);
double averageGrowthRate =
this.getGrowthRate_getAverageGrowthRate(tableOfEarnings);
***************
*** 126,129 ****
--- 125,132 ----
return returnValue;
}
+ public override double GetValue( string ticker , DateTime atDate )
+ {
+ return this.GetGrowthRate(ticker, atDate);
+ }
}
}
Index: LastAvailablePEProvider.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a4_Fundamentals/RatioProviders/LastAvailablePEProvider.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** LastAvailablePEProvider.cs 16 Jan 2011 19:01:10 -0000 1.1
--- LastAvailablePEProvider.cs 21 Aug 2011 13:05:31 -0000 1.2
***************
*** 55,61 ****
DateTime limitDateForEndingPeriodDate =
atDate.AddDays(- this.daysForAvailabilityOfData);
- //56 code for EPS; 12 months = length of period financial value refers to
returnValue =
! FinancialValues.GetLastFinancialValueForTicker(ticker, 56, 12,
limitDateForEndingPeriodDate);
return returnValue;
--- 55,60 ----
DateTime limitDateForEndingPeriodDate =
atDate.AddDays(- this.daysForAvailabilityOfData);
returnValue =
! FinancialValues.GetLastFinancialValueForTicker(ticker, FinancialValueType.EarningsPerShare, 12,
limitDateForEndingPeriodDate);
return returnValue;
***************
*** 75,78 ****
--- 74,81 ----
return returnValue;
}
+ public override double GetValue( string ticker , DateTime atDate )
+ {
+ return this.GetPERatio(ticker, atDate);
+ }
}
}
Index: LastAvailableGrowthRateProvider.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a4_Fundamentals/RatioProviders/LastAvailableGrowthRateProvider.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** LastAvailableGrowthRateProvider.cs 16 Jan 2011 19:01:10 -0000 1.1
--- LastAvailableGrowthRateProvider.cs 21 Aug 2011 13:05:31 -0000 1.2
***************
*** 22,25 ****
--- 22,26 ----
using System;
using System.Data;
+ using QuantProject.ADT;
using QuantProject.DataAccess.Tables;
using QuantProject.Business.DataProviders;
***************
*** 52,59 ****
DateTime limitDateForEndingPeriodDate =
atDate.AddDays(- this.daysForAvailabilityOfData);
- //40 financial code for "net income"
DataTable tableOfEarnings =
FinancialValues.GetLastFinancialValuesForTicker(
! ticker, 40, 12, limitDateForEndingPeriodDate);
int numOfRows = tableOfEarnings.Rows.Count;
previousEarnings = (double)tableOfEarnings.Rows[numOfRows - 2]["fvValue"];
--- 53,61 ----
DateTime limitDateForEndingPeriodDate =
atDate.AddDays(- this.daysForAvailabilityOfData);
DataTable tableOfEarnings =
FinancialValues.GetLastFinancialValuesForTicker(
! ticker, FinancialValueType.NetIncome, 12, limitDateForEndingPeriodDate);
! string[] tableOfEarningsForDebugging =
! ExtendedDataTable.GetArrayOfStringFromRows(tableOfEarnings);
int numOfRows = tableOfEarnings.Rows.Count;
previousEarnings = (double)tableOfEarnings.Rows[numOfRows - 2]["fvValue"];
***************
*** 62,65 ****
--- 64,71 ----
return returnValue;
}
+ public override double GetValue( string ticker , DateTime atDate )
+ {
+ return this.GetGrowthRate(ticker, atDate);
+ }
}
}
|
|
From: Marco M. <mi...@us...> - 2011-08-21 12:55:43
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a4_Fundamentals/FairValueProviders/LinearRegression
In directory vz-cvs-3.sog:/tmp/cvs-serv14014
Added Files:
LinearRegressionFairValueProvider.cs
Log Message:
Added LinearRegressionFairValueProvider, providing a fair value (based on a regression model) for given instruments
--- NEW FILE: LinearRegressionFairValueProvider.cs ---
/*
QuantProject - Quantitative Finance Library
LinearRegressionFairValueProvider.cs
Copyright (C) 2011
Marco Milletti
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.*/
using System;
using QuantProject.ADT.Econometrics;
using QuantProject.Business.Financial.Fundamentals.FairValueProviders;
namespace QuantProject.Business.Financial.Fundamentals.FairValueProviders.LinearRegression
{
/// <summary>
/// Class implementing IFairValueProvider Interface
/// using a linear regression model
/// </summary>
[Serializable]
public class LinearRegressionFairValueProvider : IFairValueProvider
{
private ILinearRegressionValuesProvider linearRegressionValuesProvider;
private IIndipendentValuesProvider indipendentValuesProvider;
private double[] lastComputedRegressands;
private double[] regressionCoefficients;
//regressionCoefficients[0] is the intercept: if 0, then the
//regression line goes through the origin (0,0)
public LinearRegressionFairValueProvider(ILinearRegressionValuesProvider linearRegressionValuesProvider,
IIndipendentValuesProvider indipendentValuesProvider)
{
this.linearRegressionValuesProvider = linearRegressionValuesProvider;
this.indipendentValuesProvider = indipendentValuesProvider;
}
public void Run(DateTime dateTime)
{
QuantProject.ADT.Econometrics.LinearRegression linearRegression =
new QuantProject.ADT.Econometrics.LinearRegression();
this.lastComputedRegressands =
this.linearRegressionValuesProvider.GetRegressand(dateTime);
linearRegression.RunRegression(this.lastComputedRegressands,
this.linearRegressionValuesProvider.GetRegressors(dateTime));
this.regressionCoefficients = linearRegression.EstimatedCoefficients;
}
public string Description
{
get
{
return "Num of Regressands: " +
this.lastComputedRegressands.Length.ToString();
}
}
public double GetFairValue( string ticker ,
DateTime dateOfFairValueComputation )
{
double returnValue = 0.0;
double[] indipendentValues =
this.indipendentValuesProvider.GetIndipendentValues(ticker,
dateOfFairValueComputation);
if(this.regressionCoefficients == null)
this.Run(dateOfFairValueComputation);
//indipendentValues length = regressionCoefficients length - 1 !!!
for(int i = 0; i < this.regressionCoefficients.Length; i++)
{
if( i == 0 )
returnValue = returnValue + this.regressionCoefficients[0];
else
returnValue = returnValue +
this.regressionCoefficients[ i ] * indipendentValues[ i - 1 ];
}
return returnValue;
}
}
}
|
|
From: Marco M. <mi...@us...> - 2011-08-21 12:54:43
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a4_Fundamentals/FairValueProviders/LinearRegression
In directory vz-cvs-3.sog:/tmp/cvs-serv13990
Added Files:
BasicLinearRegressionValuesProvider.cs
Log Message:
Added BasicLinearRegressionValuesProvider, providing a basic implementation of ILinearRegressionValuesProvider
--- NEW FILE: BasicLinearRegressionValuesProvider.cs ---
/*
QuantProject - Quantitative Finance Library
BasicLinearRegressionValuesProvider.cs
Copyright (C) 2011
Marco Milletti
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.*/
using System;
using System.Data;
using QuantProject.ADT;
using QuantProject.ADT.Timing;
using QuantProject.Business.DataProviders;
using QuantProject.Business.Financial.Fundamentals;
using QuantProject.Data.Selectors;
namespace QuantProject.Business.Financial.Fundamentals.FairValueProviders.LinearRegression
{
/// <summary>
/// Class implementing ILinearRegressionValuesProvider Interface
/// In this basic implementation, regressands are prices and
/// regressors are fundamental values
/// In this implementation a constant regressor is added by default
/// </summary>
[Serializable]
public class BasicLinearRegressionValuesProvider : ILinearRegressionValuesProvider
{
private ITickerSelectorByDate tickerSelectorByDate;
private FundamentalDataProvider[] fundamentalDataProviders;
private DateTime regressandDateTimeForModelling;
private DateTime regressorsDateTimeForModelling;
private DayOfMonth dayOfMonthForRegressandAndRegressors;
private HistoricalMarketValueProvider historicalMarketValueProvider;
private double[] regressand;
private double[,] regressors;
public BasicLinearRegressionValuesProvider(ITickerSelectorByDate tickerSelectorByDate,
FundamentalDataProvider[] fundamentalDataProviders,
DayOfMonth dayOfMonthForRegressandAndRegressors)
{
this.tickerSelectorByDate = tickerSelectorByDate;
this.fundamentalDataProviders = fundamentalDataProviders;
this.dayOfMonthForRegressandAndRegressors = dayOfMonthForRegressandAndRegressors;
this.regressandDateTimeForModelling = new DateTime(1900, 1 ,1);
this.regressorsDateTimeForModelling = new DateTime(1900, 1 ,1);
this.regressand = null;
this.regressors = null;
this.historicalMarketValueProvider =
new HistoricalAdjustedQuoteProvider();
}
protected virtual DataTable getTickers(DateTime dateTime)
{
DataTable returnValue =
this.tickerSelectorByDate.GetTableOfSelectedTickers(dateTime);
return returnValue;
}
protected virtual DateTime getDateTimeForModelling(DateTime dateTime)
{
int year = dateTime.Year;
DateTime returnValue = new DateTime(year, this.dayOfMonthForRegressandAndRegressors.Month,
this.dayOfMonthForRegressandAndRegressors.Day, 16, 0, 0);
int maxDaysForAvailability =
this.fundamentalDataProviders[0].DaysForAvailabilityOfData;
for(int i = 0; i < this.fundamentalDataProviders.Length; i++)
if ( this.fundamentalDataProviders[i].DaysForAvailabilityOfData >
maxDaysForAvailability )
maxDaysForAvailability =
this.fundamentalDataProviders[i].DaysForAvailabilityOfData;
DateTime dateForAvailability = dateTime.AddDays(-maxDaysForAvailability);
while(returnValue > dateForAvailability )
{
returnValue = new DateTime(returnValue.Year - 1, this.dayOfMonthForRegressandAndRegressors.Month,
this.dayOfMonthForRegressandAndRegressors.Day, 16, 0, 0);
}
return returnValue;
}
protected virtual DateTime getRegressandDateTimeForModelling(DateTime dateTime)
{
DateTime returnValue;
if(dateTime != this.regressandDateTimeForModelling)
returnValue = this.getDateTimeForModelling(dateTime);
else
returnValue = this.regressandDateTimeForModelling;
return returnValue;
}
protected virtual DateTime getRegressorsDateTimeForModelling(DateTime dateTime)
{
DateTime returnValue;
if(dateTime != this.regressorsDateTimeForModelling)
returnValue = this.getDateTimeForModelling(dateTime);
else
returnValue = this.regressorsDateTimeForModelling;
return returnValue;
}
protected virtual bool hasBothRegressandAndAllRegressors(string ticker, DateTime currentDateTimeForModelling)
{
bool returnValue = true;
double currentRegressand = 0.0;
double currentRegressor = 0.0;
try
{
currentRegressand = this.historicalMarketValueProvider.GetMarketValue(ticker, currentDateTimeForModelling);
for(int i = 0; i < this.fundamentalDataProviders.Length; i++)
{
int daysToAddForGettingRegressor =
this.fundamentalDataProviders[i].DaysForAvailabilityOfData;
currentRegressor =
this.fundamentalDataProviders[i].GetValue(ticker,
currentDateTimeForModelling.AddDays(daysToAddForGettingRegressor));
}
}
catch(Exception ex)
{
string forBreakpoint = ex.Message; forBreakpoint = forBreakpoint + "";
returnValue = false;
}
return returnValue;
}
protected virtual int getNumberOfRegressands(DateTime currentDateTimeForModelling)
{
int returnValue = 0;
DataTable tickers =
this.getTickers(currentDateTimeForModelling);
foreach(DataRow row in tickers.Rows)
{
if(this.hasBothRegressandAndAllRegressors((string)row[0], currentDateTimeForModelling))
returnValue++;
}
return returnValue;
}
protected virtual double getRegressand_getComputedRegressand_getSingleRegressand(string ticker,
DateTime currentDateTimeForModelling)
{
double returnValue = 0.0;
returnValue = this.historicalMarketValueProvider.GetMarketValue(ticker,
currentDateTimeForModelling);
return returnValue;
}
protected double[] getRegressand_getComputedRegressand(DateTime currentDateTimeForModelling)
{
double[] returnValue =
new double[this.getNumberOfRegressands(currentDateTimeForModelling)];
DataTable tickers = this.getTickers(currentDateTimeForModelling);
int idxCurrentRegressand = 0;
foreach(DataRow row in tickers.Rows)
{
if(this.hasBothRegressandAndAllRegressors((string)row[0], currentDateTimeForModelling))
{
returnValue[idxCurrentRegressand] =
this.getRegressand_getComputedRegressand_getSingleRegressand((string)row[0], currentDateTimeForModelling);
idxCurrentRegressand++;
}
}
this.regressandDateTimeForModelling = currentDateTimeForModelling;
return returnValue;
}
public double[] GetRegressand(DateTime dateTime)
{
double[] returnValue;
DateTime currentDateTimeForModelling =
this.getRegressandDateTimeForModelling(dateTime);
if( currentDateTimeForModelling == this.regressandDateTimeForModelling &&
this.regressand != null )
returnValue = this.regressand;
else
returnValue =
this.getRegressand_getComputedRegressand(currentDateTimeForModelling);
this.regressand = returnValue;
return returnValue;
}
protected double[,] getRegressors_getComputedRegressors(DateTime currentDateTimeForModelling)
{
double[] currentRegressand = this.GetRegressand(currentDateTimeForModelling);
int numOfRegressors = this.fundamentalDataProviders.Length + 1;
//the first regressor is the constant regressor,
//in order to compute the intercept
double[,] returnValue =
new double[currentRegressand.Length , numOfRegressors];
DataTable tickers = this.getTickers(currentDateTimeForModelling);
int idx_Ticker = 0;
foreach(DataRow row in tickers.Rows)
{
if(this.hasBothRegressandAndAllRegressors((string)row[0], currentDateTimeForModelling))
{
for(int idxRegressor = 0;
idxRegressor < numOfRegressors;
idxRegressor++)
{
if(idxRegressor == 0)
returnValue[ idx_Ticker, idxRegressor ] = 1;
//constant regressor
else//idxRegressor - 1 is the fundamental non constant regressor
returnValue[ idx_Ticker, idxRegressor ] =
this.fundamentalDataProviders[idxRegressor - 1].GetValue(
(string)row[0],
currentDateTimeForModelling.AddDays(fundamentalDataProviders[idxRegressor - 1].DaysForAvailabilityOfData));
}
idx_Ticker++;
}
}
this.regressorsDateTimeForModelling = currentDateTimeForModelling;
return returnValue;
}
public double[,] GetRegressors(DateTime dateTime)
{
double[,] returnValue;
DateTime currentDateTimeForModelling =
this.getRegressorsDateTimeForModelling(dateTime);
if( currentDateTimeForModelling == this.regressorsDateTimeForModelling &&
this.regressors != null )
returnValue = this.regressors;
else
returnValue =
this.getRegressors_getComputedRegressors(currentDateTimeForModelling);
this.regressors = returnValue;
return returnValue;
}
}
}
|
|
From: Marco M. <mi...@us...> - 2011-08-21 12:53:46
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a4_Fundamentals/FairValueProviders/LinearRegression
In directory vz-cvs-3.sog:/tmp/cvs-serv13935
Added Files:
BasicIndipendentValuesProvider.cs
Log Message:
Added BasicIndipendentValuesProvider, providing a basic implementation of IIndipendentValuesProvider
--- NEW FILE: BasicIndipendentValuesProvider.cs ---
/*
QuantProject - Quantitative Finance Library
BasicIndipendentValuesProvider.cs
Copyright (C) 2011
Marco Milletti
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.*/
using System;
using QuantProject.Business.Financial.Fundamentals;
namespace QuantProject.Business.Financial.Fundamentals.FairValueProviders.LinearRegression
{
/// <summary>
/// Class implementing IIndipendentValuesProvider Interface
/// In this basic implementation, indipendent values
/// (to be passed to a LinearRegressionFairValueProvider)
/// are fundamental values
/// </summary>
[Serializable]
public class BasicIndipendentValuesProvider : IIndipendentValuesProvider
{
private FundamentalDataProvider[] fundamentalDataProviders;
public BasicIndipendentValuesProvider(FundamentalDataProvider[] fundamentalDataProviders)
{
this.fundamentalDataProviders = fundamentalDataProviders;
}
public virtual double[] GetIndipendentValues(string ticker,
DateTime dateForIndipendentValues)
{
double[] returnValue = new double[this.fundamentalDataProviders.Length];
for(int i = 0; i < this.fundamentalDataProviders.Length; i++)
returnValue[i] =
this.fundamentalDataProviders[i].GetValue(ticker, dateForIndipendentValues);
return returnValue;
}
}
}
|
|
From: Marco M. <mi...@us...> - 2011-08-21 12:52:43
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a4_Fundamentals/FairValueProviders/LinearRegression
In directory vz-cvs-3.sog:/tmp/cvs-serv13847
Added Files:
ILinearRegressionValuesProvider.cs
Log Message:
Added ILinearRegressionValuesProvider, interface providing regressands and regressors for estimation of regression coefficients
--- NEW FILE: ILinearRegressionValuesProvider.cs ---
/*
QuantProject - Quantitative Finance Library
ILinearRegressionValuesProvider.cs
Copyright (C) 2011
Marco Milletti
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.*/
using System;
using QuantProject.ADT.Timing;
namespace QuantProject.Business.Financial.Fundamentals.FairValueProviders.LinearRegression
{
/// <summary>
/// Interface to be implemented by classes
/// providing values (regressand and regressors)
/// for a regression model
/// </summary>
public interface ILinearRegressionValuesProvider
{
double[] GetRegressand(DateTime dateTime);
double[,] GetRegressors(DateTime dateTime);
}
}
|
|
From: Marco M. <mi...@us...> - 2011-08-21 12:51:00
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a4_Fundamentals/FairValueProviders/LinearRegression
In directory vz-cvs-3.sog:/tmp/cvs-serv13773
Added Files:
IIndipendentValuesProvider.cs
Log Message:
Added IIndipendentValuesProvider, for providing indipendent values used by the LinearRegressionFairValueProvider for estimating the dependent value (the value that has to be forecast by a linear regression model)
--- NEW FILE: IIndipendentValuesProvider.cs ---
/*
QuantProject - Quantitative Finance Library
IIndipendentValuesProvider.cs
Copyright (C) 2011
Marco Milletti
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.*/
using System;
namespace QuantProject.Business.Financial.Fundamentals.FairValueProviders.LinearRegression
{
/// <summary>
/// Interface to be implemented by classes
/// providing indipendent values
/// to a linear regression model
/// in order to estimate dipendent values
/// </summary>
public interface IIndipendentValuesProvider
{
double[] GetIndipendentValues(string ticker,
DateTime dateForIndipendentValues);
}
}
|
|
From: Marco M. <mi...@us...> - 2011-08-21 12:45:50
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a4_Fundamentals/FairValueProviders/LinearRegression In directory vz-cvs-3.sog:/tmp/cvs-serv13516/LinearRegression Log Message: Directory /cvsroot/quantproject/QuantProject/b4_Business/a1_Financial/a4_Fundamentals/FairValueProviders/LinearRegression added to the repository |
|
From: Marco M. <mi...@us...> - 2011-08-21 12:45:15
|
Update of /cvsroot/quantproject/QuantProject/b4_Business/a07_DataProviders
In directory vz-cvs-3.sog:/tmp/cvs-serv13488
Added Files:
VirtualAndHistoricalAdjustedQuoteProvider.cs
Log Message:
Added VirtualAndHistoricalAdjustedQuoteProvider, providing historical o virtual (not stored in DB) adjusted quotes, through the given IVirtualQuotesProvider
--- NEW FILE: VirtualAndHistoricalAdjustedQuoteProvider.cs ---
/*
QuantProject - Quantitative Finance Library
VirtualAndHistoricalAdjustedQuoteProvider.cs
Copyright (C) 2011
Marco Milletti
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
using System;
using QuantProject.ADT;
using QuantProject.DataAccess.Tables;
using QuantProject.Business.Timing;
using QuantProject.Business.DataProviders.VirtualQuotesProviding;
using QuantProject.Data.DataProviders.Caching;
using QuantProject.Data.DataProviders.Quotes;
namespace QuantProject.Business.DataProviders
{
/// <summary>
/// Returns historical o virtual (not stored in DB) adjusted quotes,
/// through the given IVirtualQuotesProvider
/// </summary>
[Serializable]
public class VirtualAndHistoricalAdjustedQuoteProvider : HistoricalAdjustedQuoteProvider
{
IVirtualQuotesProvider virtualQuotesProvider;
public VirtualAndHistoricalAdjustedQuoteProvider(IVirtualQuotesProvider virtualQuotesProvider) :
base()
{
this.virtualQuotesProvider = virtualQuotesProvider;
}
public override double GetMarketValue(
string instrumentKey ,
DateTime dateTime )
{
MarketStatusSwitch marketStatusSwitch =
HistoricalAdjustedQuoteProvider.GetMarketStatusSwitch( dateTime );
double marketValue;
if( this.virtualQuotesProvider.Contains(instrumentKey) )
//the current instrument key is virtual
{
marketValue =
this.virtualQuotesProvider.GetVirtualQuote(instrumentKey,
dateTime,
this);
}
else// the given ticker is not virtual (so it should be in the DB)
{
try{
marketValue =
HistoricalQuotesProvider.GetAdjustedMarketValue(
instrumentKey , ExtendedDateTime.GetDate( dateTime ) ,
marketStatusSwitch );
}
catch(MissingQuoteException ex)
{
string str = ex.Message;
double averageQuote;
averageQuote =
Quotes.GetAverageAdjustedClosePrice(instrumentKey,
dateTime.AddDays(-45),
dateTime);
marketValue = averageQuote;
}
}
return marketValue;
}
protected override string getDescription()
{
return "VirtualAndHistoricalAdj";
}
public override bool WasExchanged(string ticker, DateTime dateTime)
{
bool wasExchanged;
if( this.virtualQuotesProvider.Contains(ticker) )
//the current ticker is virtual
wasExchanged =
this.virtualQuotesProvider.IsAvailable(ticker, dateTime);
else
//the current ticker is real (and its quotes should be stored in the DB)
wasExchanged =
HistoricalQuotesProvider.WasExchanged( ticker , dateTime );
return wasExchanged;
}
}
}
|