What’s it like to write code for a hedge fund?

Answer by Laurent Bernut:

Junior-mid level means your programing skills may be good, but your understanding of the markets is still shallow.

Coding is a formidable asset. If investing is a process, then it should be automated. That said, my advice would be to red about markets at least as much, if not more than coding language. Those who succeed extend their domain expertise.

4 types of shops You may land into: discretionary fundamental, classic quants, HFT and systematic CTA trend following style

If You land in a fundamental or discretionary shop, You will be frustrated. Systematic trading is frowned upon. They believe in the superiority of man over machine. Deep down, they feel threatened. They refuse to admit that if investment is a process as the marketing pitch, then the logical conclusion would be to automate it. Do not underestimate this point. They will experiment with You, because they recognise they need more process, but they will probably not cross the final step of trusting the machine.
You will probably be asked to program some strategies. They will be ill conceived, because they focus on entry as opposed to exit and money management. Discretionary investors focus on stock picking.
So, strategies will work until they won't, then back to the drawing boards. One of the big frustrations is the inability to communicate between programmers and front office people. They want "something that looks good, or looks like that". They cannot articulate their thoughts in a formalised manner. It will be an endless: Him" This is not what i want", You: "but this is what You told me", Him: "this is not what i want, do it again"
Make sure You code in modules, because there will be a lot of editing

Classic quants: Matlab and multifactor. This is academia meets markets: complexity, underwhelming but steady returns. It does not mean that those funds do not get big. Some do.
Same story, it works until it does not, then back to the drawing board and let's add yet another factor to the 64 pre-existing ones.
One word of caution: ask if they follow a mean reversion strategy. If they do, ask if they double down when something goes wrong and if they have a stop loss. If they double down or do not have sytop loss, then next. They follow a martingale bet sizing. Martingale has an interesting probabilistic property called "certainty of ruin", LTCM 1997 and the Vol funds in 2008
All in all, it is good if You want to explore abstract concepts, write white papers.

HFT. This is programmers' paradise. This is by far the most sophisticated domain when it comes to programming in finance. This is where the best and the brightest go. Highly competitive. You will learn about the mechanics, the pluming of the markets, not the markets themselves though. You will also learn about game theory as the latest generation of algos are designed not necessarily to trade but to induce or block other algos, fascinating stuff. The drawback is that it is an arm's race. Either You are in front of the queue, either you pay for someone else's lunch

Systematic trading, CTA style. That is what I do, but on lower frequencies than classic CTAs. The basic premise is if investment is a process, then it should be automated. Unlike discretionary investors, CTAs have done their homework, they understand trading is about probabilities. They accept they will fold a lot but win big sometimes. In terms of programming skills, it is not demanding. You may feel not challenged enough after a while.
In my opinion, this is the least abstract out of the 4. You will learn about markets. There is no subjective beliefs like in the discretionary world. Everything is tested ad nauseam. There is no factor isolation and obscure magical concoction as in quants. There is no order re-routing, spoofing.
It is also less demanding in terms of hours. Let the machine run until You have an idea, test it and if it works implement. You may find it not challenging enough.

Last but not least, as You develop your craft, ask about IP. Earlier this year, i declined an offer to join a HF: they wanted an usually long probation period (something that would extend beyond coding, testing and real trading), but of course keep the IP…

What's it like to write code for a hedge fund?

Algorithmic trading: How to get started building an algorithmic trading system?

This is an answer to a question on Quora: Algorithmic trading: How to get started building an algorithmic trading system?

Answer by Laurent Bernut:

If investment is a process, then the logical conclusion is automation.
Algorithms are nothing else than the extreme formalisation of an underlying philosophy.

This is the visual expression of a trading edge
Trading edge = Win% *Avg Win% – Loss% *Avg Loss%
It changed my life and the way I approach the markets. Visualise your distribution, always. It will help You clarify your concepts, shed light on your logical flaws, but first let’s start with philosophy and belief elicitation

1. Why is it important to clarify your beliefs ?
We trade our beliefs. More importantly, we trade our subconscious beliefs. “If You don’t know who you are, markets are an expensive place to find out”, Adam Smith
Many people do not take the time to elicit their beliefs and operate on borrowed beliefs. Unanswered questions and faulty logic is the reason why some systematic traders tweak their system around each drawdown. i used to be like that for many years.
Belief elicitation exercises:

  1. The Work by Byron Katie. After i completed a 2 beliefs a day challenge for 100 days, i could explain my style to any grandmother
  2. 5 why ? Ask yourself a question with “why” and dive deeper
  3. “I am”: beliefs about self are best elicited when we start with this sentence stem
  4. Sentence completion exercises: Nathaniel Branden in his work on self-esteem has pioneered this method. For example, “to me a robust trading is…”

