Click here to Skip to main content
15,891,316 members
Home / Discussions / C#
   

C#

 
QuestionOOP Advice Pin
Natepizzle24-Dec-11 23:28
Natepizzle24-Dec-11 23:28 
AnswerRe: OOP Advice Pin
#realJSOP25-Dec-11 1:01
mve#realJSOP25-Dec-11 1:01 
GeneralRe: OOP Advice Pin
Natepizzle25-Dec-11 9:30
Natepizzle25-Dec-11 9:30 
AnswerRe: OOP Advice Pin
PIEBALDconsult25-Dec-11 4:36
mvePIEBALDconsult25-Dec-11 4:36 
GeneralRe: OOP Advice Pin
Natepizzle25-Dec-11 9:33
Natepizzle25-Dec-11 9:33 
GeneralRe: OOP Advice Pin
PIEBALDconsult25-Dec-11 9:57
mvePIEBALDconsult25-Dec-11 9:57 
AnswerRe: OOP Advice Pin
Luc Pattyn25-Dec-11 11:36
sitebuilderLuc Pattyn25-Dec-11 11:36 
AnswerRe: OOP Advice Pin
BillWoodruff25-Dec-11 14:21
professionalBillWoodruff25-Dec-11 14:21 
First, it seems what you are modeling here now ... the "molecular object" ... is a single, static, instance of a "portfolio." And, the "atomic" elements of the portfolio are stocks/options owned now.

Certain attributes of those stocks/options are fixed (name, expiration date, purchase price); others need to be continually re-calculated based on changing current market prices (you don't state at what interval your application needs to poll the data source, the website, to refresh the calculated attributes).

At a higher level of abstraction: you are also updating the net worth of the portfolio at a current point in time, and, considering that options expire, I think you need to think about how you notify/present/warn the user of the application that an option is about to expire, or, when an option has expired, you remove it from the collection. Similarly, when you sell a stock: do the proceeds then feed back into some running total of net gain, or net loss, so that the portfolio reflects an entire "history" ?

It would seem "natural to me" that you would model a collection of portfolios, and the portfolio elements could be restricted in some ways to contain only bonds, or only puts, or calls, or whatever. Or, whatever: mix 'em all up: you're the artist here Smile | :)

This scenario suggests to me that your "macro object" that you model here is a container comprising a collection of Portfolio objects. The idea that there may be "types" of Portfolio objects, all of which share common functionality, suggests to me a class Portfolio (abstract ? virtual ?), with common fields, Properties, methods, etc., and, then, various Portofolio-Type classes/objects that inherit from the class Portfolio. Or "enforcing commonality" via use of Interfaces ?

If you choose to "mix 'em up:" what do you think about considering that what you are modeling ... at the atomic level ... is not a stock, bond, or option, but an "investment asset:" with one attribute of that investment asset being (fleshed-out as an Enum ?) its type: stock, bond, option-call, option-put, sell-short ?

The one "conspicuous" absence in your current design goal, to my eyes, is the lack of specification of the polling method to update current prices/values, and how it is controlled, or configured, by the end-user, or application. In the real world, the time-limited nature of options (puts, calls), the "tick" of each time-interval that moves you closer to expiration date may have a big influence on how frequently you monitor any given individual option.

There's also the possibility of having sell-at-price, and stop-loss sell-by, orders in place.

However, these are all just general ideas in reaction to the idea of modeling a portfolio, and I'm not saying there's anything wrong with your goals as stated here.

In terms of use of "static" classes: I certainly agree with Luc's very wise comment re: "inherently unique," and suggest you think of a static class as a place which is a repository of utility methods, in this scenario.

There are a lot resources here on CP related to web-scraping, and I'd definitely recommend you do a search for them, and take a look at your elaborate use of RegEx's to see if you could simplify that. RegEx's, however, can be compiled.

I'd also look around for a web service that may return stock/option information in a simpler format (JSON ? rather than XML ? or ?) that would be easier to parse ... assuming hsx.com is not just a name you created, a "placeholder" for accessing said information. Demand for stock/option information is so great, there are bound to be lots of ways to get that information on the web.

