Click here to Skip to main content
15,913,773 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hy , lets say we have to var like(in reality there are more) this :
var goog = new ArrayList() { goog_trades[i], trading_dates_goog[i], buysell_goog[i] };
var aapl = new ArrayList() { appl_trades[i], trading_dates_aapl[i],buysell_aapl[i] };
The data this vars is something like this :
goog=[(100,101,102...))(date1, date2....) ,(+1,-1....)
Appl the same
Whell i wan't a structure something like this :
goog[0] goog[1]....
Appl[] Appl[1].....
I meand agregated data by vertical for exaple:
goog 100 date1 +1
101 date2 -1
102 date3 +1
Appl ...the same ...



Any ideea?
I forgot to say that for loops aren't a good ideea :D
Tnks a lot :P
Posted

After looking at your code, my intuition suggests that what you want is for each stock to be a collection of "trades," where each trade has identifying information, and other data, and I think your question specifically asks how, at some point, to merge those collections in a way that maintains the "independence" of the stocks.

I'd start off by creating a Class that models a trade, rather than using the older 'ArrayList data structure which is just a "bucket" into which you can throw objects of any type:
C#
public class Trade
{
    public string name;
    public int id;
    public DateTime dt;
    public int i1;
    public int i2;

    public Trade()
    {
        // for future use
    }
}
I'd then prototype the collections of trades that each stock will have:
C#
List<Trade> Goog = new List<Trade>();
List<Trade> Aapl = new List<Trade>();
Let's create a few test instances of 'Trade:
C#
Goog.Add (new Trade { name = "Google", id = 100, dt =DateTime.Now, i1 = 1, i2 = 2 });
Goog.Add (new Trade { name = "Google", id = 101, dt = DateTime.Now, i1 = 99, i2 = 100 });
Aapl.Add (new Trade { name = "Apple", id = 102, dt = DateTime.Now, i1 = 3, i2 = 4 });
Now let's consider the need to, at some point, merge different stocks. Since the "atomic" elements are Lists of type 'Trade, then this seems natural:
List<List<Trade>> AllTrades;
At the moment we wish to merge we could do something like:
AllTrades = new List<List<Trade>> { Goog, Aapl };
Or, of course, you could pre-initialize 'AllTrades, and just use 'Add, and 'Remove, as necessary.
 
Share this answer
 
Comments
johannesnestler 6-Oct-13 9:02am    
Good answer, and good question "decrypting"!
LINQ provides a UNION command that will allow you to combine two arrays.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900