-
Notifications
You must be signed in to change notification settings - Fork 16
/
futures_research_class.html
157 lines (133 loc) · 14.7 KB
/
futures_research_class.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module futures_research_class</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head><body bgcolor="#f0f0f8">
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong>futures_research_class</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/jirong/Desktop/github/trend_following/futures_research_class.py">/home/jirong/Desktop/github/trend_following/futures_research_class.py</a></font></td></tr></table>
<p><tt>Created on Tue Dec 15 23:57:07 2020<br>
<br>
@author: jirong</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="datetime.html">datetime</a><br>
<a href="empyrical.html">empyrical</a><br>
<a href="json.html">json</a><br>
<a href="multiprocessing.html">multiprocessing</a><br>
</td><td width="25%" valign=top><a href="numpy.html">numpy</a><br>
<a href="os.html">os</a><br>
<a href="pandas.html">pandas</a><br>
<a href="pyfolio.html">pyfolio</a><br>
</td><td width="25%" valign=top><a href="matplotlib.pyplot.html">matplotlib.pyplot</a><br>
<a href="quandl.html">quandl</a><br>
<a href="random.html">random</a><br>
<a href="statsmodels.api.html">statsmodels.api</a><br>
</td><td width="25%" valign=top><a href="time.html">time</a><br>
<a href="util_futures.html">util_futures</a><br>
<a href="util.html">util</a><br>
<a href="yfinance.html">yfinance</a><br>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
<tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="builtins.html#object">builtins.object</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="futures_research_class.html#FuturesResearch">FuturesResearch</a>
</font></dt></dl>
</dd>
</dl>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="FuturesResearch">class <strong>FuturesResearch</strong></a>(<a href="builtins.html#object">builtins.object</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt><a href="#FuturesResearch">FuturesResearch</a>(data_path, ewmac_variations, breakout_variations, optimize_weights_path, forecast_diff_before_rebal, notion_capital_per_position, fix_capital, commission, boostrap_sample_size, num_samples_per_period, prop_block_boostrap, max_annual_volatility, ind_instr_ref_volatility)<br>
<br>
<br> </tt></td></tr>
<tr><td> </td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="FuturesResearch-TSMOM_all_instr_returns"><strong>TSMOM_all_instr_returns</strong></a>(self)</dt><dd><tt>Obtain TSMOM returns for all instrument based on 40% realized volatility for each single instrument</tt></dd></dl>
<dl><dt><a name="FuturesResearch-TSMOM_single_instr_monthly_returns"><strong>TSMOM_single_instr_monthly_returns</strong></a>(self, ret, lookback=12, cost=0.012)</dt><dd><tt>Obtain TSMOM returns for each single instrument based on 40% realized volatility</tt></dd></dl>
<dl><dt><a name="FuturesResearch-__init__"><strong>__init__</strong></a>(self, data_path, ewmac_variations, breakout_variations, optimize_weights_path, forecast_diff_before_rebal, notion_capital_per_position, fix_capital, commission, boostrap_sample_size, num_samples_per_period, prop_block_boostrap, max_annual_volatility, ind_instr_ref_volatility)</dt><dd><tt>Constructor for <a href="#FuturesResearch">FuturesResearch</a> class<br>
<br>
:param data_path: path to data file (e.g. "./trend_following/quantopian_data/futures_incl_2016.csv")<br>
:param ewmac_varations: list of ewmac variations (e.g. [8,16,32,64])<br>
:param breakout_variations: list of breakout variations (e.g. [40,80,160,320])<br>
:param optimize_weights_path: path to storing weights in a folder ('./research/optimize_weights') <br>
:param forecast_diff_before_rebal: Forecast difference before rebalancing an instrument position in a forecast range of -20 to +20 (e.g. 6.0)<br>
:param notion_capital_per_position (e.g 20000) (parameter used in study)<br>
:param fix_capital: (e.g 500000) (parameter not used in study)<br>
:param commission = 20,<br>
:param bootsrap_sample_size: Minimum sample size in each boostrap (e.g. 300)<br>
:param num_samples_per_period: Number of sample extracted from a period (e.g. 25)<br>
:param prop_block_boostrap: Proportion of data extracted in each bootstrap sample (e.g. 0.25)<br>
:param max_annual_volatility: Maximum portfolio realized volatility allowed (e.g. 0.15) <br>
:param ind_instr_ref_volatility: Referenced volatility level for each instrument (e.g. 0.4)<br>
:return: returns FutureResearch class</tt></dd></dl>
<dl><dt><a name="FuturesResearch-avg_optimized_sharpe_allinstr_single_period"><strong>avg_optimized_sharpe_allinstr_single_period</strong></a>(self, period)</dt><dd><tt>Parallelize optimization of sharpe across instruments in a period <br>
:param period: Indexes referenced to a dictionary with reference to period which bootstrap indexes are extracted</tt></dd></dl>
<dl><dt><a name="FuturesResearch-compute_neg_sharpe"><strong>compute_neg_sharpe</strong></a>(self, allocs_wts_forecasts, adj_forecast_single_instrument, price_series, ind_vol_target=0.4)</dt><dd><tt>Compute sharpe in each bootstrap optimization <br>
:param allocs_wts_forecasts: np.array weights applied to returns from individual forecasts.<br>
:param adj_forecast_single_instrument: Normalized forecast time series for each instrument<br>
:param price_series: Price series of instrument<br>
:param ind_vol_target: Reference individual volatility target level (e.g. 0.4)</tt></dd></dl>
<dl><dt><a name="FuturesResearch-compute_optimal_leverage_all_instruments"><strong>compute_optimal_leverage_all_instruments</strong></a>(self)</dt><dd><tt>Obtain optimal leverage scaled to portfolio target and individual forecasts</tt></dd></dl>
<dl><dt><a name="FuturesResearch-create_dictionary_window_n_bootstrap_index"><strong>create_dictionary_window_n_bootstrap_index</strong></a>(self, read_pickle=False)</dt><dd><tt>Method for creating dictionar of window and bootstrap indexes.</tt></dd></dl>
<dl><dt><a name="FuturesResearch-create_window_index"><strong>create_window_index</strong></a>(self, df, window='expanding', days_block=252)</dt><dd><tt>Method for creating window index<br>
<br>
:param df: Data-frame<br>
:param window: expanding or sliding<br>
:param days_block: testing block size which is also used to create multiple of training block size<br>
:return: returns list of training and testing indexes</tt></dd></dl>
<dl><dt><a name="FuturesResearch-extract_boostrap_periods"><strong>extract_boostrap_periods</strong></a>(self, df, num_samples=10, start_sample_index=0, end_sample_index=None, sample_size=300, prop_block_boostrap=0.25)</dt><dd><tt>Function for selecting period<br>
<br>
:param df: Data-frame<br>
:param num_samples: Number of block samples<br>
:param start_sample_index: Start of sample index <br>
:param end_sample_index: End of sample index <br>
:param sample_size: Minimum sample size length <br>
:param prop_block_boostrap: Proportion of data used in each sample <br>
:return: returns dictionary of start and end indexes</tt></dd></dl>
<dl><dt><a name="FuturesResearch-get_all_commod_returns"><strong>get_all_commod_returns</strong></a>(self)</dt><dd><tt>Obtain returns for all instruments based on optimal leverage scaled to portfolio target and individual forecasts</tt></dd></dl>
<dl><dt><a name="FuturesResearch-get_all_opt_weights"><strong>get_all_opt_weights</strong></a>(self, path='research/optimize_weights/')</dt><dd><tt>Obtain optimized weight for all files produced by method avg_optimized_sharpe_allinstr_single_period</tt></dd></dl>
<dl><dt><a name="FuturesResearch-get_combined_forecasts_all_instr"><strong>get_combined_forecasts_all_instr</strong></a>(self, allocs_wts_forecasts=None)</dt><dd><tt>Obtain combined forecasts for all instruments<br>
:param allocs_wts_forecasts: np.array forecast weights. If none, equal weights are assigned to each forecast rule</tt></dd></dl>
<dl><dt><a name="FuturesResearch-get_combined_forecasts_single_instr"><strong>get_combined_forecasts_single_instr</strong></a>(self, commod, allocs_wts_forecasts=None)</dt><dd><tt>Obtain combined forecasts for single instrument<br>
:param commod: Commodity symbol<br>
:param allocs_wts_forecasts: np.array forecast weights. If none, equal weights are assigned to each forecast rule</tt></dd></dl>
<dl><dt><a name="FuturesResearch-get_commod_returns"><strong>get_commod_returns</strong></a>(self, commod)</dt><dd><tt>Obtain returns for instrument based on optimal leverage scaled to portfolio target and individual forecasts</tt></dd></dl>
<dl><dt><a name="FuturesResearch-get_norm_breakout_info"><strong>get_norm_breakout_info</strong></a>(self)</dt><dd><tt>Obtain normalized donchian channel forecasts scaled to a range of -20 to +20</tt></dd></dl>
<dl><dt><a name="FuturesResearch-get_norm_ewmac_info"><strong>get_norm_ewmac_info</strong></a>(self)</dt><dd><tt>Obtain normalized ewmac forecasts scaled to a range of -20 to +20</tt></dd></dl>
<dl><dt><a name="FuturesResearch-get_opt_weight_file"><strong>get_opt_weight_file</strong></a>(self, file_name, path='research/optimize_weights/')</dt><dd><tt>Obtain optimized weight for single file produced by method avg_optimized_sharpe_allinstr_single_period<br>
:param period: Indexes referenced to a dictionary with reference to period which bootstrap indexes are extracted</tt></dd></dl>
<dl><dt><a name="FuturesResearch-get_returns_data"><strong>get_returns_data</strong></a>(self)</dt><dd><tt>Obtain returns data from file; convert to price level that starts at 1</tt></dd></dl>
<dl><dt><a name="FuturesResearch-optimize_sharpe_single_instrument_period"><strong>optimize_sharpe_single_instrument_period</strong></a>(self, commod, period, bootstrap_index)</dt><dd><tt>Optimize sharpe in each bootstrap optimization and return dictionary of weights and performance. Optimize weight for each isntrument for each bootstrap sample saved as json file <br>
:param commod: Commodity symbol<br>
:param period: Indexes referenced to a dictionary with reference to period which bootstrap indexes are extracted<br>
:param boostrap_index: Indexes referenced to a dictionary with reference to bootstrap indexes referenced to self.<strong>price</strong> dataframe</tt></dd></dl>
<dl><dt><a name="FuturesResearch-select_period"><strong>select_period</strong></a>(self, df, start_date, end_date, index_date='date')</dt><dd><tt>Select period in self.<strong>price</strong> data frame based on starting, ending date or indexes. indexes used in study<br>
:param start_date: start date<br>
:param end_date: end date<br>
:param index_date: select by 'index' or 'date'</tt></dd></dl>
<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list of weak references to the object (if defined)</tt></dd>
</dl>
</td></tr></table></td></tr></table>
</body></html>