Mindsets: expansive and subtractive or masala smoothie Vs band-aid
There are two types of mindset, and we need both at different times:

  1. Expansive to explore concepts, ideas, tricks etc. Expansive mindset is useful in the early stage of strategy design
  2. Subtractive: to simplify and clarify concepts. Complexity is a form of laziness. Instead of adding yet another redundant factor, try subtracting one or two. Work hard until You find an elegant and simple solution

Systematic traders who fail at being subtractive have a smoothie approach. They throw all kinds of stuff into the optimization blender and waterboard data until it confesses. Bad move: complexity is a form of laziness.
Overly subtractive systematic traders have a band aid mentality. They hard-code everything and then good luck patching
“Essentialist traders” understand that it is a dance between periods of exploration and times of hard core simplification. Simple is not easy
It has taken me 3,873 hours, and i accept it may take a lifetime

2. Exit: start with the end in mind Counter-intuitive truth
The only time when you know if a trade was profitable is after exit, right ?
So, focus on the exit logic first.
In my opinion, the main reason why people fail to automate their strategy is that they focus too  much on entry and not enough on exit.
The quality of your exits shapes your P&L distribution, see chart above
Spend enormous time on stop loss as it affects 4 components of your trading system: Win%, Loss%, Avg Loss%, trading frequency
The quality of your system will be determined by the quality of your stop loss,

3. Money is made in the money management module
Equal weight is a form of laziness. The size of your bets will determine   the shape of your returns. Understand when your strategy does not work and reduce size. Conversely, increase size when it works.
I will write more about position sizing on my website, but there are many resources across the internet

3. Last and very least, Entry
After you have watched a full season of “desperate housewives” or “breaking bad”, had some chocolate, walked the dog, fed the fish, called your mom, then it’s time to think about entry.
Read the above formula, stock picking is not a primary component. One may argue that proper stock picking may increase win%. Maybe, but it is worthless if there is neither proper exit policy, nor money management.
In probabilistic terms, after you have fixed exit, entry becomes a sliding scale probability

4. What to focus on when testing
There is no magical moving average, indicator value. When testing your system, focus on three things:

  1. False positives: they erode performance. Find simple (elegant) ways to reduce them, work on the logic
  2. periods when the strategy does not work: no strategy works all the time. Be prepared for that and prepare contingency plans in advance. Tweaking the system during a drawdown is like learning to swim in a storm
  3. Buying power and money management: this is another counter-intuitive fact. Your system may generate ideas but you do not have the buying power to execute. Please, have a look at the chart above

I build all my strategies from the short side first. The best test of robustness for a strategy is the short side:

  1. Thin volume
  2. brutally volatile: this
  3. shorter cycle: stocks go up the elevator and go out the window
  4. Borrow availability:

Platforms
I started out on WealthLab developer. It has a spectacular position sizing library. This is the only platform that allows portfolio wide backtetsing and optimisation. I test all my concepts on WLD. Highly recommend. It has one drawback, it does not connect position sizer with real live trading.

Amibroker is good too. It has an API that connects to Interactive brokers and a decent poisition sizer.

We program on Metatrader for Forex. Unfortunately, Metatrader has gone down the complexity rabbit hole. there is a vibrant community out there.

MatLab, the expensive weapon of choice for math graduates. No comment…

R: much better cost-performance than Matlab, simply because it is free

Tradestation
Perry Kaufman wrote some good books about TS. There is a vibrant community out there. It is easier than most other platforms

Final advice
If You want to learn to swim, You have to jump in the water. Many novices want to send their billion dollar ideas to some cheap programmers somewhere. It does not work like that. You need to learn the language, the logic.
Brace for a long journey

Algorithmic trading: How to get started building an algorithmic trading system?

What programs are usually used to back-test trading strategies?

Answer by Laurent Bernut:

Testing a strategy is a journey. For any journey, You need the right equipment. I test everything on WealthLab then program on other platforms. Here is why

