Update of /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv9357/b4_Business/a2_Strategies
Modified Files:
SignedTicker.cs
Log Message:
Added GetLastNightPortfolioReturn method
Index: SignedTicker.cs
===================================================================
RCS file: /cvsroot/quantproject/QuantProject/b4_Business/a2_Strategies/SignedTicker.cs,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** SignedTicker.cs 17 Sep 2006 21:33:27 -0000 1.6
--- SignedTicker.cs 27 Feb 2007 22:57:20 -0000 1.7
***************
*** 261,264 ****
--- 261,307 ----
}
+ private static double getLastNightPortfolioReturn(float[] tickersLastNightReturns,
+ double[] tickersWeights)
+ {
+ double returnValue = 0.0;
+ for(int i = 0; i<tickersLastNightReturns.Length; i++)
+ returnValue += tickersLastNightReturns[i]*(float)tickersWeights[i];
+
+ return returnValue;
+ }
+
+ private static float getLastNightPortfolioReturn_getLastNightReturnForTicker(string ticker,
+ DateTime lastMarketDay, DateTime today)
+ {
+ Quotes tickerQuotes = new Quotes(ticker, lastMarketDay, today);
+ return ( (float)tickerQuotes.Rows[1]["quOpen"] *
+ (float)tickerQuotes.Rows[1]["quAdjustedClose"]/
+ (float)tickerQuotes.Rows[1]["quClose"] ) /
+ (float)tickerQuotes.Rows[0]["quAdjustedClose"] - 1;
+ }
+
+
+ /// <summary>
+ /// Gets portfolio's last night return for the given tickers
+ /// </summary>
+ /// <param name="signedTickers">Array of signed tickers that compose the portfolio</param>
+ /// <param name="tickersWeights">Array of weights for tickers - the same order has to be provided!</param>
+ /// <param name="lastMarketDay">The last market date before today</param>
+ /// <param name="today">today</param>
+ public static double GetLastNightPortfolioReturn(string[] signedTickers,
+ double[] tickersWeights,
+ DateTime lastMarketDay,
+ DateTime today)
+ {
+ float[] tickersLastNightReturns = new float[signedTickers.Length];
+ for(int i = 0; i<signedTickers.Length; i++)
+ {
+ tickersLastNightReturns[i] =
+ getLastNightPortfolioReturn_getLastNightReturnForTicker(
+ SignedTicker.GetTicker(signedTickers[i]), lastMarketDay, today );
+ }
+ return getLastNightPortfolioReturn(tickersLastNightReturns, tickersWeights);
+ }
+
private static string[] getSignedTickersArray( ICollection signedTickers )
{
|