from flask import Flask, request, render_template import backtrader as bt import yfinance as yf import pandas as pd app = Flask(__name__) class CustomStrategy(bt.Strategy): params = (('sma_period', 15),) def __init__(self): self.sma = bt.indicators.SimpleMovingAverage(self.data.close, period=self.params.sma_period) self.order = None def next(self): if not self.position: if self.data.close[0] > self.sma[0]: self.buy() else: if self.data.close[0]
Posts
- Get link
- X
- Other Apps
from flask import Flask, request, render_template import backtrader as bt import yfinance as yf import pandas as pd app = Flask(__name__) class CustomStrategy(bt.Strategy): params = (('sma_period', 15),) def __init__(self): self.sma = bt.indicators.SimpleMovingAverage(self.data.close, period=self.params.sma_period) self.order = None def next(self): if not self.position: if self.data.close[0] > self.sma[0]: self.buy() else: if self.data.close[0] < self.sma[0]: self.sell() def run_backtest(ticker, sma_period, days): cerebro = bt.Cerebro() cerebro.addstrategy(CustomStrategy, sma_period=sma_period) ...
- Get link
- X
- Other Apps
from flask import Flask, request, render_template import backtrader as bt import yfinance as yf import pandas as pd app = Flask(__name__) class CustomStrategy(bt.Strategy): params = (('sma_period', 15),) def __init__(self): self.sma = bt.indicators.SimpleMovingAverage(self.data.close, period=self.params.sma_period) self.order = None def next(self): if not self.position: if self.data.close[0] > self.sma[0]: self.buy() else: if self.data.close[0]