仓库源文站点原文


layout: post title: "ML4T | week9 The Big Short, Time Series Data and Technical Trading" date: "2019-02-19 02:20:20" categories: 计算机科学 excerpt: "This week, you should watch ... well, no lessons, but a few video..." tags: [ML4T, Machine_Learning ]

auth: conge

This Week's Lessons.

This week, you should watch ... well, no lessons, but a few videos: The Big ShortTime Series Data (First 30 Minutes), and Technical Trading.

the videos are hosted on Youtube.

Project 5 Video

Project 5 Video

Here is the process to create a market simulator

  1. construct a df_prices to record the prices (adjusted close price) for each trading day for each stock in the portfolio. Add a cash variable in the data frame and set the value for cash to $1.
  2. construct df_trades to hold all the tradings. Make sure to get the value of the "cash" column correct.
  3. df_holdings: the number of stocks and cash for each column.
  4. df_value: = df_prices * df_holdings.
  5. df_port_val: = sum of the df_value.

Time Series Data (First 30 Minutes)

Backtesting to Validate the Model

  1. go back to the beginning of the data, select a chunk of them for training and building the model; Based on that model, make a Forecast towards the future (n days ahead), then make a trade decision.
  2. Then skip the train and forecast period, select another chunk of data to repeat step 1.

This process is called Roll forward cross validation or Out of sample validation

In this method, we can only use the slice of data in the future for testing. because it is easier to predict past than predict the future

10 Ways that backtest can go wrong.

1. In sample backtesting

2. survivor bias

image.png

3. ignore the market impact


Case Study in Vectorization of Technical Strategy Python Code

In the graph above, there are

strategy

the easy but slow way of calculating the indicators

The above method is a correct way of doing the calculation. However, it is very slow to calculate the needed statistics using the method.

real 5m24.461s user 5m24.281s sys 0m0.185s

Solution: vectorize the calculation. Here is the PPT used in the video