stocks_info = get_symbols(sec_type1=1010, symbols=symbols, trade_date=now_str, skip_suspended=True, skip_st=True)symbols = [item['symbol'] for item in stocks_info if item['listed_date'] < context.now and item['
buy_stocks) #交易函数 def trade(context, buy_stocks): #卖出 for stock in cont...
b) 他们的收益不相关。 c) 他们的交易模式 - 您不希望交易流动性不足的资产;您限制自己只交易交易活跃的资产。 应该定义相关的金融数据: a) 频率:每日、每月、日内等等 b) 数据来源 应该定义模型的参数。 应定义它们的定时、入场、退出规则和头寸规模策略 - 例如,我们不能交易超过平均每日交易量的 10%;通常,...
deftrading_strategy(market_data):# 示例策略:假设我们选择价格低于某个阈值的股票threshold_price=100forstockinmarket_data['stocks']:ifstock['price']<threshold_price:print(f"建议买入股票:{stock['name']}价格:{stock['price']}")returnstock['code']# 返回建议买入的股票代码returnNone 1. 2. 3. 4...
import requests #The requests library for HTTP requests in Python import xlsxwriter #The XlsxWriter libarary for import math #The Python math module from secrets import IEX_CLOUD_API_TOKEN #import Token from secrets.py file stocks = pd.read_csv('sp_500_stocks.csv') ...
(df)//10)) for ax in axes: ax.set_xticks(x_ticks) if hasattr(df['日期'].iloc[0], 'strftime'): ax.set_xticklabels([df['日期'].iloc[i].strftime('%m-%d') for i in x_ticks], rotation=45) plt.tight_layout() plt.show() return fig def generate_trading_strategy(self, df):...
{ "items": [ { "margin_trading_amt_balance": 960745756, "short_selling_amt_balance": 2888439, "margin_trading_balance": 957857317, "td_date": 1541347200000 }, { "margin_trading_amt_balance": 948660728, "short_selling_amt_balance": 2767982, "margin_trading_balance": 945892746, "td_date...
df1=pd.read_csv('数据/月个股回报率/月个股回报率.csv',converters = {'Stkcd':str})stocks_code=set(list(df1['Stkcd']))new_code=[]foriinstocks_code:i=i.split('.')[0]new_code.append(i)foriinrange(0,len(new_code)):stock_df=df1[(df1['Stkcd']==new_code[i])]stock_df=stock_...
find( {'date': adjust_date, 'pe': {'$lt': 30, '$gt': 0}, 'index':False, 'is_trading': True}, sort=[('pe', ASCENDING)], projection={'code': True}, limit=100 ) codes = [x['code'] for x in daily_cursor] this_phase_codes = [] if len(last_phase_codes) > 0: ...
togetthe basic infomationofstocks on"date":param date::return:''' #ifthe date is None,getthe last trading date df_basics=ts.get_stock_basics(date)#ifthe infomation is None,return.ifdf_basics is None:returnupdate_requests=[]codes=set(df_basics.index)forcodeincodes:doc=dict(df_basics.lo...