Monday 2 July 2012

Integrating crucial hierarchical binding feature to the trading applications

Hierarchical binding present in the trading and financial applications offer a variety of features to its users. Most of the .Net grid or MFC grid based applications implement Hierarchical binding. The benefits of using Hierarchical binding are many. For example an application implementing the Hierarchical binding techniques can easily sort and filter data compared to ones that do not. Thus the use of Hierarchical binding techniques is becoming more and more popular. Most of the developers working on the .Net platform and designing trading applications make use of Hierarchical binding benefits. The Hierarchical binding techniques also allow better data integration techniques in case of real time data update. Since most of the modern day trading and financial applications need real time voluminous updates therefore hierarchical binding is necessary to implement performance and security. Most of the hierarchical binding modules can be designed in secured manner to ensure data and application integrity.
public class Order
{
    private readonly string _instrument;
    private readonly double _price;
    private readonly long _quantity;

    public Order(string instrument, double price, long quantity)
    {
        _instrument = instrument;
        _price = price;
        _quantity = quantity;
    }

    public string Instrument
    {
        get { return _instrument; }
    }

    public double Price
    {
        get { return _price; }
    }

    public long Quantity
    {
        get { return _quantity; }
    }
}

public void PopulateGrid(Grid grid)
{
    BindingList<Order> orders = new BindingList<Order>();

    orders.Add(new Order("Instrument1", 10.55, 34));
    orders.Add(new Order("Instrument2", 12.26, 154));
    orders.Add(new Order("Instrument1", 13.16, 14));
    orders.Add(new Order("Instrument5", 9.85, 52));
    orders.Add(new Order("Instrument1", 16.47, 11));

    grid.DataSource = orders;
}
The above code implements the hierarchical binding features. Most of the hierarchical binding modules enable better data integration customizability along with data safety. The hierarchical binding modules also allow the developer to make the application more robust and scalable for regular use.
public void PopulateGrid(Grid grid)
{
    Strategy strategy = new Strategy("Strategy 1");
    strategy.Orders.Add(new Order("SubOrder1", 10.15, 34));
    strategy.Orders.Add(new Order("SubOrder2", 30.51, 43));
    grid.Rows.Add(strategy);

    Strategy strategy = new Strategy("Strategy 2");
    strategy.Orders.Add(new Order("SubOrder1", 10.15, 34));
    strategy.Orders.Add(new Order("SubOrder2", 30.51, 43));
    grid.Rows.Add(strategy);
}

public class Order : INotifyPropertyChanged
{
    ...

    public double Price
    {
        get { return _price; }
        set
        {
            _price = value;
            if(PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs("Price"));
            }
        }
    }

    public long Quantity
    {
        get { return _quantity; }
        set
        {
            _quantity = value;
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs("Quantity"));
            }
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;
}
In the above code the hierarchical binding modules implement two known features of Data binding with multi threading features and the INotifyPropertyChanged feature. The hierarchical binding modules are applied in such a way that these features are used effectively in designing the applications for regular usage. Since most of the applications are financial and trading in such cases therefore the use of these features are crucial for development.

Sunday 1 July 2012

Datagridview: The best thing about Dapfor’s Datagridview

The best thing about using Dapfor’s application is its capability to offers lots of feature and that too with good performance. One of the most important features of Dapfor application is its Datagridview. Datagridview is not only stable but also supports various version of CLR such as 2.0, 3.0, 3.5 and 4.0. This is the main reason that Datagridview is used in many applications of Dapfor. Users can find many others Datagridview from many organizations but they lack the capability to handle event-based model efficiently as Dapfor applications do. Others organizations Datagridview doesn’t face any kind of problem while handling non-event based model but when it comes to event based model there is no better than the Dapfor’s Datagridview. Dapfor’s Datagridview also consumes less system and memory resources which make them among the best in the business. 
For example, take the sorting mechanism on the Datagridview. In such kind of scenario all the relevant information’s are stored in grid headers. Look at the code below which states the sort direction using simple inbuilt methods provided by the Dapfor’s Datagridview.
//Get top-level header
Header header = grid.Headers [0];

