views:

202

answers:

2

how to define a "class" for "stock" using c++ language? The class should include the method of "meanvalue" and "variance", meanwhile it should also contain "trading volume" and some historical data. Thank you very much.

+3  A: 

Here's a start:

class Stock
{
public:
    Stock();
    ~Stock();

    int MeanValue();
    int Variance();

private:
    int mMeanValue;
    int mVariance;
};

I'll leave the implementation of the methods in this class up to you.

LeopardSkinPillBoxHat
Missing that final semi.
just_wes
@just_wes - fixed.
LeopardSkinPillBoxHat
And a container for historical data.
Duck
@Duck - And I quote: Here's a *start* :-)
LeopardSkinPillBoxHat
@LeopardSkinPillBoxHat - Just busting you. You put more into it than I would have.
Duck
ints for mean values? You can't be serious...
Tim
@tim - Yes, I only put in a fraction more thought into my answer than the poster did for the original question!
LeopardSkinPillBoxHat
Stock also should have instrument ID and at least one symbol name I think. But that should be derived from Instrument class, which also would be a base for Option, for example.
Vlad Lazarenko
A: 

You'll probably want to have a name property, and perhaps an exchange property, method to handle updates to specific things like volume, quotes, trade prices, etc. You can do this with key/value pairs or define methods for each.

For things like variance and history, you will have to have methods that are triggered by the updates so you can change the calculated values.

You really should consider showing us what you have, then we'll be more likely to help...

Tim