Last active
October 15, 2022 22:29
-
-
Save natyrix/ef795c2e297af1f7bc2016747a6a7988 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def setup_sma(self): | |
if self.is_experiment: | |
mlflow.log_param("stock_sma", self.stock) | |
mlflow.log_param("stock_fast_sma", self.fast_ma) | |
mlflow.log_param("stock_slow_sma", self.slow_ma) | |
mlflow.log_metric("init_cash", self.init_cash) | |
price = vbt.YFData.download(self.stock, start=self.start, end=self.end).get('Close') | |
self.calc_fast_ma = vbt.MA.run(self.price, self.fast_ma, short_name='fast_ma') | |
self.calc_slow_ma = vbt.MA.run(self.price, self.slow_ma, short_name='slow_ma') | |
entries = self.calc_fast_ma.ma_crossed_above(self.calc_slow_ma) | |
exits = self.calc_fast_ma.ma_crossed_below(self.calc_slow_ma) | |
self.pf = vbt.Portfolio.from_signals(self.price, entries, exits, init_cash=self.init_cash) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment