QQQ TLT 股债平衡策略

网友投稿 998 2022-10-11

QQQ TLT 股债平衡策略

QQQ TLT 股债平衡策略

1.年回报

"""This is a template algorithm on Quantopian for you to adapt and fill in."""from quantopian.algorithm import attach_pipeline, pipeline_outputfrom quantopian.pipeline import Pipelinefrom quantopian.pipeline.data.builtin import USEquityPricingfrom quantopian.pipeline.factors import AverageDollarVolumefrom quantopian.pipeline.filters.morningstar import Q1500US def initialize(context): """ Called once at the start of the algorithm. """ set_benchmark(symbol('QQQ')) context.firstBuy = False context.firstYear = "%d"%(get_datetime("US/Eastern").date().year) context.leverage = 1.0 # Rebalance every day, 1 hour after market open. schedule_function(my_rebalance, date_rules.every_day(), time_rules.market_open(hours=1)) # Record tracking variables at the end of each day. schedule_function(my_record_vars, date_rules.every_day(), time_rules.market_close()) def my_assign_weights(context, data): """ Assign weights to securities that we want to order.a """ pass def my_rebalance(context,data): """ Execute orders according to our schedule_function() timing. """ currentYear = "%d"%(get_datetime("US/Eastern").date().year) if currentYear != context.firstYear or context.firstBuy == False: context.firstYear = currentYear context.firstBuy = True order_target_percent(symbol('QQQ'), 0.5 * context.leverage) order_target_percent(symbol('TLT'), 0.5 * context.leverage) pass def my_record_vars(context, data): """ Plot variables at the end of each day. """ pass def handle_data(context,data): """ Called every minute. """ pass

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:tensorflow 汽车分类
下一篇:Awesome Pyramid:开源Python web 框架Pyramid的应用程序,项目和资源集合(awesome是什么牌子)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~