.

Matthew Rathbone's Blog

I was tagged in: tools windows top5

Friday, December 05, 2008

Lots of tools are useful, but here's my favourite 5 tools which I install on every pc I use regularly.

1. Notepad ++

LINK

An extremely useful application which replaces the regular notepad. It has tonnes of language support so that you get colored code in everything from perl to caml to xml. It's VERY quick to load, has a tabbed interface, and is generally lovely to use.

2. Tail

LINK

I'm jealous of a whole bunch of UNIX stuff I don't get access to on a daily basis and tail is one of those things. This windows app lets you 'tail' text files (such as log files), updating the view every time the file changes and always scrolling to the bottom. Debugging through log files is made 100x easier!

3. Winmerge

LINK

Winmerge is the open-source version of 'Beyond Compare' style applications. It allows you to easily compare and merge documents. It's not as feature-rich as beyond compare, but for what this type of tool is typically used for it's absolutely perfect.

4. Google Desktop

LINK

Stay with me on this one! This has improved my productivity 300%, being able to instantly open applications and common files is fantastic. I guess you could also use Windows Live Desktop, or switch to Vista. Personally, I found Google Desktop much faster than the Microsoft alternative.

The most useful bit: Simply press CTRL twice and type:

5. TortoiseSVN

LINK

This is a no-brainer. TortoiseSVN provides incredible Subversion integration into the Windows Shell, it changes folder icons based on item status' handles conflict resolution well, allows you to compare files (even better with Winmerge(see above)), and even enables comparison of Microsoft Office Documents (which is the REAL killer feature. Imagine lengthy functional requirements documents).

BONUS: PuTTY

LINK

SSH into a networked / remote Linux box with ease, you can even do it over t'internet with some help from a dynamic DNS Provider. Not only can you control your 'nix machine, but if you set up some Tunnels you can use it as a http proxy, access the machine's local drives, access shared music and more.

Plus you can make the Windows command prompt extremely jealous.

kick it on DotNetKicks.com

0 Comments

I was tagged in: bloomberg vba excel real-time

Wednesday, December 03, 2008

The RTD / BDP functions provide real-time data from bloomberg directly to an excel sheet. However if you're subscribing to fields which Bloomberg hasn't designated to be 'real-time enabled' you have to manually refresh bloomberg data for it to have any effect.


Let's look at an example

 

FUT_CTD_PX (Cheapest to deliver price) is a static FIELD for a real-time VALUE. IE, if you check in the BB terminal this value will be constantly changing, but excel sees it as a static field.

To get the CTD price for a future we can use the following formula:

=BDP("SOME FUTURE'S TICKER", "FUT_CTD_PX")

This field will never update, it will stay static with it's initial value. If the spreadsheet has been open for 5 days, it's the price from 5 days ago which will be displayed.

Microsoft's RTD server model is event driven, in that the data-source notifies the RTD server when a new value is available and that value is picked up by a spreadsheet when excel calls it's RTD.RefreshData method (which it does every 2 seconds by default). In our example, Bloomberg's data-source never notifies the RTD server of a change in value for any of it's STATIC fields, and they therefore remain the same indefinitely.

This also explains why calling RTD.RefreshData from VBA code has no effect, as the RTD server has no new value to pass forwards.

Solutions

The only REAL solution is for Bloomberg to provide such key fields as real-time. Static fields should be reserved for values which do not change on a regular basis, such as instrument name, maturity date, ISIN, and so forth.

As a manual solution, Bloomberg does provide a Excel menu containing data-refresh commands. Clicking 'refresh entire workbook' will eventually update all static values (it can take up to 10 seconds), but only for the =BDP formula. If you're using =RTD you'll have to re-open your workbook or delete and re-type the formulas.

"Can I do this Programatically?" I hear you cry.... Why yes you can!

It's not a graceful solution by any means but you can use one of the following to activate the respective bloomberg command:

Application.Run ("bloombergui.xla!RefreshData") [Default]

Application.Run ("bloombergui.xla!RefreshCurrentSelection")

Application.Run ("bloombergui.xla!RefreshEntireWorksheet")

Application.Run ("bloombergui.xla!RefreshEntireWorkbook")

Application.Run ("bloombergui.xla!RefreshAllWorkbooks")

be sure to wrap any use of these in good error checking to avoid Excel getting mad at the user.


Summary

It's important to be aware that some bloomberg fields are not real-time. If you're using one of these fields for a key calculation you'll have to make sure that you manually refresh regularly, or that you have integrated a crude automation into your code.

0 Comments

I was tagged in: excel file-size

Monday, December 01, 2008

If you have an excel file over 10mb in size excel could become unstable and it will take forever to save, backup, or pretty much do anything with. It will also use significantly more memory, degrading the performance of your machine as a whole.

I've worked in several offices dealing with excel files pushing 30mb. The reality is that these files need only be around 3 or 4mb. Regardless of how many rows of data you may be storing.

Here are my key tips to reducing the size of your excel file:

1. Remove pictures

Shadows, images, and drawings all increase file size, drawing objects created by adding 3d effects or shadows have the worst effect as they're just stored as (large) pictures. If you've added shadows to some cells, remove them.

Coloring cells also has a negative effect on file size, although more limited.

2. Delete unwanted Rows

This sounds silly, but it has a massive effect on file size.

Here's a really simple example:
I've created a workbook with 3 sheets, each with 1000 records covering 18 columns. if I write some simple text to cell 65000 in each sheet the file size jumps by 500kb.

Excel File size comparison

Excel sometimes seems to extend the lower boundry of worksheets without any real reason, so if you're working with large files I suggest you check to see if there are reams of unused rows.
I've reduced the size of one particular file from 24mb to 1.5mb using only this tactic.

