我对Python和编码还很陌生,只有大约6周的经验。我开始了一个金融项目,试图找出投资组合应该有多少现金,以及应该根据当前市场表现投资多少。不知道这项研究是否有任何相关性,但在每一步都卡住了并学到新东西时很有帮助。
对于任何感兴趣的人,这是Google Collab Jupiter笔记本 https://github.com/Jakub-MFP/My_FIRE_Project/blob/master/portfolio_management/cashposition_backtest.ipynb
在第4步中,我正在尝试运行类似排列组合的模拟。我一直在阅读https://docs.python.org/3/library/itertools.html 但是它让我感觉有些压不住想要从哪里开始。只是想寻求一些指导,例如我应该研究哪些术语或内容来解决这个具体问题。
我还看到了一个叫tpot的东西,可以用于排列组合?
排列组合问题
目前,在第3步中,我为市场下跌的各种情况设置了预定义循环。它看起来像这样
if (current_market_status == 0): # all time high record
current_cash_required_equity = 0.3
elif (current_market_status < -0.05): #less than 5%
current_cash_required_equity = 0.25
elif (current_market_status < -0.10): #less than 10%
current_cash_required_equity = 0.20
elif (current_market_status < -0.15): #less than 15%
current_cash_required_equity = 0.15
elif (current_market_status < -0.20): #less than 20%
current_cash_required_equity = 0.10
elif (current_market_status < -0.25): #less than 25%
current_cash_required_equity = 0.05
elif (current_market_status < -0.30): #less than 30%
current_cash_required_equity = 0
现在我想做的是尝试每种市场状态组合,在
0.50到-0.50
之间以0.01
为增量。针对每个市场状态,尝试设置现金头寸在0.50和0之间
。应该设置一个限制只尝试类似于
5 elif
设置吗?还是有更多组合方式的方法?我为期权设置了这个。
options_market_status = [0.50,0.49,0.48,0.47,0.46,0.45,0.44,0.43,0.42,0.41,
0.40,0.39,0.38,0.37,0.36,0.35,0.34,0.33,0.32,0.31,
0.30,0.29,0.28,0.27,0.26,0.25,0.24,0.23,0.22,0.21,
0.20,0.19,0.18,0.17,0.16,0.15,0.14,0.13,0.12,0.11,
0.10,0.09,0.08,0.07,0.06,0.05,0.04,0.03,0.02,0.01,0,
-0.50,-0.49,-0.48,-0.47,-0.46,-0.45,-0.44,-0.43,-0.42,-0.41,
-0.40,-0.39,-0.38,-0.37,-0.36,-0.35,-0.34,-0.33,-0.32,-0.31,
-0.30,-0.29,-0.28,-0.27,-0.26,-0.25,-0.24,-0.23,-0.22,-0.21,
-0.20,-0.19,-0.18,-0.17,-0.16,-0.15,-0.14,-0.13,-0.12,-0.11,
-0.10,-0.09,-0.08,-0.07,-0.06,-0.05,-0.04,-0.03,-0.02,-0.01
]
options_cash_req = [0.50,0.49,0.48,0.47,0.46,0.45,0.44,0.43,0.42,0.41,
0.40,0.39,0.38,0.37,0.36,0.35,0.34,0.33,0.32,0.31,
0.30,0.29,0.28,0.27,0.26,0.25,0.24,0.23,0.22,0.21,
0.20,0.19,0.18,0.17,0.16,0.15,0.14,0.13,0.12,0.11,
0.10,0.09,0.08,0.07,0.06,0.05,0.04,0.03,0.02,0.01,0
]
因此,组合数学的规则如下:
- 对于每种市场状态,尝试从高到低的现金需求
- 首先,如果语句是0.50,则下一个语句只能是0.5-0
- 其次,如果语句是0.45,则下一个语句只能是0.45-0
提前感谢任何花时间阅读帖子并发布一些文档链接或建议的人。