Thursday, January 25, 2007

Possible Profile

LondonNet - London Jobs Guide
« Back to List | « Browse Category
One Delta Desk Strategist – Equities Division (London) »
My client, a Top Tier Global Investment Bank, is looking for a One Delta Desk Strategist to work with the program trading and Pan European Shares trading desk to improve trading efficiency. You will play a key role in identifying prop trading ideas, analysing principal program trades and constructing hedge baskets.

The role will involve improving trading efficiency through automation and analysis, historical analysis of trading patterns, maintaining bespoke index products, developing risk management solutions and analysis of VaR.

The ideal candidate must have an Advanced Quantitative degree and extensive experience (3-4 years) in a similar trading and sales environment. You must have the ability to develop computer programs for real time trading and risk analysis. In terms of knowledge, you will be a specialist in portfolio theory, asset pricing, transaction cost analysis and derivative modelling.

This is an exciting opportunity to get involved with a relatively new business and be part of the growth and
development of a Global operation. You will be highly rewarded with the very best in remuneration. Please send your CV in the first instance or call Alana Wight to discuss on +44 207 604 4444.

Tuesday, January 09, 2007

excercise

发信人: LegendinG (赤兔|男人~简单&沉默&坚持), 信区: FitnessWorld
标 题: Re: 晚上锻炼完吃鸡蛋外还能吃些什么?
发信站: 水木社区 (Tue Jan 9 16:42:06 2007), 站内

早餐:鸡蛋+豆奶+麦片+苹果+复合维生素片;
中餐:瘦肉+鸡蛋+米饭+蔬菜+蒺藜皂甙1粒;
训练前:肌酸+葡萄糖+支链氨基酸+香蕉;
训练后:乳清蛋白粉+谷氨酰胺+支链氨基酸+葡萄糖;
晚餐:瘦肉+鸡蛋+米饭+蔬菜+复合维生素片+蒺藜皂甙1粒;
睡觉前:乳清蛋白粉+牛奶;

【 在 cashcow (日产斗金) 的大作中提到: 】
: 建议大牛们给个现在用的食谱,当然最好把自己的运动量说明一下。

Saturday, January 06, 2007

Lehman电面面经

发信人: linfeiumd (afei), 信区: Quant
标 题: Re: 急:求Lehman电面面经
发信站: BBS 未名空间站 (Sat Jan 6 20:33:23 2007)

questions include math, finance (and c++ if it is the analytics intern/
fulltime). you are expected to be familiar with black-scholes, binomial tree
and some simple derivatives like barriers. also, it is desirable you have
some knowledge about term structure models. math-wise you will be tested on
probabilities and stochastic calculus.
--

Barclays Ph.D.s Build Hedge Fund Giant Inside Bank (Update1)

Barclays Ph.D.s Build Hedge Fund Giant Inside Bank (Update1)

By Edward Robinson

Jan. 5 (Bloomberg) -- One morning in October, a money manager named Seanna Johnson flips on her computer and watches the screen fill with numbers. In front of her is a list of 100 Japanese stocks she should buy or sell.

The shares had been picked overnight by computer software at San Francisco-based Barclays Global Investors, where Johnson, 39, manages three hedge funds. BGI insiders call the program the Optimizer.

``Which stocks should I hold and which should I short?'' Johnson asks. To find the answer, she turns to the Optimizer, which crunches corporate earnings data and dozens of other variables for almost every stock in the world.

BGI is one of the most powerful forces in money management today. It's a den of finance Ph.D.s, mathematicians and other disciples of quantitative analysis, or quants. BGI quants design investing strategies for thousands of stocks, bonds and currencies and then use computers to pick which ones to buy and sell.

BGI manages almost $1.7 trillion in assets and has a finger in 65 of the world's 100 largest pension plans. Its iShares exchange-traded funds, which are low-cost index trackers that can be traded like stocks, have made the firm the Wal-Mart of the $383 billion ETF world. Lately, BGI's size and reach have helped fan speculation that its parent, London-based Barclays Plc, is headed for a megamerger with a big U.S. bank. Barclays is the third-largest U.K. bank by assets.

Blake Grossman, the Stanford University-educated economist who runs BGI, has used his quants to quietly transform a firm built on index investing into one of the world's largest hedge fund managers.

Hedge Fund Science