This also leads me on to my third point

3. Don't let macro's loop over every cell in a row / column

There are plenty of macros that will perform an assessment on every single cell in a particular column, all the way down to row 65k

Not only will this make it take about 20 minutes to run, but it can easily trick excel into thinking that it needs to save the contents of every single row (see point 2).
Here's a simple loop which will only iterate over cells if they're occupied (your data will have to be in a proper table-structure):

dim usefulCell as Range 

set usefulCell = SampleSheet.Range(col1_header_range_name)

Do until usefulCell.Value = ""

	'Do some stuff here, for example:

	CustomerObject.Name = usefulcell.Value

	CustomerObject.Address = usefulcell.offset(0, 1).Value

	CustomerObject.Age = usefulcell.offset(0, 2).Value

	'etc

	set usefulCell = usefulCell.offset(1, 0)

Loop

4. Don't do things twice

Don't have more formulae than you have to. If you're relying on a specific calculation multiple times, only calculate it once, then refer to that calculation in subsequent cells.

Don't replicate data, there's no point copying huge wads of data from one worksheet to another, reorganize so that you only need it in one place

Use static values wherever possible: If data comes from some external source, milk that source to the max. Anything you are calculating which could be imported SHOULD be imported, calculations increase file size and reduce performance.

I hope these tips help to make your excel user experience a better one. Please email me with any questions or comments.

 

0 Comments

I was tagged in: vba ioc dependency injection csharp

Monday, November 10, 2008

Regardless of how much time Microsoft invests into developing Visual Studio Tools for Office there’s still going to be a market for VBA, but that doesn’t mean we have to compromise our methodologies or best practices.

Dependency injection in VBA is not only possible, but it’s not as much work to implement as you might think. Sure VB6’s system for Interface inheritance leaves a lot to be desired, and it’s a whole lot less flexible than modern languages, but you can still add a massive amount of flexibility and control to your code through a little thought and planning.

There are a few key things we need for a basic IoC implementation.

1. Interfaces for key dependencies that we want to ‘inject’ (for example a data-repository)
2. A centralized way to change what concrete object is mapped to that interface by default
3. A way to inject that concrete object upon creation of a dependant object (as VBA does not allow you to pass parameters on construction)

Let’s address how to do each of these things in turn:

Interfaces

Interfaces in VBA are created by making a class and populating it with stub methods and properties which don’t do anything, that’s it. You don’t have to declare it as an interface, but it would probably make sense to prefix the name with an ‘I’.
For example, here’s an interface for IDataSource:


Option Explicit
Public Function GetOrders(customerID As String) As collection
End Function
Public Function GetAllOrders() As collection
End Function

Easy!

And here’s a basic example implementation of that interface:

Option Explicit
Implements IDatasource
Public Function IDatasource_GetOrders(customerID As String) As collection
	Dim returnCollection As New collection

	returnCollection.Add ("Item1")
	'Collection logic here
	Set IDatasource_GetOrders = returnCollection
End Function

Public Function IDatasource_GetAllOrders() As collection
	Dim returnCollection As New collection

	returnCollection.Add ("Item1")
	returnCollection.Add ("Item2")
	'Collection logic here
	Set IDatasource_GetAllOrders = returnCollection

End Function


Object Mapping

Because we don’t have use of Unity, Spring.net, or any other IoC framework, the simplest thing to do is to completely dedicate a module to the job of being an ‘object provider’

Because VBA doesn’t need to be compiled, it’s almost as easy as using a configuration file as you can change it on the fly without having to recompile and redeploy.

Additionally, if you want to externalize the assignment of concrete objects to a configuration file, you can just extend this basic object.

Here is an example of a simple object provider:

Option Explicit
'set your bindings here
Private mDataSource As New SqlDataSource
Public Property Get DataSource() As IDatasource
Set DataSource = mDataSource
End Property

All you have to do is chage the type of the private members to switch the default concrete class.

Dependency Injection

VBA doesn’t allow us to have non-default class constructors, which means we cannot construct objects like below:

Dim dataService as new OrderService(SqlRepository)


Instead we simple have to be a little more creative with our objects, I tend to add a method called Initialize which takes a IDataRepository class. If you haven’t initialized the class, no methods that rely on this private member will work, which acts as a failsafe:

Dim repository as IOrderRepository
Dim dataService as new ObjectService
Set repository = ObjectProvider.OrderRepository
dataService.Initialize repository

 

Summary

Coding VBA can be frustrating and confusing when one is used to more elegant languages and frameworks, but that doesn’t mean it’s impossible to import modern programming strategies and methodologies.

Using inversion of control in any framework promotes code reuse, separates concerns, and makes for more manageable maintenance going forwards. Working with an outdated framework does not mean one has to write code like it’s 1995.
 

0 Comments

I was tagged in: internet interests c sharp

Thursday, October 09, 2008

I've just started delving into StackOverflow.com, and I think it's great! Good job all involved!

I know it's made by mr Coding Horror himself, so it always had a lot of promise, but it's easy to use, responsive, well thought out, and ADDICTIVE!

For those who don't know, it's basically the Yahoo Answers for programmers, except that it has extra addictive features, it's very fast and some of the answers that come out of it are just pure quality.

The idea of the 'badges' is great, makes you almost feel like you're in a game trying to score points, you earn a badge when you accomplish something, it's like being in a MMORPG but instead of killing 3000 lizards you're letting someone know how to write graceful REGEX patterns.

I suggest everyone check it out

0 Comments

Page: 1 2 3 

Copyright Matthew Rathbone 2008 © : about me : contact