observations - se.cuhk.edu.hkseem7550/lecture notes/lc/seg5550f-5.pdf · 121 observations...
TRANSCRIPT
121121
ObservationsObservations
nn InIn--sample performance is reasonably sample performance is reasonably goodgood
nn OutOut--ofof--sample results show regions of sample results show regions of bad model predictionbad model prediction•• High nonHigh non--linearity in the bad regionslinearity in the bad regions•• Better models are needed for those Better models are needed for those
regions (by further training in those regions (by further training in those regions)regions)
122122
KK--step NN predictive model step NN predictive model
nn It is straightIt is straight--forward to use CW(tforward to use CW(t--k) and k) and %BB(t%BB(t--k) as inputs for a kk) as inputs for a k--step NN modelstep NN model
Training on return
priceIn-sample
123123
Technical analysis and NNTechnical analysis and NN
nn Technical indicators or signals can thus be Technical indicators or signals can thus be used with NN in various waysused with NN in various ways
nn NN used for nonNN used for non--linear time series modeling linear time series modeling (see notes on engineering techniques)(see notes on engineering techniques)
nn But it can be extended for general nonBut it can be extended for general non--linear linear modeling problems that do not involve time, modeling problems that do not involve time, inertia or dynamics (in continuous system => inertia or dynamics (in continuous system => differentiated signals; in discrete system => differentiated signals; in discrete system => lagged signals) at alllagged signals) at all
124124
NonNon--linear modeling without linear modeling without timetime
nn We are only interested in a nonWe are only interested in a non--linear linear mapping (or a causal relationship) between mapping (or a causal relationship) between the inputs and outputsthe inputs and outputs
nn An input pattern is a combination of inputs An input pattern is a combination of inputs that bear certain relationship with the outputthat bear certain relationship with the output
nn Order in a sequence of input patterns is not Order in a sequence of input patterns is not relevant (in contrast with a time series where relevant (in contrast with a time series where order is defined by time)order is defined by time)
125125
What do we mean?What do we mean?
nn Consider u, v as inputs and y as outputConsider u, v as inputs and y as output•• y = u+v is a linear mappingy = u+v is a linear mapping•• y = u*v y = u*v -- sqrt(usqrt(u) is a non) is a non--linear mappinglinear mapping
nn We are interested in finding a good nonWe are interested in finding a good non--linear mapping for the given u, v, and ylinear mapping for the given u, v, and y
Non-linearityuv
y
126126
Meaningful symbols make a Meaningful symbols make a relevant financial problemrelevant financial problem
nn Let u = volatility, v = interest rate, and y = Let u = volatility, v = interest rate, and y = option priceoption price
nn We have y = f(u, v) by assuming that volatility We have y = f(u, v) by assuming that volatility and interest rate will affect option priceand interest rate will affect option price
nn So consider a So consider a ““babybaby””BlackBlack--ScholesScholes modelmodel•• a faked linear one: y = u+va faked linear one: y = u+v•• a faked nonlinear one: y = k1*u + k2*v a faked nonlinear one: y = k1*u + k2*v --
sqrt(usqrt(u)* v^2 + random noise)* v^2 + random noise•• a real one: y = f(u, v, a real one: y = f(u, v, …… ))
127127
Can the nonCan the non--linearity be linearity be captured or learned?captured or learned?
nn Using a BackUsing a Back--propagation NN (relative easy propagation NN (relative easy for the faked linear and nonlinear cases)for the faked linear and nonlinear cases)
Testing sequence of volatility
Testing sequence of interest rate
128128
Faked linear and nonFaked linear and non--linear linear cases are relatively easycases are relatively easy
Faked non-linear
129129
Get a feel on using NN for Get a feel on using NN for handling nonhandling non--linearitylinearity
nn Try out Try out ““bs_testbs_test””on using the faked nonon using the faked non--linear and real Blinear and real B--SS
nn Alter the nonAlter the non--linearity to see whether the linearity to see whether the BackBack--propagation NN can handle thempropagation NN can handle them
nn What is the effect of added What is the effect of added ““random noiserandom noise””??
nn Can you get the NN to deal with the real BCan you get the NN to deal with the real B--S?S?
130130
NN can still handle the real NN can still handle the real ““BlackBlack--ScholesScholes””
nn BackBack--propagation NN seems to have problem propagation NN seems to have problem in handling the real Bin handling the real B--SS
nn A Radial basis function NN (see notes on A Radial basis function NN (see notes on engineering techniques) is more effective engineering techniques) is more effective
Call price
NN Model errorIn-sample
131131
Another useful referenceAnother useful reference
nn J. Hutchinson, et al., J. Hutchinson, et al., ““A Nonparametric A Nonparametric Approach to Pricing and Hedging Derivative Approach to Pricing and Hedging Derivative Securities Via Learning NetworksSecurities Via Learning Networks””, J. of , J. of Finance, Vol. 49(3), pp. 851Finance, Vol. 49(3), pp. 851--889, 1994.889, 1994. See See onon--line version in CUHK Library web page.line version in CUHK Library web page.
132132
Summarize to focusSummarize to focus
nn NonNon--linearity handling is important for many linearity handling is important for many financial problemsfinancial problems
nn NonNon--linearity handling is used for both time linearity handling is used for both time series and nonseries and non--time related problemstime related problems
nn Engineering techniques (such as NN) can be Engineering techniques (such as NN) can be applied with advantagesapplied with advantages
nn Bridging engineering and finance should be a Bridging engineering and finance should be a thoughtful but not a blind exercisethoughtful but not a blind exercise
133133
Basics are neededBasics are needed
nn Further understanding of technical Further understanding of technical indicators and analysisindicators and analysis
nn Financial basics of optionFinancial basics of option•• The modeling implicationThe modeling implication•• Financial engineering of investment Financial engineering of investment
strategiesstrategies
134134
Further background on technical Further background on technical analysisanalysis
nn StochasticsStochasticsnn MACDMACDnn Trading volume and related signalsTrading volume and related signalsnn …… Why so many? Information explosionWhy so many? Information explosionnn MatlabMatlab toolboxtoolbox
•• Financial toolbox (only contains some)Financial toolbox (only contains some)•• FTS toolbox (more, but still not yet available on FTS toolbox (more, but still not yet available on
the network)the network)•• Well, write it yourself Well, write it yourself ---- not very difficult once you not very difficult once you
know the equationsknow the equations
135135
StochasticsStochastics (%K and %D)(%K and %D)
nn Take a fiveTake a five--day window, find the HH day window, find the HH (Highest high) and LL (Lowest low)(Highest high) and LL (Lowest low)
nn %K(t) = 100* (%K(t) = 100* (cp(tcp(t) ) -- LL) / (HH LL) / (HH --LL) LL) nn %D(t) is the five%D(t) is the five--day average of %K(t)day average of %K(t)nn What do they mean? In words!What do they mean? In words!
•• Consider the extreme cases %K=100 and Consider the extreme cases %K=100 and %K =0%K =0
•• %D is just a lagged follower of %K%D is just a lagged follower of %K
136136
Why do they come in pair (%K Why do they come in pair (%K and %D)?and %D)?
nn A guess: ThatA guess: That’’s the trick of MAs the trick of MA--type type trading rules trading rules ---- we need to find the we need to find the intersection points as our buyintersection points as our buy--sell sell signalssignals
nn Fast Fast stochasticsstochastics may be noisymay be noisynn Slow Slow stochasticsstochastics
•• Take %D in fast Take %D in fast stochasticsstochastics as %Kas %K•• Generate a nGenerate a n--day MA for %K to use as %Dday MA for %K to use as %D
137137
StochasticsStochastics trading rules now trading rules now look familiarlook familiar
nn %K cuts %D from below to above => buy%K cuts %D from below to above => buynn %K cuts %D from above to below => sell%K cuts %D from above to below => sellnn Exactly in the same jacket of MAExactly in the same jacket of MA--trading trading
rules, but replace the price with a relative rules, but replace the price with a relative index (w.r.t priceindex (w.r.t price’’s HH and LL over a small s HH and LL over a small window)window)
nn ““DivergenceDivergence””phenomenon (that what some phenomenon (that what some people observe)people observe)•• %K and price move in opposite direction%K and price move in opposite direction•• Signal for major market change?Signal for major market change?
138138
MACDMACD(Moving Average Convergence/ Divergence)(Moving Average Convergence/ Divergence)
nn Consider two MA curves (MA1 and MA2)Consider two MA curves (MA1 and MA2)•• ““convergenceconvergence””means the two curves come means the two curves come
closer togethercloser together•• ““divergencedivergence””means the two curves go means the two curves go
further apartfurther apart
nn MACD = MA1 MACD = MA1 -- MA2 MA2 •• Actually EMA1 (for exponential MA) for shortActually EMA1 (for exponential MA) for short--term term
MA, and EMA2 for longMA, and EMA2 for long--term MAterm MA•• cf. Channel width in Bollinger Bandcf. Channel width in Bollinger Band
139139
Convergence and Divergence in Convergence and Divergence in MACDMACD
nn ConvergenceConvergence•• MACD (+) towards zero => market fallsMACD (+) towards zero => market falls•• MACD (MACD (--) towards zero => market rises) towards zero => market rises
nn DivergenceDivergence•• MACD (+) becomes more MACD (+) becomes more ‘‘++’’=> market => market
rises rises rapidlyrapidly•• MACD (MACD (--) becomes more ) becomes more ‘‘--’’=> market falls => market falls
rapidlyrapidly
140140
Can you distinguish Can you distinguish ““convergence convergence /divergence/divergence”” in MACD and label them?in MACD and label them?
141141
Signal lines in MACDSignal lines in MACD
nn EMA1 is using 12EMA1 is using 12--day EMAday EMAnn EMA2 is using 26EMA2 is using 26--day EMAday EMAnn MACD signal and Convergence/ divergence MACD signal and Convergence/ divergence
are defined w.r.t. these two linesare defined w.r.t. these two linesnn Another shortAnother short--term signal is also usedterm signal is also used
•• a 9a 9--day EMAday EMA•• it works together with the MACD to generate buy/ it works together with the MACD to generate buy/
sell signalssell signals
142142
MACD trading rulesMACD trading rules
nn The 9The 9--day EMA works with MACD in a day EMA works with MACD in a similar way as the familiar MA trading similar way as the familiar MA trading rulesrules•• 99--day EMA as the day EMA as the ““shortshort--term MAterm MA””•• MACD as the MACD as the ““longlong--term MAterm MA””•• Apply the MA trading rules Apply the MA trading rules
143143
Do you agree with the MACD Do you agree with the MACD buybuy--sell signals?sell signals?
144144
Trading rules are not the final words Trading rules are not the final words (simply ignore them to fit your needs)(simply ignore them to fit your needs)
145145
Trading volumeTrading volume
nn The signal is usually very noisyThe signal is usually very noisynn From trading volume to OBV (recall From trading volume to OBV (recall
engineering notes (slide 51)engineering notes (slide 51)
146146
OnOn--BalanceBalance--Volume (OBV)Volume (OBV)
nn It looks at market functions either as It looks at market functions either as ““collectorcollector””(accumulator) or (accumulator) or ““givergiver””(distributor)(distributor)
nn If If cp(tcp(t) > cp(t) > cp(t--1) , then 1) , then obv(tobv(t) = obv(t) = obv(t--1) + 1) + vol(tvol(t))
nn If If cp(tcp(t) < cp(t) < cp(t--1), then 1), then obv(tobv(t) = obv(t) = obv(t--1) 1) -- vol(tvol(t))nn OBV minimizes many fluctuations in the OBV minimizes many fluctuations in the
trading volume signaltrading volume signal
147147
OBV may be too roughOBV may be too rough
nn A slight cp change works the same as a A slight cp change works the same as a large cp changelarge cp change
nn If the market is really working as a good If the market is really working as a good ““collectorcollector””or or ““givergiver””, then somehow the , then somehow the ““degreedegree””of cp change should be of cp change should be reflected in the indicatorreflected in the indicator
148148
Volume Price Trend (VPT)Volume Price Trend (VPT)
nn vpt(tvpt(t) = vpt(t) = vpt(t--1) + 1) + vol(tvol(t) * () * (cp(tcp(t) ) -- cp(tcp(t--1)) 1)) /cp(t/cp(t--1))1))
149149
VPT can be dynamically related VPT can be dynamically related with pricewith price
price
VPT
150150
More indicators?More indicators?
nn The list is quite exhaustive The list is quite exhaustive …… but I think but I think some of these signals reflect similar some of these signals reflect similar information and are correlatedinformation and are correlated
nn But we are still faced with so much But we are still faced with so much informationinformation•• Input dimension reduction is a needInput dimension reduction is a need•• Features extraction to reduce the Features extraction to reduce the
dimensionsdimensions
151151
ForexForex(Foreign exchange)(Foreign exchange)
nn Are there any differences between using what Are there any differences between using what we learned to stock data and to exchange we learned to stock data and to exchange rate data? rate data? •• Basically very similar. Fundamentals may need to Basically very similar. Fundamentals may need to
consider International Finance basics. Technical consider International Finance basics. Technical analysis tools and engineering techniques should analysis tools and engineering techniques should be the samebe the same
•• Trading strategies may be different due to local Trading strategies may be different due to local contextcontext
–– e.g., US/Sterling via USe.g., US/Sterling via US--> HK, HK> HK, HK--> Sterling> Sterling
152152
In HK (local In HK (local vsvs international)international)
little variation
HK $ForexInvestment
153153
Interpreting on Interpreting on ForexForex graphsgraphs
UK/HK Rate
UK/US Rate
US holiday
buy
sell
154154
Working on estimated modelsWorking on estimated models
Using AR directlyon de-trend data
AR on differential-log
155155
Exchange rate theoriesExchange rate theories
nn Exchange market modeled as an asset Exchange market modeled as an asset marketmarket•• A price that equilibrates the demand and A price that equilibrates the demand and
supply of supply of ““stocksstocks””of domestic and foreign of domestic and foreign currenciescurrencies
nn Rational expectations theoryRational expectations theory•• Looking into the future (expectation)Looking into the future (expectation)•• The The ““newsnews””modelmodel
156156
The The ““newsnews”” modelmodel
nn Two componentsTwo components•• past information (via charts, technical past information (via charts, technical
analysis, exogenous variables)analysis, exogenous variables)•• future information or expectation (via future information or expectation (via
fundamentals, fundamentals, ““newsnews””likely to affect the likely to affect the future)future)
•• p(t) = G(tp(t) = G(t--1) + b* E (p(t+m))1) + b* E (p(t+m))
Current priceCurrent price PastPast Future
157157
Expectation of the futureExpectation of the future
nn It is something interesting It is something interesting …… at least a at least a positive step on how positive step on how ““expectationexpectation””can can affect the current priceaffect the current price•• IsnIsn’’t that the same for the stock market t that the same for the stock market
too?too?•• Current price does react to future Current price does react to future
expectation (e.g., of expectation (e.g., of ““newsnews””))
nn Modeling of expectation is difficult and Modeling of expectation is difficult and errorerror--proneprone
158158
LetLet’’s consider modeling s consider modeling expectation of the futureexpectation of the future
nn A very simple example to illustrate onlyA very simple example to illustrate onlynn It is certainly not practical and It is certainly not practical and
unrealisticunrealisticnn But it does show some interesting But it does show some interesting
consequences of the modelconsequences of the model•• A logistic equationA logistic equation•• Chaotic behavior (see also engineering Chaotic behavior (see also engineering
notes)notes)
159159
Useful referenceUseful reference
nn L.S. Copeland, L.S. Copeland, ““Exchange Rates and Exchange Rates and International FinanceInternational Finance””(2nd Edition), (2nd Edition), AddisonAddison--Wesley, 1994Wesley, 1994•• Chapter 14: A Certain Uncertainty: NonChapter 14: A Certain Uncertainty: Non--
linearity, Cycles, and Chaoslinearity, Cycles, and Chaos””
nn An interesting discussion on how the An interesting discussion on how the logistic equation is related to Financelogistic equation is related to Finance
nn See also the See also the ““newsnews””modelmodel
160160
SpeculatorsSpeculators’’viewsviews
nn Change of foreign currency price, Change of foreign currency price, delta_p(t+1) = K(t) * (equilibrium price delta_p(t+1) = K(t) * (equilibrium price -- p(t))p(t))
nn Equilibrium price, bar_p (to be scaled) Equilibrium price, bar_p (to be scaled) nn K(t) is an increasing function of p(t) = k * p(t)K(t) is an increasing function of p(t) = k * p(t)nn Through proper scalingThrough proper scaling
•• p(t+1) = k * p(t) (1p(t+1) = k * p(t) (1-- p(t))p(t))•• The logistic equationThe logistic equation•• A simple nonA simple non--linear equationlinear equation
161161
Some thoughts on the equationSome thoughts on the equation
nn It may look artificial (in the sense that It may look artificial (in the sense that we want to get the logistic equation)we want to get the logistic equation)
nn But there is economic rationale behind But there is economic rationale behind more than pure math symbolsmore than pure math symbols•• K(t) = k*p(t)K(t) = k*p(t)•• The rationale: When the domestic currency The rationale: When the domestic currency
is cheap (p(t) is high), exports are buoyant is cheap (p(t) is high), exports are buoyant and so there is more scope for speculation and so there is more scope for speculation against itagainst it
162162
It is difficult to know kIt is difficult to know k
nn But it may represent how the But it may represent how the speculatorsspeculators’’action on the marketaction on the market
nn LetLet’’s see how the market price p(t) is s see how the market price p(t) is affected if the logistic equation is trueaffected if the logistic equation is true
nn Interesting p(t) behavior is known for Interesting p(t) behavior is known for different k in the logistic equationdifferent k in the logistic equation
163163
Logistic equationLogistic equation
nn p(t+1)= k*p(t)(1p(t+1)= k*p(t)(1--p(t))p(t))nn What happen for different k and for What happen for different k and for
different initial values of p(t)?different initial values of p(t)?nn Time responseTime response
•• tranquility, limit cycles, chaostranquility, limit cycles, chaos•• sensitivity to initial valuessensitivity to initial values
nn Phase portrait (web diagram)Phase portrait (web diagram)nn BifurcationBifurcation
164164
Logistic equation has a long Logistic equation has a long historyhistory
nn VerhurstVerhurst (1837) derived this equation based (1837) derived this equation based on a modeling on the on a modeling on the ““growthgrowth””and and ““deathdeath””of of a populationa population
nn It is simple, but nicely captures the interaction It is simple, but nicely captures the interaction of two important of two important ““forcesforces””•• growth growth -- k*p(t)k*p(t)•• death death -- k*p(t)^2k*p(t)^2•• p(t) = growth p(t) = growth -- deathdeath
nn Different interpretation of Different interpretation of ““growthgrowth””and and ““deathdeath””in Financein Finance
165165
Getting a feel on time responseGetting a feel on time response
166166
The phase portrait The phase portrait (p(t+1) (p(t+1) vsvs p(t))p(t))
167167
FeigenbaumFeigenbaum bifurcation bifurcation
168168
The amazing world of The amazing world of ““ fractalsfractals””
nn Geometrical shapes with regular Geometrical shapes with regular patternspatterns
169169
Fractal dimensionFractal dimension
nn In between the topological dimension In between the topological dimension and embedding dimensionand embedding dimension
nn ““IntegerInteger””dimension of 0,1, 2, 3, dimension of 0,1, 2, 3, ……nn Think about examples: point, line, circle, Think about examples: point, line, circle,
cubecubenn Fractal dimension is nonFractal dimension is non--integerintegernn A geometrical concept (by A geometrical concept (by MandlebrotMandlebrot) )
to describe irregular shapeto describe irregular shape
170170
Similarity dimensionSimilarity dimension
nn SelfSelf--similarity in a fractal objectsimilarity in a fractal objectnn Similarity dimension = log (no. of copies)/ Similarity dimension = log (no. of copies)/
log(reduction)log(reduction)nn Concept of correlation dimension, DConcept of correlation dimension, D
•• For each data point, find the number of other data For each data point, find the number of other data points N(r) which is within a points N(r) which is within a hyperspherehypersphere of radius of radius R centered at that pointR centered at that point
•• N(r) = C1 * r^D, as RN(r) = C1 * r^D, as R--> 0> 0
•• Obtain D from a log(N) Obtain D from a log(N) vsvs log(r) plotlog(r) plot
171171
Useful referenceUseful reference
nn P. De P. De GrauweGrauwe, H. , H. DewachterDewachter, and M. , and M. EmbrechtsEmbrechts, , ““Exchange Rate Theory Exchange Rate Theory --Chaotic Models of Foreign Exchange Chaotic Models of Foreign Exchange MarketsMarkets””, Blackwell Publishers, 1993., Blackwell Publishers, 1993.
172172
What is the relevance of chaos?What is the relevance of chaos?
nn Suppose we detect chaos (not a easy Suppose we detect chaos (not a easy task in itself based only on empirical task in itself based only on empirical data), we still havendata), we still haven’’t answered the t answered the questionquestion
nn A domainA domain--dependent interpretation is dependent interpretation is still neededstill needed•• Say in finance, in stock price, what happen Say in finance, in stock price, what happen
if there are hints for chaotic patterns?if there are hints for chaotic patterns?
173173
Further study of logistic equationFurther study of logistic equation(a dynamic scenario)(a dynamic scenario)
nn A timeA time--varying k(t)varying k(t)
Output
k
Recovered k
174174
ObservationsObservations
nn A timeA time--varying k has its practical significance varying k has its practical significance (say, representing adjustment to avoid violent (say, representing adjustment to avoid violent fluctuations)fluctuations)
nn The output does not follow exactly that in the The output does not follow exactly that in the static casestatic case•• for k above 3, we should already in the for k above 3, we should already in the
highly chaotic region but now the system highly chaotic region but now the system behavior is less violentbehavior is less violent
nn Recovered k Recovered k -- not the original k?not the original k?•• sensitivity to initial conditionssensitivity to initial conditions
175175
Can we view in phase space?Can we view in phase space?
nn For 1For 1--dimensional signal?dimensional signal?nn Yes, how about we try y(t), y(tYes, how about we try y(t), y(t--1), and y(t1), and y(t--2)?2)?
A bat?
176176
LetLet’’s get the system more exciteds get the system more excited
Output
k
Recovered k
177177
Similar pattern emergesSimilar pattern emerges
178178
But it is in fact a But it is in fact a ““crowncrown””
179179
ObservationsObservations
nn The experiment shows some interesting The experiment shows some interesting properties of chaosproperties of chaos•• sensitivity to initial conditionssensitivity to initial conditions•• cannot exactly recovered kcannot exactly recovered k•• interesting chaotic pattern, or interesting chaotic pattern, or ““fractalfractal””, or strange , or strange
attractorattractor
nn The pattern can be explained for this caseThe pattern can be explained for this case•• cyclical variation of kcyclical variation of k
nn System seems to be calm even in highly System seems to be calm even in highly chaotic region (as determined by k) once it is chaotic region (as determined by k) once it is in itin it
180180
But we better watch out!But we better watch out!
nn We are still using a deterministic system We are still using a deterministic system without any noisewithout any noise
nn Some small uncertainties can easily trigger Some small uncertainties can easily trigger fluctuations in output fluctuations in output ---- try out by injecting try out by injecting some random noise and control its magnitudesome random noise and control its magnitude
nn AfterallAfterall, we are using a simple time, we are using a simple time--varying varying logistic equation to model the exchange ratelogistic equation to model the exchange rate
nn The actual behavior in exchange rate still The actual behavior in exchange rate still defies good modeling defies good modeling ---- mankind behavior is mankind behavior is just as difficult as natural phenomenonjust as difficult as natural phenomenon