Jay Fields
Posts: 765
Nickname: jayfields
Registered: Sep, 2006
|
Jay Fields is a software developer for ThoughtWorks
|
|
|
|
sidenum function
|
Posted: May 22, 2012 7:38 AM
|
|
|
This post originated from an RSS feed registered with Ruby Buzz
by Jay Fields.
|
Original Post: sidenum function
Feed Title: Jay Fields Thoughts
Feed URL: http://blog.jayfields.com/rss.xml
Feed Description: Thoughts on Software Development
|
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Jay Fields
Latest Posts From Jay Fields Thoughts
|
|
sidenum function
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
Read: sidenum function
|
|