Stock Model

The stock model library contains all the classes that model the abstract concept of a stock and its related entities (like Quotations, etc). These are the available classes:

contains the list of quotations a stock can have over a day and all the information about the relevant data a day has (open and close price, max and min, etc)

  • Stock: its main goal is to model a stock in memory, to do this it contains the properties of a stock.
  • StockId: it stores the id of a stock. An Id is composed by a ticker symbol and a ticker name. Looks like each provider uses its own symbols and names (symbols are completely different while names usually have small differences but sometimes are completely different). Check tickers here.
  • QuotationCalendar: is the collection of quotations that a stock has in memory. As this application (and the model) is headed towards day trading the data is stored as a list of quotations into a dictionary of days, each day containing its own list of quotations. Currently a stock only has loaded one day but this design allows us to expand the functionality in the future.
    • It has methods to Load and Unload days, to get the quotations of a day and to query if a day has quotations.
      • Note 1: days are created the first time they are accessed (returning an empty observable collection that will get filled when LoadDay is called) or created with all the data available if the LoadDay is called before the GetDay. When GetDay is called first and LoadDay second all the loaded quotes raise a NotifyCollectionChanged event. When LoadDay is called first and GetDay second you should loop all the available data into the existing day before adding a handler to the NotifyCollectionChanged event.
      • Note 2: the calendar notifies when a day is created / loaded through the NotifyCollectionChanged event.
  • QuotationDailyInfo: contains the list of quotations a stock can have over a day and the engines to calculate the information about the relevant data a day has. Previously it contained all the logic but it has been split into the following classes to follow the SOLID paradigm.
  • DailyKeyQuotations: contains the different quotations that represent the key points of the day. They are stored as quotations instead of values because this way we have more information Currently these quotations are:
    • Max: maximum last value of the day. It will probably changed to store the quotation with the maximum bid of the day as this is the real highest value we could have achieved.
    • Min: minimum last value of the day. It will probably changed to store the quotation with the minimum ask of the day as this is the real lowest value we could have achieved.
    • Opening: the value of the first operation with volume of the day.
    • Closing: the value of the first operation with Type closed.
    • PreviousClosing: the value of the last operation executed the previous day.
    • LastOperation: the last operation currently executed (the last quotation with a volume different from the previous one).
    • LastQuotation: the last quotation received.
  • DailyKeyQuotationsCalculator: it is the engine that calculates the DailyKeyQuotations values. It does its work hooking to the collection changed event of the QuotationDailyInfo quotes collection.
  • QuotationDailyStatistics: contains the different values calculated using the different DailyKeyQuotations, these values are shown at the Viewer and will be probably used by the Viewer.
  • QuotationDailyStatisticsCalculator: it is the engine that calculates the QuotationDailyStatistics. It does his work hooking to the PropertyChanged event 
  • QuotationDailyInfo: contains the list of quotations a stock can have over a day and all the information about the relevant data a day has (open and close price, max and min, etc). The information is stored always as a quotation, this way we have all the information available at the moment of the "event". For example, we do not store the max value of a quotation but the quotation that had the max value. The class updates the values of all its properties while Quotations are being loaded but the Previous Closing that is loaded externally as this data is not available inside today's Quotations.
    • Open: the open quotation is the first quotation with volume on a day.
    • Close: the close price is the last quotation.
    • Max: the quotation with the higher value on a day.
    • Min: the quotation with the lower value on a day.
    • LastOperation: the quotation of the last operation executed.
    • Previous Closing: the last quotation of the previous day with the market closed.  
      • Note: the object has a property that informs about the loaded day on it. If you try to load quotations from different days onto the object an exception will be thrown. The value will be set at construction time.
  • Quotation: represents the information available of a stock in a definite moment. The data stored is:
    • Value: the value of the last operation done on the stock. The number is formatted to have at least one 0 and 4 decimals at maximum.
    • Acquisition: time when the quotation was taken.
    • Date: time represented by the quotation. As quotations are generated at regular intervals but they are only stored on change we need two DateTime to store both values.
    • Volume: volume in number of titles when the quotation was taken.
    • Sellers: list of sellers
    • Buyers: list of buyers
      • Note 1: the model is prepared to store more than one ask / bid value but currently only 1 is used as is it easier to read the information from the provider. It has been observed that the first value is the more meaningful one.
    • Type: type of quote based on the time when it was taken. All the stock markets has 4 types of quotations.
  • QuoteType: is an enumeration of all the 4 types of quotes available based on the time when the quote was taken:
    • OpeningBid: quotes read while in the opening bid. It can depend on the provider but with Interdin they have no volume and their value is the closing value of the previous day. It happens half an hour previous to the open of the market.
    • Open: quotes read while the market is open. Normal quotes.
    • ClosingBid: quotes read while in the closing bid. The volume and the value does not change. It happens 5 minutes before closing the market.
    • Closed: quotes read with the market closed. They do not change and a QuotationDailyInfo should contain only one of these.
  • Order: represents the orders a buyer / seller can put on the exchange market. It has a value (formatted as the one at the quotation) and a quantity.
  • StockGroup: represents a logical group of stocks, usually done to create a index. In the actual model a stock must pertain to a single group. A StockGroup pertains to an ExchangeMarket which defines the different times and the different states each market has (different bids, etc).
    • Note 1: this probably needs to be enhanced to allow for stocks without group and stocks that pertain to more than one group.
    • Note 2: stock groups are static data and they have a fixed name. Due to this the name of the stock groups is an enumeration instead of a string.
  • StockGroupName: is an enumeration of all the groups actually managed by the tool (and all of them are linked to the Interdin provider). As they are static data we use an enum instead of a string to have always valid data:
    • Ibex35: the stocks of the Ibex35 index.
    • MEFFFutures: contains the futures over the Ibex35 index.
    • EUREXFuture: contains the futures offered by the Eurex market.
    • OtherIndexFutures: contains diverse futures over indexs.
    • EnergyFutures: contains futures over energy markets.
    • MetalFutures: contains futures over metal markets.
    • MoneyFutures: contains futures over currencies.
    • EuroStockxx50: contains the stocks of the EuroStockxx50 index
    • ContinuousMarket: contains some stocks of the Spanish continuous market.
  • StockGroupItem: models the relation between a stock and a group. Contains the stock and the dates when the stock was added to the group and removed (if any).
    • Note: maybe this class can be removed and the properties be added to the stock class directly. Looks like recreating too directly the db table structure.
  • StockGroupDataSource: the responsibility of this class is to store / retrieve stocks from / to the database. Internally uses the ExchangeMarketDataSource to fill the dependences of the stockgroups It has the following methods:
    • Save: saves a StockGroup to the database. The process is the next one:

 

  •  
    •  Load: it allows you to load a group with today's element or with the elements the group had certain day.
  • QuotationCollectionFiller: the responsibility of this utility class is to fill the gaps in a Quotation collection. We store only the data changes but we need quotations in memory every second to be able to calculate some indicators and to calculate them at regular intervals. This class take a collection with a possible gap at the end and appends a new quotation filling the gap if it exists.
  • QuotationDataSource: the responsibility of this class is to store / retrieve quotations from / to the database. It has methods to:
    • Save a quote.
    • Save a quote if it does not exist: some providers update quotes even when the market is closed. As we only store one quote when the market is closed we must check if it does. This has to be reviewed to find a better way of handling the scenario.
    • Load a day.
    • Check if a stock has quotations for a specified day.
    • Get all days with quotes for a specific stock.
    • Get all days with quotes.
  • ExchangeMarket: models a market and defines its own times. A market can have up to 4 states that happen at different times: Closed, Pre-Opening, Opened and Closing. Some markets do not have a closing bid and then they have a null value. ExchangeMarkets are static data and they have a fixed name. Due to this the name of the stock groups is an enumeration instead of a string. They contain a list of holidays stored as static data. Provide methods to check if the market is open and which is the state of the market.
  • ExchangeMarketName: is an enumeration of all the markets actually managed by the tool (and all of them are linked to the Interdin provider). As they are static data we use an enum instead of a string to have always valid data:
    • Standard: represents the spanish market and european stock markets, you can find it here.
    • Eurex: represents the Eurex market, you can find it here.
    • Globex: represents the Globex market, you can find it here.
  • ExchangeMarketDataSource: the responsibility of this class is to retrieve markets from the database. It has one method to read a Market based on its name or a method to load all the available Markets. It will return a new Market instance even when reading the same market twice. Not sure if this can have side-effects.
  • Operation: represents an operation. Currently we model an operation as a buy and sell pair (in any order), we cannot model operations that consist on more than two executed order. This will make the model more complex and we don't need them. This could be changed in the future if it's required. This class is very related with the execution of orders and strategies so maybe it's moved to the strategy library in the future.
  • RawStockDataSource: its responsibility is to give access to the stocks in database directly without using groups. Its designed as a hack to overcome a current limitation: futures with different expiry dates have different symbols but are the same stock. The RawStockDataSource searches all the stocks grouping them by name, then we can get all the different stocks that share the same name because they are futures with different expiry dates and are used as if they were just a stock. It also provides other utility methods to access stocks without using groups as some strategies work with only one stock and there is no need of the group concept.

Last edited Feb 18, 2013 at 10:03 AM by somos, version 49

Comments

No comments yet.