Valuation Date Construction
30/03/2009 30,625.26
30/04/2009 269,825.04
30/05/2009 850,056.45
30/06/2009 1,922,475.06
30/07/2009 3,500,852.19
30/08/2009 5,757,055.16
30/09/2009 8,699,041.1
30/10/2009 12,232,330.17
30/11/2009 16,612,763.46
30/12/2009 19,166,542.19
30/01/2010 22,098,191.54
28/02/2010 33,539,289.47
30/03/2010 40,518,025
30/04/2010 48,372,377.98
30/05/2010 56,543,248.62
30/06/2010 65,507,314.28
30/07/2010 74,607,415.4
30/08/2010 84,352,063.34
30/09/2010 94,325,187.87
30/10/2010 104,060,459.19
30/11/2010 114,040,884.2
30/12/2010 119,094,482.8
30/01/2011 124,342,210.61
28/02/2011 140,316,539.09
30/03/2011 146,909,564.95
Calculated from this formula:
public string Calculation(double b, DateTime validation, DateTime start, DateTime end, double alpha, double beta)
{
//start date(t1)
System.TimeSpan sp_start =
validation.Subtract(start);
string sp_start_str = sp_start.TotalDays.ToString("#");
double t1 = double.Parse(sp_start_str);
// change accordingly
if (validation.Month == 12)
t1 = t1 - 14;
if (validation.Month == 01)
t1 = t1 - 28;
// end date(t2)
System.TimeSpan sp_end =
end.Subtract(start);
string sp_end_str = sp_end.TotalDays.ToString("#");
double t2 = double.Parse(sp_end_str);
t2 = t2 - 28;
double divide = (t1) / (t2);
double minus1 = (1 - (divide));
double pow1 = 1 - (Math.Pow(minus1, alpha));
double calculation = Math.Round(b * (Math.Pow(pow1, beta)), 2);
return String.Format("{0:#,###,###,###.##}", calculation);
}
What i need to do is:
The first January, all the months following t2 = 28;
After the second January, all the months following t2 = 56;
I probably need to use a for loop??? But not sure how to go about this.
Please someone help!!
Thanks.

Augustin Jianu10 reputationPosted Apr 21, 2010, 2:13 AM EDT
for (DateTime dtIndex = startDate; dtIndex <= endDate; dtIndex = dtIndex.AddDays(1))
{
//your code here
}
Or you could try dtIndex.AddMonths() instead of dtIndex.AddDays() or you could combine the two to get the desired result dtIndex.AddMonths(months).AddDays(days)
Try being a more specific and detail the steps that you want to take. If you're not sure about the code try writing the desired algorithm in common language instead of code.
Sarah Nel19 reputationPosted Apr 21, 2010, 2:22 AM EDT
every year 14 has to be added to t1
I know for loop is for(int 1 = 0; 1 < something; i++)
what I'm not sure of is, is for loop the best way to do this and if so how.