which programming languages changed toooo much

No elaboration please. Pointers will do.

perl 6?
python 3?  but the excessive changes are not taken up!
php5 was better received.
C# ?
MFC -> winforms -> WPF ? Different technologies. More like delphi/powerBuilder/coldFusion declining than a language evolving.
java 8? not much change. Lambda is the biggest
c++11? not much change. Rval ref is the biggest

overvalue ^ undervalued in tech IV – random picks

–overvalued – 10 items unranked:
problem solving with comp science constructs — mostly algos
fast coding
code quality – in those take-home coding tests
corner cases
OO design theories, principles
–undervalued practical skills:
stackoverflow type of know-how, including syntax details. These aren’t quizzed in high-end interviews.
tools including IDEs
[T] bug hunting
[T] large code base reading
[T] reading lots of documentation of various quality to figure out why things not working
[T = hard to test in IV]

java8 default method break backward compatibility #HSBC

Among the java8 features, I think default  method is a more drastic and fundamental change than lambda or stream,  in terms of language

In my HSBC interview a London interviewer (Wais) challenged me and said that he thought default methods are designed for backward compatibility. I now think he was wrong.

—- Based on P171 [[Mastering Lambdas]]
Note The rare cases of incompatibility is an obscure (almost academic) concern. More important are the rules of method resolution when default methods are among the candidates. This topic is similar in spirit to popular interview questions around overriding vs overloading.

Backward compatibility (BWC) means that when an existing interface like Collection.java includes a brand new default method, the existing “customer” source code should work as before. Default methods has a few known violations of BWC.

  • simplest case: all (incl. default) methods in an interface must be public. No ifs or buts.  Suppose Java7 MyConcreteClass has private m2() and implements MyIntf. What if MyIntf is now updated with a default method m2()? Compilation error!
  • a more serious case: java overriding rule (similar to c++) is very strict so m(int) vs m(long) is always, automatically overloading not overriding.  Consider a method call myObj.m(33). Originally, this binds to the m(long) declared in the class. Suppose the new default method is m(int) … an Overload! At compile time, this is seen as a better match so selected by compiler (not JVM runtime)… Silent, unexpected change in business logic and a violation of BWC!

This refreshingly thin book gives 2 more examples. Its last example is a serious backward incompatibility issue but I am not convinced it is technically possible. Here’s my rationale —

Any legacy code relying on putIfAbsent() must have an implementation of putIfAbsent() somewhere in some legacy java7 class. Due to “class-wins-over-interface” rule, a new default method putIfAbsent() will never be chosen when compiling the legacy code using java8 tool chain.

linker error in java – example

[[mastering lambda]] points out one important scenario of java linker error. Can happen in java 1.4 or earlier. Here’s my recollection.

Say someone adds a method m1() to interface Collection.java. This new compiled code can coexists with lots of existing compiled code but there’s a hidden defect. Say someone else writes a consumer class using Collection.java, and calls m1() on it. This would compile in a project having the new Collection.java but no HashSet.java. Again, this looks fine on the surface. At run time, there must be a concrete class when m1() runs. Suppose it’s a HashSet compiled long ago. This would hit a linker error, since HashSet doesn’t implement m1().


oldest programmer in a team, briefly

I’m unafraid of being the oldest programmer in a team, for example in China or Singapore, as long as I’m competent. If my foundation is strong and I know the local system well, then I will be up to the challenge. It takes an amount of effort to gain the local system knowledge though. Consider GS, Citi, OC, Stirt and CFM.

More than half the times, contractors aren’t required to  gain that much local system knowledge.

Actually, Can be fun and stimulating to work with young programmers. Keeps me young. My experience might add unique value, if it’s relevant.

I can think of many Wall St consultants in this category.

HFT guys seldom need2optimize latency;always quizzed@latency

I bet 90% of HFT developers (non-architects) Never need to optimize latency or throughput, based on my experience in

  • RTS
  • mvea

Why? The latency sensitive codebase is low-level and stable, so no change required. Regular developers only need to use existing frameworks and avoid latency penalties.

If the frameworks are strict, then there are few chances to hit latency penalty.

Best way to acquire professional experience in latency engineering — put your ideas to work in a real project and tune it until it works. Look at my wait/notify code in 95G. I think Kam did something similar in the TREP project in RTS.

If you don’t have such an opportunity, then you must read up in your spare time and ask some good questions in a good contexx.

[14] less stressful job in financial IT@@ #XR

You wrote:

Pros: Less time spent in learning new things, since  most new technical skills will be abandoned in several years, so a lot of time is saved.

I agree that saving time is important, for stressful daddies like you and me. I try to identify those technology fads and avoid wasting time on them, except when the fad (like silverlight) is really needed on my job.

While working for big banks I feel I’m paying a price in terms of family life and my health (i.e. stress level).

Q: Is a less stressful job more healthy in the long run? not sure.

My OCBC job was slower after the initial 6 months, but my learning slowed down too much. I became less competitive less strong less marketable on the job market. That won’t help with long term well-being. So in this case answer is No.

My Citigroup contract project was also slower than other Wall St jobs, but I kept myself busy by learning c++. I guess the ideal situation is low-stress high-motivation, highly engaging. Perhaps a job we could cope well, but gives us motivation to exceed expectation. So in this case answer is Yes.

Overall, I felt (a bit) less stressful on Wall St as a contractor than now as an employee. As a result, my health condition was probably (a bit) better in U.S. Paradoxically, I think my health condition has a lot to do with the job market demand — Wall St relatively easy to find a job, so I didn’t need to work so hard to keep a job.

Before entering finance IT, was my work stress lower? Sometimes yes sometimes no. Some of the stress on Wall St we can learn to cope, so it won’t affect health in a massive and destructive way. However, some of my non-finance jobs (in Singapore) were extremely unstable — one company let me go within 1 month, another company extended probation period. Stressful? What stress? Livelihood stress? I was a bachelor and didn’t feel stressful but I imagine a father of two would feel traumatized! In the early 2015 layoff, I was feeling really stressed and depressed after getting so few calls on the job market. I felt the local financial IT job market here was dead. The banks were not hiring. I was happy just to see a Barclays Singapore role below AVP. A Commerz bank java opening was taking 2-3 months to get approved.

Perhaps the key factor is the feeling of in-control — When I felt I could handle the turbulence, the ups and downs, the sudden changes… then I felt OK. Now, with kids, I need stable income and time to spend with family. I don’t like anything to rock my boat.

You don’t have to read these but my earlier comments are at

On Thu, Oct 2, 2014 at 9:18 AM, you wrote:

Talking about learning, some people actively learn, just like what you did: plan what to learn, then take spare time to learn it. While some others passively learn, such as they are forced to learn in work. For example, one developer work in a company for several years, and then company wide technology upgrade to some main stream skills. So the developer can still keep pace with relatively new skills. Although those relatively new skills are not the latest, they should be proved to be accepted by big financial firms.

