MCPcopy Create free account
hub / github.com/alpha2phi/python-apps / get_benchmark

Function get_benchmark

copilot-labs/bollinger_bands.py:180–195  ·  view source on GitHub ↗
(stock_prices, start_date, investment_value)

Source from the content-addressed store, hash-verified

178print(cl('Profit percentage of the BB strategy : {}%'.format(profit_percentage), attrs = ['bold']))
179
180def get_benchmark(stock_prices, start_date, investment_value):
181 spy = get_historic_data('SPY')
182 spy = spy.set_index('date')
183 spy = spy[spy.index >= start_date]['close']
184 benchmark = pd.DataFrame(np.diff(spy)).rename(columns = {0:'benchmark_returns'})
185
186 investment_value = investment_value
187 number_of_stocks = math.floor(investment_value/stock_prices[-1])
188 benchmark_investment_ret = []
189
190 for i in range(len(benchmark['benchmark_returns'])):
191 returns = number_of_stocks*benchmark['benchmark_returns'][i]
192 benchmark_investment_ret.append(returns)
193
194 benchmark_investment_ret_df = pd.DataFrame(benchmark_investment_ret).rename(columns = {0:'investment_returns'})
195 return benchmark_investment_ret_df
196
197benchmark = get_benchmark(tsla['close'], '2020-01-01', 100000)
198

Callers 1

bollinger_bands.pyFile · 0.85

Calls 1

get_historic_dataFunction · 0.85

Tested by

no test coverage detected