The objective of back-testing is to simulate real trading. When You trade real money, You face the following problems:

  1. Position size: You do not trade 1 share per trade. You may have sophisticated position sizing algo. Platforms offering position sizing algos in back-testing phase are few and far between: WealthLab & amiBroker. QuantConnect and Quantopian may but I have not tried
  2. Cash constraint: You strategy may generate signals but if You do not have cash to execute either a Buy Long or a Buy to Cover, it is a moot point. WLD and amiBroker
  3. Portfolio rotation: this is similar to the above point. Test may look great/poor on one security but in real life, you trade a portfolio.
  4. Slippage & commission: always set slippage at max. My settings is -0.5% one-way, that is 1% slippage + commission for a round trip
  5. Volume: only academics and efficient market believers trade on thin markets and banking holidays
  6. Borrow and uptick: structural shorts are a dime a dozen. Profitable structural shorts are the unicorns of short-selling. If You find one, capture it safely and let’s study it

The journey:
The first part of the journey is to get the signal right. This is where most people stop. They identify a signal that they test across a population of stocks one after the other. This may seem fine in theory but in practice You will rapidly come across a concept called Buying Power. If You don’t have the cash, You can’t execute. If You can’t execute, then it’s all academic. This excludes primitve versions of Matlab, MT4 and older versions of TradeStation
Math formula for that level is: Signal Validity = Win%

Second stage is when You start testing at portfolio level
You have realised that signals must be executable to be worth anything.
At this stage, You will test signals. These are where most people stop. This is the province of most sell-side quants using R or Matlab. Tradestation does not go any further. Not sure about Ninja, never tested that one
It assumes all positions are equal weight. This is primitive
math is  Win rate = Win% – Loss %
Bloomberg BTST is a rudimentary version of that

Third stage is when You start working on the real trading edge formula
Trading Edge = Win% *Avg Win% -Loss%* Avg Loss%
This is when You start to realise that size does matter in the markets, particularly when strategy fails to deliver.
At this stage, there are only two platforms which deliver: WealthLab Developer and Amibroker. Both have a comprehensive position sizing library.
Matlab can deliver but You will need to buy an additional expensive module. Matlab is an expensive guillotine, hardly suitable for neurosurgery. I do not recommend it.
WealthLab and amibroker are both C#. They both have canned strategies You can learn from and a vibrant community.

Personally WealthLab changed my life. It permanently changed the way I perceive the markets.

A word about optimisation: the masala smoothie approach
When I started working on the strategy, I, as everyone else, ventured on the side of complexity. I resorted to optimistion to find the best indicator value.

Most people, most quants, love to optimise and re-reoptimise and re-re-optimise their optimisations.
Bad news: it gives the right mathematical answer to the wrong question. Optimisation is the monosodium glutamate MSG of strategies: it gives depth and substance to poor quality food.
Work on the logic, not on the value of some hypothetical Billion Dollar idea.
Do not throw everything in hoping it will stick. Optimisers will waterboard the data until it confesses everything

PS: 100% Free Kick -A@#resource:
Andrew Swanscott interviewed me on Better System Trader.
Interview with Laurent Bernut – Better System Trader
Off line, he suggested I should offer something to his audience. Here is a tool I use daily.

The Trading Edge Visualiser User’s Manual
The way to use it to load your backtest data and look at distribution. I use this tool many times a day during strategy development.

What programs are usually used to back-test trading strategies?

Weekly ETF signals

: Our sincere apologies for the long silence. We were immersed in a fascinating auto-trade project. It has been a wonderful watchmaking experience. “If investment is a process, then automation is a logical conclusion”. We will come back with solid content soon.

  1. SJNK Weekly Bearish Strength 2015-07-06.png
  2. RSX Weekly Bearish Strength 2015-07-06.png
  3. EWZ Weekly Bearish Strength 2015-07-06.png
  4. EWP Weekly Bearish Strength 2015-07-06.png
  5. EWC Weekly Bearish Strength 2015-07-06.png
  6. ERUS Weekly Bearish Strength 2015-07-06.png
  7. DLS Weekly Bearish Strength 2015-07-06.png
  • If investment is a process, then automation is the logical conclusion
  • Complexity is a form of laziness
  • Great traders are not smarter, they have smarter trading habits
  • If investment is a process, then automation is a logical conclusion
  • If You are interested in short-selling, trading systems, position sizing, trading psychology, visit us at: www.alphasecurecapital.com
  • Bullish weakness: Longer-term trend is bullish. There has been some temporary weakness, but the uptrend is likely to resume
  • Bearish strength: Longer-term trend is bearish. There has been some temporary rally, but the downtrend is likely to resume
  • Volatility Channels (Horizontal dotted lines) : Markets often retest swings. This is a volatility buffer to allow wiggle room.
  • Volatility Channel: Think of the other side of a volatility channel of the distance it would take to close half the position to break even if the remainder was to hit the stop loss
  • #n%: Think of it as a rudimentary equity at risk position sizing. It is 1% divided by the distance from the day the swing is recorded to the volatility channel
  • Disclaimer: this is neither a solicitation, nor an investment advice