The latter guys won’t easily get an ideal job, but they should be able to get a job in most market conditions.
Cons: Difficult for them to pursue the ideal job. Dare not to change job just for better payment.
Pros: Less time spent in learning new things, since some most new technical skills will be abandoned in several years, so a lot of time is saved.

On Wed, Oct 1, 2014 at 5:34 PM, Bin TAN (Victor) wrote:

Forgot to mention that my study of c#, c++ and financial math study
will, I believe, help with my career ….somewhere down the road. When
i get interview questions on these topics, I’m sure I can handle them
better thanks to my recent study. I tell myself to be patient with
this “investment” in myself.

As mentioned in the last mail, In the last 2 years after I came back
to SG, the study has slowed down quite a bit, but i believe i still
improved my knowledge and understanding in certain areas.

Another potential long-term return of my financial math study is ….
teaching as a career. A lot of finance professionals switch gear to an
academic career after a certain age. I keep this option open by
working hard on my studies. If i get decent grades i might qualify to
teach. Compared to financial IT, teaching is hopefully less stressful,
even though i don’t want to underestimate the job duty of a dedicated
teacher. A good teacher can really impart useful knowledge. I may not
be a top teacher but i have my strengths in this area.

On Mon, Sep 29, 2014 at 1:38 AM, Bin TAN (Victor) wrote:
> I believe our mind (esp. our memory) is like a muscle. If we don’t
> seriously use it, it tends to age, weaken and lose capacity.
> Over the last 5 years, i spent 2009-2011 in the US on my own —
> tremendous learning and improvement, perhaps the most active learning
> period in my professional life. Then after I came back to SG, i
> studied financial math program, c#/dotnet, and some c++.
> I feel the serious study keeps my mind active. However, over the last
> 18 months, I notice various signs of my learning capacity reducing,
> but it’s not all due to aging —
> * biggest factor is lack of concentration, due to kids and family commitment
> * not enough time to periodically re-visit each topic,
> After all, I feel it’s vital and paramount to keep our mind in
> constant learning mode. 活到老学到老.

##[15] once-valuable tech skills: personal xp

perl – lost to python
[$] tomcat, jboss. Weblogic lost most market share
apache, mysql
dns, unix network config
autosys – not used after GS
[$] sybase, oracle – after ML edge project I didn’t need it again.
[$] VBA – used once only. But Excel is going strong!

[$ = still has value]

–random list (not “top 10”) of longevity skills
eclipse, MSVS
Excel and add-in
javascript, though I don’t use it in my recent jobs
Linux shell
compiler knowledge
make, msbuild
bash and DOS batch scripting, even though powershell, vbscript and python/perl are much richer.

BUY a (low) interest rate == Borrow at a lock-in rate

Q: What does “buying at 2% interest rate” mean?

It’s good to get an intuitive and memorable short explanation.

Rule — Buying a 2% interest rate means borrowing at 2%.

Rule — there’s always a repayment period.

Rule — the 2% is a fixed rate not a floating rate. In a way, whenever you buy you buy with a fixed price. You could buy the “floating stream” …. but let’s not digress.

Real, personal, example — I “bought” my first mortgage at 1.18% for first year, locking in a low rate before it went up.

factors affecting bond sensitivity to IR

In this context, we are concerned with the current market value (eg a $9bn bond) and how this holding may devalue due to Rising interest rate for that particular maturity.

* lower (zero) coupon bonds are more sensitive. More of the cash flow occurs in the distant future, therefore subject to more discounting.

* longer bonds are more sensitive. More of the cashflow is “pushed” to the distant future.

* lower yield bonds are more sensitive. On the Price/yield curve, at the left side, the curve is steeper.

(I read the above on a slide by Investment Analytics.)

Note if we hold the bond to maturity, then the dollar value received on maturity is completely deterministic i.e. known in advance, so why worry about “sensitivity”? There are 3 issues with this strategy:

1) if in the interim my bond’s MV drops badly, then this asset offers poor liquidity. I won’t have the flexibility to get contingency cash out of this asset.

1b) Let’s ignore credit risk in the bond itself. If this is a huge position (like $9bn) in the portfolio of a big organization (even for a sovereign fund), a MV drop could threaten the organization’s balance sheet, credit rating and borrowing cost. Put yourself in the shoes of a creditor. Fundamentally, the market and the creditors need to be assured that this borrower could safely liquidity part of this bond asset to meet contingent obligations.

Imagine Citi is a creditor to MTA, and MTA holds a bond. Fundamental risk to the creditor (Citi) — the borrower (MTA)  i.e. the bond holder could become insolvent before bond maturity, when the bond price recovers.

2) over a long horizon like 30Y, that fixed dollar amount may suffer unexpected inflation (devaluation). I feel this issue tends to affect any long-horizon investment.

3) if in the near future interest rises sharply (hurting my MV), that means there are better ways to invest my $9bn.

c++ parametrized functor – more learning notes

Parametrized Functor (class template) is a standard, recommended construct in c++, with no counterpart in java. C# delegae is conceptually simpler but internally more complex IMO, and represents a big upgrade from c++ functor. Better get some clarity with functor before comparing with delegates.

The most common functor is the simple stateless functor (like a simple lambda). The 2nd common category is the (stateful but) immutable functor. In all cases, the functor is designed for pass-by-value (not by ref or by pointer), cheap to copy, cheap to construct. I see many textbook code samples creating throwaway functor instances.

Example of the 2nd category – P127[[essentialC++]].

A) One mental block is using a simple functor Class as a template type param. This is different from java/c#

B) One mental block is a simple parametrized functor i.e. class template. C++ parametrized functor can take various type params, more “promiscuous” than c#/java.

C) A bigger mental block, combining A+B, is a functor parametrized with another functor Class as a template param. See P186[[EssentialC++]].

This is presented as a simple construct, with about 20 lines of code, but the more I look at it, the more strange it feels. I think this is somwehwat powerful but unpopular and unfamiliar to mainstream developers.

Functional programming in c++?

In java, we write a custom comparitor class rather than a comparitor class Template. We also have the simpler alternative of a Comparable interface, but that’s not very relevant in this discussion. Java 8 lambda — http://www.dreamsyssoft.com/java-8-lambda-tutorial/comparator-tutorial.php

64-bit java — my own mini Q&A

Q: will 32-bit java apps run in 64-bit JVM?
A: Write once, run anywhere. Sun was extremely careful during the creation of the first 64-bit Java port to insure Java binary and API compatibility, so all existing 100% pure Java programs would continue running just as they do under a 32-bit VM. However, non-pure java, like JNI, will break.
ficc acc
Q: 32bit apps need recompilation?
A: Unlike pure java apps, all native binary code that was written for a 32-bit VM must be recompiled for use in a 64-bit VM. All currently supported operating systems do not allow the mixing of 32 and 64-bit binaries or libraries within a single process.

Q: The primary advantage of running Java in a 64-bit environment?
A: larger address space. This allows for a much larger Java heap size and an increased maximum number of Java Threads.

