Collection of C++ Resources
how to debug c++ program before main()
set a break at _start()
- 'start'
- The name of the main procedure can vary from language to language. With C or C++, the main procedure name is always main, but other languages such as Ada do not require a specific name for their main procedure. The debugger provides a convenient way to start the execution of the program and to stop at the beginning of the main procedure, depending on the language used.
- The ‘start’ command does the equivalent of setting a temporary breakpoint at the beginning of the main procedure and then invoking the ‘run’ command.
- Some programs contain an elaboration phase where some startup code is executed before the main procedure is called. This depends on the languages used to write your program. In C++, for instance, constructors for static and global objects are executed before main is called. It is therefore possible that the debugger stops before reaching the main procedure. However, the temporary breakpoint will remain to halt execution.
- Specify the arguments to give to your program as arguments to the ‘start’ command. These arguments will be given verbatim to the underlying ‘run’ command. Note that the same arguments will be reused if no argument is provided during subsequent calls to ‘start’ or ‘run’.
- It is sometimes necessary to debug the program during elaboration. In these cases, using the start command would stop the execution of your program too late, as the program would have already completed the elaboration phase. Under these circumstances, insert breakpoints in your elaboration code before running your program
Dynamic Memory Management : Quick Reference
In C++, the new() and delete() operators provide built-in language support for dynamic memory allocation and deallocation. This feature has several benefits:- – Reduces common programmer errors: it is easy to forget to multiply the number of objects being allocated by sizeof when using malloc(), e.g., // oops, only 2 1/2 int’s! int *a = (int *) malloc (10);
- – Enhances source code clarity: generally, there is no need to: (1) declare operator new() and delete(), (2) explicitly use casts, or (3) explicitly check the return value.
- – Improves run-time efficiency: (1) users can redefine operator new() and delete() globally and also define them on a perclass basis and (2) calls can be inlined.
May 2014: Media coverage of High Freq Trading Stories after 'Flash Boys'
Chairman Mary Jo White Stops Short of Saying There Is an Unlevel Playing Field
On high-frequency trading, Rep. Carolyn Maloney (D., N.Y.) said she is concerned high-speed firms subscribe to data feeds that are significantly faster than data feeds that are available to the public, allowing them to detect trades before other investors can see them and take advantage of the information.
Ms. White said she doesn't believe the ability of high-frequency firms to take advantage of fast-moving market information unavailable to other investors meets the legal definition of insider trading.
"As I understand the question, as it's been described, it is not unlawful insider trading," she said, in response to questions from Mr. Garrett. She added there was "confusion" on the difference between early access to order information and certain firms' ability to "more quickly react to... public information."
NYSE to Curtail Order Types Amid Debate Over Their Fairness
- “I am surprised Sprecher took such a strong leadership role in resolving the order type controversy,” Bodek said by e-mail today. “I applaud his efforts and hope other exchanges will follow.”
- Eric Ryan, an NYSE spokesman, declined to provide further details about the order types that might be eliminated.
ICE Seeks to Reduce Stock Order Types at NYSE
- As a first step toward "unilaterally reducing the excessive complexity," Mr. Sprecher said the exchange plans to apply to the Securities and Exchange Commission to eliminate roughly one dozen existing order types, without singling out which order types would be targeted for elimination.
- Others said the types of orders the exchange ultimately removes will be as telling as the announcement itself. A 2013 report by Rosenblatt Securities found that many order types are little used.
- "It's hard to know how consequential this will be until you see which order types they are going to get rid of," said Justin Schack, Rosenblatt's head of market structure.
Goldman, Barclays, Credit Suisse Draw High-Speed Trading Scrutiny
- Dark pools accounted for an estimated 14% of U.S. stock-trading volume in March 2014, according to Rosenblatt, which tracks trading activity.
- Goldman has held discussions over the future of its private stock-trading venue, called Sigma X, and in conversations with other market participants in recent months had broached the subject of shutting it down,
- Barclays's venue, known as LX, is among the largest in the U.S., trading an average of 110 million shares a day in March, or 11.4% of all dark-pool volume, according to Rosenblatt Securities Inc., which tracks trading activity.
- Credit Suisse's dark pool, Crossfinder, another popular alternative-trading venue, doesn't report its volumes.
Apr 2014:Media coverage of High Freq Trading Stories after 'Flash Boys'
- HFT - WSJ op-ed ; HFT Hyperbole [Apr 2014 ]
- "How do we feel about high-frequency trading? We think it helps us. It seems to have reduced our costs and may enable us to manage more investment dollars. We can't be 100% sure"
- "ICE Chief Executive Officer Jeff Sprecher, has been a vocal critic of the overall stock market, saying it is too complicated and rife with conflicts of interest. Katsuyama would not comment on whether ICE had tried to buy his company. But he did say: "We're very aligned in philosophy and I have only good things to say about Jeff ".
"why did the market in any given stock dry up only when he was trying to trade in it? To make his point, he asked the developers to stand behind him and watch while he traded. “I’d say: ‘Watch closely. I am about to buy 100,000 shares of AMD. I am willing to pay $15 a share. There are currently 100,000 shares of AMD being offered at $15 a share — 10,000 on BATS, 35,000 on the New York Stock Exchange, 30,000 on Nasdaq and 25,000 on Direct Edge.’ You could see it all on the screens. We’d all sit there and stare at the screen, and I’d have my finger over the Enter button. I’d count out loud to five.
. . .
“ ‘One. . . .
“ ‘Two. . . . See, nothing’s happened.
“ ‘Three. . . . Offers are still there at 15. . . .
“ ‘Four. . . . Still no movement. . . .
“ ‘Five.’ Then I’d hit the Enter button, and — boom! — all hell would break loose. The offerings would all disappear, and the stock would pop higher.”
The exchange in question...
“What do you use to price trades in your matching engine on Direct Edge?” Mr. Katsuyama asked Mr. O’Brien.
“We use the direct feeds,” Mr. O’Brien said.
Mr. Katsuyama, whose IEX dark pool markets itself as a haven for investors against high-speed traders, later brought up the issue again. “You use the SIP to price trades on Direct Edge,” he said. “That is not true,” Mr. O’Brien said.
- Via Nanex, Between 8:00 and 9:20 on February 4, 2014, in the stock of The WhiteWave Foods Company (symbol WWAV, market cap $4 Billion), one or more High Frequency Trading (HFT) algos, generated 2.04 million top of book orders at Direct Edge. Most of these affected the NBBO (National Best Bid/Offer) hundreds of times per second. There were 3 trades
- "HFT lobbyist group Modern Markets Initiative (MMI). In the article, MMI attempts to discredit the Wall Street Journal's A Suspect Emerges in Stock-Trade Hiccups: Regulation NMS, and seizes the opportunity to "revisit some commonly held misconceptions about electronic markets and high frequency trading (HFT)". We'll seize the opportunity to point out some intellectual dishonesty. "
- "Sophisticated traders have been aware of CME's order-latency issue for years and have incorporated the information into their trading strategies, according to an official with Jump Trading LLC, a big Chicago high-frequency company.Officials with Virtu Financial LLC, a high-speed trading firm in New York, view a slight head start as good for the overall market, according to a person familiar with their thinking."
- "Under an arrangement in use since the 1980s, discount brokerages sell most of their clients' orders to wholesale companies, which then trade against the orders without sending them directly to traditional stock exchanges. The wholesalers capture tiny profits on many of the trades, using superfast computers with complex algorithms to match orders."
- "This practice is called 'payment for order flow', and it's not new to the market. Bernie Madoff used to do it by paying other brokers a penny per share. Then his firm would use that to trade with a better understanding price."
- HFT - Should high-frequency trading be regulated? Washington Post Article Apr 6 2014
- "What does this mean about regulation? To me, this means first that the state of knowledge is sufficiently ambiguous that at the current time I’m not persuaded that there is a case for regulation. But second, it also suggests a case for experimentation — which is to say that there may be a market for different markets, some of which permit HFT and some that don’t. If HFT increases market efficiency, then you’d expect parties to gravitate to those markets. If not, then you’d expect the opposite"
- Larry Tabb of Tabb Group: ‘No, Mr. Lewis. The Markets Are Not Rigged’
- Takeaways : Now, is there a single best way to execute an order? Are brokers perfect? Are there conflicts in the pricing structure of trades that may push brokers to trade off-exchange in their own dark pool versus at a lit exchange? Absolutely. That said, investors, brokers, and third-party measurement firms are trying to help better analyze the problems, help investors shift flow toward better performing brokers and algorithms, and help traders better understand where there is leakage.We have not yet reached execution nirvana.
- HFT - Security Traders Assoc. of NY [ STANY] - Brainstrom Session
- Key points
- Lots of rhetoric about a “broken” market structure
- Internal industry infighting has spilled into the public arena
- The media loves a good fight!
- My take on it: Our markets are (mostly) better, but they are different than before.
- Different imperfections
- Fail in different ways
- Need to work on these rough edges!
- What is broken
- Need better containment against technical failures
- The decline in the number of public companies: Need to experiment!
- Let issuers pick their own tick sizes – they have the incentives to get it right.
- Regulation: Push SEC to hire experienced market people and move SEC to NY.
- Volume drought
- Need more companies, more splits, longer trading hours for most active stocks
- Haim Bodek's book : The Problem of HFT - Collected Writings on High Frequency Trading & Stock Market Structure
- HFT - Virtu Financial IPO prospectus
- The chart below illustrates our daily Adjusted Net Trading Income from January 1, 2009 through December 31, 2013," Virtu writes in the filing. "As a result of our real-time risk management strategy and technology, we had only one losing trading day during the period depicted, a total of 1,238 trading days
Apr 2014:Media coverage of High Freq Trading Stories after 'Flash Boys'
- Trade Tactics: Slow vs. Speed [Feb 2014]
- Slow guy
- At IEX Trading Group Inc., all orders are slowed down by a fraction of a second after they enter the trading system, a tactic designed to prevent fleet-footed trading firms from racing ahead of orders from large institutions and driving up prices. Some proprietary-trading firms have been known to use their greater speed to change their bids and offers based on activity they notice on other trading venues and exchanges. By slowing things down, IEX hopes to put all traders on equal footing.
- Fast guy
- LeveL ATS, a dark pool. The company in October launched one of the industry's fastest matching engines connecting buyers and sellers. Its average speed for an order acknowledgment is below 60 microseconds, according to the company. The firm saw an average of 23.3 million shares traded a day in January, it said. Mr. Conary argues that the best way to avoid information leaking about an order, which could be taken advantage of by other traders, is being as fast as possible. LeveL is essentially fighting fire with fire: Its new matching engine was built by Thesys Technologies, the infrastructure arm of high-frequency trading firm Tradeworx Inc.
- HFT in Australian Equity Exchanges.[ Apr 2014 ]
- “ASIC’s study into high frequency trading in the Australian markets found no fundamental deterioration of market quality, or systematic abuse that threatens the integrity of our market. Rather, we found the Australian market, which is less fragmented than the US, to be one of high quality and integrity,” the spokesperson said in a written response to questions from Business Insider.
- But profiting is neither abuse nor manipulation. If it consistently happens to one side, over another, due to some sort of advantage, it is just unfair.
- Trading Profits of HFT shops. - An academic study [Apr 2014]
- "HFT traders do influence prices and outcomes for investors. A US research paper – The Trading Profits of High Frequency Traders [pdf], by Matthew Baron, Princeton University, Jonathan Brogaard, Foster School of Business, University of Washington and Andrei Kirilenko, Commodity Futures Trading Commission (CFTC) – found that HFTs make on average $0.25 per trade. “This equates to $18,799 per day for each HFT in the August 2010 E-mini S&P 500 contract alone,” the paper said."
- HFT Class Action Suit: City of Providence v. Bats Global Markets, Inc., et al. [Apr 2014]
- The City of Providence, RI, filed a putative class action complaint in the U.S. District Court for the Southern District of New York, naming as defendants 16 different national securities exchanges, 12 major securities brokers, and 11 high-frequency trading (“HFT”) firms. The Plaintiff, in the case titled City of Providence v. BATS Global Markets Inc., et al., claims to represent every class of investor who bought or sold stock on a U.S. exchange from April 2009 through the present. The defendant class is only slightly smaller.
- The allegations in the complaint are generally derivative of Michael Lewis’s recent book, Flash Boys: A Wall Street Revolt, and the complaint repeatedly cites that publication. The Complaint alleges that the named HFT firms engaged in a number of trading behaviors that distorted stock markets and disadvantaged other market participants. The complaint alleges that the broker defendants allowed the HFT defendants access to their clients’ trade orders, which gave the HFT firms an informational advantage when trading against the brokers’ clients in the market. The complaint also alleges that the stock exchanges and alternate trading venues allowed HFT defendants to “co-locate” computer equipment, which allowed an informational advantage that enabled them to disadvantage other market participants.
- The Complaint alleges three counts, all under the Securities Exchange Act of 1934: (i) violation of the anti-fraud provisions of Section 10(b) and SEC Rule 10b-5 promulgated thereunder; (ii) violation of Section 6(b) of the Act, as pertaining to registration of National Exchanges; and (iii) “insider trading” allegations for alleged violations of Section 20A of the Act.
- HFT Book - Broken Markets
- If you know little of financial markets you might find "Broken Markets" difficult to follow. But the Arnuk's and Saluzzi's thesis is not all that complex. The authors argue that our financial markets are thoroughly broken. They explain how stock exchanges have been taken over by high frequency traders who use sophisticated computer algorithms to scalp pennies off nearly every share traded. This has essentially transformed stock exchanges from facilitators of capital formation to arbitrage driven casinos that are rigged in favor of a class of speculators, the high frequency traders, who account for 50 to 70 percent of the volume traded on stock exchanges and, still more ominously, 80% of the profits.
- HFT Book - Dark Pools a book featuring Haim Bodek
- Manipulating the order flow can be done by placing very low bids or very high offers for stock, which jump to the head of the order queue. When counterparties disappear as the computers cancel orders at superhuman speed, which often happens in turbulent markets, stocks can sell for one cent or $10,000 per share. Disappearing orders can be placed to test the market flow, and orders invisible to other participants in the market are also possible.
- As yet, this high-frequency trading has not led to anything like 1987's one-day 22 percent fall in the Dow Jones industrial average. But the occasional "flash crash" is alarming, as is the effect on large orders. These have become more expensive to execute, thanks to front-running computer-piranhas which move the price before big orders can be fully executed. Thus effective liquidity, the ability to buy and sell large institutional positions at close to the market price, has been greatly impeded - needless to say producing large additional profits for the algo traders.
- In response, big orders are increasingly broken into smaller bits to avoid algo-detection. Patterson cites research, commissioned by the Financial Times, according to which average order size declined by 67 percent on the New York Stock Exchange and by 68 percent on Nasdaq between 2005 and 2010
- HFT - By Rishi K. Narang ; Another good writings on HFT ; From Quantitative perspective.
- Narang co-founded and was president of Tradeworx, Inc., a quantitative hedge fund manager, from 1999-2002
- HFT trading shop - Meet Getco HFT Trading King. [ Aug 2009]
- "Traders at Getco, a private company with fewer than 250 employees, use powerful computers and algorithms to engage in high-frequency trading. "
- "They are probably the biggest market maker in the U.S. stock market," said Justin Schack, a vice president at Rosenblatt Securities Inc. who closely tracks high-frequency trading. A market maker is a firm that always stands ready to buy or sell a stock.
Apr 2014: Media (Video) coverage of High Freq Trading Stories after 'Flash Boys'
- HFT - Video : Michael Lewis on CBS 60 Minutes.
- HFT - Video - Michael Lewis is promoting "Flash Boys" book on Jon Stewart show.
- HFT - Video - Michael Lewis duelling with DirectEdge CEO in CNBC
- Michael Lewis is promoting his book "Boomerang" on Jon Stewart show
- HFT - Video - Haim Bodek - US Market Structure Primer
- Part 1 : Retail Order Flow Routing, Payment for Order flow
- Part 2 : RegNMS 612 - Sub Penny Rule / Retail Price Improvement
- Part 3 : Dark Pools
- Part 4 : Latency arbitrage
- Part 5 : HFT Strategies/Order Types/Micro Structure
- Part 6 : Order Routing
- Part 7 : Exchange Rebates
- HFT - Video - Haim Bodek featuring in "Wall Street Code"
- HFT- Video - "The Quants : The Alchemists of WallStreet"
- HFT - Video - Money and Speed : Flash Crash of 2012
Movies - non fiction
All the President's Men [1976] @ Wikipedia
- All the President's Men is a 1976 American political thriller film based on the 1974 non-fiction book of the same name by Carl Bernstein and Bob Woodward, the two journalists investigating the Watergate scandal for The Washington Post.
- All the President's Men is a 1976 American political thriller film based on the 1974 non-fiction book of the same name by Carl Bernstein and Bob Woodward, the two journalists investigating the Watergate scandal for The Washington Post.
Bugsy - [1991] @ Wikipedia
Bugsy is a 1991 American crime-drama film directed by Barry Levinson which tells the story of mobster Bugsy Siegel. Based on Benjamin Siegel (February 28, 1906[1] – June 20, 1947) was an American mobster with the Luciano crime family. Nicknamed "Bugsy" Siegel was known as one of the most "infamous and feared gangsters of his day". Described as handsome and charismatic, he became one of the first front-page-celebrity gangsters. He was also a driving force behind the development of the Las Vegas Strip.
Nixon [1995] @ Wikipedia
- Nixon is a 1995 American biographical film that tells the story of the political and personal life of former US President Richard Nixon as a complex and, in many respects, admirable, though deeply flawed, person. Nixon begins with a disclaimer that the film is "an attempt to understand the truth [...] based on numerous public sources and on an incomplete historical record."
The Insider - [1999] @ Wikipedia
- The Insider is a 1999 American drama film directed by Michael Mann, based on the true story of a CBSs "60 Minutes segment" about Jeffrey Wigand, a whistleblower in the tobacco industry.
- The CBS's 60 Minutes story originally aired in November 1995 in an altered form because of objections by CBS' then-owner, Laurence Tisch, who also controlled the Lorillard Tobacco Company. The story later aired in a complete and uncensored form on February 4, 1996.
Good night and Good Luck - [2005] @ Wikipedia
- Good Night, and Good Luck. is a 2005 American drama film portrays the conflict between veteran radio and television journalist Edward R. Murrow and U.S. Senator Joseph McCarthy of Wisconsin, especially relating to the anti-Communist Senator's actions with the Senate Permanent Subcommittee on Investigations.
- Based on Edward R. Murrow, a pioneer of television news broadcasting, Murrow produced a series of TV news reports that helped lead to the censure of Senator Joseph McCarthy.
Charlie Wilson's War - [2007] @ Wikipedia
- Charlie Wilson's War is a 2007 American biographical-drama film, recounting the true story of U.S. Congressman Charlie Wilson who partnered with CIA operative Gust Avrakotos to launch Operation Cyclone, a program to organize and support the Afghan mujahideen during the Soviet war in Afghanistan.
- Based on adapted George Crile III's 2003 book Charlie Wilson's War: The Extraordinary Story of the Largest Covert Operation in History.
The ides of March - [2008] @ Wikipedia
- Based on Farragut North a 2008 play written by Beau Willimon, who worked for Sen. Charles E. Schumer (D-NY) and former Governor of Vermont and 2004 Democratic presidential candidate Howard Dean, loosely based on the 2004 Democratic primary campaign of Howard Dean.
- The play is billed as "a classic tale of hubris set against a contemporary landscape – about the lust for power and the costs one will endure to achieve it". It is titled after Farragut North, a Washington Metro station, on the Red Line. Farragut North serves downtown Washington and is located just north of Farragut Square near Connecticut Avenue.
- Titled the play for the Metrorail station located nearest the district's center for think tanks, lobbyists, and advocacy groups.
W. - [2008] @ Wikipedia
- W. is a 2008 American biographical drama film based on the life and presidency of George W. Bush. It was produced and directed by Oliver Stone, written by Stanley Weiser, and stars Josh Brolin as Bush.
The Informant! - [2009] @ Wikipedia
The Informant! is a 2009 American biographical-comedy-crime movie based on a true Story about Mark Whitacre's involvement as a whistle blower in the lysine price-fixing conspiracy of the mid-1990s Mark Whitacre, a rising star at Decatur, Illinois based Archer Daniels Midland (ADM) in the early 1990s, blows the whistle on the company’s price-fixing tactics at the urging of his wife Ginger
Based on the 2000 nonfiction book The Informant: A true Story, by journalist Kurt Eichenwald.
Extraordinary Measures - [2010] @ Wikipedia
- Extraordinary Measures is a 2010 medical drama film is based on the true story of John and Aileen Crowley, who formed a biotechnology company to develop a drug to save the lives of their children, whose children have Pompe's disease - a life-threatening disease.
- Based on Geeta Anand's book The Cure: How a Father Raised $100 Million--and Bucked the Medical Establishment--in a Quest to Save His Children. Parts of the book first appeared as a series of articles in the Wall Street Journal.
Fair Game - [2010] @ Wikipedia
- Fair Game is a 2010 biographical spy drama film directed by Doug Liman and starring Naomi Watts and Sean Penn.[3] It is based on Valerie Plame's memoir, Fair Game: My Life as a Spy, My Betrayal by the White House,[3] and Joseph C. Wilson's memoir, The Politics of Truth: Inside the Lies that Led to War and Betrayed My Wife's CIA Identity: A Diplomat's Memoir.
- Fair Game is a 2010 biographical spy drama film directed by Doug Liman and starring Naomi Watts and Sean Penn.[3] It is based on Valerie Plame's memoir, Fair Game: My Life as a Spy, My Betrayal by the White House,[3] and Joseph C. Wilson's memoir, The Politics of Truth: Inside the Lies that Led to War and Betrayed My Wife's CIA Identity: A Diplomat's Memoir.
Nothing but Truth - [2010] @ Wikipedia
- Nothing but the Truth is a 2008 American drama film written and directed by Rod Lurie. According to comments made by Lurie in The Truth Hurts, a bonus feature on the DVD release, his inspiration for the screenplay was the case of journalist Judith Miller, who in July 2005 was jailed for contempt of court for refusing to testify before a federal grand jury investigating a leak naming Valerie Plame as a covert CIA operative, but this was merely a starting point for what is primarily a fictional story. In an April 2009 interview, Lurie stressed: "I should say that the film is about neither of these women although certainly their stories as reported in the press went into the creation of their characters and the situation they find themselves in."
- Inside Job is a 2010 documentary film, directed by Charles H. Ferguson, about the late-2000s financial crisis. In five parts, the film explores how changes in the policy environment and banking practices helped create the financial crisis..
J. Edgar [2011] @ Wikipedia
- J. Edgar is a 2011 American biographical drama film directed, co-produced, and scored by Clint Eastwood.Written by Dustin Lance Black, the film based on the career of FBI director J. Edgar Hoover.
Game Change - [2012] @ Wikipedia
- Game Change is a 2012 American HBO political drama film based on events of the 2008 United States presidential election campaign, directed by Jay Roach and written by Danny Strong,
- Based on the 2010 book of the same name documenting the campaign by political journalists Mark Halperin and John Heilemann.
- Zero Dark Thirty is a 2012 American action thriller war film dramatizes the decade-long manhunt for al Qaeda leader Osama bin Laden after the September 11, 2001 terrorist attacks in the United States. This search eventually leads to the discovery of his compound in Pakistan, and the military raid on it that resulted in his death on May 2, 2011.
- Loosely based on the book No Easy Day: The Autobiography of a Navy Seal: The Firsthand Account of the Mission That Killed Osama Bin Laden by Mark Owen et al.
The Wolf of Wall Street - [2013] @ Wikipedia
- The Wolf of Wall Street is a 2013 american drama film directed by Martin Scorsese, based on Jordan Belfort's memoir of the same name. Belfort, a New York stockbroker who ran a financial services firm that engages in securities fraud and corruption on Wall Street in the 1990s was convicted of fraud crimes related to stock market manipulation and running a penny stock boiler room, for which he spent 22 months in prison. He recounted his life in his memoir, The Wolf of Wall Street.
Citizen Four - [2014] @ Wikipedia
- Citizenfour is a 2014 documentary film directed by Laura Poitras concerning Edward Snowden and the NSA spying scandal. Shot in the cinéma vérité style. The film features Glenn Greenwald and was co-produced by Poitras, Mathilde Bonnefoy, and Dirk Wilutzky, with Steven Soderbergh and others serving as executive producers. Citizenfour won the Academy Award for Best Documentary Feature at the 2015 Oscars..
Apr 2014: Media Coverage of High Freq Trading Stories
- "Reg NMS, as it is often called, grew out of an effort nearly a decade ago to keep the U.S. abreast of financial centers such as London, Frankfurt and Hong Kong that were leaping ahead in embracing electronic systems. Securities and Exchange Commission officials worried that control of U.S. capital markets could begin to shift offshore if the U.S. didn't evolve."
- HFT - Brad's IEX ; WSJ article Orginally appeared on Jun 29 ,2013
"IEX also will forgo the so-called rebates that many exchanges pay firms that help provide buy and sell orders. The payments, typically about 25 to 30 cents per 100 shares, primarily benefit high-frequency trading firms that provide orders".
- HFT - Birth of an Electronic Trading Venue - TradeBot - WSJ article pub. on Dec 15 2006
- "In Mr. Cummings's world, the fundamentals of a stock are of little consequence. His firm favors large stocks, such as Microsoft, because it can trade in and out quickly. On one recent afternoon, a computer screen in Tradebot headquarters indicated that the firm accounted for more than 10% of that day's trading in Microsoft. On many days, Tradebot's trading totals account for as much as 5% of all Nasdaq trading, on par with trading levels at such giant firms as Fidelity Investments."
- HFT trading shop - Meet Getco HFT Trading King. [ Aug 2009]
- "Traders at Getco, a private company with fewer than 250 employees, use powerful computers and algorithms to engage in high-frequency trading. "
- "They are probably the biggest market maker in the U.S. stock market," said Justin Schack, a vice president at Rosenblatt Securities Inc. who closely tracks high-frequency trading. A market maker is a firm that always stands ready to buy or sell a stock.
- NYSE's Fast-Trade Hub Rises Up in New Jersey - WSJ.com [Jul 2009]
- MAHWAH, N.J. -- The future of the New York Stock Exchange is inside the red-brick building that is rising from the ground here about 35 miles from Wall Street.
- The exchange is building a similar facility outside London, which will cater to clients who want access to overseas markets. The combined price tag for the two data centers will be about $500 million, according to people familiar with the matter.
- The NYSE is seeking to stem a slide in market share from more than 80% in 2004 to about 40% this year, according to data from Equity Research Desk, a research company in Greenwich, Conn. Second-quarter earnings are expected to slide 40% from a year ago to 45 cents a share, according to a survey of analysts by Thomson Reuters.
- Fast Trader's new Edge is Light Speed - WSJ.com [Jun 2010]
- Critics call the practice the modern day equivalent of looking at share prices listed in tomorrow's newspaper stock tables today.
- "It is a rigged game," Sal Arnuk, co-founder of brokerage firm Themis Trading, said Wednesday at a Securities and Exchange Commission roundtable discussion in Washington, D.C., referring to the trading activity, which some call "latency arbitrage."
- HFT - Flash Crash - Most likely cause - Initial suspect
- Fund managers at Waddell & Reed Financial Inc. in Overland Park, Kan., moved to hedge their U.S. stock holdings, which total more than $7 billion, by betting that the S&P 500 would fall. Waddell decided on a large short sale of futures contracts known as E-minis, which mimic movement of the S&P 500. As Waddell's computers began parceling out the trade, other investors also were trying to hedge their portfolios, so trading volume in E-minis shot up to six times the usual volume.
- But liquidity, the ability to buy or sell easily, was drying up. Between about 2:35 and 2:45, the six "market-making" firms that were most active that afternoon in E-mini trading—they step in as buyers or sellers on many trades—cut back their trading. Some pulled out altogether.
- As a result, traders say, the big Waddell trade accelerated the sell-off. Waddell says it did not intend to "disrupt" the market.
- HFT - Flash Crash - Did Shutdowns Make Plunge Worse?
- "Some high-frequency traders, including Mr. Cummings at Tradebot, say their moves didn't accelerate declines. He says other firms selling large positions caused the market turmoil and that Tradebot would have been risking losses if it had continued trading. He says exchanges need to install better systems that automatically stop or slow trading when the market becomes overly chaotic."
- HFT - Flash Crash - Trading-Firm Breakdowns Accompanied Market Chaos - Wsj.com May 2010
- As the stock market spiraled out of control two weeks ago, two major firms that handle trades for retail brokerages suffered trading breakdowns.
- One, the big Chicago hedge-fund firm Citadel Investment Group, stopped taking orders for a number of securities, according to an internal email and people familiar with the matter. Shortly after the market plunged, Citadel asked clients, including discount brokers such as E*Trade Financial Corp. and TD Ameritrade Holding Corp., to route orders elsewhere.
- HFT - Haim Bodek Story - An insider narrative of HFT market participants - WSJ.com [Jun 29,2013]
- "Haim Bodek told the SEC what he had learned about order types. His sword was a gift from a friend who said he would need it in business.
- "HFT - charles schwab position on HFT [Apr 2014]
- "The integrity of the markets is at the heart of our economy. High-frequency trading undermines that integrity and causes the market to lose credibility and investors to lose trust. This hurts our economy and country. It is time to treat the cancer aggressively."
- "HFT- What Goldman Sachs President[@Apr 2014] (gary cohen) thinks about HFT ?[ Apr 2014 ]
- "Three powerful forces have been at work: technology, regulation and competition. The result has been narrower spreads, faster execution and lower overall explicit costs to trading stocks."
- HFT- What Mark Cuban's thinks about HFT ? [ Apr 2014]
- "The output of the algorithms, the This Then That creates the trade (again, this is a simplification — I'm open to better examples), which creates a profit of some relatively small amount. When you do this millions of times a day, that totals up to real money. IMHO, this is the definition of high-frequency trading. Taking advantage of an advantage in speed and algorithmic processing to jump in front of trades from slower market participants to create small, guaranteed wins millions of times a day. A high frequency of trades is required to make money. Therein lies the problem. This is where the game is rigged
Java programming with lambda expressions
Java programming with lambda expressions
A mathematical example demonstrates the power of lambdas in Java 8
By
Jan 29, 2014 8:41 PM PT
In the technical keynote address for JavaOne 2013, Mark Reinhold, chief architect for the Java Platform Group at Oracle, described lambda expressions as the single largest upgrade to the Java programming model ever. While there are many applications for lambda expressions, this article focuses on a specific example that occurs frequently in mathematical applications; namely, the need to pass a function to an algorithm.
As a gray-haired geek, I have programmed in numerous languages over the years, and I have programmed extensively in Java since version 1.1. When I started working with computers, almost no one had a degree in computer science. Computer professionals came mostly from other disciplines such as electrical engineering, physics, business, and mathematics. In my own former life I was a mathematician, and so it should come as no surprise that my initial view of a computer was that of a giant programmable calculator. I've broadened my view of computers considerably over the years, but I still welcome the opportunity to work on applications that involve some aspect of mathematics.
Many applications in mathematics require that a function be passed as a parameter to an algorithm. Examples from college algebra and basic calculus include solving an equation or computing the integral of a function. For over 15 years Java has been my programming language of choice for most applications, but it was the first language that I used on a frequent basis that did not allow me to pass a function (technically a pointer or reference to a function) as a parameter in a simple, straightforward manner. That shortcoming is about to change with the upcoming release of Java 8.
The power of lambda expressions extends well beyond a single use case, but studying various implementations of the same example should leave you with a solid sense of how lambdas will benefit your Java programs. In this article I will use a common example to help describe the problem, then provide solutions written in C++, Java before lambda expressions, and Java with lambda expressions. Note that a strong background in mathematics is not required to understand and appreciate the major points of this article.
Learning about lambdas
Lambda expressions, also known as closures, function literals, or simply lambdas, describe a set of features defined in Java Specification Request (JSR) 335. Less formal/more readable introductions to lambda expressions are provided in a section of the latest version of the Java Tutorial and in a couple of articles by Brian Goetz, "State of the lambda" and "State of the lambda: Libraries edition." These resources describe the syntax of lambda expressions and provide examples of use cases where lambda expressions are applicable. For more about lambda expressions in Java 8, watch Mark Reinhold's technical keynote address for JavaOne 2013.
Lambda expressions in a mathematical example
The example used throughout this article is Simpson's Rule from basic calculus. Simpson's Rule, or more specifically Composite Simpson's Rule, is a numerical integration technique to approximate a definite integral. Don't worry if you are unfamiliar with the concept of a definite integral; what you really need to understand is that Simpson's Rule is an algorithm that computes a real number based on four parameters:
- A function that we want to integrate.
- Two real numbers
aandbthat represent the endpoints of an interval[a,b]on the real number line. (Note that the function referred to above should be continuous on this interval.) - An even integer
nthat specifies a number of subintervals. In implementing Simpson's Rule we divide the interval[a,b]intonsubintervals.
To simplify the presentation, let's focus on the programming interface and not on the implementation details. (Truthfully, I hope that this approach will let us bypass arguments about the best or most efficient way to implement Simpson's Rule, which is not the focus of this article.) We will use type
double for parameters a and b, and we will use type int for parameter n. The function to be integrated will take a single parameter of type double and a return a value of type double.Function parameters in C++
To provide a basis for comparison, let's start with a C++ specification. When passing a function as a parameter in C++, I usually prefer to specify the signature of the function parameter using a
typedef. Listing 1 shows a C++ header file named simpson.h that specifies both the typedef for the function parameter and the programming interface for a C++ function named integrate. The function body forintegrate is contained in a C++ source code file named simpson.cpp (not shown) and provides the implementation for Simpson's Rule.Listing 1. C++ header file for Simpson's Rule
#if !defined(SIMPSON_H)
#define SIMPSON_H
#include
using namespace std;
typedef double DoubleFunction(double x);
double integrate(DoubleFunction f, double a, double b, int n)
throw(invalid_argument);
#endif
Calling
integrate is straightforward in C++. As a simple example, suppose that you wanted to use Simpson's Rule to approximate the integral of the sine function from 0 to π (PI) using 30 subintervals. (Anyone who has completed Calculus I should be able to compute the answer exactly without the help of a calculator, making this a good test case for the integrate function.) Assuming that you had included the proper header files such as and "simpson.h", you would be able to call function integrateas shown in Listing 2.Listing 2. C++ call to function integrate
double result = integrate(sin, 0, M_PI, 30);
That's all there is to it. In C++ you pass the sine function as easily as you pass the other three parameters.
Another example
Instead of Simpson's Rule I could have just as easily used the Bisection Method (aka the Bisection Algorithm) for solving an equation of the form f(x) = 0. In fact, the source code for this article includes simple implementations of both Simpson's Rule and the Bisection Method.
Java without lambda expressions
Now let's look at how Simpson's Rule might be specified in Java. Regardless of whether or not we are using lambda expressions, we use the Java interface shown in Listing 3 in place of the C++
typedef to specify the signature of the function parameter.Listing 3. Java interface for the function parameter
public interface DoubleFunction
{
public double f(double x);
}
To implement Simpson's Rule in Java we create a class named
Simpson that contains a method,integrate, with four parameters similar to what we did in C++. As with a lot of self-contained mathematical methods (see, for example, java.lang.Math), we will make integrate a static method. Method integrate is specified as follows:Listing 4. Java signature for method integrate in class Simpson
public static double integrate(DoubleFunction df, double a, double b, int n)
Everything that we've done thus far in Java is independent of whether or not we will use lambda expressions. The primary difference with lambda expressions is in how we pass parameters (more specifically, how we pass the function parameter) in a call to method
integrate. First I'll illustrate how this would be done in versions of Java prior to version 8; i.e., without lambda expressions. As with the C++ example, assume that we want to approximate the integral of the sine function from 0 to π (PI) using 30subintervals.Using the Adapter pattern for the sine function
In Java we have an implementation of the sine function available in
java.lang.Math, but with versions of Java prior to Java 8, there is no simple, direct way to pass this sine function to the method integratein class Simpson. One approach is to use the Adapter pattern. In this case we would write a simple adapter class that implements the DoubleFunction interface and adapts it to call the sine function, as shown in Listing 5.Listing 5. Adapter class for method Math.sin
import com.softmoore.math.DoubleFunction;
public class DoubleFunctionSineAdapter implements DoubleFunction
{
public double f(double x)
{
return Math.sin(x);
}
}
Using this adapter class we can now call the
integrate method of class Simpson as shown in Listing 6.Listing 6. Using the adapter class to call method Simpson.integrate
DoubleFunctionSineAdapter sine = new DoubleFunctionSineAdapter();
double result = Simpson.integrate(sine, 0, Math.PI, 30);
Let's stop a moment and compare what was required to make the call to
integrate in C++ versus what was required in earlier versions of Java. With C++, we simply called integrate, passing in the four parameters. With Java, we had to create a new adapter class and then instantiate this class in order to make the call. If we wanted to integrate several functions, we would need to write an adapter class for each of them.
We could shorten the code needed to call
integrate slightly from two Java statements to one by creating the new instance of the adapter class within the call to integrate. Using an anonymous class rather than creating a separate adapter class would be another way to slightly reduce the overall effort, as shown in Listing 7.Listing 7. Using an anonymous class to call method Simpson.integrate
DoubleFunction sineAdapter = new DoubleFunction()
{
public double f(double x)
{
return Math.sin(x);
}
};
double result = Simpson.integrate(sineAdapter, 0, Math.PI, 30);
Without lambda expressions, what you see in Listing 7 is about the least amount of code that you could write in Java to call the
integrate method, but it is still much more cumbersome than what was required for C++. I am also not that happy with using anonymous classes, although I have used them a lot in the past. I dislike the syntax and have always considered it to be a clumsy but necessary hack in the Java language.Java with lambda expressions and functional interfaces
Now let's look at how we could use lambda expressions in Java 8 to simplify the call to
integrate in Java. Because the interface DoubleFunction requires the implementation of only a single method it is a candidate for lambda expressions. If we know in advance that we are going to use lambda expressions, we can annotate the interface with @FunctionalInterface, a new annotation for Java 8 that says we have a functional interface. Note that this annotation is not required, but it gives us an extra check that everything is consistent, similar to the @Override annotation in earlier versions of Java.
The syntax of a lambda expression is an argument list enclosed in parentheses, an arrow token (
->), and a function body. The body can be either a statement block (enclosed in braces) or a single expression. Listing 8 shows a lambda expression that implements the interface DoubleFunction and is then passed to method integrate.Listing 8. Using a lambda expression to call method Simpson.integrate
DoubleFunction sine = (double x) -> Math.sin(x);
double result = Simpson.integrate(sine, 0, Math.PI, 30);
Note that we did not have to write the adapter class or create an instance of an anonymous class. Also note that we could have written the above in a single statement by substituting the lambda expression itself,
(double x) -> Math.sin(x), for the parameter sine in the second statement above, eliminating the first statement. Now we are getting much closer to the simple syntax that we had in C++. But wait! There's more!
The name of the functional interface is not part of the lambda expression but can be inferred based on the context. The type
double for the parameter of the lambda expression can also be inferred from the context. Finally, if there is only one parameter in the lambda expression, then we can omit the parentheses. Thus we can abbreviate the code to call method integrate to a single line of code, as shown in Listing 9.Listing 9. An alternate format for lambda expression in call to Simpson.integrate
double result = Simpson.integrate(x -> Math.sin(x), 0, Math.PI, 30);
But wait! There's even more!
Method references in Java 8
Another related feature in Java 8 is something called a method reference, which allows us to refer to an existing method by name. Method references can be used in place of lambda expressions as long as they satisfy the requirements of the functional interface. As described in the resources, there are several different kinds of method references, each with a slightly different syntax. For static methods the syntax is
Classname::methodName. Therefore, using a method reference, we can call the integrate method in Java as simply as we could in C++. Compare Java 8 call shown in Listing 10 below with original C++ call shown in Listing 2 above.Listing 10. Using a method reference to call Simpson.integrate
double result = Simpson.integrate(Math::sin, 0, Math.PI, 30);
Page 2
Page 2 of 2
As a final thought, although I prefer writing the interface
DoubleFunction because I think that it makes the code easier to understand, even that interface can be eliminated. Java 8 has a new package,java.util.function, that contains a number of commonly used functional interfaces. Many are expressed using generics, but there are specializations for primitive types. I'll leave the use of one of these interfaces in place of DoubleFunction as the proverbial exercise for the reader. (For a hint, look closely at DoubleUnaryOperator in java.util.function. If you get stuck, see class Simpson2 in the source code provided with this article.)In conclusion
Overall I have found it a pleasure to code in Java, and it has been my preferred programming language for more than 15 years. There are (still) a few places where Java's syntax seems awkward, however. With the addition of lambda expressions, Java 8 will correct one of them. Taken together, the major points of this article remind me of Cay Horstmann's so-called March of Progress, a portion of which is copied below with his permission.
The March of Progress, by Cay Horstmann
1980: C
printf("%10.2f", x);
1988: C++
cout << setw(10) << setprecision(2) << showpoint << x;
1996: Java
java.text.NumberFormat formatter = java.text.NumberFormat.getNumberInstance();
formatter.setMinimumFractionDigits(2);
formatter.setMaximumFractionDigits(2);
String s = formatter.format(x);
for (int i = s.length(); i < 10; i++) System.out.print(' ');
System.out.print(s);
2004: Java
System.out.printf("%10.2f", x);
Learn more about this topic
- Download the C++ and Java source code for this article.
- The formal definition of lambda expressions is provided in Java Specification Request (JSR) 335.
- An informal overview of lambda expression is provided by Brian Goetz, the project lead for JSR 335, in "State of the Lambda." See also the companion document by Brian, "State of the Lambda: Libraries Edition."
- The latest version of the Java Tutorial contains a section entitled "Lambda Expressions."
- Watch Mark Reinhold's technical keynote address during JavaOne 2013.
- Download a JDK 8 Early Access Release
- If you use the Eclipse IDE, you can download an unofficial build of Eclipse with experimental support for lambda expressions.
- Wikipedia contains an introduction to Simpson's Rule as well as an introduction to the Bisection Method (aka the Bisection Algorithm).
- The definitive reference for software design patterns is the original "Gang of Four" book: Design Patterns: Elements of Reusable Object-Oriented Software (Erich Gamma, et al.; Addison Wesley, 1995).
- For an excellent introduction to the new features of Java 8, including three chapters on lambda expressions, see the relatively small book, Java SE 8 for the Really Impatient (Cay Horstmann, Addison Wesley, 2014).
- More of Cay Horstmann's humorous take on The March of Progress can be found on his homepage.
Subscribe to:
Comments (Atom)