header["Product"].SortDirection = SortDirection.Ascending;
header["Price"].SortDirection = SortDirection.Descending;
If the users want to restrict the sorting property from the GUI, they can use the Column.Sortable property. Datagridview implements the IComparable interface for applying sorting on the view. During sorting objects generally returns simple data types such as int, float, string pr Timespan. IComparable interface uses these data types for sorting purposes on the Datagridview. Dapfor’s Datagridview also has the capability to handle sorting for different rows as well for complex type of data types. The task of the IComparable interface is to compare between the simple data types and the complex data types. This interface doesn’t take into account about the stocks which is present on the grid cells. The code below gives you the insight about the Datagridview sorting using the DateTime value.
class AnotherDateSortingExample
{
    private readonly DateTime _date;

    public DateExample(DateTime date)
    {
        _date = date;
    }

    public DateTime Date
    {
        get { return _date; }
    }
}

//Create header and column
grid.Headers.Add(new Header());
grid.Headers[0].Add(new Column("Date"));

//Configure the header
grid.Headers[0].StretchMode = ColumnStretchMode.All;
grid.Headers[0][0].SortDirection = SortDirection.Ascending;
grid.Headers[0]["Date"].Format = new StringFormat("d", new CultureInfo("fr-FR"));

//Populate grid with random data
Random random = new Random();
BindingList<DateExample> source = new BindingList<DateExample>();
for (int i = 0; i < 6; ++i)
{
    source.Add(new DateExample(DateTime.Now + TimeSpan.FromDays(random.Next(1000))));
}
grid.DataSource = source;
Dapfor’s Datagridview provides provision to do user defined sorting technique. This can be achieved using the ICustomSort interface which helps is setting the sorting rules.
//An implementation ICustomSort that sorts values by day of week
class MonthOfYearCustomSort : ICustomSort
{
    public int Compare(Row row1, Row row2, string fieldId, object value1, object value2, int defaultResult)
    {
        if(fieldId == "Date")
        {
            DateTime d1 = (DateTime) value1;
            DateTime d2 = (DateTime) value2;

            if (d1. MonthOfYear != d2. MonthOfYear)
            {
                return d1. MonthOfYear > d2.MonthOfYear? 1 : -1;   
            }
        }
        return defaultResult;
    }
}

//Setup custom sorting
grid.CustomSort = new MonthOfYearCustomSort();

Saturday 16 June 2012

Trading and Finance application on .Net platform for performance benefits

Real time trading and finance applications have to be performance oriented in order to allow the real time updating process along with automatic sorting. The .Net performance enhances this performance for the real time trading and finance applications with the use of many available features. .Net performance features allow techniques like grid update of the real time data which can be sorted based on the needs. Even the .Net performance benefits allow high amount of data to be inserted directly in the rows for further sorting techniques. In trading applications every minute there might be millions of rows which are being updated. Tips and tools of the .Net performance features enable perfect insertion of the data into the rows and the columns of the grid view in the application. Though the general rate of .Net performance might vary for various trading applications in multiple configurations, the general concept of performance enhancement remains the same.
For example while updating the data in a non event model based development might use the .Net performance feature as listed below.
grid.Rows.Add(new object[]{"val1", 153, true, DateTime.Now});
//The required data is updated by calling the Cell.Value property.
Row r1 = ...;
Cell c1 = r1 [0];
c1.Value = "val2";

There are other .Net performance features too which allows multiple different types of data objects to be updates on the grid in real time. For example the .Net performance feature ThreadSafeBindingList is used in place of general BindingList in order to make the application a thread safe one.

grid.Sort.Enabled = false;
grid.DataSource = _datasource_;
//Add one object to the launch of the grid
grid.Nodes.Insert(0, _new_object_);

