# 專題計畫
## The basic requirements of this project
1. Implement at least 5 market impact models
2. Develop a model calibration mechanism
• To calibrate models and then choose the best well-calibrated model for each market
3. Implement at least 3 execution algorithms and develop an execution algorithm evaluation mechanism based on the well-calibrated impact model for each market
#### The framework of impact models and execution algorithms developments

# Paper List
### 1. First generation market impact models
- [x] [Bertsimas & Lo (1998)](https://drive.google.com/drive/folders/1M4GPv-GPdmVBX-_ks3Ad-JS6EJDPgjZP?usp=sharing)
* [market impact model](#market-impact-model)
* [execution strategy](#execution-strategy)
* model 1 (linear permanent impact)
* model 2 (LPT)
* model 3 (imposing constraints)
* file path :
* GitLab/test/main/Bertsimas and Lo
* NYCU_dev1/Desktop/Bertsimas and Lo/
* hyperparameter 的校正方法須明確定義(如資訊影響變數的校正需使用台股指數報酬率等)
- [x] [Almgren & Chriss (1999, 2000)](https://drive.google.com/drive/folders/1GqQ7Q7yLlxYUigxhvx6gzXVVBg7z-WVi?usp=sharing)
* [market impact model](#market-impact-model1)
* [execution strategy](#execution-strategy1)
* 5日台積電收盤價(已完成)
* 日內資料(已完成_2914.T)
* file path :
* GitLab/test/main/Almgren_Chriss
* NYCU_dev1/Desktop/Almgren_Chriss/
- [x] [Continuous-time variant by Almgren (2003)](https://drive.google.com/drive/folders/1g8EviMm3sm_5aR-aHi2IvWYdn9jRLrNd?usp=sharing)
* [market impact model](#market-impact-model2)
* [execution strategy](#execution-strategy2)
* file path :
* C:\Users\nycu_dev2\Desktop\AC_nonlinear
* GitLab/test/main/continuous time variant by Almgrem
- [x] [Kissell, R., Glantz, M., & Malamut, R. (2004)](https://drive.google.com/drive/folders/1uobE98lA0L9HT45z54joeK4kw8nj0hMk?usp=sharing)
### 2. Second generation market impact models
- [x] [Bouchaud, Gefen, Potters & Wyart (2004)](https://drive.google.com/drive/u/0/folders/1TO1KM3OhGf3zOnIOix_SM1U6zVj7asD1)
* [market impact model](#models)
* [execution strategy](#Execution-sreategy)
- [ ] [Obizhaeva & Wang (2005)](https://drive.google.com/drive/u/0/folders/1wXOr_fxO76fzPBh5mannChkYrA_mpHrd)
目前進度 : Paper已讀完,開始implement中
- [x] [Gatheral (2010)](https://drive.google.com/drive/folders/1VhYWz4mdvlcp2QKMR0j4aUmakjHfv4fP?usp=sharing)
* [market impact model](#Market-Impact-Model1)
* [execution strategy](#Execution-Strategy1)
- [ref:Price Manipulation And Quasi-Arbitrage](https://drive.google.com/drive/u/0/folders/1q-Plea9b2yYZHQdjb752M0ZNcB4_L-Ae)
execution strategy : 未提供
market impact model : 類似Almgren-Chriss Model
- [x] [Alfonsi, Fruth & Schied (2008, 2010)](https://drive.google.com/drive/u/0/folders/1hoFsSbUubvcVfI5rcObFKFPqpjinOcvL)
- [x] [Alfonsi, Schied & Slynko (2009)](https://drive.google.com/drive/folders/1s3Q-lunIr8KD08NfXMCRnxHhp5BedWMF?usp=sharing)
已完成implementation且程式碼已上傳至gitlab
- [x] [Predoiu, Shaikhet & Shreve (2010)](https://drive.google.com/drive/folders/1TP3nHmzjWq4l_4YQM5Mhr2AyZF0pjGpZ)
### 3. Other modeling approaches
- [ ] [P. Bank and D. Baum (2004)](https://drive.google.com/drive/folders/1k6yy-Xfq9MALCoTgssREJlYCqcjyU09E)
進度:intro.+conclusion;對過去model優化的數學推導,沒有實作方面的內容
- [ ] [U. Cetin, R. Jarrow, and P. Protter (2004)](https://drive.google.com/drive/folders/1mwOEmVDhlsW-nBgjvY88gX6OmZtjAWn-)
目前進度:CH2
- [ ] [S. Gokay, A. Roch, and M. Soner (2010)](https://drive.google.com/drive/folders/1KvgSBkNOlxSsV8SkP45JJMa1t54itrbP)
其內容為先前paper的總整理,沒有自己的model
- [ ] J.P. Morgan Model (2010)
* 衍伸論文(RL相關)
| Paper | Sample code | Introduction |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [Nevmyvaka, Yuriy, Yi Feng, and Michael Kearns. **"Reinforcement learning for optimized trade execution."** 2006.](https://drive.google.com/drive/u/0/folders/1Tu5BnaYulMIVER1iKVyo8zXdzp7Gh2CP) | [Yes](https://github.com/luliu31415926/Reinforcement-Learning-for-Optimized-trade-execution)(只是相似) | First large-scale application of RL in optimized trade execution |
| [A reinforcement learning extension to the Almgren-Chriss framework for optimal trade execution](https://drive.google.com/drive/u/0/folders/1jCEhIAimcNclRkGoh31oghxl2IJNPPw1) |NO | 利用RL動態考慮市場變化調整AC model 所計算出的建議交易量。 |
| [Fang, Yuchen, et al. **"Universal trading for order execution with oracle policy distillation."** 2021.](https://drive.google.com/drive/u/0/folders/1vEFA7Prv2l5TqMqpeu_1dZJ6RjIcjyF-) | [Yes](https://github.com/microsoft/qlib/tree/high-freq-execution/examples/trade/) | 通過在多個時刻分別預測股票的價格變化,從而確定最適合的交易策略。此篇論文提出之方法與現有的基於固定時間窗口的方法不同,是根據市場波動性動態調整時間窗口的大小,以適應不同市場條件下的交易。 |
| [Théate, Thibaut, and Damien Ernst. **"An application of deep reinforcement learning to algorithmic trading."** 2021.](https://drive.google.com/drive/u/0/folders/1o0LFv6P9OczLn3W26_6SRMtWtdGdrAMF) | [Yes](https://github.com/ThibautTheate/An-Application-of-Deep-Reinforcement-Learning-to-Algorithmic-Trading) | 介紹如何使用深度強化學習算法來對股票市場中的算法交易進行優化,論文中提出結合了Dueling網絡和Double Q-Learning的算法,通過學習使得每次交易產生的收益最大化的策略。總體來說,該論文表明,深度強化學習算法是一種有潛力的方法,可以用來改進股票市場中的算法交易,為量化交易提供更加智能化和高效的解決方案。 |
|[Ning, Brian, Franco Ho Ting Lin, and Sebastian Jaimungal. **"Double deep q-learning for optimal execution."** 2021.](https://drive.google.com/drive/u/0/folders/1xJ3n6Hwvo1RV8IbPgThiPPr07GO-g_H7)|No|使用DDQN算法。|
|[Lin, Siyu, and Peter A. Beling. **"An End-to-End Optimal Trade Execution Framework based on Proximal Policy Optimization."** 2020.](https://drive.google.com/drive/u/0/folders/1NQpN4ZsGlYE-ZryLAq1LOwvAWC1SvS_8)|No|使用 PPO 的解法,結合LSTM|
- [ ] I-star models
- [ ] [linear model: $a_1\cdot (\frac{Q}{ADV})+a_2\cdot \sigma+a_3$](https://drive.google.com/drive/folders/1gUQwt5QkwzdcygoYjOM7tVoPz_6-x4YR)
- [ ] [non-linear model: $a_1\cdot (\frac{Q}{ADV})^{a_2}+a_3\cdot \sigma+a_4$]()
- [ ] [power function: $a_1\cdot (\frac{Q}{ADV})^{a_2}\cdot\sigma^{a_3}$]()
- [ ] [Simplified Model (Kissell [2006]): $a_1\cdot Size^{a_2}\cdot\sigma^{a_3}$](https://drive.google.com/drive/u/0/folders/1GUBFoSDh9HAwVV4UxKP9JOdvwT4PhZQF)
- [ ] [Toth, B. et. al._ I-STAR (2011)](https://drive.google.com/drive/folders/1gUQwt5QkwzdcygoYjOM7tVoPz_6-x4YR)
- [x] [Toth, B. Anomalous price impact and the critical nature of liquidity in financial markets (2011)](https://drive.google.com/drive/folders/1JUN0Y_HNwces3SS60nHymFMShYdk1HJq)
- [x] [E.Zarinelli, M.Treccani, J.Doyne Farmer, and F.Lillo(2014)](https://drive.google.com/drive/folders/124jo590YGc1QeN56TkTR9q6SU6KJyqF9?usp=sharing)
* [market impact model](#Market-Impact-Model)
* [execution strategy](#Execution-Strategy)
### 4. Papers about LOB
- [ ] [The dynamics of ex-ante weighted spread: an
empirical analysis](https://drive.google.com/drive/u/0/folders/1aMS8SXsObZf8sp4ndEk6PwC8xGDcZQJ1)
### 5. Summary
- [Summary of metaorder](https://drive.google.com/drive/u/0/folders/1ztxJxECROq-xCi-rktoRB2OD3zLbOg_Q)
# Papers
## Optimal control of execution costs
### market impact model
* linear market impact without information (permanent)
* linear market impact with information (permanent)
* linear percentage temporary(LPT)
### execution strategy
* the goal of the execution strategy in this paper is to minimize the expected cost of trades
* uncertainty is not considered
### Outline
* 本篇討論多種market impact 模型,包含liner permanent impact 和 linear temporary impact 等,並同時利用 stochastic dynamic programming 遞迴求出最佳策略解。
* 另外,文中包含將單一執行策略延伸至portfolio執行策略,並說明如何將限制(如限制買賣方向等)考慮進模型中。
* 最後提到本篇模型之優缺點,以下簡單列舉幾項:
* 優點:模型較為簡單直覺、執行上簡單、相較naive strategy(平均分攤交易策略)有更好的表現(較低的expected cost)
* 缺點:模型的穩定性低、參數的校正問題、未能考慮效用(utility)
## Optimal Execution of Portfolio Transactions
### market impact model
* assume the impact is linear
* divide the impact into two case : temporary and permanent
* temporary impact : imbalances in supply and demand caused by our trading leading to temporary price movements away from equilibrium
* Permanent impact : changes in the “equilibrium” price due to our trading, which remain at least for the life of our liquidation
### execution strategy
* to minimize the negative utility with different given λ (risk averse coefficient).
* negative utility (in paper is called ‘utility’, but here we use ‘negative utility’ to describe) : expected value of trading cost + variation*λ.
### Outline
*By Robert Almgren and Neil Chriss*
* 計算價格動態曲線後討論trading cost
* 計算trading cost 的期望值、變異數在線性市場影響的假設下討論不同case的utility
* 深究utility的效率前沿
* 討論drift的影響(information effect)
---
## Beyond the square root: Evidence for logarithmic dependence of market impact on size and participation rate
### Market Impact Model
* 本論文將 Market Impact 依據交易時間的推進分成 immediate, temporary and permanent
* The Almgren-Chriss Model 假設 Market Impact 並不會隨著時間而 decay
* The Propagator Model 則將 decay factor 納入考量
### Execution Strategy
* 探究在不同 Market Impact Model 以及 Trading Strategy下, Market Impact 與 metaorder 參數 $\eta$ (duaration) 以及 $F$ (participation rate) 的關係
---
## Fluctuations and response in financialmarkets: the subtle nature of ‘random’ price changes
### Outline
**Goal** : Study how price changing at the trade by trade level & analyze the interplay between the impact of each trade on the price and the volatility
---
**According to the empirical data, we know:**
1. The price (midpoint) process is **close** to being purely diffusive, even at the trade by trade scale

$$D(l)=<(p_{n+l}-p_n)^2>$$
2. The temporal structure of the impact function first increases and reaches a maximum after 100 − 1000 trades, before decreasing back, with a rather limited overall variation

$$R(l)=<(p_{n+l}-p_n)\cdot\varepsilon_n>$$
3. The sign of the trades shows surprisingly long range (power-law) correlations.

$$C_0(l)\simeq\frac{C_0}{l^\gamma}$$
$$C_1(l)=<\varepsilon_{n+l}\varepsilon_n lnV_n>\ \approx\ <lnV>C_0(l)$$
$$C_2(l)=<\varepsilon_{n+l}lnV_{n+l}\varepsilon_n lnV_n>\ \approx\ <lnV>^2C_0(l)$$
* <> means "average", it represents the average impact in the time lag 𝑙
* compare two observables at time 𝑛 and 𝑛+𝑙, 𝑙 represents how many trades have done.
* $p_n$ represents the price at time 𝑛.
* $\varepsilon_n$ represents the sign of the trade at time n ($bid=+1, ask=-1$)
* $V_n$ represents the volume traded at time n
### models
1. **Micro-model of price:** (詳細證明可看Presentation Part3)
Define:$$p_n=\sum_{n^{'}<n}G_0(n-n{'})\varepsilon_{n^{'}}lnV_{n^{'}}+\sum_{n^{'}<n}\eta_{n^{'}}$$
* $G_0$ is the ‘bare’ impact function of a single trade, that we assume to be a fixed (is not itself fluctuating), non random function that only depends on time differences. (the average impact of a single trade after ℓ trades)
* $\eta_n$ represents random variables, assumed to be independent from the ε_n and model all sources of price changes not described by the direct impact of the trades: the bid-ask can change as the result of some news, or of some order flow, in the absence of any trades. (其他所有除了能用模型表示的變因,像是消息面的影響等等)
The price increment between an arbitrarily chosen initial time 0 and time ℓ:$$p_l-p_n=\sum_{0\le n<l}G_0(l-n)\varepsilon_nlnV_n+\sum_{n<0}[G_0(l-n)-G_0(-n)]\varepsilon_nlnV_n+\sum_{0\le<l}\eta_n$$
2. **Diffusion (Price fluction) :**
Define:$$D(l)=<(p_{n+l}-p_n)^2>$$將市場因價格隨機運動而產生的波動量化出來
$\varepsilon_n$ have long range correlations(買賣單之間的sign存有關聯性。詳細證明推倒過程可看Presentation Part4):$$D_t(l)=<ln^2V>[\sum_{0\le<l}G^2_0(l-n)+\sum_{n>0}[G_0(l+n)-G_0(n)]^2]+2\Delta l+D_\eta l$$
* $\Delta l=\sum_{0\le<n^{'}<l}G_0(l-n)G_0(l-n^{'})C2(n^{'}-n)+\sum_{0<n<n^{'}}[G_0(l+n)-G_0(n)][G_0(l+n^{'})-G_0(n^{'})]C2(n^{'}-n)+\sum_{0\le<l}\sum_{n^{'}>0}G_0(l-n)[G_0(l+n^{'})-G_0(n^{'})]C2(n^{'}+n)$
* $D_\eta$ is the variance of the η’s
*另外有當$ε_n$是獨立變數情況的model,同見Part4(買賣單之間的sign互相獨立,但與事實不符)*
3. **Response function (Temporary price impact):**
Define:$$R(l)=<(p_{n+l}-p_n)\cdot\varepsilon_n>$$
$ε_n$ were independent random variables(買賣單之間的sign互相獨立,但與事實不符):$$$$
可想成投資人與市場彼此想法的關聯值。
Ex : 當投資人買進,而$𝑝_{𝑛+𝑙}> 𝑝_𝑛$,表示市場與投資人的共識相同( $𝑅(𝑙)$大於0,且值隨市場上升的價格變大)
$\varepsilon_n$ have long range correlations(買賣單之間的sign存有關聯性。詳細證明推倒過程可看Presentation Part4):$$R_t(l)=<lnV>G_0(l)+\sum_{0<n<l}G_0(l-n)C_1(n)+\sum_{n>0}[G_0(l+n)-G_0(n)]C_1(n)$$
*另外有當$ε_n$是獨立變數情況的model,同見Part4(買賣單之間的sign互相獨立,但與事實不符)*
### Execution sreategy
* 透過歷史資料來獲得參數$C_0以及\gamma$,並帶入到paper中的market impact模型。
---
## No-Dynamic-Arbitrage and Market Impact
By Gatheral(2010)
### Market Impact Model
* A round trip trade is a sequence of trades whose sum is zero.
* Price manipulation is a round-trip trade whose expected cost is negative.
* The cost of trading can be decomposed into two components:
- The impact of trading on the market price, which may decay over time.
- The market friction called slippage that affect only execution price, which is neglected in this paper.
* The principle of No-Dynamic-Arbitrage states that price manipulation is not possible, which means the cost of trading is non-negative on average.
### Execution Strategy
* Disscuss whether price manipulation is possible or not under different trading strategies, market impact function and decay kernal.
* We try to find the best market impact model to exclude the possibility of price manipulation.
# Execution algos
## VWAP Strategy
### VWAP strategy
* Target the average execution price to be VWAP.
* Minimize the market impact.
* Do not assure to minimize risk exposure or high price appreciation cost.
* If there's no anticipated natural price appreciation, VWAP strategy has the lowest trading cost as market impact is the only cost component.
* To execute the order in proportion follows the percentage of volume traded in specified trading period, aka **slicing strategy**. => follow historical volume profile, which is pretty stable and consistent.
$\hat u_j=\frac{1}{n}\sum_{i=1}^{n}u_{ij}=\frac{1}{n}\sum^{n}_{i=1}\frac{v_{ij}}{V_i}$, $u_{ij}$ is the percentage of total volume traded in $j$-th period, $i$ days ago.
### VWAP-hedge strategy
* To execute the order in shorter period if the volume of order for trading is small.
### VWAP tilt strategy
* Adjust the VWAP strategy if the trader anticipates there's a price movement.
* VWAP tilt strategy : $w_j=\frac{u_ja_j}{\sum^n_{j=1}u_ja_j}$, where $a_j=\frac{A_j}{\sum^n_{j=1}A_j}$.
| VWAP tilt | | $\Delta p>0$ | | $\Delta p<0$ |
| --------- | --------- | ------------------- | --------- | ------------------- |
| | Tilt type | Equation | Tilt type | Equation |
| Buy | morning | $A_j = (p_0+nk)-kj$ | afternoon | $A_j=p_0+k(j-1)$ |
| Sell | afternoon | $A_j=p_0+k(j-1)$ | morning | $A_j = (p_0+nk)-kj$ |
$p_0$ is current stock price, $k$ is an intensity parameter
**Concern**
* The anticipation isn't promised to be happened, high $k$ may cause serious underperformance if anticipation didn't happen.=>Set a benchmark risk $\sigma^*$ to restrict $k$'s range.
* $A_j$ shown in table above is only one of the models to derive the tilting strategy, can extend the model by setting the inital stock price of every time sections to be different. => setting the stock price of every time section as $p_j$ instead of $p_0$.
___
## Optimal execution with nonlinear impact functions and trading-enhanced risk
### market impact model
* divide the impact into two case : temporary and permanent
* temporary impact : imbalances in supply and demand caused by our trading leading to temporary price movements away from equilibrium
* Permanent impact : changes in the “equilibrium” price due to our trading, which remain at least for the life of our liquidation
* trading enhence risk : Representing the increased uncertainty in execution price incurred by demanding rapid execution of large blocks.
* 本篇為 Optimal Execution of Portfolio Transactions 的延伸,主要探討下面兩種情形
- Model 1 :linearly permenent impact and nonlinearly temporary impact
- Model 2 :linearly permenent impact and linearly temporary impact and linearly trading enhence risk
### execution strategy
* to minimize the negative utility with different given λ (risk averse coefficient).
* negative utility (in paper is called ‘utility’, but here we use ‘negative utility’ to describe) : expected value of trading cost + variation*λ.
### Outline
* 以欲交易時間長短決定風險趨避參數λ
* Model 1 探討在不同的 nonlinearly temporary impact function 下的 optimal strategy
* 考慮了流動性的問題,但其交易策略未考慮到與自身相同方向交易的人,所以會低估交易成本
* 此處列舉幾項優缺點
* 優點:
- Model 1 中無論市場的 nonlinearly temporary impact function 是幾次多項式,Model 1 和 Model 2 都比 naive strategy的表現得好(有較小的 negative utility)
* 缺點:
- nonlineariy temporary impact function 的真實長相無從參考
- 某些情形下的λ無法完全以欲交易時間推得