Grossman, 44, is converting corporate and public pension funds to what BGI calls a scientific approach to these often secretive, sometimes volatile investment vehicles, which strive to make money in bull and bear markets. He's championed the idea that pension managers should not only bet on stocks, or go long, but also wager against them, or go short. This twin tactic is employed by so-called long/short hedge funds.

Sitting in a 32nd-floor conference room in BGI's headquarters, Grossman hardly comes across as a swashbuckling hedge fund manager. He's a native of the San Fernando Valley area of Los Angeles, which is known for its shopping malls and Valley Girls. In 1985, Grossman earned a master's degree in economics from Stanford, where he wrote a paper on corporate divestments with his mentor, Nobel Prize-winning economist William Sharpe. A trim man with glasses and graying hair, Grossman speaks in long, unbroken sentences peppered with terms such as ``externalities'' and ``investment efficiency.''

Radical Change

Institutional investing is undergoing radical change, according to Grossman. Ten or 20 years ago, money managers who'd been entrusted with people's retirement nest eggs refused to make risky investments or short stocks.

Now, these managers are adopting hedge fund strategies to generate the returns they'll need to keep their promises to workers and retirees.

``We think this artificial divide between long-only and long/short is one that's destined to become extinct over the next several years,'' Grossman says.

During the past year, BGI has pitched investment strategies that employ leverage, or borrowed money, to short stocks and boost returns. Selling short can be risky. When you buy a stock for $10, the worst thing that can happen is that the price falls to zero and you lose $10. When you short a stock, which involves borrowing shares and then selling them, the potential losses are, in theory, bottomless.

Pensions Pile In

BGI exemplifies a shift that's taking place in the hedge fund industry, which, according to Chicago-based Hedge Fund Research Inc., had about $1.34 trillion in assets as of Dec. 13. During the 1980s, hedge funds catered mostly to the rich. Then, during the '90s, universities and foundations jumped into these funds, which enable their managers to participate substantially in investment gains. Now, corporate and public pension funds are turning to these loosely regulated private pools of capital.

The rush into hedge funds may end badly, says Zvi Bodie, a finance professor at Boston University who has studied pension issues for more than 25 years. If hedge fund trades go wrong, the use of short sales could leave pension funds in a hole, he says.

Lately, the average hedge fund manager has struggled to beat the Standard & Poor's 500 Index. HFR's HFRX US Absolute Return Index, for example, returned 7.5 percent during the 12 months ended on Dec. 28, trailing the 15.3 percent return of the S&P 500.

``There is very little evidence that anyone can consistently beat the market,'' Bodie says. ``The pensions don't want to suck it up, so they're grasping at anything that might provide an answer.''

Reaching for Alpha

Every pension manager today talks about the Greek letters alpha and beta. In Wall Street parlance, alpha is the premium an investment earns above some particular benchmark, such as the S&P 500. Beta is the volatility of that benchmark.

U.S. pension funds are reaching for alpha because many of them don't have the money they'll need to meet future liabilities. In 2005, 319 of the 500 companies in the S&P 500 were carrying more than $472 billion in underfunded pensions and other post-retirement employee benefits, such as health care, according to David Zion, a New York-based analyst at Credit Suisse Group.

State and local pensions in the U.S. are underfunded by as much as $380 billion, according to the National Association of State Retirement Administrators.

Pension funds typically need to earn 8-9 percent annually to meet their obligations, according to Daniel Celeghin, an associate director at Casey, Quirk & Associates LLC, a Darien, Connecticut-based consulting firm that advises big investors.

$1 Trillion

By 2010, institutions are likely to have $1 trillion in assets invested in hedge funds, almost three times the $360 billion invested today, according to an October report by Casey Quirk and Bank of New York Co.

``They are forced to take more risk to match liabilities,'' says Niclas Hiller, a senior manager of the $300 billion petroleum fund at Norges Bank, the central bank of Norway. ``The pressure is on.''

So far, Grossman's quants have lagged rivals. Through Sept. 30, BGI's Global Ascent hedge fund, a macro fund that invests in stocks, bonds, currencies and other assets, returned 36 percent, net of fees, since its inception in July 2003, according to performance data obtained from a hedge fund consultant who asked not to be identified. The Credit Suisse Tremont Hedge Fund Global Macro Index of 3,000 hedge funds returned 39 percent during that period.

Quiet Giant

All the same, hedge fund money has flooded into BGI. As of Sept. 30, the firm had amassed $17 billion in long/short funds, according to HFR.

``We didn't set out to be a hedge fund giant,'' Grossman says.