//Add one object to the start of the binding list
IBindingList bl = ...;
bl.Insert(0, _new_object_);

If in the above .Net performance case “grid.Sort.Enabled = true;” is used then the data is supposed to be automatically updated and sorted. But the .Net performance case is not used in order to avoid issues with large volumes of data. While developing .Net performance based applications not only performance but security of the data also needs to be kept in mind by the developers to avoid disastrous results.
For example it is not a good idea to format the values of the data in .Net performance based applications, directly into the object. 

class DateEx1
{
    ...

    // Not a good idea   
     public string FormattedD1
    {
        get { return string.Format("{0:yyyy-MM-dd}", _date); }
    }

    //Better idea: the property must return a non formatted value
    [Format("yyyy-MM-dd")]
    public DateTime D1
    {
        get { return _date; }
    }
}


Large data volumes can be added easily using the .Net performance features like INotifyPropertyChanged and IBindingList. These two .Net performance features allows the real time data update procedure in much safe and interactive way, so that no data is lost form this huge volume.

Developing effective and performance based trading applications

Trading applications are developed for the organizations which deal with trade on daily basis. There are numerous features that all the effective trading applications must have. Some of these features are handling voluminous data update on routine basis, data security, customizability, robustness etc… Nowadays most of the effective trading applications are developed on the .Net platform in order to support the above features. There are certain very crucial features that professional trading applications must possess. Real time data updating is one such feature of the trading applications. 
//Some data object
public class Service : INotifyPropertyChanged
{
    //Some fields
    private double Cost;
    private TimeDate maturity;

    [DoubleFormat(Precision = 3, ShortForm = true, ShowZero = false)]
    public double Cost
    {
        get { return Cost; }
        set
        {
            Cost = value;
            if(PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs("Cost"));
            }
        }
    }
    public TimeDate Maturity
    {
        get { return maturity; }
    }
    public event PropertyChangedEventHandler PropertyChanged;
}

//Add a data object to the grid to the trading applications.
Service Service = new Service();
Row row = grid.Rows.Add(Service);

//The grid will automatically sort, filter, group and highlight corresponding row in the trading applications!
//The Service is your business logic and may be placed in any assembly within the trading applications that doesn't need to have references to Dapfor assemblies!
Service.Cost = 123;

//The value in the "Cost" cell should equal to '123'.
Assert.AreEqual(row["Cost"].Value, 123);
The above code demonstrates the real time update feature of the trading applications. Most of the trading applications need to do regular real time data update from sources like stock markets. Thus the trading applications must be secured enough in order to enable voluminous update along with data security.

public void FilterUsing(Grid grid)
{
    //Initialize the grid
    grid.Headers.Add(new Header());
    grid.Headers[0].Add(new Column("Object Title"));
    grid.Headers[0].Add(new Column("Type"));
    grid.Headers[0].Add(new Column("Cost"));

    //Set filter
    grid.Filter = new CustomFilter();

    //Populate the grid
    Row row1 = grid.Rows.Add(new object[] { "Audi", Type.Black, 23000d});
    Assert.IsFalse(row1.Visible);

    Row row2 = grid.Rows.Add(new object[] { "HYUNDAI", Type.White, 35000d });
    Assert.IsTrue(row2.Visible);

    //Set a new Cost for "Audi"
    row1["Cost"].Value = 58000d;
    Assert.IsTrue(row1.Visible);
}

The above code demonstrates the real time data filtering feature of the trading applications. Most of the trading applications need to do regular the real time data filtering feature for the data received from various sources like stock markets. Thus the trading applications must be secured enough in order to enable the real time data filtering feature of the voluminous update along with interactive interface.

The trading applications also must be developed based on other features like hierarchical sorting and binding, thread safe nature, customizability of data handling etc…. Most of the trading applications in the modern day with the use of the .Net grid and MFC grid can incorporate all the above mentioned features. Thus the modern trading applications are effective.

