def quantstats_analysis(env, df, rl_name, start_index, end_index): qs.extend_pandas() net_worth = pd.Series(env.history['total_profit'], index=df.index[start_index + 1:end_index]) returns = net_worth.pct_change().iloc[1:] qs.reports.full(returns) qs.reports.html(returns, output=f'./data/result_analysis/{rl_name}_quantstats.html')
def extend_pandas(): """Enhances pandas objects.""" import quantstats as qs from pandas.core.base import PandasObject as _po qs.extend_pandas() _po.gmean = stats.gmean
def stock_report(symbol): import quantstats as qs # extend pandas functionality with metrics, etc. qs.extend_pandas() # fetch the daily returns for a stock stock = qs.utils.download_returns(symbol) #qs.core.plot_returns_bars(stock, "SPY") qs.reports.html(stock, "SPY", output="report.html")
import quantstats as qs # extend pandas functionality with metrics, etc. qs.extend_pandas() # fetch the daily returns for a stock stock = qs.utils.download_returns('FB') stock.to_csv("FB.csv") print(stock) qs.reports.full(stock) # show sharpe ratio #qs.stats.sharpe(stock) # or using extend_pandas() :) #stock.sharpe(