And yet that's precisely what BGI has become. The firm has made Barclays, which traces its history back to the 17th century, the parent of the world's fifth-largest hedge fund manager, according to HFR.

Size means money for hedge funds. BGI collects annual management fees equal to 2 percent of assets under management for some of its dozens of hedge funds, the industry standard. Like most hedge funds, BGI then takes a cut of about 20 percent of any profits on those funds, according to a record of fees that BGI has filed in Ireland. BGI's U.S.-based ETFs, by contrast, charge average annual fees of 0.32 percent.

As money has poured in, BGI has become Barclays's second- fastest-growing division, after its investment banking unit, Barclays Capital. BGI's profit before taxes rose 61 percent to 542 million pounds ($1 billion) in 2005. During the first half of 2006, the firm earned $710 million before taxes.

Hot Property

BGI and Barclays Capital have helped make its British parent a potential hot property. On Dec. 11, Barclays rose to a then-record of 746.50 pence a share after Merrill Lynch & Co. analysts Brian Bedell, John-Paul Crutchley and Edward Najarian wrote to investors that Bank of America Corp. might be interested in buying the bank.

Bank of America Chief Executive Officer Kenneth Lewis later said he was in no hurry to make a European acquisition.

``We never say never, but I don't think it's a strategic imperative,'' Lewis told journalists in New York on Dec. 13. Barclays stock has kept rising anyway. The shares traded at 751 pence today in London.

BGI, which originated in 1964 as part of San Francisco- based bank Wells Fargo & Co., has been a quant shop from the start. During its early years, Myron Scholes and Sharpe, who would go on to become Nobel laureates, helped the firm create the world's first index fund.

Today, Grossman and his quants say they've built a system that strips emotions such as fear and greed out of hedge fund investing.

No Heroes

``If you look at the history of this investor-as-hero-type guy over the last 20 years, you can see that they're rockets -- and they burn out like rockets,'' says Richard Grinold, who runs BGI's advanced strategies and research group, which directs BGI's actively managed funds, as opposed to its indexed investing. ``Our organization is the antithesis of that. It's a non-star system. It's really the process that's the star, if anything.''

BGI money managers and researchers must run a gauntlet of peer-review hearings every time they pitch an investment idea. It can take months before a panel of as many as 25 money managers and analysts debate the idea. Senior fund managers, who get the final say, reject two of every three ideas. BGI researchers, many of them former college professors, boast that the ordeal is similar to the way academics vet each others' research.

New Tack

This process sometimes prevents BGI money managers from moving fast. ``It's absolutely, without any doubt, one of the shortcomings of our research process, but I would argue that's also a strength -- because when we do bet on an idea, we know it's a solid idea,'' says Kenneth Kroner, head of the global markets research and strategy team. ``It's not just a flier, a gut feeling that someone had when they woke up in the morning.''

Lately, BGI, originator of the index fund, has been pushing a new type of long/short strategy designed to mimic hedge fund investing at a fraction of the cost. These funds short the equivalent of 20-30 percent of their assets and employ a tool common to hedge funds: leverage. Money managers call these investments 120/20s or 130/30s, because they borrow the equivalent of 20-30 percent of the value of their assets to finance the short sales.

The funds aren't bona fide hedge funds, because they short on a limited basis and otherwise track an index such as the S&P 500. Fees for most 120/20s run closer to what index funds charge, about 0.6-0.9 percent of assets under management, according to Morgan Stanley.

Calpers Calling

BGI has marketed these funds, which were invented by Analytic Investors Inc., a Los Angeles-based quant firm. In October 2005, BGI unveiled its Alpha Advantage 500 Fund, which shorts the equivalent of 20 percent of its assets. Through Sept. 30, it had returned 18.3 percent compared with a 15.3 percent return for the S&P 500, according to performance data obtained by Bloomberg News.

Pension funds like what they see. In December, the $217.6 billion California Public Employees' Retirement System selected five asset managers, among them Analytic Investors and Goldman Sachs Group Inc., to run 135/35s as part of its U.S. domestic equity portfolio. BGI didn't bid to manage the fund, according to spokesman Lance Berg.

Calpers expects these funds to beat the market, says Christianna Wood, a senior investment officer at Calpers. Calpers won't classify the 135/35s as part of the $3.6 billion in assets it already has in true hedge funds, Wood says.

``This is the next extension of reducing constraints around managers that are highly skilled,'' Wood says.