Q: complications?
A: Any JNI native code in the 32-bit SDK implementation that relied on the old sizes of these data types is likely to require updating.
%%A: if java calls another program, maybe that program will need to be 64-bit compatible. This answer is slightly relevant.

Q: how is 32/64 bit JDK’s installed?
A: Solaris has both a 32 and 64-bit J2SE implementation contained within the same installation of Java, you can specify either version. If neither -d32 nor -d64 is specified, the default is to run in a 32-bit environment. All other platforms (Windows and Linux) contain separate 32 and 64-bit installation packages.

nant.build Rebuild ^ build

In nant.build,

A) if a compilation is Rebuild, then it could be slow for a large solution. This is similar to MSVS solution rebuild

B) If a compilation is Build, then it can make use of whatever you have already built in MSVS, but if one of the projects was cancelled half-way it may come up as corrupted and break the nant build. I guess you can clean that project and rerun nant.

WallSt productivity + risk@losing job

label: threat,
Productivity issue is usually in the first 6 months. (i feel OC was not too hard. I was learning fast, though not superfast.) Some say “2 months”? I tend to feel that I form an opinion of a tech colleague within a month, but it's not always fair. If someone is fast learning, he may lose interest quickly.
I guess boss assesses how much value you add to his promotion prospect. Staff is seldom let go primarily due to productivity. Exceptions:

1) contractors — even if you are good
2) head count pressure — someone must go
Even thought it's probably not life or death, it's not good to be considered unproductive. Poor image, poor rapport, low self-esteem, ..

Here's a positive story — in GS I took more than a year to come up to speed.

pointer in C +other lang-(early) learning notes

Every variable in any lang is a 3-some — name + addr + content (but see the post on mutability, initialize etc). http://aelinik.free.fr/c/ch11.htm has a good explanation:

int x;

x = 7;

the variable x now has two values:

Left value: 1000

Right value: 7

Here the left value, 1000, is the address of the memory location reserved for x. The right value, 7, is the content stored in the memory location.


Now a few simple rules on & and *

rule — &var1 returns address of var1.

rule — I don't think &var1 can be on the left side of =

rule — var1 must be a L-value expression. See http://bigblog.tanbin.com/2011/11/c-func-call-as-l-value-key-points.html

Now suppose we assign ptr1 = &var1

rule — *ptr1 returns the content of var1. If you print *ptr1, and print var1, you get same.

rule — *ptr1 can be on the left side of =

I believe *ptr1 == *(&var1) == var1

to a novice programmer — the importance of data structures in financial IT systems

Data structure is essential and non-trivial to every programming language on wall street — java (collections), c++ (STL), python/perl (high-level data types)… A lot of algorithms (in the traditional, strict sense of the word) are created on or using classic data structures. There are a lot of jargons you need to grasp. Everyday programming requires you to be familiar with common operations on these data structures, but these are relatively straightforward. However, here are some of the non-trivial aspects of data structures and


* sort python dict or tuple

* internals of hash table and ConcurrentHashMap

* STL container holding pointers

* STL pair

* STL stream iterators

* customize a sorted set/map for MyClass in C++, which is harder than java

* sort a map by value (real interview question) in java. Perl and python is easy.

* whiteboard-implement a blocking stack/queue (UBS)

* whiteboard-implement a basic hash table (MS)

* find top 99 in a large array (Barc) but no need to return them sorted

* choose array vs circular array vs linked list, in terms of memory efficiency (JPM).

* given 2 nodes in a binary tree, with no pointers except pointer-to-parent, find lowest common ancestor (Google)

* iterative tree walk (Barc)

* filtering iterator (MS)

* STL transform(), erase(), partition() etc

* STL allocators

* STL functors, binders

* STL iterator adaptors (back_inserter etc)

Posted By familyman to learning finance,c++,py… <http://bigblog.tanbin.com/2011/05/to-novice-programmer-importance-of-data.html> at 5/03/2011 07:34:00 PM

hard edit vs soft edit when submitting order to mainframe

In one order entry system (A big European megabank), new orders are sent to mainframe. Upon validation, mainframe can return a message to the order entry system.

If the message is a hard edit, the order is rejected by mainframe validation module.

If  the message is a soft edit, the order is accepted by mainframe validation module. The soft edit is purely informational. Not necessarily a warning. No action is required on the user of the order entry system. I guess the soft edit is just “FYI”.

Posted By familyman to learning finance,c++,py… at 3/15/2011 11:52:00 PM

cobol copybook = input format spec

a cobol-copybook is “a file describing an input data format”.

“cobol copybook” is the standard term (“cobol-layout” is less common) for files like that mentioned in https://ssl.kundenserver.de/shop.softproject.de/downloads/CobolCopybookToolkitForJava.pdf


— based on http://edocs.bea.com/JAM/v51/program/egenapp.html
A COBOL CICS or IMS mainframe application typically uses a copybook source file to define its data layout. This file is specified in a COPY directive within the LINKAGE SECTION of the source program for a CICS application, or in the WORKING-STORAGE SECTION of an IMS program. If the CICS or IMS application does not use a copybook file, you will have to create one from the data definition contained in the program source.

A copybook is conceptually (not technically) part of a cobol program. Usually this copybook is a standalone file, included from its parent-program.

Posted By familyman to learning finance,c++,py… at 1/20/2008 08:53:00 PM

q[screen] command cheatsheet

For each feature, let’s verify it and give links to only good web pages

Even after the “parent shell” of the screen is killed, the screen is still alive and “attached”!

–[ Essential] How to tell if I’m in a screen

echo $STY


–[ Essential ] reattach

— [ Essential ] list all child screens
screen -R # lists all or reattach if only one.
screen -ls # just list

— [ Essential ] detach i.e. put current screen session to the background
Ctrl-A then ‘d’

keep a session alive after I log out. Almost like windows mstsc.exe

–feature – log the screen output
See http://www.rackaid.com/blog/linux-screen-tutorial-and-how-to/
The log file is created in the current dir …

–feature – Run a long running process without maintaining an active shell session
See http://www.rackaid.com/blog/linux-screen-tutorial-and-how-to/ — using top as a long command

–(untested) feature – monitor a screen for inactivity as a sign of job done.
See http://www.rackaid.com/blog/linux-screen-tutorial-and-how-to/

—– A real example:

Motivation — I need to run some daemon process in “background” but ideally inside a separate container/shell, so I can switch between that environment and my original environment. However, I don’t want to create another putty session. That’s indeed a more “separate” environment, but comes with higher cost like a lengthy log-in procedure.

[in console] screen # to create a new screen
[in screen-1] ./startDaemon # Note the command doesn’t return
[in screen-1] Ctrl-A d #to switch back to console
[in console] screen -ls # shows screen-1
[in console] screen -R # to switch into screen-1
[in screen-1] # now we are back in the running command which has not returned !
[in screen-1] Ctrl-Z # to suspend this stubborn command
[in screen-1] bg %1 # to put the command into proper background of screen-1



teach your kid – interest in finance subjects, !! just salary