Track record 2015 – 05 – 22

Nothing speaks louder than a track record. There is no shortage of interesting indicators, strategies, ideas, but in the end, we trust only one thing: track-record. Track record sheds a crude light over two things: robustness of the strategy and quality of execution. Here are the things I have committed to:
  • run this strategy live with real money: 3/4 of my life savings
  • publish the track record on our website
Week in review: May 22nd
Attached is a pdf of the track record:  Track Record 2015 – 05 – 22
Forex impact:
Cash deposits are held in Euro, GBP and JPY. Base currency is denominated in USD. Converting everything into USD would eliminate the currency risk. Forex is however one more tool in the toolbox. EUR and GBP trends have turned bullish against USD. This may juice up NAV growth. This week, it detracted -0.6% from performance.
Performance analysis:
Performance excluding Forex impact was +1.01% inception and month to date. It was +0.48% YTD, inclusive of Forex impact. Both Long and Short books have contributed. Portfolio is still in ramp-up phase. No open position has been either reduced or closed yet. Hit ratio is 32% and 67% on the Long and Short sides, respectively.
Risk:
Cumulative risk is -6.69% to the equity. Risk-per-trade remain below budget (-0.68%) at -0.24% and -0.3% on the Long and Short side, respectively.
Customised metrics measure risk. Sharpe, Sortino, Treynor are the right mathematical answers to the wrong question: volatility is not the enemy. Formulas of the Common Sense ratio, amygdala index and other risk measures will be disclosed in ulterior articles.
Exposures
Net exposure is +60%. Directionality is intentional. Correlation between ETFs is low. For example, correlation between uranium long and Dow Jones Transportation short is low. If securities were correlated, i-e constituents of an index, then relative instead of absolute series would be traded. This would collapse the net exposure to +/-20%.
Signals are taken as they appear. The vast majority of signals are longs for now. Short signals with expensive borrow (>5% ) are rejected.
Gross exposure is now +138%. It will rise as long as the quality of performance (measured by the amygdala index) warrants it. The amygdala index is an asynchronous version of the ulcer index.
Productivity
 A time-sheet keeps precise record of time and activities. This week, it took 2 hours 49 minutes to reconcile trades, process signals and trade. Friction can be further reduced.
Time invested to build the file is not recorded (approximately 29 hours 38 minutes), as it will be amortised over the lifetime of the spreadsheet.
Strategy synopsis
This strategy was developed on the short side in order to underperform the longest bear market in modern history: Japan equities. It follows a philosophy of essential simplicity: complexity is a form of laziness.
The strategy is composed of two modules: entry/exit signals and money management.
Signal Module
Entry and re-Entry conditions are simple. It is easy to get in, but hard to stay in. Entry is a choice, exit is a necessity
  1. Regime definition for all constituents in the universe
    1. Bullish: higher highs & higher lows
    2. Bearish: lower lows & lower highs
  2. Entry: “Buy on Weakness” (Bullish Weakness) and “Short on Strength” (Bearish Strength)
    1. Long: enter the day after a swing low has been recorded && dominant trend remains bullish, “Bullish weakness”
    2. Short: enter the day after a swing high has been recorded && dominant trend remains bearish, “Bearish Strength”
  3. Exits: There are three types of exits:
    1. Isometric staircase stop loss: all open positions are simultaneously closed. Stop Loss is calculated as the swing value +/- an allowance for volatility in Average True Range (ATR).
    2. Trend reversal: if a trend reverses from bullish to bearish, all Long open positions are closed. This is the highest possible point at which positions can be logically closed. Symmetrical rules apply on the short side when a trend reverses from bearish to bullish
    3. Risk reduction: our primary concern is risk. Every new position adds risk. So, the priority is to reduce. We have developed a proprietary adaptive exit threshold (AET) algorithm that optimizes the quantity to be closed, while reducing risk to near zero level
  4. Re-Entry: re-entries are allowed only after a partial exit has taken place. Re-entries are only possible along the trend
  5. Stock selection and order priority:
    1. Signals: every day, signals on ETFs, Forex and major indices are published on our website. Candidates come exclusively from that list. The exact same information is available to everyone, including myself.
    2. Priority: Candidates are ranked by position size: the bigger, the better. Borrow check happens before position sizing. Thin expensive borrow is an indication of how crowded trades are. All trades with borrowing fee above 5% are rejected. This is the only difference between Longs & Shorts.