`No Free Lunch'

Calpers, which invests $140 billion in global equity funds, eventually plans to deploy billions in this new strategy and may move assets away from index funds and underperforming money managers.

The shift will expose Calpers to bigger risks, according to a three-page opinion on the funds written by Los Angeles-based Wilshire Consulting at Calpers' request.

``There is no free lunch in this strategy,'' wrote Michael Schalchter, a managing director at Wilshire, before endorsing the idea.

From the start, the firm now known as BGI has sought to erase wishful thinking from investing. The firm was born inside the trust department of Wells Fargo.

Then called the management sciences group, the division was led by John ``Mac'' McQuown, a mechanical engineer with an MBA from Harvard University, who was an early evangelist for using computers and quantitative analysis to invest in stocks.

Fama's Followers

McQuown, now 72, was a devotee of the efficient markets hypothesis espoused by Eugene Fama, an economics professor at the University of Chicago. The hypothesis states that stock prices reflect all available information in the marketplace, so it's impossible to beat the market over time.

McQuown, who used to tinker with International Business Machines Corp. vacuum tube mainframe computers in his spare time, wanted to build a system that would put the theory to work in portfolios encompassing virtually the entire market, or as many as 5,000 stocks. He assembled a dream team of economists to consult with the management sciences group.

In addition to Fama, Scholes and Sharpe, the team included then University of California, Berkeley, finance professor Barr Rosenberg; economist Fischer Black; and Czech mathematician Oldrich Vasicek. In 1990, Sharpe won a Nobel Memorial Prize in Economic Sciences for his work on measuring risk and return. Scholes won a Nobel in 1997 for the Black-Scholes options pricing model, which he had devised with Black. Black had died in 1995.

`Dynamite Team'

``We created a dynamite team of brains to work on the problem, the bank's senior management was willing to foot the bill and we spent millions,'' says McQuown, who's co-founder of Diversified Credit Investments, a San Francisco-based investment firm.

The team set out to use Sharpe's capital asset pricing model, which quantified the relationship between risk and return, to build a portfolio. In those days, measuring risk was a fuzzy exercise because there was no metric.

Sharpe's CAPM provided one: the model defined risk as volatility relative to the entire market and established that investors expect higher returns for greater risks. Relative volatility was measured by the beta coefficient. The S&P 500 has a beta of 1. A stock with a beta of more than 1 is more volatile than the index and thus riskier; a stock with a beta of less than 1 is safer.

McQuown and his team logged 100-hour workweeks and finally made a breakthrough: the construction of a computerized simulator that enabled researchers to create portfolios of stocks showing risk and return and then test them through history.

Hedge Fund Seeds

At last, Wells Fargo's money managers had a tool that could put the theories of Fama, Sharpe and their colleagues into practice. On their own, Black and Scholes also planted the seeds of a hedge fund approach in 1969 when they proposed creating a fund that mixed long positions in low-beta stocks and short positions in high-beta stocks.

``They didn't call it a hedge fund at the time, but this was early,'' says Perry Mehrling, an economics professor at Barnard College in New York and author of ``Fischer Black and the Revolutionary Idea of Finance'' (John Wiley, 374 pages, $29.95).

In 1971, Wells Fargo unveiled a portfolio that tracked the performance of shares listed on the New York Stock Exchange for the pension fund of luggage maker Samsonite Corp. The first index fund was born. Over the next decade, the firm expanded its index fund offerings.

Dream Job

By the time Grossman was hired in 1985, at age 23, the firm had $29.2 billion in assets under management and was committed to building an actively managed fund group that could deliver market-beating returns to its pension fund clients.

From the get-go, Grossman wanted to work in active management. He joined the team that launched the firm's Alpha Tilts fund, an enhanced index portfolio that sought to beat the broad market by investing more heavily in promising stocks.

In 1992, Grossman landed his dream job: founding and directing the advanced strategies group. Its mission was to pick up where McQuown had left off and develop new ways to beat the market using the firm's quantitative system. Then, in 1996, Barclays acquired the firm for $440 million and changed its name to Barclays Global Investors.

By that time, then CEO Frederick Grauer had tapped Grinold, president and former research director at Barra Inc., a Berkeley, California-based quantitative investing consulting firm, to lead the research effort.

Going Short