If we focus on the salary, interviews .. then the learning interest won’t last. In addition, it’s worthwhile to develop interest in the subjects….

Some subjects in finance are dirty, shallow, pointless, superfluous (same in technology ;-). Some subjects are about gambling. I won’t elaborate further. Instead, Identify those areas with depth and worth studying.

Financial math subjects have depth. However, some of those stochastic subjects feel like too theoretical and ivory tower, and too removed from reality to be relevant. I feel the statistics subjects are more practical.

There are many books …

change of .. numeraire^measure

Advice: When possible, I would work with CoN rather than CoM. I believe once we identify another numeraire (say asset B) is useful, we just know there exists an equivalent measure associated with B (say measure J), so we could proceed. How to derive that measure I don’t remember. Maybe there’s a relatively simple formula, but very abstract.

In one case, we only have CoM, no CoN — when changing from physical measure to risk neutral measure. There is no obvious, intuitive numeraire associated with the physical measure!

CoN is more intuitive than CoM. Numeraire has a more tangible meaning than “measure”.

I think even my grandma could understand 2 different numeraires and how to switch between them.  Feels like simple math.

CoM has rigorous math behind it. CoM is not just for finance. I guess CoM is the foundation and basis of CoN.

I feel we don’t have to have a detailed, in-depth grasp of CoM to use it in CoN.

beta definition in CAPM – confusion cleared

In CAPM, beta (of a stock like ibm) is defined in terms of
* cov(ibm excess return, mkt excess return), and
* variance of ibm excess return

I was under the impression that variance is the measured “dispersion” among the recent 60 monthly returns over 5 years (or another period). Such a calculation would yield a beta value that’s heavily influenced or “skewed” by the last 5Y’s performance. Another observation window is likely to give a very different beta value. This beta is based on such unstable input data, but we will treat it as a constant, and use it to predict the ratio of ibm’s return over index return! Suppose we are lucky so last 12M gives beta=1.3, and last 5Y yields the same, and year 2000 also yields the same. We still could be unlucky in the next 12M and this beta
fails completely to predict that ratio… Wrong thought!

One of the roots of the confusion is the 2 views of variance, esp. with time-series data.

A) the “statistical variance”, or sample variance. Basically 60 consecutive observations over 5 years. If these 60 numbers come from drastically different periods, then the sample variance won’t represent the population.

B) the “probability variance” or “theoretical variance”, or population variance, assuming the population has a fixed variance. This is abstract. Suppose ibm stock price is influenced mostly by temperature (or another factor not influenced by human behavior), so the inherent variance in the “system” is time-invariant. Note the distribution of daily return can be completely non-normal — Could be binomial, uniform etc, but variance should be fixed, or at least stable — i feel population variance can change with time, but should be fairly stable during the observation window — Slow-changing.

My interpretation of beta definition is based on the an unstable, fast-changing variance. In contrast, CAPM theory is based on a fixed or slow-moving population variance — the probability context. Basically the IID assumption. CAPM assumes we could estimate the population variance from history and this variance value will be valid in the foreseeable future.

In practice, practitioners (usually?) use historical sample to estimate population variance/cov. This is, basically statistical context A)

Imagine the inherent population variance changes as frequently as stock price itself. It would be futile to even estimate the population variance. In most time-series contexts, most models assume some stability in the population variance.

physical measure is impractical

Update: Now I think physical probability is not observable nor quantifiable and utterly unusable in the math including the numerical methods.  In contrast, RN probabilities can be derived from observed prices.

Therefore, now I feel physical measure is completely irrelevant to option math.

RN measure is the “first” practical measure for derivative pricing. Most theories/models are formulated in RN measure. T-Forward measure and stock numeraire are convenient when using these models…

Physical measure is an impractical measure for pricing. Physical measure is personal feeling, not related to any market prices. Physical measure is mentioned only for teaching purpose. There’s no “market data” on physical measure.

Market prices reflect RN (not physical) probabilities.

Consider cash-or-nothing bet that pays $100 iff team A wins a playoff. The bet is selling for $30, so the RN Pr(win) = 30%. I am an insider and I rig the game so physical Pr() = 80% and Meimei (my daughter) may feel it’s 50-50 but these personal opinions are irrelevant for pricing any derivative.

Instead, we use the option price $30 to back out the RN probabilities. Namely, Calibrate the pricing curves using liquid options, then use the RN probabilities to price less liquid derivatives.

Professor Yuri is the first to point out (during my oral exam!) that option prices are the input, not the output to such pricing systems.

drift ^ growth rate – are imprecise

The drift rate “j” is defined for BM not GBM
                dAt = j dt + dW term
Now, for GBM,
                dXt = r Xt  dt + dW term
So the drift rate by definition is r Xt, Therefore, it’s confusing to say “same drift as the riskfree rate”. Safer to say “same growth rate” or “same expected return”

so-called tradable asset – disillusioned

The touted feature of a “tradable” doesn’t impress me. Now I feel this feature is useful IMHO only for option pricing theory. All traded assets are supposed to follow a GBM (under RN measure) with the same growth rate as the MMA, but I’m unsure about most of the “traded assets” such as —
– IR futures contracts
– weather contracts
– range notes
– a deep OTM option contract? I can’t imagine any “growth” in this asset
– a premium bond close to maturity? Price must drop to par, right? How can it grow?
– a swap I traded at the wrong time, so its value is decreasing to deeply negative territories? How can this asset grow?

My MSFM classmates confirmed that any dividend-paying stock is disqualified as “traded asset”. There must be no cash coming in or out of the security! It’s such a contrived, artificial and theoretical concept! Other non-qualifiers:

eg: spot rate
eg: price of a dividend-paying stock – violates the self-financing criteria.
eg: interest rates
eg: swap rate
eg: future contract’s price?
eg: coupon-paying bond’s price

Black’s model isn’t interest rate model #briefly

