Skip to content

Finding Maximum Profit

bengof Gof

Asked Mar 18, 2010, 2:30 PM EDT1 answer
Share
LinkedInX
I am writing an application where I need to test for 7 parameters.  Each parameter has a range which will generate about 2600 possibilities for each value being evaluated.  The total number of rows generated when the test is complete would be about 50GB of data stored on SQL Server.   I am using a "FOR " Loop to test for each value of each parameter.  The problem is it takes a long time to complete the test.  I am wondering if anyone knows a better way to do this.  I have been thinking to do it on SQL server using stored procedures but some of the calculations are some what more complex which I need to do it in C#.  here is a snippet of what I am doing:
 
MA_TypeArrayList = new ArrayList();
MA_TypeArrayList.Add("TA_MAType_EMA");
MA_TypeArrayList.Add("TA_MAType_SMA");
MA_TypeArrayList.Add("TA_MAType_WMA");
...............................
MA_SeriesArrayList = new ArrayList();
MA_SeriesArrayList.Add("HLC3");
MA_SeriesArrayList.Add("CLOSE");
.....................................................
foreach (string strMA1Type in MA_TypeArrayList)
{
   cboMA1Type.Text = strMA1Type;
   foreach (string strMA1Series in MA_SeriesArrayList)
   {
      cboSeriesType1.Text = strMA1Series;
      RunTest();
      if (dblProfitLoss > dblHighestProfit)
      {
         dblHighestProfit = dblProfitLoss;
         strBestValues = "Optimal MA1 Value = " + x.ToString() +
                              " Optimal MA1 Type = " + strMA1Type.ToString() +
                                " Optimal MA1 Series = " + strMA1Series.ToString() +
                                 " Optimal MA2 Value = " + y.ToString() +
                                   " Optimal MA2 Shift Value = " + z.ToString() +
                                       " Max Profit = " + dblHighestProfit.ToString();
   }

}
 
Thanks in advance.
 
Ben G
 
 
 
 
}

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    After some research I figured that the best way to do this would be using a Thread pool.   Start by creating a class which will take all the parameter via the constructor, then create a thread pool and start multiple threads.  The only thing that one must look into would be disk access since all the threads are reading and writing from and to the disk and creating too many threads will cause contention. 
     
    All and all I am very happy with this approached and it is extremely fast.
     
    behzad ghofranian
    0