Labels

_fuxi (75) _IV (146) _misc (5) {610610 (30) algo (1) automatedTrading (8) banking/economy (3) book (14) c++misc (125) c++real (15) c++STL/java_container (7) cppTemplate (1) db (13) DB_tuning (4) deepUnder (1) dotnet (69) eTip (17) excelVBA (12) finance+sys (34) financeMisc (24) financeRisk (2) financeTechMisc (4) financeVol (21) finmath (17) fixedIncome (25) forex (16) IDE (24) invest (1) java (43) latency (4) LinearAlgebra (3) math (30) matlab (24) memoryMgmt (11) metaPrograming (2) MOM (15) msfm (1) murex (4) nofx (11) nosql (3) OO_Design (1) original_content (4) scriptUnixAutosys (19) SOA (7) socket/stream (15) sticky (1) subquery+join (2) swing (32) sybase (6) tech_orphan (12) tech+fin_career (30) telco (11) thread (21) timeSaver (13) tune (10) US_imm (2) US_misc (2) windoz (20) z_algo+dataStructure (4) z_arch (2) z_c#GUI (30) z_career (10) z_career]US^Asia (2) z_careerBig20 (1) z_careerFinanceTech (11) z_FIX (6) z_forex (31) z_hib (2) z_ikm (7) z_inMemDB (3) z_j2ee (10) z_oq (14) z_php (1) z_py (26) z_quant (4) z_skillist (3) z_spr (5)
Showing posts with label z_oq. Show all posts
Showing posts with label z_oq. Show all posts

Wednesday, July 10, 2013

LINQ - narrow moving window

Which part of linq operates this way??

-----
Imagine you can only use 1 unit of memory.... You get the narrowest possible moving window (size 1) over the "stream" of items. You can't query how many items in total -- You have to remember the past items. You can't query the sequence for a past or future item.

I feel this is similar to SAX parser...

I feel this is similar to database drivers. When you iterate the rows from a large query, the server gives you one row at a time.

It also reminds me of the c++/java/c# stream concept, but streams consist of bytes not "composite, structured objects"

Sunday, June 30, 2013

dotnet unmanaged RESOURCES, learning notes

(Many open questions below are a bit arcane and may not be relevant to IV or projects.)

I feel "managed" means "automatically-released". In that case, most dotnet Objects qualify as managed "Resources". Any time you need Dispose() in your CLASS, that's a telltale sign of unmanaged resources.

"Resource" is a rather abstract term, best understood by example[1]. In my mind, a resource is some runtime object(s) needed by our App, something constructed and configured. Like a natural resource it is scarce, shared and rationed. Like a library book, there's usually an acquisition "protocol", and a return protocol.

[1] As a crude example, what's a city and what's not a city? Best learn by example.

http://stackoverflow.com/questions/13786570/determine-managed-vs-unmanaged-resources has some interesting comments.

--Unmanaged resource and ... IntPtr + handle ?
What's an IntPtr? Basically a struct that represents a native void pointer (or a native handle) --
http://stackoverflow.com/questions/1148177/just-what-is-an-intptr-exactly Many unmanaged "resources" are accessed via IntPtr.

--Unmanaged resource and unsafe code?

--Unmanaged resoruce and p/invoke?

--Unmanaged resource and ... win32 + COM?

--some managed resources
filestream is a MR. It contains a native file handle, which is UR. It's IntPtr, but not a integer-based file descriptor as in C/python. See MSDN.

A socket object is a MR. It contains a socket handle, which is UR and IntPtr

A DB connection is probably UR.

Sunday, June 9, 2013

%% c# brain bench

Q: what modifiers are equivalent to static when defining a class? Perhaps a invalid question
Q: build a comparison lambda using expression tree. Will we use Binary.. or Boolean....?
Q: foreach on my custom class ... will call which methods -- MoveNext/Current or GetEnumerator()
Q: calling ToUpper() on a dynamic variable, where ToUpper is both an instance method and an extension method?
%%A: instance meth takes precedence. Ext method may not be found at all. But there are workarounds.

Q: benefit of compiling an expression tree?
Q: can I assign twice to an out parameter within Method1? I think there's no restriction.
Q: how to p/invoke on a win32 DLL
Q: execution order between base ctor, my ctor, static ctor of a type used in my ctor
Q: GetType().ToString() on System.NotSupportedException shows "System...." ?
Q: linq group-by

Q: can Main() method take 0 parameter?
AA: yes

Q: in Main(), can I initialize a variable before passing it to a out parameter of Method1?
%%A: yes optional. Pre-initialize is compulsory for ref-params and optional for out-params. Consequently, the method is requried to
populate out-param (since pre-initlialize was possibly skipped) but not required for ref-params.

Q: which is a managed resource - file handle, memory stream, socket, windows handle, db conn?
A: socket

Q: throw; vs throw ex;
A: throw; is better -- more complete stack trace. see stack overflow

Q: can you pass an anonymous delegate into Thread ctor?
A: quite common

Q: static readonly field - set in static ctor or declaration?
A: both

Saturday, March 3, 2012

ways to count elements in STL

Q: for any container how to get the size

Q3: if i give you a range (2 iterators), count how many items

Q3b: what about a home-grown loop to get the count?

Q: accumulate()?

Q: for_each()? I feel this is more clumsy than home-grown loop

Tuesday, September 6, 2011

a node in a hash map (open questions

Q: is there a "pair" (like in STL) object in each node?

Q: In the pair object, is there a ptr to the key object + a ptr to the value object?

Q: is there a nextNode ptr in the link node?

Friday, August 26, 2011

SCB comm c++ IV

Q: you have identical rows in a table. How do you clean it up?
%A: select into a new table, then overwrite the old, but this involves a lot of disk space and IO
%A: perhaps delete where (select count(*)...) > 1 and rowid > 1 -- using oracle rowid

Q: given a long string of letters A-Z, print a histogram like A:865 times, B:9932 times....

Q: copy a vector to another vector. What if the source is very large? Correct -- you get reallocation, so how do you avoid that?
%A: either reserve or initialize the target vector with sufficient capacity

Q: when would you use private inheritance?

Monday, March 14, 2011

c++ IV west coast portfolio mgmt

Q5: can a dtor throw exception as the last statement?
%%A: no cos the dtor can be invoked as part of stack unwinding

Q5b: so what?
%%A: stack is unwinding due to another exception, and now your dtor creates a 2nd exception object. System is going to lose critical information in the 2 exceptions. The original exception handling flow is halfway through.

Q: given an instance of an absolutely empty class, can I downcast a ptr (or reference) to it?
%%A: assuming this class inherits from another empty class, you can't since there's no vtbl.

Q: diff between malloc and new?
%%A: must cast void ptr; must call ctor
A(hind sight): array new
A (hind sight): new can be a (static) method, therefore inherited or hidden.

Q: ok, so malloc doesn't call ctor, but can I pass the malloc void ptr to a ctor for initialization?
%%A: placement new will initialize a block of memory without allocation.
%%A: it's not common. C++ language doesn't encourage this operation.
A????

Q3: can you call a dtor explicitly?
%%A: yes though not a good idea. See C++ FAQ

Q3b: when would yo do that?
%%A: when i want to free a large block of memory as early as possible, and the dtor is not scheduled to run any time soon.
%%A: probably delete can achieve the same purpose without looking ugly.
%%A: again, not  common and not encouraged by C++ language. I don't think i would ever do that.
A???

Q4: can you specialize a template with a ptr type as the type argument?
%%A: yes vector of ptr is common

Q4b: what must this template do to accommodate ptr template arguments?
%%A: handle dtor, assignment and copier.
%%A: any memory-management operations must be customized. Default behavior is not good for ptr type arguments
A???

Q: which part of c++ is most interesting to you?
%%A: low level access. Few other languages provide the low-level access

Q: perl pass an array by reference into a sub?
%%A: you can pass the address of the array. Array can be modified in-placer by the receiving sub
A: http://www.troubleshooters.com/codecorn/littperl/perlsub.htm

Q: chomp?

Q: perl open a file in append mode?
A: use ">>"

Q: when would you create a non-clustered index?

Q: select 2nd highest salary from a salary table?

Q: if my query need all 3 columns of an index (id, name, salary), how would you order the 3 columns when creating the index? Suppose salary has the highest selectivity
%%A: salary first

Saturday, January 22, 2011

overload operators (as methods) are inherited@@

I think they should. All public or protected methods are inherited by default.

operator= are not inherited. See [[effective c++]]

Saturday, December 11, 2010

Cantor IV

Q3: what can go wrong during a write to a socket???
Q3b: if buffer is full, will the writing thread block???
%A: by default it blocks, but it’s probably possible to configure it to return an error code or even thrown an exception

Q: blocking vs non-blocking socket???

Q: socket programming – what’s a select ?

Q: what’s the implementation of the std::map?
%A: tree, probably red-black

Q: Should base class dtor always be virtual?
A: deleting a derived object via a base pointer results in undefined behavior.

Q: how many ways to share data between 2 processes? How about shared memory

Q: synchronize 2 unix processes accessing a shared file?
A: named semaphore

Thursday, July 1, 2010

UBS emerging market credit/rates - C++, Perl, java

Say your perl program needs to create 15 concurrent child processes,
Q: How do you wait for all children to finish?

Q: how do you call c from java?

Q: How do you connect your (perl) STDIN to a child process?

Q: what does a credit spread mean?

Q: how do you price an interest rate swap?

Q: strengths of java vs c++?

Q: Challenges of multithreading?
A: one feature of java can restrict the number of threads to a number smaller than the number of processors. Can't name that feature.

Q: How do you create a deep copy of a List where each element could be an Integer, Float ...?

Q: Say a master thread puts objects (like tasks or ...) into a shared collection, and work threads pick them up and put results objects into a shared place. How do you ensure data integrity/consistency.
A: the collection has to be thread safe, but all the inside objects need to be guarded too. Any shared object (including the inside objects) need to be guarded.

credit desk -- CDS, corp bonds, MBS
rate desk -- IRS, treasuries
excel VBA, c#
c++ is used by quants but not really others.

Friday, March 5, 2010

iview JPMC stock loan

Q: concurrent hashmap locking -- locking on an internal bucket object or a map entry object?

Q: a weak reference object can have a finalize()? What if in finalize() you make the object "reachable from the GC root set"?

Q: when do you use WeakHashMap?

Q: what's a phantom reference?

Q: static fields during serialization?

Q: how do you make a hashmap (not a hashtable) thread safe?

Q: how does jms provider keep track of which message has not been delivered to each durable subscriber?

Q: different modes of acknowledgment in JMS? what's the default mode?

Q: what's JMS correlation id?

Q: how does a java app know a file is already open for writing by another unix process id, so it should wait and avoid concurrent edit?

Q: if one method has synchronized(b){synchronized(c){...}}, and another method has synchronized(c){synchronized(b){...}}, and b and c point to the same object, can you think of when people write such code?
A: always bad design, unnecessarily confusing. Deadlock prone. Programmer must know for certain that b and c reference the same object throughout. I'd add an assert as documentation.

Q: what changed in 1.5 for notify()?

Q: key differences between Set and List?

Q: A set should contain unique objects but what if you input 2 unique objects and then make them identical twins (ie a.equals(b))? So the set has duplicate entries? Consequence?

Q: how many types of iterators are there?

Q: what classic design patterns did you use?

Q: what categories of design patterns do you know?

Q: what j2ee patterns did you use?

Q: how is the treeMap or TreeSet implemented internally? What kind of binary tree?

Q: what's Shell sort? What other sorts do you know?

Q: what's the time complexity of quick sort?

Q: name 5 things you would consider before developing a java threading app.
A: privatize all fields in shared objects
A: immutables
A: reduce number of locks
A: I should know exactly how many threads system will create. Reduce the number.
A: any wait/notify required? Need to know early since they tend to mess up my design
A: extremely mindful of deadlocks
A: avoid synchronization if possible -- use concurrent data structures
A: producer/consumer and other threading patterns. Avoid creating my own threading "pattern" or framework.

Friday, May 29, 2009

update jtable from inside an event listener - short sample

Note: one event only. In other cases, the event listener (on EDT) often generate cascading events to update other JComponents
Note: the stateful listener, which is common. The simplest listeners are stateless functors.
Note: setModel -- "swapping" in a new model

Note the jtable object vs the table model object. Different addresses!

The listener ctor can receive the jtable object and save it as a field --
public SelectionChangeListener(JTable table) {
   this.table = table;
}
// now in the event handler
DefaultTableModel model = new DefaultTableModel(...);
this.table.setModel(model);
this.table.repaint(); // must run on EDT???

Monday, March 2, 2009

spring template objects

*JMS -- a template instance is a jms session
** anon inner class

*JDBC -- a template instance is a database connection
** callback -- an anon inner class

*hibernate -- a template instance is a hibernate Session

*transaction -- a template instance is a ... transaction session?
** callback -- an anon inner class

Spring Templates follow template-method design pattern. The callback objects provide the missing steps int the template method.

Sunday, July 27, 2008

OMS in FX vs equities

OMS is often the biggest and the core module in any trading platform that supports pending orders and FIX execution.

What are the differences between an eq OMS (see the Complete Guide) and an FX OMS?

FX is fundamentally OTC and quote-driven, not order driven as listed markets are.

Q: in FX, there's no exchange making the (irrevocable) matching?