My professors emphasized repeatedly
* first generation IR model is the one-factor models, not Black model.
* Black model initially covered commodity futures
* However, IR traders adopted Black’s __formula__ to price the 3 most common IR options
** bond options (bond price @ expiry is LN
** caps (libor rate @ expiry is LN
** swaptions ( swap rate @ expiry is LN
** However, it’s illogical to assume the bond price, libor ate, and swap rates on the contract expiry date (three N@FT) ALL follow LogNormal distributions.

* Black model is unable to model the term structure. I think it doesn’t eliminate arbitrage. I would say that a proper IR model (like HJM) must describe the evolution of the entire yield curve with N points on the curve. N can be 20 or infinite…

mean reversion in Hull-White model

The (well-known) mean reversion is in drift, i.e. the inst drift, under physical measure.

(I think historical data shows mean reversion of IR, which is somehow related to the “mean reversion of drift”….)

When changing to RN measure, the drift is discarded, so not relevant to pricing.
However, on a “family snapshot”, the implied vol of fwd Libor rate is lower the further out accrual startDate goes. This is observed on the market [1], and this vol won’t be affected when changing measure. Hull-White model does model  this feature:
<!–[if gte msEquation 12]>σte-a T-t <![endif]–>
[1] I think this means the observed ED future price vol is lower for a 10Y expiry than a 1M expiry.

HJM, again

HJM’s theory started with a formulation containing 2 “free” processes — the drift (alpha) and vol (sigma) of inst fwd rate

df­T=α(t) dt+σ(t) dW –>    
, both functions of time and could be stochastic.
Note the vol is defined differently from the Black-Scholes vol.
Note this is under physical measure (not Q measure).
Note the fwd rate is instantaneous, not the simply compounded.
We then try to replicate one zero bond (shorter maturity) using another (longer maturity), and found that the drift process alpha(t) is constrained and restricted by the vol process sigma(t), under P measure. In other words, the 2 processes are not “up to you”. The absence of arbitrage enforces certain restrictions on the drift – see Jeff’s lecture notes.
Under Q measure, the new drift process [1] is completely determined by the vol process. This is a major feature of HJM framework. Hull-white focuses on this vol process and models it as an exponential function of time-to-maturity:
<!–[if gte msEquation 12]>σte-a T-t <![endif]–> 
That “T” above is confusing. It is a constant in the “df” stochastic integral formula and refers to the forward start date of the (overnight, or even shorter) underlying forward loan, with accrual period 0.
[1] completely unrelated to the physical drift alpha(t)
Why bother to change to Q measure? I feel we cannot do any option pricing under P measure.  P measure is subjective. Each investor could have her own P measure.
Pricing under Q is theoretically sound but mathematically clumsy due to stochastic interest rate, so we change numeraire again to the T-maturity zero bond.
Before HJM, (I believe) the earlier TS models can’t support replication between bonds of 2 maturities — bond prices are inconsistent and arbitrage-able

vol, unlike stdev, always implies a (stoch) Process

Volatility, in the context of pure math (not necessarily finance), refers to the coefficient of dW term. Therefore,
* it implies a measure,
* it implies a process, a stoch process

Therefore, if a vol number is 5%, it is, conceptually and physically, different from a stdev of 0.05.

* Stdev measures the dispersion of a static population, or a snapshot as I like to say. Again, think of the histogram.
* variance parameter (vol^2) of BM shows diffusion speed.
* if we quadruple the variance param (doubling the vol) value, then the terminal snapshot’s stdev will double.

At any time, there’s an instantaneous vol value, like 5%. This could last a brief interval before it increase or decreases. Vol value changes, as specified in most financial models, but it changes slowly — quasi-constant… (see other blog posts)

There is also a Black-Scholes vol. See other posts.

FX vol quoting convention

? the terms “strangle” and “butterfly” seem to be used rather loosely. Not sure which is actually right. Do they mean the same thing?

On the fx vol dealer market, you get quotes in the form of RiskReversal, Strangle and ATM straddle.
An example of a RR quote is a 25 delta RR contract to convert 1 million USD to JPY. The exact sums of yens are denoted Kp25 and Kc25, and not in the quote. In this kind of confusing discussions, just treat the commodity currency (USD in this case) as a commodity like silver. When you (market-Taker) go Long any RR contract, you are Long the Call and Short the Put on that silver – Be very clear about these in your mind.
Now let’s zoom into a hypothetical RR quote. The quote says
“            On Mar 1, dealer UBS is willing to WRITE a USD call + BUY a USD put for a premium amount of x yens[1], where x will be determined at the RR volatility of 3.521% per annum. (An unrealistic fictitious vol value, because USD/JPY RR quote is usually Negative.)
The underlying Put has a strike Kp25 corresponding to a delta of -0.25. (But since you the market Taker will be Short the Put, your delta is +0.25.)
The underlying Call has a strike Kc25 corresponding to a delta of +0.25. This Call strike will be Above the Put strike.
Both the put and the call are OTM for 1 million unit of USD and expire end of May.
Optionally, the quote might mention a reference spot rate of “USD/JPY = 93.32”. This probably helps people back out the strikes Kp25 and Kc25.
That is a one-way Offer/Ask quote. For a 2-way, dealer would give 2 quotes — a bid and an ask.

[1] Note the RR instrument is denominated in yen i.e. yen is the “2nd” currency whereas dollar is the commodity like “silver”

At the time when you accept this quote, Kp25 might come out to be 88 million yens, and Kc25 might come out to be 111 million yens. The premium x might come out to be 2.5 million yens – all hypothetical figures. However, if you accept the quote an hour later, live prices would move, and Kp25, Kc25 and x would be different even if the 3.521% quote stays largely unchanged. FX volatility smile curve is known to be sticky-delta, rather than sticky-strike (stocks).

Lets see how to compute Kp25 from this quote. In the standardized RR contract, the quoted vol of 0.03521 pa is defined as the vol difference i.e. 
sigmaKc25sigmaKp25 = 0.03521 per annum
sigmaKc25 is the implied vol of the underlying call (subcontract) at strike Kc25
sigmaKp25 is the implied vol of the underlying put (subcontract) at strike Kp25
On any FX/Equity smile curve, Kp25 < Kp25, so on the graph the sigmaKc25 (implied vol on the OTM Put) is always marked on the LHS and the Call always on the RHS. For USD/JPY, smile curve looks like a stock, so LHS sigma is Higher than RHS. Therefore the RR vol is usually negative.
To determine the exact Kc25 and Kp25 values, we need to compute the 2 above-mentioned sigmas, which bring us to the Strangle and ATM quotes.
The Strangle quote says something like
“           On Mar 1, dealer UBS is willing to WRITE 2 options — a USD (i.e. silver/JPY) put + WRITE a USD (i.e. silver/JPY) call for a premium amount of x yens, where x will be determined at the volatility level of 5.1% per annum.
The put has a strike Kp25 corresponding to a delta of -0.25.
The call has a strike Kc25 corresponding to a delta of +0.25.
Both the put and the call are OTM for 1 million unit of USD (silver) and expire end of May.
The quoted vol of 0.051 pa is defined as (sigmaKc25 + sigmaKp25) / 2 – sigmaATM = 0.051 per annum
The ATM (straddle) quote says something like
“            On Mar 1, dealer UBS is willing to WRITE a USD (i.e. silver/JPY) call + WRITE a USD (i.e. silver/JPY) put for a premium amount of x yens, where x will be determined at the volatility level of 11% per annum.
The call and the put both have exactly the same strike K such that net delta = 0.0. (This K is not specified in the quote. This K makes both options ATM but K is not exactly equal to current spot rate.)
Both are ATM for 1 million unit of USD (“silver”) and expire end of May.
The quoted 11% vol is the above-mentioned sigmaATM. ATM put and call should have very similar (implied) sigmas. Their delta should both be very close to 0.50.
With these 3 quotes, it’s simple arithmetic to back out the 2 unknown sigmas – the implied vol for the underlying 25-delta OTM call and the underlying 25-delta OTM put. The RR is a portfolio of these 2 primitive instruments. The Strangle is also a combination of these 2 basic instruments. Note the 3 quotes may come from 3 dealers, so as a market taker we can mix and match the available contracts.
If we know the implied vol (sigmaKc25) of a 25-delta OTM call, and also the spot price and expiration, BS can back out the strike price Kc25. Remember there’s a one-to-one math relationship between delta values and strike values. Imagine we have a lot of (3000) call contracts with equally spaced strikes, same expiration. If we plot their Theoretical values against their strikes, we will see a smile curve. Mathematically, their delta values (not defined this way but) are numerically identical to the gradient along this smile curve. If we plot delta against strikes, we will see the one-to-one-mapping.

Gaussian HJM, briefly

… is a subset of HJM models.

An HJM model is Gaussian HJM if vol term is deterministic. Note “vol” term means the coefficient of the dW term. Every Brownian motion must always refer to an implicit measure. In this case, the RN measure.

How about the drift term i.e. the “dt” coefficient? It too has to be deterministic to give us a Gaussian HJM.

Well, Under the RN measure, the drift process is determined completely by the vol process. Both evolve with time, but are considered slow-moving [1] relative to the extremely fast-moving Brownian Motion of “dW”. Extremely because there’s no time-derivative of a BM

[1] I would say “quasi constant”

Language is not yet precise so not ready to publish on recrec…

various discount curves

For each currency

For each Libor tenor i.e. reset frequency like 3M, 6M

There's a yield curve

STIRT traders basically publish these curves via Sprite. Each currency has a bunch of tenor curves + the FX-OIS curve

This is the YC for the AA credit quality. In theory this yield curve is not usable for a different credit quality. For a BB credit quality, the mathematicians would, correctly, assume a yield curve but in reality I doubt there's a separate curve.

In contrast, there is indeed a tenor curve at 1Y, and other tenors too.

Basis swap means interest rate swap between 2 floating “floating streams”.

* swap between 2 currencies

* swap between 2 Libor tenors

* swap between 2 floating indices. These curves below have different credit qualities:

** Libor — AA banks

** OIS — much lower credit risk given the short tenor

** T-bill — US government credit

fwd contract arbitrage concept – less useful

label – fwd deal

The basic relationship (between spot price, fwd contract price, T-maturity bond price..) is intuitive, low-math, quite accessible to the layman, so I decided to really understand it, but failed repeatedly. Now I feel it’s not worth any further effort. It’s not quitting. It’s saving effort.

– interviewers won’t ask this
– real projects won’t deal with it, because the (arbitrage-enforced) precision mathematics simply doesn’t manifest in the real data, perhaps due to bid/ask spread
– Only financial math literature makes extensive use of it

I think this is like the trigonometry or the integration techniques — you seldom need them outside academics.

Radon-Nikodym derivative #Lida video

Lida pointed out CoM (change of measure) means that given a pdf bell curve, we change its mean while preserving its “shape”! I guess the shape is the LN shape?

I guess CoM doesn’t always preserve the shape.

Lida explained how to change one Expectation integral into another… Radon Nikodym.

The concept of operating under a measure (call it f) is fundamental and frequently mentioned but abstract…

Aha – Integrating the expectation against pdf f() is same as getting the expectation under measure-f. This is one simple, if not rigorous, interpretation of operating under a given measure. I believe there’s no BM or GBM, or any stochastic process at this stage — she was describing how to transform one static pdf curve to another by changing measure. I think Girsanov is different. It’s about a (stochastic) process, not a static distribution.

discounted asset price is MG but "discount" means…@@

The Fundamental Theorem

A financial market with time horizon T and price processes of the risky asset and riskless bond (I would say a money-market-account) given by S1, …, ST and B0, …, BT, respectively, is arbitrage-free under the real world probability P if and only if there exists an equivalent probability measure Q (i.e. risk neutral measure) such that
The discounted price process, X0 := S0/B0, …, XT := ST/BT is a martingale under Q.

#1 Key concept – divide the current stock price by the current MMA value. This is the essence of “discounting“, different from the usual “discount future cashflow to present value
#2  key concept – the alternative interpretation is “using MMA as currency, then any asset price S(t) is a martingale”
I like the discrete time-series notation, from time_0, time_1, time_2… to time_T.
I like the simplified (not simplistic:) 2-asset world.
This theorem is generalized with stochastic interest rate on the riskless bond:)
There’s an implicit filtration. The S(T) or B(T) are prices in the future i.e. yet to be revealed [1]. The expectation of future prices is taken against the filtration.
[1] though in the case of T-forward measure, B(T) = 1.0 known in advance.
–[[Hull]] P 636 has a concise one-pager (I would skip the math part) that explains the numeraire can be just “a tradable”, not only the MMA. A few key points:

) both S and B must be 2 tradables, not something like “fwd rate” or “volatility”
) the measure is the measure related to the numeraire asset
) what market forces ensure this ratio is a MG? Arbitragers!