Assuming the user will want to create, use, change, their portfolio, and assuming your application does not run continuously: what about the issues of saving "state" when you close the application. Are you going to serialize, send a bunch of whatever off into a "Cloud:" and, if the application is closed, and then re-opened: should it automatically refresh ... warn the the user it is not currently refreshed ... or should the user, through the UI, control when refersh occurs.

My personal vote is for some dramatic visual indicator on the main UI when the current prices are not currently refreshed, or cannot be accessed to be refreshed.

If you do get involved in saving and restoring "state," do see Mehdi Gholam's remarkable work on a super-duper JSON writer/reader here on CP:[^].

Do you wish the user to be able to save "snapshots" of the Portfolio, or to introduce a "history mechanism" into the Portfolio: in which the Portfolio itself contains the entire data for each refresh that has occurred ?

Specific comments on the code:

1. in a static class ... or in a dynamic class ... there's absolutely no need to use private "backing field" variables as well as a public Property: ... unless you are using a very old version of .NET: just use the short-form like: "public static double CurrentPrice { get; set; }" : the private "backing field" will be created for you automatically.

2. by using slightly different casing in variable names in your parameter lists, you can eliminate a lot of the the use of syntax like: "this.optionType = optionType;" typical practice would be to name the variable, or Property, "OptionType," and the parameter name "optionType."

I think imagining what kind of UI a user would want to use your classes/objects is a good exercise ... even if, in this case, you don't choose to implement one ...

good luck, best, Bill
"It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle


modified 26-Dec-11 6:55am.

GeneralRe: OOP Advice Pin
Natepizzle25-Dec-11 22:13
Natepizzle25-Dec-11 22:13 
Questionvalue of using Func and lambdas vs. Delegates vs. Interface ? Pin
BillWoodruff23-Dec-11 23:20
professionalBillWoodruff23-Dec-11 23:20 
AnswerRe: value of using Func and lambdas vs. Delegates vs. Interface ? Pin
PIEBALDconsult24-Dec-11 2:57
mvePIEBALDconsult24-Dec-11 2:57 
AnswerRe: value of using Func and lambdas vs. Delegates vs. Interface ? Pin
Eddy Vluggen24-Dec-11 10:00
professionalEddy Vluggen24-Dec-11 10:00 
AnswerRe: value of using Func and lambdas vs. Delegates vs. Interface ? Pin
Shameel25-Dec-11 22:55
professionalShameel25-Dec-11 22:55 
Questionshould I create a filter? Pin
is90057james23-Dec-11 17:46
is90057james23-Dec-11 17:46 
QuestionLooking for developers to help in free and opensource project Pin
Constantinos Coudounaris23-Dec-11 8:38
Constantinos Coudounaris23-Dec-11 8:38 
AnswerRe: Looking for developers to help in free and opensource project Pin
Not Active23-Dec-11 9:12
mentorNot Active23-Dec-11 9:12 
QuestionCrystal Report Designing Issue Pin
AmbiguousName22-Dec-11 22:55
AmbiguousName22-Dec-11 22:55 
AnswerRe: Crystal Report Designing Issue Pin
Richard MacCutchan23-Dec-11 0:45
mveRichard MacCutchan23-Dec-11 0:45 
AnswerRe: Crystal Report Designing Issue Pin
Blue_Boy23-Dec-11 4:18
Blue_Boy23-Dec-11 4:18 
QuestionDetecting silence / low level in a WAV file Pin
SimonwHill22-Dec-11 4:55
SimonwHill22-Dec-11 4:55 
AnswerRe: Detecting silence / low level in a WAV file Pin
Alan Balkany22-Dec-11 5:43
Alan Balkany22-Dec-11 5:43 
AnswerRe: Detecting silence / low level in a WAV file Pin
Albert Holguin22-Dec-11 7:43
professionalAlbert Holguin22-Dec-11 7:43 
GeneralMessage Removed Pin
22-Dec-11 7:57
professionalN_tro_P22-Dec-11 7:57 
GeneralRe: Detecting silence / low level in a WAV file Pin
Albert Holguin22-Dec-11 8:44
professionalAlbert Holguin22-Dec-11 8:44 
QuestionHelp Me ! How to add the video OSD? Pin
is90057james21-Dec-11 23:33
is90057james21-Dec-11 23:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.