(stock_prices, start_date, investment_value)
| 178 | print(cl('Profit percentage of the BB strategy : {}%'.format(profit_percentage), attrs = ['bold'])) |
| 179 | |
| 180 | def 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 | |
| 197 | benchmark = get_benchmark(tsla['close'], '2020-01-01', 100000) |
| 198 |
no test coverage detected