shokru / mlfactor.github.io

Website dedicated to a book on machine learning for factor investing
198 stars 95 forks source link

Notebook Chapter 12 #69

Closed pm145 closed 3 years ago

pm145 commented 3 years ago

Hi,

There are 2 missing variables in file "Chapter 12.Rmd" that prevent the notebook to run as standalone. It is possible to get the example working by copying code from notebook "Chapter 05.Rmd".

In the Initialization code chunk, line 53 : t_oos <- returns$date[returns$date > sep_oos] %>%

Error in unique(.) : object 'returns' not found

In the backtesting loop, code chunk: temp_weights <- portf_compo(train_data, test_data, features, j) # Weights

Error in (function (cond) : error in evaluating the argument 'x' in selecting a method for function 'as.matrix': object 'features' not found

Kind regards, Pieter

pm145 commented 3 years ago

The code for the second example (12.7) is missing in file "Chapter 12.Rmd". I don't know if this is done on purpose or not, but thought it could be useful to mention it.

I have copied the code from the online book and that worked perfectly. Thank you for the excellent book!

shokru commented 3 years ago

Thank you for noting this. I confess that I did not look into the details enough and that I don't work on these notebooks too much. I forgot how long the backtest took! In the next version, I will need to introduce parallel computing... I updated everything. In the second error, in my case, it was because the object "features" was not defined.

Thanks for the warm feedback!