def test_calc_stats(): # test twelve_month_win_perc divide by zero prices = df.C['2010-10-01':'2011-08-01'] stats = ffn.calc_stats(prices).stats assert 'twelve_month_win_perc' not in stats.index prices = df.C['2009-10-01':'2011-08-01'] stats = ffn.calc_stats(prices).stats assert 'twelve_month_win_perc' in stats.index # test yearly_sharpe divide by zero prices = df.C['2009-01-01':'2012-01-01'] stats = ffn.calc_stats(prices).stats assert 'yearly_sharpe' in stats.index prices[prices > 0.0] = 1.0 stats = ffn.calc_stats(prices).stats assert 'yearly_sharpe' not in stats.index
def test_calc_stats(): # test twelve_month_win_perc divide by zero prices = df.C['2010-10-01':'2011-08-01'] stats = ffn.calc_stats(prices).stats assert pd.isnull(stats['twelve_month_win_perc']) prices = df.C['2009-10-01':'2011-08-01'] stats = ffn.calc_stats(prices).stats assert not pd.isnull(stats['twelve_month_win_perc']) # test yearly_sharpe divide by zero prices = df.C['2009-01-01':'2012-01-01'] stats = ffn.calc_stats(prices).stats assert 'yearly_sharpe' in stats.index prices[prices > 0.0] = 1.0 # throws warnings stats = ffn.calc_stats(prices).stats assert pd.isnull(stats['yearly_sharpe'])
def getWatchlist(source='qa'): ''' get stats from all the symbols :param source: :return: stats ''' startdate, enddate = getDateFromSetting() if source == 'ffn': data = getDataFromFFN(','.join(getSymbolListFromSetting()), startdate, enddate) perf = data.calc_stats() return perf.stats else: data = getDataFromQA([s.upper() for s in getSymbolListFromSetting()], startdate=startdate, enddate=enddate) tdata = transQAToFFN(data) tdata.columns = map(str.lower, tdata.columns) perf = ffn.calc_stats(tdata) return perf.stats
import ffn as fn import QUANTAXIS as QA import pandas as pd symbols = ['WBAI', 'TSLA'] startdate = "2019-05-01" enddate = "2019-05-30" data = QA.QA_fetch_stock_day_adv(symbols, startdate, enddate) dn = data.to_pd().close.reset_index().set_index("date") frame = {} for s in symbols: frame.update({s: dn[dn.code == s].close}) df = pd.DataFrame(frame) perf = fn.calc_stats(df) print(perf.stats)