HJM, briefly

* HJM uses (inst) fwd rate, which is continuously compounded. Some alternative term structure models use the “short rate” i.e. the extreme version of spot overnight rate. Yet other models [1] use the conventional “fwd rate” (i.e. compounded 3M loan rate, X months forward.)

[1] the Libor Mkt Model

* HJM is mostly under RN measure. The physical measure is used a bit in the initial SDE…

* Under RN measure, the fwd rate follows a BM (not a GBM) with instantaneous drift rate and instantaneous variance both time-dependent but slow-moving. Since it’s not GBM, the N@T is Normal, not LG
** However, to use the market-standard Black’s formula, the discrete fwd rate has to be LN

* HJM is the 2nd generation term-structure model and one of the earliest arbitrage free model. In contrast, the Black formula is not even an interest rate model.

[[Hull]] is primarily theoretical

[[Hull]] is first a theoretical / academic introductory book. He really likes theoretical stuff and makes a living on the theories.

As a sensible academic, he recognizes the (theory-practice) “gaps” and brings them to students’ attention. but I presume many students have no spare bandwidth for it. Exams and grades are mostly on the theories.

bonds – relevant across FI models #HJM..

Bonds are no longer the dominant FI instrument, challenged by IRS and futures. However, I feel for Fixed Income models bonds are more important, more useful than any other instrument.

– Bond (unlike swap rates, FRA rates etc) is a tradeable, and obeys many nice martingale pricing rules.

– Zero Bond can be a numeraire.

– For model calibration, zero bond prices are, IMO, more easily observable than swap rates, FRA rates, cap prices, swaption prices etc. I think futures prices could be more “observable” but the maturities available are limited.

– Zero bond’s price is exactly the discount factor, extremely useful in the math. I believe a full stochastic model built with zero bond prices can recover fwd rates, spot rates, short rates, swap rates and all others …

– I believe term structure models could be based on fwd rate or short rate, but they all need to provide an expression for the “zero bond process” i.e. the process that a given bond’s price follows. Note this process must converge to par at maturity.

– Bond as an instrument is closely related to caps and floors and callable bonds.