Money Management
Money is made in the money management module. Risk is not an abstract debate over an investment thesis. Risk is a series of numbers, made visual so as to stay painfully compelling at all times. Our basic philosophy is: profits look big only to the extent that losses are kept small. Tomorrow’s reward cannot be predicted, but risk can be managed today. Our Alpha Secure proprietary position sizing algorithm responsively manages risk (per trade and in aggregate), exposures (Gross/Net), position sizes in real time.
  1. Alpha Secure: This proprietary position sizing algorithm is so impressive that the company was named after it. This tool weathers drawdowns and re-accelerate during winning streaks.
  2. Net exposure:
    • This is an absolute directional Long and Short model: both sides are expected to generate alpha. Directionality (Net +/-100%) is only tolerated because of the low correlation between constituents (ETFs). If the universe was composed of stocks within a index, we would run relative series and collapse net exposure to +/- 20%
    • Net exposure is a direct function of signal generation. For now, the vast majority of signals are bullish. I woke up -100% net short every day for 8 years. So, net exposure will go deeply net negative when needed.
  3. Gross exposure: Gross exposure will be limited to less than 400% so as to avoid margin calls. Gross exposure is a function of market’s money and the Alpha Secure algorithm
  4. Cash deposits: Cash is maintained in various currencies. Forex is another tool in the toolbox to increase equity
Objectives
When managers say “I want to make as much money as possible”, it usually means “I have no risk-control in place”. Expressing objectives in terms of absolute performance percentage points falls into the outcome bias trap. This is a process driven portfolio. Accordingly, objectives are expressed in risk metrics
  1. Reward to risk ratio above 3 for risk management
  2. Common Sense Ratio between 1.8 to 2.1 for robustness
  3. System will be deemed bankrupt if maximum drawdown reaches -20%.
Chart examples:
Charts published every day contain the same information as the ones traded, but presented in a different fashion.

The first chart shows over-imposition of the Buy/Sell strategy over the public chart. They contain rigorously the same information. The only difference is the order logic component, absent in the public display chart, so as not to constitute a Buy/Sell strategy.
  • Stop Loss is the dotted line below each swing Low
  • Numbers preceded by the # sign (for example:#7.6%) are a rudimentary position sizing algorithm that assumes -1% loss to the equity if a position was entered at the Close of the day when the signal happens and stopped at the lower dotted line on the Long side (upper dotted line on the short side)
  • The upper dotted line is a level at which closing half (50%) the position would ensure the trade breaks even thereafter
Black triangles symbolise entries. Stacked black triangles represent single entry but multiple/split exits
Red/Green inverted triangles symbolise exits. Stacked triangles represent final exits. In the example above, the four triangles show the final exit of 4 open positions. Trend reversed from bullish to bearish.
 This is the public version of the same chart. Numbers are rigorously the same. Any smart trader can figure out for herself. In fact, the public version has the advantage of giving free will back to traders. It leads itself to multiple permutations, free from the “mechanical” constraint of a systematic strategy. For example, sideways periods can be used to accumulate stocks, or stay out of the markets.
Below are examples on the short side, with both the “weaponized” and public versions of the same chart. Strategy is symmetrical. It was developed on the short side and then translated to the Long side.
 
The key to being successful on the short side is to take risk off the table. and top-up successful positions. This is exactly what this strategy does.
Charts stripped of Buy/Sell signals lend themselves to multiple combinations and permutations. For example, the three low dotted lines indicated a volatility adjusted inverse head and shoulder pattern: volatility abated and as a result, stop loss moved higher, a movement that preceded a trend reversal.
Call to action
Please opt-in on our website. You will receive daily/weekly signals on equity indices, ETFs and Forex. The same signals on ETFs go into the portfolio.
You will also receive research on money management, trading strategies and trading psychology.
In addition, You will receive codes on C#, free Excel files. Those tools and utilities are not available to non-subscribers.
http://alphasecurecapital.com/subscribe/