Jay Fields is a software developer at DRW Trading. He has a passion for discovering and maturing innovative solutions. His most recent work has been in the Domain Specific Language space where he's delivered applications that empowered subject matter experts to write the business rules of the applications. He is also very interested in maturing software design through software testing. Jay is a DZone MVB and is not an employee of DZone and has posted 116 posts at DZone. You can read more from them at their website. View Full User Profile

The Sidenum Function

06.01.2012
| 2022 views |
  • submit to reddit
The sidenum function appends a sign to a number based on a side. The name sidenum was chosen due to it's similarities with signum in spelling and behavior (dealing with signs).

Definition The sidenum function of a side x and a number y is defined as follows:
note: 'bid' can be replaced with 'buy', and 'ask' can be replaced with 'sell' or 'offer'. The string representation or type of side varies by trading system.

Usage The sidenum function appears in most trading applications, though not always named 'sidenum'. It can be helpful for both position related math and conserving screen real-estate by displaying 2 concepts (side & quantity) as 1 (a signed quantity).

Examples Java
    public static int sidenum(String side, int quantity) {
        if (side.equals("ask"))
            return -quantity;
        return quantity;
    }
Clojure
    (defn sidenum [side quantity]
      (if (= side "ask")
        (- quantity)
        quantity))
Ruby
    def sidenum(side, quantity)
      if side == "ask"
        -quantity
      else
        quantity
      end
    end
Published at DZone with permission of Jay Fields, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags:

Comments

Daniel Slazer replied on Tue, 2012/06/12 - 12:13pm

I just want to insert a string into the head of txt file. I try to use fileChannel,i can put the string into the head but the orignal content is overrided.
For example, the orignal content in txt file is 111 and i want to add "222" into the head. the result should be 222111.
who can tell me the most efficient way? thx a lot!!!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.