Grinold, 68, a one-time navigator on a U.S. Navy destroyer, studied physics at Tufts University in Medford, Massachusetts, and earned a doctorate in operations research at UC Berkeley. He was a finance professor at UC Berkeley's Haas School of Business for 20 years. In 1996, Grossman and Grinold launched a long/short fund. Their reasoning was simple: If they have data on winners and losers, why not use all of it?

``What attracted us to investing on a long-short basis had to do with the investment efficiency that we could gain,'' Grossman says.

In 1998, Grauer turned over the reins to Patricia Dunn, his co-CEO since 1995. She built BGI's business in ETFs. Dunn resigned as CEO in 2002 and as vice chairman this past October, after she was indicted by the state of California on fraud and conspiracy charges for her alleged role in the board leak scandal at Hewlett-Packard Co., where she was chairman. Dunn has pleaded not guilty.

That same year, Grinold recruited Ronald Kahn, a fellow physicist who taught at Harvard, as global head of advanced equity strategies.

From Physics to Finance

As a postdoctoral fellow at UC Berkeley in the mid-1980s, Kahn had worked with Nobel-winning physicist Luis Alvarez and his son, geologist Walter Alvarez, on research into whether the dinosaurs were wiped out by an asteroid's collision with Earth, a theory now widely accepted.

``If you have any questions about the early universe, he's your man,'' Grinold says, pointing at Kahn.

With Grossman's blessing, Grinold and Kahn cultivated an academic culture inside the research process that stoked the free exchange of ideas.

``It's a quest for what we believe is truth,'' says Grinold, an intense man with white hair and a baritone voice.

They also adopted a ``no-jerk'' policy. ``We don't tolerate ranters and ravers,'' says Kahn, 50, a bespectacled man with a finely trimmed beard, who smiles when he talks.

This culture and the allure of testing theories on real billion-dollar funds has proved irresistible to academics. In 2002, Charles Lee, then a finance professor at Cornell University, was happy teaching and directing a hedge fund lab for business students that invested donated funds from the school's endowment. In five years, the lab's Cayuga MBA Fund LLC swelled from $600,000 to $11 million.

Farewell, Cornell

Lee left academia to become BGI's global director of equity research in 2004. ``If you really want to learn more and develop more, $11 million is not a lot of money,'' Lee, 49, says. ``If you really want to push the envelope, to have the resources and challenges, I don't think you can do it from an academic post.''

At the heart of BGI's investment system is an array of ``signals'' designed to predict how a security will behave by assigning scores to certain market forces, such as volatility, earnings expectations and market momentum. The key was creating one expandable system that could be applied to a range of strategies, from index funds to long/short portfolios.

Grinold and Kahn understood that the human element couldn't be dismissed from investing. Simply turning loose a computer program to find promising bets -- a practice called data mining

To contact the reporter on this story: Edward Robinson in San Francisco at edrobinson@bloomberg.net .

Last Updated: January 5, 2007 12:14 EST

Thursday, January 04, 2007

Brain teaser

9个球,重量为1,2,3,...,9,外表一样,但是我可以区分,你却不能。
有一个天平,问至少我称给你看几次,你可以区分得出这9个球?
(copyright:多年前一个哥们问我的)
至于一般情况(n个球)是怎么回事我还没搞清楚。

发信站: BBS 未名空间站 (Thu Jan 4 17:12:12 2007)

there are several solution with 4 times

but I only have one with 3

the key is to maximize the utility of the 3rd time by taking the advantage
of the fact that the scale has two sides.

First I show you

1+2+3+4+5<7+9

then you know it is one of the following three ordered sets

a: (1,2,3,4,5),(7,9).(6,8)
b: (1,2,3,4,5),(8,9),(6,7)
c: (1,2,3,4,6),(8,9, (5,7)

next I show you

1+2+3+7<6+8

since 1,2,3,7, are the smallest in (1,2,3,4,5), (7,9) and no other selection
could produce such an inequality, then you know we are in case (a) and know
the ball weight 7 and 9 now.

and now before you eyes, you know the left balls are ordered as
(1,2,3),(4,5),(6,8)
then I show you
1+4+6<3+9
since 1,4,6 are the smallest in each set, and 3 is the largest in (1,2,3)
then you know which is which~

I hope I made no error :)

My way of sorting them in 3 times.

1. a+b+c+d+e=f+i
You then sort them into 3 groups. (a,b,c,d,e) is (1,2,3,4,5); (f,i) & (g,h)
are (6,9) or (7,8)