Trading Application: Manage your finances through a application

In the finance industry using software which provides users with real-time data which are not only useful but should also be stable, is very tough to find. Developing a trading application is no child’s play it takes considerable amount of time from the experienced developers so that the users won’t face any kind of difficulty in handling it. Dapfor is one of the organizations which have the experience as well extensive knowledge to do that. Dapfor’s trading application are developed by group of experienced professional who have worked in this filed for many years and know what is needed to develop a perfect software with which user can get maximum benefit. User’s main requirements from a trading application are user interface and its functionality. These two requirements must be easy to use so that any naïve user can operate it without any problem. Dapfor’s trading application is also thread safe which means that deadlock situation doesn’t arise like many other applications. Their trading application tactically uses the synchronized method so that deadlock like situation can be avoided, since it cannot be guaranteed that it won’t happen ever. Another very important aspect while developing a trading application is that it should have provision for further enhancement which in this changing environment is very necessary. Dapfor consider all these factors before developing a perfect trading application for the customers. Performance wise also Dapfor’s trading application is also very good; it consumes least amount of memory as well as system resource. Real time data is the most interesting feature of Dapfor’s trading application. For example in any trading application, change is currency is very common which must be notified to the users about every single change. To handle this Dapfor uses the CurrencyRate Class in their trading application which implements the INotifyPropertyChanged interface. This interface is the main reason behind the notifications about the changes in the currency. Look at the coding below to understand it more clearly.
public class CurrencyRate : INotifyPropertyChanged
{

public IList<string> AvailableCurrencies
{
get { return _availableCurrencies; }
}
public string MainCurrency
{
get { return _mainCurrency; }
}
}
CurrencyRate currencyRate = CurrencyRate(“USD”, Provider.Instance.AvailableCurrencies);
//Get current USD/EUR rate
double rate = currencyRate["EUR"];
//Set a new USD/EUR rate
currencyRate["EUR"] = 1.42; 

All the changes are in real-time so that the user can understand the changes evidently. To display the changes to the user, Dapfor’s trading application uses their proprietary grid which is known as the Grid.Source. The data source is then connected to this grid.
Header header = Header.FromDataType(typeof (CurrencyRate));
grid.Headers.Add(header);
//Bind grid to the collection of CurrencyRate
grid.DataSource = new List<CurrencyRate>(Provider.Instance.CurrencyRates.Values);  

In this way a perfect trading application is developed and there is more to it such as the real-time highlighting, blotting, hierarchical binding and many more.

Hierarchical binding: Bind various data very easily

For every application data binding is an important aspect without it no application is complete. There are various sources from where the application can get data such as array, data set etc. All these data needs to be implemented in the application to get the benefit out of it. One of the ways of binding data is by hierarchical binding. There is always a possibility that a data objects may contain hierarchical data which is to be implemented in the application by using the hierarchical binding technique. This type of hierarchical binding is not easy to achieve but with Dapfor’s features it can be done in a simple and easy manner. For example look at the hierarchical binding code below:
// data objects which implements the hierarchical binding capability
class Author
{
    private readonly IList<Book> _books = new List<Book>();
    private readonly string _name;

    public Author(string name)
    {
        _name = name;
    }

    public IList<Book> Books
    {
        get { return _books; }
    }
    public string Name 
    {
        get { return _name; }
    }
}

class Book
{
    private readonly Author _author;
    private readonly string _name;

    public Book(Author author, string name)
    {
        _author = author;
        _name = name;
    }

    public Author Author
    {
        get { return _author; }
    }
    public string Title 
    {
        get { return _name; }
    }
}
 The IBindingList interface contains all the authors and can be bounded on the grid for the purpose of implementing hierarchical binding by the following code:
//Populate binding list with some authors
BindingList<Author> authors = new BindingList<Author>();
Author author = new Author("Agata Kristi");
author.Books.Add(new Book(author, "Second front"));
author.Books.Add(new Book(author, "Shameful Star"));
authors.Add(author);

