tutorials-trading

to anyone reading this besides me: WOAH! I DONT KNOW ANYTHING ABOUT TRADING! I AM WRITING THIS AS I LEARN MYSELF. PLEASE TAKE IT WITH A HUGE GRAIN OF SALT!

http://www.funelf.net/photos/I-have-no-idea-what-i%60m-doing.jpg


topics:

How stuff works

Basic terminology

Exchanges

Products

You and your broker

Metrics

Intermission: some accidental properties of our world

market participants

investors ('buy-side') * pension funds, insurance companies * retail investors * mutual funds * hedge funds * prop trading * retail traders issuers * and their broker-dealers and underwriters ('sell-side') market-makers corporations that need hedging, etc governments central banks market regulators * in the U.S.: SEC, CFTC, NFA, FINRA, others?

what the big boys have that you don't (and what you have that they don't)

in the U.S.: legal rules 4 u

4 retail traders (basically just pay ur taxes, are there others i'm not aware of?) 4 prop trading companies (are there more than 4 retail? if so, what?) 4 hedge funds 4 mutual funds

types of products

commodities equities * fundamentals corporate accounting terms bonds * fundamentals currencies volatility ETFs and ETNs commoditized strategies (e.g. VQT, XVZ) what else?

Characterizing strategies

types of strategies (qualitative attributes of strategies)

return drivers (e.g. what service are you performing for society)

also called 'alpha source'

* investment * predictive enforcing constraints opponent modeling (note controversy) new information, diligence, superior intelligence/information processing method can be directional or other, but is generally directional * illiquidity * risk * trading: moving things in space, time (market-making), and other dimensions (e.g vertical spreads on options)

systemicity

risks

structural types

max dama's list

quantitative strategy attributes

capacity speed expected return volatility cost of carry maximum gain/loss Sharpe other metrics (Calmar, avg and worst return time, etc)

How the market behaves

Paradigms

the efficient markets hypothesis * note that this doesnt mean that the service of trading is profitless, just that it is a commodity (equilibrium theory; but then, at equilibrium, companies have exactly zero profit..) entreprenuership/service to society view of trading * these mathematical relationships dont keep themselves (e.g. triangle arb) * price discovery * pattern suppression * moving stuff around * insurance, etc the market as cognitive system (my favorite) * note: the feedback loops that cause large jumps in price, sometimes in the absence of external events, seem to be a requirement for cognition (a mind can figure something out that causes a discrete jump in its expectations, although this jump may have to be realized by way of a continuous underlying computational platform) the market as a poker game the market as dynamical system the market as nonstationary probabalistic system the market as a conspiracy (i dont buy this one) ...and the madness of crowds * greed and fear

General behavior

stylized characteristics of financial time series

Well-known classes of strategies

Well-known indicators

Anatomy, and debugging, of a strategy with a predictive return driver

Predictive Alpha sources

Capital

computation and infrastructure

tactics

(i have a bunch to go in here)

strategy archetypes:

adverse selection:

combining strategies

Short-term predictive strategy

todo others

problems:

indicators, predictions, and strategies:

note that even if you have a good prediction, you still have some work to do to make this into a strategy. In some cases you can have a good prediction that cannot (on its own) be turned into a strategy; for example, if the mean predicted value of the change in price is so small that it is eclipsed by the spread. Even if you have a prediction that SPY will go up, for example, you must decide if you should buy SPY and if so, how much and when, and using what order type with which parameter values.

For example, you might decide that although you have a prediction that SPY will probably go up, the mean predicted change in price is too small compared to the spread, so you will do nothing. Or, you might decide to put all of your (algorithm's) free cash into SPY, and in addition margin borrow and spend that to purchase more SPY. Or, you might decide to sell everything in your portfolio and put all of that into SPY. Or, your decision of whether and how much SPY to buy might depend on what you currently hold and how strongly it is correlated to SPY. Or, your decision of whether and how much SPY to buy might depend on your prediction for the standard deviation of SPY. If you do decide to buy SPY, do you use a market order or a limit order or a primary peg order? If you use a limit order, what's the limit? If the limit order never fills, what do you do about that, if anything, and when? If the VIX suddenly spikes, or if the market starts crashing, do you close all your positions or do you ignore it or do you double down?

Even after specifying a strategy algorithmically, there are implementation level details of strategy to specify. What do you do if you stop receiving new prices and cannot form predictions? Do you close all your positions, or do you do nothing? Do you have a failsafe that shuts down automated trading if your account value falls too low? Are there broker constraints, such as OER, that your implementation should cause to always be satisfied even if the strategy would, left to itself, violate them? Do you doublecheck margins to make sure a bug in your strategy doesn't lead to unnecessary margin calls?

And even after that, there are details of implementation design beneath the level of strategy. Do you have multiple threads, one watching for each condition that could cause you to take action? Do you have multiple threads, one watching each financial asset that you are trading? Do you have listeners that fire upon every price change, or do you just periodically reasses things?

timescale:

People often talk of predictions like 'after X happens, SPY tends to go up". But without a timescale, such statements aren't very useful. Does SPY tend to go up one second after X happens? In that case, unless i can get my order filled in less than a second, i shouldn't bother buying SPY when i hear that X has occurred. Does SPY tend to go up sometime between one second and thirty years after X happens? In that case, this is only useful if i am going to run this same strategy for a very long time.

techniques for representing and dealing with timescale:

todo

Break-even strategies

risk management

Software

Analytics

Portfolio analysis

also:

misc tactics:

machine learning features, instances, labels, and timescales:

misc practices

short-term vs. long-term strategies

in many ways, short-term is easier because you can develop by running live simulations using a broker 'paper trading' simulation, rather than with an offline simulator running on your own computer. The latter involves either (a) developing a basic simulator, which is probably much less faithful than available broker paper-trading, or (b) paying a boatload of money upfront to buy a really good simulator, or (c) developing a really good simulator, which probably takes a long time. It also involves either (a) downloading a ton of historical data from a broker, which takes forever, or (b) buying a ton of historical data, which is expensive; as well as storing a ton of historical data, which takes some space.

In addition, if you do use a non-realtime simulator, you can backtest short-term strategies many times on the timescale on which they operate; very long-term strategies may only have a few iterations over the whole historical record.

In addition, if you did manage to find a strategy with X% profit over a short time scale, of course that's better than the same X% over a longer timescale.

However, i suspect that profitable short-term strategies are harder to find, mostly because of the above considerations.

version control

Use a revision control/scm/version control system when developing a strategy. This is crucial because you'll want to change a zillion little things and then run a test, and you'll want to revert to old versions of the code and branch, and then later temporarily abandon the branch and switch to a different branch, and then later change your mind and go back to the abandoned branch; and often the important things won't be what you thought they were and you'll want to say, 'huh, i just want to revert to what it was like a few days ago', or maybe later on you'll look at your notes and you'll say, 'Right now i'm at version A but i really want to know EXACTLY what the differences in the code were between old version B and old version C, neither of which are direct descendents of the other'.

I recommend git.

Anonymous branching is really useful for this because, as you don't know beforehand which changes are important and which are unimportant, the salient characteristics of branches change over time (e.g. you first branches because you wanted to experiment with X but while doing that you changed Y, and then you change W and Z, and then for most of the time you think that W is the most important of these changes, but eventually you find out that actually Y is the only important one), making it difficult to associate branches with memorable names except in hindsight. With git you can refer to everything with commit hashes. WARNING: BY DEFAULT GIT WILL EVENTUALLY GARBAGE COLLECT ORPHAN COMMITS (e.g. anonymous commits not on any named branch) ; use "git config gc.pruneExpire never" to disable this for your repo if you are using it this way (as of this writing, i've not tested it but i think that command will disable this, at least)!

i like to reserve the 'master' branch in the repo for the current version running in production, if any. I have a branch 'develop' which is sort of the latest-and-greatest thing i am working on or trying out in the simulator, but which is not yet in production.

Release staging

The first stage is development on a simulator. There will usually be a few remaining differences between the simulator and production/live accounts/real life, however, so it is suggested to stage releases to production, as with other software.

One way to do it:

version numbers

i like http://semver.org/ -- since there is no 'public API', i use changes to 'patch version' for bugfixes, nonfunctional changes (e.g. logging, restarting after X hours, etc), and account- or user- dependent parameters (e.g. position limits), 'minor version' for 'minor' changes to the strategy (e.g. changes that probably wouldn't change how you would give a quick overview of the strategy to a human, e.g. a retuning of a free parameter, or a minor change in order execution tactics), and 'major version' for major changes to the strategy.

notes files

i like to keep 3 notes files for each strategy.

(1) a journal/log: records the git hash for each version that i try in simulation, along with the net liquidation value of the simulation account before and after running it, and also whatever other stats the strategy reports. Possibly also records some timepoints in the middle. My own thoughts are interspersed.

(2) a todo file: variations on this strategy that i have thought of that i might want to try

(3) an analysis file: mostly a list of profitable git hash versions, how profitable they were per hour and per hour per margin. Also some todos and thoughts.

i also keep one note file for each live account, which is similar to the journal/log, except the file is per-account rather than per-strategy.

misc quotes

"Would someone go to the trouble of putting in a zero-expected-profit order, just for the psychic joy of doing a trade? We shouldn't rule it out." -- http://pages.stern.nyu.edu/~jhasbrou/Teaching/2011%20Winter%20Markets/PDFHandouts/MarketStructure201.pdf

links:

case studies

http://www.dukascopy.com/fxcomm/fx-article-contest/?Machine-Learning-Applied-To-Forex&action=read&id=1768 says from high to high and from low to low is better than from open to close they predict for a fixed time window, from 3 to 10 days they get 60% accuracy over a 1-year test set they have 3 data sets; train, validate, test, from nonoverlapping time periods they have take-profit and stop-loss orders, which should never be too far apart (in trigger prices). if you have a near take-profit and a far stop-loss and ur training set is too short, you'll seem to be very profitable, but in real life eventually you'll hit the stop-loss and be sad. they place the stop-loss and take-profit triggers symmetrically around (the trade opening price?) and optimized the distance between them, which turned out to be about 18 pips. would have placed them even closer, but for commissions and fees. they care about profit factor, gross profit divided by gross loss. theirs is 2.87. maximum consecutive drawdown 5%. max consecutive profit 18%. they use jForex api. they trained on a few years of data. their strategy isnt really black-box, it has a simple form (that they are keeping secret). uses genetic algorithms for feature selection, including selecting the duration of indicators.

http://www.dukascopy.com/fxcomm/fx-article-contest/?action=blog&nickname=olga&contest_period_id=275

features built off of only 8 daily bars into the past. two years training data, one year testing. " For each day, four values are recorded, the first three record information on the movement from the previous day’s close to the day’s high, low and close, in percent while the fourth records the volume for the day. This makes for 32 independent variables total. The data is obtained from three instruments in the dukascopy database, EURUSD, AUDJPY and GBPCHF daily Ask bars from the 1st January 2008 to the 31th December 2011, with weekends blended in the following Monday. ". used WEKA. tried MP-5 regression tree, 15-nearest neighbors (weight by 1/distance), SVM regression, RBF network, Gaussian process. none of these could predict future price direction (from close to close over one day). all of them could predict overall range (difference between the day’s high and the day’s low as a percentage of the previous close) (correlation coefficient above .5, except for RBF). nearest neighbors and SVM did best, RBF did worst. all of them could predict the absolute movement (again for one day), not quite as well (correlation slightly lower than .4 for all except RBF and MP-5 regression tree). volume is also predictable based on time of day and the previous day's pattern.

http://www.dukascopy.com/fxcomm/fx-article-contest/?Best-Practices-When-Optimizing-Automated&action=read&id=1081

trains on at least 200 trades. training objective function is either profit ratio or sharpe ratio. uses "long short term memory" recurrent neural net model

http://www.dukascopy.com/fxcomm/fx-article-contest/?Long-Term-Fx-Strategies&action=read&id=1888 presents a table of short term strats with Sharpe, showing they are terrible. presents 3 longterm currency strats: carry, value, momentum.

links

2011:

ritesh:

NagarajaAdiga?:

petefader:

2012:

jlongo:

LinnuxFX?:

doctortyby:

RobertBric?:

SmithJr?:

SpecialFX?:

2013:

tdurai84:

Likerty:

DumbAsArock?:

HumbleAko?:

scramble:

nsteve:

positive:

AdrianWS?:

Airmike:

Daytrader21:

geula4x:

Efegen:

Skif:

Fxtrader500:

Paulito:

piter44:

drishti:

dennis14685:

rokasltu:

2014:

jezz:

olga:

relu21:

Andrew Ryan:

todo

http://www.dukascopy.com/fxcomm/fx-article-contest/?Sharpe-Ning-Up-Your-Strategies&action=read&id=29

intro to sharpe, with annualization. suggests Sharpe above 3. notes that you should choose strategies and parameters whose score (Sharpe ratio) is relatively stable to small perturbations of the parameters chosen.

--