2. a+b+f=d+e
Then you know (a,b) is (1,2), c is 3, (d,e) is (4,5), f is 6, (g,h) is (7,8)
and i is 9.

3. a+d+g=c+i
Then you got it.

Monday, January 01, 2007

C+编程容易犯的错误

标 题: [转贴]C+编程容易犯的错误
发信站: BBS 水木清华站 (Mon May 26 19:41:33 2003), 转信

//觉得不错,不知道以前是否贴过:)
//如果贴过,可以在复习一下,呵呵~~
C++编程易范的错误
[美]Stephen R.Davis
C/C++语言中有许多对初学者(甚至是有经验的编程人员)来说很容易范的错误。通晓
这样的错误可使你免于陷入其中。
忘记初始化指针
这种错误只是一般"忘记初始化变量"错误的一个特殊形式(C/C++中变量不会自动初
始化,而Basic可以)。使这种错误更糟糕的原因是它的后果往往更加糟糕:
void SomeFunction()
{
int *pnVar
int nVal;
nVal = *pnVar; // Bad enough.
*pnVar = nVal; // Much worse.
}
在这个例子中,指针变量pnVar从未被赋值。因此你必须假设它含有的是杂乱的数据
,从一个混乱信息指针中读数糟糕的很,因为结果肯定是杂乱数据,向一个混乱信息指
针写数据更糟,因为它将导致一些不知道什么地方的数据被重写。
如果被重写的区域无用,这到没什么危害。如果被重写的区域有用,数据就会丢失
。这种类型的错误那么难找,是因为直到程序企图使用已丢失的数据时问题才会呈现出
来。这种问题可能是在数据丢失后好久才发生的。
由于这一问题手工判断很困难,Visual C++编译器就通过一些努力来避免它的发生
。例如,当你编译上述函数时就会产生一个警告。在这种情况下,编译器会告诉你变量
在使用前未被赋值。在很多情况下,它不可能告诉你。
Windows 95操作系统试图用保护存储器在一定程度上帮助解决难题:如果应用程序
企图从不属于它的存储器读或写,Windows通常能截获该请求,并立即终止该程序。可惜
,Windows 95不能截获对应用程序拥有的存储器的无效访问,它也不能截获所有非法访
问,因为必须保留某些缺口,以与Windows 3.1的兼容性名义开放。
忘记释放堆内存
请记住从堆获得分配的任何内存都必须要释放。如果你用完内存以后,忘记释放它
,系统内存就会变得愈来愈小,直到最后你的程序不能运行而崩溃。
这个问题会出现在诸如下列的一些情况中:
Car* GetAnewCar(int nOccupants)
{
Car* pCar;
if(nOccupants < pcar =" new" pcar =" new" pcar =" GetAnewCar(nOccupants);">Drive(Store);
}
}
在此例中,函数GoToTheStore()首先分配一辆新车来开——这有点浪费,但你肯定
会同意这种算法可以正常工作。只要分配了新车,它就会开到有调用pCar->Drive(Stor
e)所指向的商店。
问题是在它安全到达目的地之后,函数不破坏Car对象。它只是简单地退出,从而使
内存丢失。

通常,当对象pCar出了程序中的作用域时,程序员应该依靠析构函数~Car释放内存
。但这里办不到,因为pCar的类型不是Car而是Car*,当pCar出了作用域时不会调用析构
函数。
修正的函数如下:
void GoToTheStore(int nOccupants)
{
// get a car。
Car* pCar = GetAnewCar(nOccupants);
// Now drive to the store。
if(pCar)
{
pCar->Drive(Store);
}
// Now delete the object,returning the memory.
delete pCar;
}
使用new操作符构造的对象都应该用delete运算符删除,这一点必须牢记。
返回对局部内存的引用
另一个常见的与内存有关的问题是从函数返回局部内存对象的地址。当函数返回时
,对象不再有效。下一次调用某函数时,这个内存地址可能会被这个新函数使用。继续
使用这个内存指针就有可能会写入新函数的局部内存。
这个常见问题以这种方式出现:
Car* GetAnewCar(int nOccupants)
{
Car* pCar;
if(nOccupants < 4)
{
pCar = &Car(2); // get a two-door.
}
else
{
pCar = &Car(4); // otherwise, a four-door.
}
return pCar;
}
请注意指针pCar怎样被赋予由构造函数Car()建立的未命名对象的局部地址的。到目
前为止,没有问题。然而一旦函数返回这个地址,问题就产生了,因为在封闭的大括号
处临时对象会被析构。
使运算符混乱
C++从它的前辈C那里继承了一套含义相当混乱模糊的运算符。再加上语法规则的灵
活性,就使它很容易对程序员造成混乱,使程序员去使用错误的运算符。
这个情况的最出名的例子如下:
if(nVal = 0)
{
// do something if nVal is nonzero.
}
程序员显然想要写if(nVal == 0)。不幸的是,上述语句是完全合法的,虽然没有什
么意义,C++语句将nVal赋值为0,然后检查结果看看是否为非零(这是不可能发生的)
。结果是大括号内的代码永远不会被执行。
其它几对容易弄错的运算符是&和&&,以及/和//。
0的四种面孔
根据使用它的方式,常数0有四种可能的含义:
☆ 整数0
☆ 不能是对象地址的地址
☆ 逻辑FALSE
☆ 字符串的终结符
我可以向你证明这些含义的差别是很实际的。例如,下列赋值是合法的:
int *pInt;
pInt = 0;// this is leagal.
而下列赋值是不合法的:
int *pInt;
pInt = 1;// this is not.
第一个赋值是合法的,因为表中的第二定义:常数0可以是地址,然而常数1则不行