author = new Author("Conan Doyle");
author.Books.Add(new Book(author, "The Blanched Soldier"));
author.Books.Add(new Book(author, "The Mazarin Stone"));
authors.Add(author);

//Bind grid to author collection
grid.DataSource = authors;
But if you look carefully hierarchical binding is not formed because the grid doesn’t have the knowledge about the relation between the Author and Book class. This is where the usefulness of Dapfor hierarchical binding feature comes into the picture; it provides an attribute with which it notifies the grid about the hierarchical binding by marking the Author.Book relationship.
class Author
{
    ...

    [HierarchicalField]
    public IList<Book> Books
    {
        get { return _books; }
    }

    ...
}
If any author writes a new book which is to be added to the collection for the purpose of hierarchical binding, you can do use the following code:
/Add a book to a collection
author.Books.Add(new Book(author, "His Last Bow"));
Users won’t find any change because the Book collection implements the IList<Book>. To send notification about the changes users need to implement the BindingList<Book> instead of the IList. This will make the grid receive notification about the changes and displays them automatically. If some kind of sorting, filtering or grouping is required on the application which has hierarchical binding feature, the grid does the checking for the users.
class Author
{
    private readonly IList<Book> _books = new BindingList<Book>();

    ...
}
In this way, Dapfor grid provides the functionality of the hierarchical binding. Implementing the hierarchical binding is achieved very easily and less modification is required on the different classes.  

Saturday 21 April 2012

Trading blotter

For a trading blotter application to be good it needs to incorporate the real time feature to satisfy the needs of the user. Trading blotter application must be able display data that are real time data which are used heavily by the users. For a simple trading blotter application it must have some kind of trading benchmark in this CAC40 Is used and another tab for currencies. CAC40 is used in French stock market. In developing trading blotter application developers needs to create three classes which are Market, Instrument and Feeder classes respectively. In market class all the common and necessary properties are included such as CloseTime, OpenTime, Name and MarketState. Instrument class has different important properties such as Shares, Weight, and Capitalization etc. Instrument class also helps to track different market worldwide such as the NASDAQ, BSE etc. In the Feeder class information of the Instrument class is stored and other important information’s like the price information, information of that particular instrument, history of the change in price and availability of a product. Every change in the instrument like selling or purchasing must be notified to the user with the help of the trading blotter application which is done with the Feeder Class. That’s why Feeder class implements the INotifyPropertyChanged interface. As earlier mentioned that the trading blotter application should be able to access different market wit the help of Instrument class, creation of the CAC40 class is done to put it under the Tab Control. A good trading blotter application must have separate design and data presentation. This trading blotter application makes use of this design. To connect data to the .net grid the following code is added.       
public CAC40Control()
{
    InitializeComponent();
    grid.DataSource = Provider.Instance.Cac40Feeders;
}
Composite objects can also be incorporated in this trading blotter application. Composite objects are nothing but the amalgamation of different properties and the returned object will also be a composite object. In this trading blotter application, feeder class has the reference of the Instrument class so the properties of these classes are combined to form a composite property. This property is marked with the CompositeFieldAttribute attribute.
public class Feeder : INotifyPropertyChanged
{
    private readonly Instrument _instrument;
    ...
    [CompositeField]
    public Instrument Instrument
    {
        get { return _instrument; }
    }
}

public class Instrument
{
   ...
    [Field("InstrumentId")]
    public string Isin
    {
        get { return _isin; }
    }
}
This will display ISIN from the Instrument class on the grid of the trading blotter application. Other type of Instrument can also be incorporated in the trading blotter application with the help of InstrumentId identifier. This will use market object in Feeder class.
public class Feeder : INotifyPropertyChanged
{
    private readonly Market _market;
    ...
    [CompositeField]
    public Market Market
    {
        get { return _market; }
    }
}