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.