这个含义的多重性能导致一些难以发现的错误:
// copy a string from pSource to pTarget -- incorrect version.
while(pSource)
{
*pTarget++ = *pSource++;
}
此例中的while循环试图把由pSource指向的源字符串复制到由pTarget指向的内存块
。但不幸的是,条件写错了,它应这样写出:
// copy a string from pSource to pTarget -- incorrect version.
while(*pSource)
{
*pTarget++ = *pSource++;
}
你可以看到,当由pSource指向的字符为NULL时,终止条件出现。这是0的第四定义
。然而,这里写出的代码却是去查看地址pSource是否为零,这是第二定义。
最终结果是while()循环继续写入内存直到程序崩溃。
0的其他定义之间也可能产生混乱。唯一的解决办法就是当你使用常数0的时候小心
一点。
声明的混乱处
复合声明是非常混乱的,但C++——以它的热忱保持了与C的反向兼容性——但也产
生了一些声明间的矛盾,你必须避免这种矛盾。
class Myclass
{
public:
Myclass(int nArg1 = 0,int nArg2 = 0);
};
Myclass mcA(1,2);
Myclass mcB(1);
Myclass mcC();
mcA是参数1和2构成的对象,而mcB是参数1和0构成的对象。因此你可能认为mcC是参
数0和0构成的对象,然而情况不是这样。而mcC()是一个不带参数的函数,它用数值返回
类Myclass的对象。
另一个混乱产生于初始化运算符=的使用:
Myclass mcB = nA; // same as Myclass mcB(nA)
为了增强与C的兼容性,允许这样使用=;然而你应该避免这种结构,因为它不是一
贯适用的。例如下列程序就不会有预期的效果:
Myclass mcA = nA,nB;
这说明一个对象mcA(nA),它后面有一个独立的使用缺省构造符的对象nB,而不是说
明一个对象mcA(nA,nB)。
坚持使用C++格式——这是最安全的。
计算顺序混乱
C和C++运算符的先后顺序,使你能够知道怎样计算诸如下列表达式:
a = b * c + d;
然而先后次序不会影响子表达式的计算顺序。让我们以看上去不重要的方式改变示
例的表达式:
a = b() * c() + d();
现在的问题是,在这个表达式中以什么样的顺序调用函数b(),c()和d()?答案是,
顺序是完全不确定的。更糟的是,顺序不能借助圆括号的使用而确定。所以下列表达式
没有作用:
a = (b() * c()) + d();
函数计算顺序通常不值得去关心。然而,如果这些函数有副作用,以某种方式彼此
影响(称为相互副作用),那么顺序就是重要的了。例如,如果这些函数改变相同的全局
变量,则结果就是不同的,这取决于其中函数被调用的顺序。
甚至当不涉及函数调用时,相互副作用也会产生影响:
int nI = 0;
cout<<"nA[0]="<<<"nA[1]="<<<"\n";
这个表达式的问题是单个表达式包含有相互副作用的两个子表达式——变量nI是增
量。哪个nA[nI++]首先被执行,左边的nA[nI++]还是右边的nA[nI++]?没法说,上述代码
可能会以预期的方式工作,但也可能不会。
说明虚拟成员函数
为了在子类中重载虚拟成员函数,必须用和基本类中函数一样的形式说明子类中函
数的参数和返回类型。这并不总是清楚的。例如,下列代码似乎讲得通:
class Base
{
public:
virtual void AFunc(Base *pB);
};
class Subclass:public Base
{
public:
virtual void AFunc(Subclass *pS);
};
这个代码会编译通过,但不会有迟后联编。函数Base::AFunc()的参数是Base*类型
的,而函数Subclass::AFunc()的参数是Subclass*,它们是不同的。
这个规则的唯一例外是下面的例子,它符合ANSI C++标准:
class Base
{
public:
virtual void Base* AFunc();
};
class Subclass:public Base
{
public:
virtual void Subclass* AFunc();
};
在此例中,每个函数返回其固有类型对象的地址。这种技术很通用,所以标准委员
会决定承认它。
从构造函数内调用虚拟成员函数
从构造符内调用虚拟函数是前期联编的,这样,它就短路掉了那些原本可能的简洁
的能力:
class Base
{
public:
Base();
virtual void BuildSection();
};
class Subclass:public Base
{
public:
Subclass();
virtual void BuildSection();
};
Base::Base()
{
BuildSection();
};
在此例中,程序员希望构造函数能够多态地调用BuildSection(),当正在构造的对
象是Base对象时调用Base::BuildSection(),当对象是类Subclass对象时调用Subclass
::BuildSection()。
由于下列简单的原因这个例子不起作用:当调用BuildSection()完成时,正在构造
的对象仅仅是一个Base对象。即使对象最终成为Subclass对象,也要等到Subclass的构
造函数把它过一遍以后。在这些情况下调用Subclass::BuildSection()可能是致命的。
即使对象将最终成为Subclass对象,但在调用BuildSection()的时候,对象只不过是Ba
se对象,而且,这个调用必须要前期联编到函数Base::BuildSection()。
指针对准
当你在80x86处理器(例如,你的PC机的芯片)上执行你的程序时,这个问题不是致
命的,但对其他的绝大多数芯片来说,这就是致命的了。它还会对你的应用程序移植到
某个其他环境的能力产生影响。此外,甚至对于Intel 处理器来说,这个问题也将导致
低于标准的性能。
当你的指针从一种类型转换到另一种类型的时候,就有可能产生一个非对准指针(m
isaligned pointer)。处理器一般要求内存块的地址要与一个和这个内存块的尺寸匹配
的边界对齐。例如,字只能在字边界上被访问(地址是二的倍数),双字只能在双字边界
上被访问(地址是四的倍数),依次类推。
编译器通常确保监视这个规则。但是当你的指针类型从一种类型转换成较大类型时
,你就可以很容易地违反这个规则:
char cA;
char* pC = &cA;
int* pI;
pI = (int*)pC;
*pI = 0; // this may be fatal.
因为字符仅仅是一个字节长,所以地址&cA可能有任意值,包括奇数值。可是,pI应
只包含四的倍数的地址。通过转换,允许把pC赋给pI,但是如果地址不是四的倍数,则
接着发生的赋值可能使程序崩溃。
对于Intel处理器来说,甚至当pC值为奇数时,该赋值也不是致命的;虽然占用的时
间要长得多,但是赋值还是能够正常执行。请你谨防非对准指针。
这种情况只在你正在把你的指针从指向一种类型转换成指向较大类型时才会出现。

我来推荐Stochastic Calculus的书

标 题: 我来推荐Stochastic Calculus的书
发信站: BBS 未名空间站 (Sun Jun 25 11:04:15 2006)

[1] Stochastic Differential Equations: An Introduction with Applications
by B K Ksendal, Bernt Oksendal

比较容易入门,需要probability的知识。

[2] Continuous Martingales and Brownian Motion by Daniel Revuz and Marc Yor
1999
经典教材,难度较大,适合长期反复阅读,简洁严谨。

[3] Stochastic Integration and Differential Equations by Philip Protter

从Levy Process 的观点入手,风格清爽,发人深思, 难度较大。Levy Process 正成为
随即分析,数学金融的研究热点,因为Brownian Motion考虑的是连续的随机过程,而
Levy Process是带有Jump的process。 当然Brownian motion 就是Levy Process 的特殊
例子。

[4] Brownian Motion and Stochastic Calculus by Ioannis Karatzas and Steven E.
Shreve

有Bible之称,但过于琐碎,有失简洁美妙。难度较大。