– Bonds are issued by all types of issuers. Other instruments (like swaps, IR futures) tend to have a smaller scope.

– Bonds are liquid over most regions of the yield curve, except the extreme short end.

importance@GBM beyond BS-M #briefly

To apply BS-formula on interest rate derivatives, the underlyer process must become GBM, often by changing measure. I guess the dividend-paying stock also needs some treatment before the BS-formula can apply…

But GBM is not just for BS-Model:

GBM is used in Girsanov!

I guess most asset prices show an exponential growth rate, so a GBM with time-varying mu and sigma (percentage drift and percentage volatility) is IMO general and flexible, if not realistic. However, I don’t feel interest rate or FX spot rates are asset prices at all. Futures prices converge. Bond prices converge…

trailing comment in DOS batch


set "var=3"     %= This is a comment in the same line=%
dir junk >nul 2>&1 && %= If found =% echo found || %= else =% echo not found
The leading = is not necessary, but I like if for the symmetry.
There are two restrictions:
1) the comment cannot contain %
2) the comment cannot contain :

fwd price@beach^desert – intuitive

Not that easy to develop an intuitive understanding…

Q2.46 [[Heard on the street]]. Suppose the 2 properties both sell for $1m today. What about delivery in x months? Suppose the beach generates an expected (almost-guaranteed) steady income (rental or dividend) of $200k over this period. Suppose there’s negligible inflation over this (possibly short) period.

Paradox: you may feel after x months, the beach would have a spot price around $1m or higher, since everyone knows it can generate income.
%%A: there’s no assurance about it. It could be much lower. I feel this is counter-intuitive. There might be war, or bad weather, or big change in supply/demand over x months. Our calculation here is based solely on the spot price now and the dividend rate, not on any speculation over price movements.

I guess the fair “indifferent” price both sides would accept is $800k, i.e. in x months, this amount would change hand.
– If seller asks $900k forward, then buyer would prefer spot delivery at $1m, since after paying $1m, she could receive $200k dividends over x months, effectively paying $800k.
– If buyer bids $750k forward, then seller would prefer spot delivery.

What would increase fwd price?
* borrowing interest Cost. For a bond, this is not the interest earned on the bond
* storage Cost

What would decrease fwd price?
* interest accrual Income
* dividend Income

each year grow towards a principal developer

A lead developer of any system (not just a component) needs a few years experience [1] building a similar system. Each year, I hope to accumulate relevant know-how [2]. I’m not a people manager or project manager but I can be the principal developer.

Pause ….

However, I’m not accumulating “everything relevant” because … A lot of the know-how is never quizzed in tech interviews. Here are a few examples
* build/release/test/cont-int
* version control
* peer review/QA/release process
* wiki, jira
* back-up
* system admin scripting
* job schedulers

As a wall st contractor, I used to work in kinda greenhouse environment with all of the infrastructure taken care of, so I just focused on “get-code-done” and get productive with it. It’s an easier life.

Non-lead interviews often focus on implementation details. Benny Zhao once /identified/ just 4 or 5 clusters like 1) algo 2) language details 3) OO design. This skill set is insufficient for a principal developer.

[1] but look at Saurabh, Sundip, Kirupa, Yang … they came in with only something slightly similar
[2] not useful to focus on coding year in year out.

std::vector memory allocation/free: always heap@@

https://stackoverflow.com/questions/8036474/when-vectors-are-allocated-do-they-use-memory-on-the-heap-or-the-stack is concise.

  • The vector “shell” can be on stack or heap or static memory, as you wish.
  • The continuous array (payload objects) are always allocated on the heap, so that the vector can grow or deallocate them.

Deallocation is explained in https://stackoverflow.com/questions/13944886/is-stdvector-memory-freed-upon-a-clear

arbitrate-free term structure models

Sound byte — if we have 2 unrelated stochastic processes for 2 points on the YC, the 2 calculated prices can induce arbitrage.

Jargon: whenever you see “process”, always think of “distro” under some “measure”.

Jargon: whenever you see “price”, it almost always means a fair “quote” on some contract whose terminal value is yet to be revealed. This price comes directly from the distro by discounting the expected payoff

Jargon: bond prices basically mean loan rates, possibly forward-start. Libor is a loan. FRA is a loan. ED-future represents a loan. A single-period IR swap consists of 2 loans. OIS is based on overnight loans. I notice that from any term structure model, we always want to back out the PROCESS of various bond prices. I guess that's because the actual contracts are invariably written in terms of loans.

Preliminary: IMO, a simple IR option is a call/put on one point of the YC. Example is a call on the 3M Libor. Libor rate changes every day, so we can model it as a stochastic PROCESS. We can also model the evolution of the entire YC with 20 “points” or infinite points.

Earlier formula used to price IR options (including bond options, caps, swaptions) is not from an IR model at all. Black's formula was proposed for options on commodity futures. When adapted to interest rates, Black's formula was kind of OK to price options on one point on the (evolving) yield curve, but problematic when applied to multiple points on the YC.

As a consequence, such a model can

– give a distribution of an (yet unrevealed) discount factor of maturity M1, after calibrating the model params with one set of market data

– give a distribution of an (yet unrevealed) discount factor of maturity M2, after calibrating the model params with another, unrelated set of market data

As a result, the 2 distributions are like the speculations by 2 competing analysts — can be contracting. If a bank uses such a model, and gives quotes based on these 2 distros, the quotes can be self-contradicting, i.e. inducing arbitrage. I would imagine the longer-maturity yield (converted from the discount factor) could turn out to be much lower than short-maturity, or the yield curve could have camel humps.

Following Black's formula, First generation of IR models describe the short rate evolution as a stochastic process, but short rate can't “reproduce” a family photo. In other words, we can't back out the discount factor of every arbitrary maturity.

More precisely, given a target date “t” [1] the model gives the distribution of the (unrevealed) short rate on that target date, but the zero-curve on that target date has infinite points, each being a discount factor from some distant future (like 30Y) to the target date. The short rate distribution is not enough to reproduce the entire YC i.e. the family photo.

The only way I know to give consistent [2] predictions on all points of the YC is a model describing the entire YC's evolution. We have to model the (stochastic) process followed by any arbitrary point on the YC, i.e. any member on the family photo. The model params thus calibrated would be self-consistent.

[1] that's later than the last “revelation” date or valuation date, i.e. any IR rate on the target date is unknown and should have some probability distribution.

[2] arb-free, not self-contradicting

Sound byte — disconnected, unrelated Processes for 2 bonds (eg 29Y vs 30Y) could induce arbitrage. These 2 securities are unlike Toyota vs Facebook stocks. I think the longer maturity bond can be used to arbitrage the shorter maturity. I think it's safe to assume non-negative interest rate. Suppose both have face value $1. Suppose I could buy the long bond at a dirt cheap $0.01 and short-sell the short bond at a high $0.98 and put away the realized profit…..

liquidity = immediacy + resiliency

A Market (a particular exchange or an instrument) shows its true liquidity upon a Client-market-order. The other types of order are typically market-maker orders, which are (always?) limit orders.

