Bug's Rhapsody

未来是一枚失落的指针,往昔是一片无法删除的内存

Wednesday, 18 June 2008

一个相当牛逼的C程序

/* mystery.c */
#include <stdio.h>
main(t,_,a)
char *a;
{return!0<t?t<3?main(-79,-13,a+main(-87,1-_,
main(-86, 0, a+1 )+a)):1,t<_?main(t+1, _, a ):3,main ( -94, -27+t, a
)&&t == 2 ?_<13 ?main ( 2, _+1, "%s %d %d\n" ):9:16:t<0?t<-72?main(_,
t,"@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l,+,/n{n+\
,/+#n+,/#;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l q#'+d'K#!/\
+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;# ){n\
l]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#\
n'wk nw' iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c\
;;{nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;\
#'rdq#w! nr'/ ') }+}{rl#'{n' ')# }'+}##(!!/")
:t<-50?_==*a ?putchar(a[31]):main(-65,_,a+1):main((*a == '/')+t,_,a\
+1 ):0<t?main ( 2, 2 , "%s"):*a=='/'||main(0,main(-61,*a, "!ek;dc \
i@bK'(q)-[w]*%n+r3#l,{}:\nuwloca-O;m .vpbks,fxntdCeghiry"),a+1);}

Friday, 29 February 2008

Financial Date Algorithms

Day Count Conventions

TODO:

Rolling Conventions

Firstly, given a start date and a maturity, the rolling conventions are used to determine the end date of the calculation period. Suppose today is 2007-02-28 (the last day of February), and we would like to generate a calculation period using a maturity of 6 months. The end date may be ambiguous as both 2007-08-28 and 2007-08-31 seem reasonable. In this case, the non-end-of-month convention will generate 2007-08-28, while the end-of-month convention will generate 2007-08-31.

Secondly, if the start date or end date of a calculation period falls on a non-business day, the rolling conventions are also used to adjust the dates. There are 5 adjustment conventions:

- No Adjustment: the date will not be adjusted, even if it falls on a non-business day.
- Following: the non-business date will be adjusted to the first following day that is a business day.
- Preceding: the non-business date will be adjusted to the first preceding day that is a business day.
- Modified Following: the non-business date will be adjusted to the first following day that is a business day unless that day falls in the next calendar month, in which case that date will be the first preceding day that is a business day.
- Modified Preceding: the non-business date will be adjusted to the first preceding day that is a business day unless that day falls in the previous calendar month, in which case that date will be the first following day that is a business day.

Besides, there are 2 special conventions for adjusting dates:

Two business days prior to third Wednesday of the month

This convention is related to exchange traded contracts where trading stops two business days prior to the third Wednesday of the month. For annual, semi-annual, quarterly or monthly frequencies, generated dates are adjusted to fall 2 business days prior to the third Wednesday of the month. For all other frequencies, dates are generated as usual with no adjustment. The maturity date is not adjusted.

Third Wednesday

This convention is related to exchange traded contracts where trading stops on the third Wednesday of the month. For annual, semi-annual, quarterly or monthly frequencies, generated dates are adjusted to fall on the third Wednesday of the month. For all other frequencies, dates are generated as usual with no adjustment. The maturity date is not adjusted.

Irregular Calculation Period Conventions

For financial products such as interest rate swaps, we need to generate a sequence of calculation periods. Given a start date, an end date and a frequency, there may be a remaining irregular calculation period. For example, if today (start date) is 2008-02-01, the maturity date of the swap (end date) is 2009-03-01, and the frequency is 3 months. In this case, we may use the following conventions (stubs) to determine how to generate the irregular calculation periods:

- Short Initial: generate an irregular calculation period at the beginning of the sequence, which is shorter than the frequency.
- Short Final: generate an irregular calculation period the end of the sequence, which is shorter than the frequency.
- Long Initial: generate an irregular calculation period at the beginning of the sequence, which is longer than the frequency.
- Long Final: generate an irregular calculation period at the end of the sequence, which is longer than the frequency.

References

- EURIBOR and EONIA
- BBA

Monday, 11 February 2008

The Greek Letters

The Greek Letters

Each Greek letter measures a different dimension to the risk in a portfolio and the aim of a trader is to manage the Greeks so that all risks are acceptable.

Delta

The delta of a portfolio is defined as the rate of change of the portfolio price with respect to the price of the underlying asset.

The delta of a portfolio can be calculated from the deltas of the individual derivatives in the portfolio.

TODO: delta hedging.

Theta

The theta of a portfolio is the rate of change of the value of the portfolio with respect to the passage of time with all else remaining the same. Theta is sometimes referred to as the time decay of the portfolio.

Note that theta is not the same type of hedge parameter as delta. There is uncertainty about the future price of the underlying asset, but there is no certainty about the passage of time. It makes sense to hedge against changes in the price of the underlying asset, but it does not make any sense to hedge against the effect of the passage of time on a portfolio. In spite of this, many traders regard theta as a useful descriptive statistic for a portfolio. This is because in a delta-neutral portfolio, theta is a proxy of gamma.

Gamma

The gamma of a portfolio is the rate of change of the portfolio's delta with respect to the price of the underlying asset. It is the second partial derivative of the portfolio with respect to asset price.

If gamma is small, delta changes slowly, and adjustments to keep a portfolio delta-neutral need to be made only relatively infrequently. However, if gamma is large in absolute terms, delta is highly sensitive to the price of the underlying asset. It is then quite risky to leave a delta-neutral portfolio unchanged for any length of time.

TODO: gamma hedging.

Relationship Between Delta, Theta and Gamma

TODO: Who can tell me how to write mathematical formula in HTML?

Vega

The vega of a portfolio is the rate of change of the value of the portfolio with respect to the volatility of the underlying asset.

If vega is high in absolute terms, the portfolio's value is very sensitive to small changes in volatility. If vega is low in absolute terms, volatility changes have relatively little impact on the value of the portfolio.

Rho

The rho of a portfolio is the rate of change of the value of the portfolio with respect to the interest rate.