#1 obvious sign of every illiquid product — wide bid/ask.
#2 obvious sign — tiny sizes of quotes (i.e. limit orders)

Now the defining features of a Liquid instrument. Look at EUR/USD…
1) Immediacy — client order is immediately filled. It’s necessary but not sufficient to have a tight bid/ask spread.

2) Resiliency — low-impact. Minimal impact on equilibrium price even in the face of a large trade. Depth of market. If there are relatively large bid/ask volumes close to the best bid/ask, then impact will be low.

2a) strong demand — large bids around mid-price
2b) firm and adequate supply — large offers around mid-price

Even the largest instrument in the world — EUR/USD can show a (temporary) drop in mid-price after a 100mio trade.

[15] %% bashrc


<![CDATA[ << ______________end_of_comment_1________________ J4 etc: to reduce section spacing modified [11 Jan 2007] ______________end_of_comment_1________________ [ -z “$(echo $- | grep i)” ] && return # # # # # # # # # # # # # # # # # # # # <> should be first # # # # # # # # # # # # # # # # # # # # # # # export PS1=’\n\s!\! \u@\h [ \t \d ] \w/ \n\$ ‘ export EDITOR=vi # primarily for sqlplus export EXINIT=” :se nu | :map v :w ” # must export LESS=”–ignore-case” export TMOUT=987654; [ $root ] && export TMOUT=100600 HISTSIZE=900 set -o emacs set +o nounset export PATH=/usr/xpg4/bin:$PATH; [ $(id -u) = 0 ] && root=yesur set +o noclobber; [ $root ] && set -o noclobber sav=$LOGNAME # # PAGER and TERM issues: # # “vt100 less -E” is ok on linux # TERM ‘linux’ breaks vi in gnome-terminal; ‘linux’ imperfect for solaris # for “less”, -E needed for dir-viewing, file-viewing but affects man # export PAGER=more export PAGERE=more if [ -z “$(which less |grep ‘^no less’)” ]; then export PAGER=”less” # breaking some x terminals but ok in “console” export PAGERE=”less -E” # -E needed for dir-viewing, file-viewing but affects man fi echo TERM=$TERM initially export TERM=vt100 # ‘linux’ breaks vi in gnome-terminal; ‘linux’ imperfect for solaris # # # # # # # # # # # # # # # # # # # # # # # # <># # # # # # # # # # # # # # # # # # # # # # # alias killthem=”perl -pe ‘s/^\S+(\s+\d+).*/\1/ or s/.*//’|xargs -pt kill” # p str1 | killthem # alias killthem=”perl -pe ‘s/\S+(\s+\S+).*/\1/s’|xargs -pt kill” # p str1 | killthem # sortable : alias %=cd_l # typing trainer alias ..=’cd_l ..’ alias cp=’cp -i’ # defuse alias egi=’export |grep -i’ alias h=history alias hgi=”history |grep -i” alias j1=”fg %1″ alias j2=”fg %2″ alias m=$PAGERE alias mv=’mv -i’ # defuse alias p=ps_grep alias path=” echo \$PATH |perl -pe ‘s/:/\n/g’ |sort -u|m ” alias rm=myrm alias s=’ source $HOME/.bashrc ‘ # .profile absent alias t=’l -t’ alias top=’prstat’ # # # # # # # # # # # # # # # # # # # # # # # # <> difficult to sort # # # # # # # # # # # # # # # # # # # # # # # cd_l(){ [ $# -eq 0 ] && l && return [ -n “$( file $* | grep directory )” ] && cd $* && l && return [ -n “$( file $* | perl -ne ‘print if /text|script/’ )” ] && m $* && /bin/echo “\n\n” && l $* } d(){ [ $# -ne 0 ] && cd $* [ `pwd` = ‘/’ ] && target=/ && echo I am in / echo “In MB :” eval du -ks * |sort -n|perl -pe ‘s|^(\d+)|$1/1000|e’ } g(){ # bug with g -v pattern=$1; shift cmd=” grep -i \”$pattern\” $* ” /usr/bin/printf ‘%s\n’ “cmd=__$cmd __” eval $cmd |$PAGERE } l(){ # can’t be completely replaced by ‘cd_l’ or ‘]’, because “cd_l -tr dir1″ is confusing and should be avoided /bin/ls -alFs $* |$PAGERE } myrm(){ cmd=”mv -i $* /var/tmp/$sav/ ” /usr/bin/printf ‘%s\n’ “cmd=__$cmd __” eval $cmd } ps_grep(){ ## cmd1=’/bin/ps -ef’ # truncation risk # ps auxwww : inconsistent for root vs non-root cmd1=’/usr/ucb/ps auxwww’ # |grep -v grep — no cos some real commands contain grep for f in $*; do cmd1=”$cmd1 | g $f” done eval $cmd1 } sav(){ suffix=$RANDOM$(date +”%H%d%b”) # to avoid misleading readers,make the suffix ambiguous for f in $*; do f=$(echo $f|perl -pe ‘s|/$||’) # sav dir/ b=`basename $f` ( cd `dirname $f` ; tar cf – $b | (cd /tmp; tar xpf -) /bin/mv -i /tmp/$b $b.b4${sav}edit$suffix [ -d $f ] && opt=’ -d’ eval ls -lt $opt $b* ) done } # # # # # # # # # # # # # # # # # # # # # <>, an exercise in grouping # # # # # # # # # # # # # # # # # # # # # # # exa(){ #testing: exa -t ss ~/.ssh local ops while is_opt=`echo $1 |perl -ne ‘print if /^-/’ ` && [ “$is_opt” ]; do ops=”$ops $1″; shift done if [ $# -eq 1 ]; then fullpath=$1 shortname=`echo $1|perl -pe ‘s|/$||;s|^.*/||’ ` else fullpath=$2 shortname=$1 fi [ -x $fullpath ] || return # export “$shortname”=”$fullpath” set $shortname=”$fullpath” prj=”$fullpath” alias “$shortname”=”cd $fullpath;l $ops” alias prj=$shortname # USE MORE } exa /tmp/ exa /etc # # # # # # # # # # # # # # # # # # # # # <># # # # # # # # # # # # # # # # # # # # # # # add_path(){ [ -r $1 ] || return [ “$(echo $PATH|grep :$1)” ] && return # check world write perm, esp for root PATH=$PATH:$1 } set_manpath(){ # very slow on some systems. Run this when u need it. for d in `ls -d /[uo]*/*/man /[uo]*/*/*/man /[uo]*/*/*/*/man`; do export MANPATH=$MANPATH:$d done } set_path(){ add_path /usr/sbin add_path /usr/bin add_path /sbin add_path /usr/local/bin add_path /usr/cluster/bin add_path /usr/openwin/bin/ add_path /usr/ucb add_path $ORACLE_HOME/bin add_path /usr/sfw/bin # pre-installed add_path /opt/csw/bin [ $root ] && return add_path . add_path $HOME/bin } set_path ]]>